From 94cd0420a7876c87e063b4ed2acb73d9b91f97af Mon Sep 17 00:00:00 2001 From: FKHals <5229803-FKHals@users.noreply.gitlab.com> Date: Fri, 17 Mar 2023 16:23:32 +0100 Subject: [PATCH] Distinguish syscalls in pb-scheduler to prepare for using the pbm-model as the scheduling policy. --- kernel/exit.c | 10 ++++++++++ kernel/fork.c | 10 ++++++++++ kernel/sched/pb.c | 16 ++++++++++++++++ kernel/sched/sched.h | 3 +++ 4 files changed, 39 insertions(+) diff --git a/kernel/exit.c b/kernel/exit.c index c4d3a454dcda..de4261f61cca 100644 --- a/kernel/exit.c +++ b/kernel/exit.c @@ -69,6 +69,7 @@ #include <asm/mmu_context.h> #include "behave.h" +#include "sched/sched.h" static void __unhash_process(struct task_struct *p, bool group_dead) { @@ -767,6 +768,15 @@ void __noreturn do_exit(long code) struct task_struct *tsk = current; int group_dead; + struct rq* rq; + + rq = this_rq(); + // prevent syscalls from outside of the measured program (e.g. admin tasks) to be recognized + if (PB_EXEC_MODE == rq->pb.mode) { + // set flag so that the pb-scheduler knows which syscall triggered the scheduling + rq->pb.triggering_syscall = sched_trig_EXIT; + } + // call the readout before the process is terminated if (is_relevant_process(tsk)) { pbm_exit(tsk->pid, tsk->real_parent->pid); diff --git a/kernel/fork.c b/kernel/fork.c index b3ec7595bd1c..812c9cbc1c41 100644 --- a/kernel/fork.c +++ b/kernel/fork.c @@ -102,6 +102,7 @@ #include <trace/events/task.h> #include "behave.h" +#include "sched/sched.h" /* * Minimum number of threads to boot the kernel @@ -2016,10 +2017,19 @@ long _do_fork(unsigned long clone_flags, int trace = 0; long nr; + struct rq* rq; + pbm_NODE* fork_date; pid_t parent_pid = current->pid; fork_date = NULL; + rq = this_rq(); + // prevent syscalls from outside of the measured program (e.g. admin tasks) to be recognized + if (PB_EXEC_MODE == rq->pb.mode) { + // set flag so that the pb-scheduler knows which syscall triggered the scheduling + rq->pb.triggering_syscall = sched_trig_FORK; + } + // FIXME: This will not get called for mpirun since then bash will be the parent here if (is_relevant_process(current)) { printk(KERN_EMERG "DO FORK CALLED by: '%s' %u\n", current->comm ,parent_pid); diff --git a/kernel/sched/pb.c b/kernel/sched/pb.c index f01375d73a0b..39748bde8531 100644 --- a/kernel/sched/pb.c +++ b/kernel/sched/pb.c @@ -283,6 +283,22 @@ static struct task_struct * pick_next_task_pb(struct rq *rq, // EXEC Mode is next, so we return our next task to be executed if (next_mode == PB_EXEC_MODE) { + + switch(pb->triggering_syscall) { + case sched_trig_FORK: + printk(KERN_WARNING "FORK TRIGGERED THIS!!!\n"); + break; + case sched_trig_EXIT: + printk(KERN_WARNING "EXIT TRIGGERED THIS!!!\n"); + break; + default: + printk(KERN_WARNING "OTHER STUFF TRIGGERED THIS!!!\n"); + break; + } + + // reset the flag so that the relevant syscalls can be detected if they are the trigger + pb->triggering_syscall = sched_trig_OTHER; + // printk(KERN_ALERT "DEBUG: Passed %s %d \n",__FUNCTION__,__LINE__); if(current_mode == PB_ADMIN_MODE) { printk(KERN_DEBUG "PB ADMIN,STOP,%u,%llu\n", pb->c_entry, sched_clock()); diff --git a/kernel/sched/sched.h b/kernel/sched/sched.h index f6d363a4c25a..876ef5b02926 100644 --- a/kernel/sched/sched.h +++ b/kernel/sched/sched.h @@ -546,6 +546,8 @@ struct pb_plan { size_t num_tasks; // number of tasks in the plan }; +enum sched_trigger_syscall { sched_trig_FORK, sched_trig_EXIT, sched_trig_OTHER }; + struct pb_rq { struct plan_entry *plan; // plan (used to be proxy_task) @@ -563,6 +565,7 @@ struct pb_rq u64 total_instr; // total counted instructions for current plan struct perf_event *pevent; // linux perf handle + enum sched_trigger_syscall triggering_syscall; // which syscall triggered the scheduler /* * flag determining whether the plan is completely initialized and should be run -- GitLab