From 5e18b3ba892c74fb54fae8121bf30ec6e78f04af Mon Sep 17 00:00:00 2001
From: FKHals <5229803-FKHals@users.noreply.gitlab.com>
Date: Tue, 26 Sep 2023 18:31:47 +0200
Subject: [PATCH] Fix premature error detection

which prevously did not check if a process was expected to do more tasks
than it did.
---
 kernel/exit.c     | 3 ---
 kernel/sched/pb.c | 7 +++++++
 2 files changed, 7 insertions(+), 3 deletions(-)

diff --git a/kernel/exit.c b/kernel/exit.c
index 08b0df2566ae..35b90b54afb7 100644
--- a/kernel/exit.c
+++ b/kernel/exit.c
@@ -791,9 +791,6 @@ void __noreturn do_exit(long code)
 		// inform the pb-scheduler knows which syscall triggered the scheduling
 		rq->pb.triggering_syscall.type = sched_trig_EXIT;
 		rq->pb.triggering_syscall.origin = current;
-
-		// inform the plan runtime state
-		plan_rt_state_incr_num_exited_procs();
 	}
 
 	// call the readout before the process is terminated
diff --git a/kernel/sched/pb.c b/kernel/sched/pb.c
index 6563a62e4d27..2b73632a2eef 100644
--- a/kernel/sched/pb.c
+++ b/kernel/sched/pb.c
@@ -239,6 +239,13 @@ static void dequeue_task_pb(struct rq *rq, struct task_struct *p, int flags)
 		// remove the exited process from the stack and run the next available
 		plan_rt_state_pop();
 		process_exited = true;
+
+        // only mark the process as exited if it is not expected to do more tasks
+        // (if it would still have child tasks it would be a premature exit)
+        if (cur_node && !cur_node->children) {
+            plan_rt_state_incr_num_exited_procs();
+        }
+
 		//terminate_perf_event(get_pevent_by_pid(prev_proc->pid));
 		plan_rt_state_debug_print();
 
-- 
GitLab