From 185d388e62957871192a06472e3f6abf2b17d324 Mon Sep 17 00:00:00 2001 From: FKHals <5229803-FKHals@users.noreply.gitlab.com> Date: Mon, 6 Mar 2023 10:25:16 +0100 Subject: [PATCH] Disable preemption inside the PBM-functions since all of those operate on shared data structures and therefore are mostly critical sections. --- kernel/behave.c | 15 ++++----------- kernel/exit.c | 2 ++ kernel/fork.c | 4 ++++ 3 files changed, 10 insertions(+), 11 deletions(-) diff --git a/kernel/behave.c b/kernel/behave.c index 4936bc8d2c7e..ad9335c1f5b0 100644 --- a/kernel/behave.c +++ b/kernel/behave.c @@ -340,7 +340,6 @@ int pbm_task_start(PBM* pbm, uint8_t type, struct task_struct* proc) { /* Conclude the last task of the given PBM */ int pbm_task_end(PBM* pbm) { - unsigned long irq_flags; int read_error; struct perf_event *pevent; u64 perf_counter; @@ -379,11 +378,8 @@ int pbm_task_end(PBM* pbm) { pbm->last->count = perf_counter; } - // disable performance counter while preventing context switching - local_irq_save(irq_flags); perf_event_disable(pevent); perf_event_release_kernel(pevent); - local_irq_restore(irq_flags); pevent = NULL; printk(KERN_WARNING "TASK: %u | ...Counting stopped: %llu instr.\n", current->pid, perf_counter); @@ -449,8 +445,6 @@ int pbm_task_end(PBM* pbm) { * run (current == child) otherwise the perf counting will fail! */ int pbm_fork(struct task_struct* proc, pid_t parent_pid, pbm_NODE* fork_node) { - unsigned long irq_flags; - PBM* parent_pbm; PBM* child_pbm; @@ -459,13 +453,10 @@ int pbm_fork(struct task_struct* proc, pid_t parent_pid, pbm_NODE* fork_node) { * pbm_fork_parent_new_task() to not be called but pbm_fork() since the child is "mpirun" so we * put the initialization in here instead of into pbm_fork_parent_new_task(). */ - // avoid context switching during initialization by disabling interrupts - local_irq_save(irq_flags); if (!is_initialized) { pbm_init(); is_initialized = 1; } - local_irq_restore(irq_flags); child_pbm = get_pbm_by_pid(proc->pid); parent_pbm = get_pbm_by_pid(parent_pid); @@ -532,8 +523,10 @@ int pbm_fork(struct task_struct* proc, pid_t parent_pid, pbm_NODE* fork_node) { // only one before the join-operation) // * child_pbm->root != NULL: since the previously called pbm_task_start() should have // written to that - child_pbm->root->next_sib = fork_node->children; - fork_node->children = child_pbm->root; + if (fork_node) { + child_pbm->root->next_sib = fork_node->children; + fork_node->children = child_pbm->root; + } return 1; } diff --git a/kernel/exit.c b/kernel/exit.c index c86736ac91d5..1db6b15cf9dc 100644 --- a/kernel/exit.c +++ b/kernel/exit.c @@ -767,6 +767,7 @@ void __noreturn do_exit(long code) struct task_struct *tsk = current; int group_dead; + preempt_disable(); // call the readout before the process is terminated if (is_relevant_process(tsk)) { pbm_exit(tsk->pid, tsk->real_parent->pid); @@ -775,6 +776,7 @@ void __noreturn do_exit(long code) pbm_join_and_print_graph_self(tsk->pid); } printk(KERN_EMERG "EXIT: %u, CMD: '%s', PARENT-CMD: '%s', PTR: %llu\n", tsk->pid, tsk->comm, tsk->real_parent->comm, (u64)tsk); + preempt_enable(); TASKS_RCU(int tasks_rcu_i); diff --git a/kernel/fork.c b/kernel/fork.c index b863c1dcb940..e0fbef1bcab2 100644 --- a/kernel/fork.c +++ b/kernel/fork.c @@ -2021,10 +2021,12 @@ long _do_fork(unsigned long clone_flags, fork_date = NULL; // FIXME: This will not get called for mpirun since then bash will be the parent here + preempt_disable(); if (is_relevant_process(current)) { printk(KERN_EMERG "DO FORK CALLED by: '%s' %u\n", current->comm ,parent_pid); fork_date = pbm_fork_parent_new_task(current); } + preempt_enable(); /* * Determine whether and which event to report to ptracer. When @@ -2084,12 +2086,14 @@ long _do_fork(unsigned long clone_flags, // FIXME: The problem is that at this stage we can not identify the MPIrun process since // the p->comm is not up to date yet so we simply record all bash childs which is // rather wasteful! + preempt_disable(); if (is_relevant_process(p) || (strcmp(p->comm, "bash") == 0)) { // At this point p->comm is not up to date but shows the command of the parent! printk(KERN_EMERG "FORKED!!!!: %u, Parent: %s, Super-Parent:%s\n", p->pid, p->comm, p->real_parent->real_parent->comm); pbm_fork(p, parent_pid, fork_date); } + preempt_enable(); } else { nr = PTR_ERR(p); } -- GitLab