From 3be17e660d5e8e6461a708a22dd0cd3331bdb3f4 Mon Sep 17 00:00:00 2001 From: Pawel Wieczorkiewicz Date: Fri, 21 Jul 2023 13:02:44 +0200 Subject: [PATCH] sched: add execute_tasks() helper function The execute_tasks() helper is responsible for collectively unblocking all CPUs, calling run_tasks() on BSP CPU and waiting for all AP CPUs untile they are finished. In kernel_main the execute_tasks() is called before test_main() just in case. Currently there are no tasks scheduled before the test_main(). The execute_tasks() called after the test_main() makes sure all APs and the BSP get unblocked and their tasks executed or the states of the CPUs are set to finished. Signed-off-by: Pawel Wieczorkiewicz --- common/kernel.c | 8 ++++---- include/sched.h | 5 +++++ tests/test.c | 2 ++ 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/common/kernel.c b/common/kernel.c index e81675cc..3ab05eb6 100644 --- a/common/kernel.c +++ b/common/kernel.c @@ -51,13 +51,13 @@ void kernel_main(void) { display_multiboot_mmap(); } - test_main(NULL); - run_tasks(cpu); - unblock_all_cpus(); - wait_for_all_cpus(); + execute_tasks(); + test_main(NULL); printk("All tasks done.\n"); + execute_tasks(); + #ifdef KTF_PMU pfm_terminate(); #endif diff --git a/include/sched.h b/include/sched.h index d40af72e..2e4af358 100644 --- a/include/sched.h +++ b/include/sched.h @@ -105,4 +105,9 @@ static inline task_t *new_user_task(const char *name, task_func_t func, void *ar return new_task(name, func, arg, TASK_TYPE_USER); } +static inline void execute_tasks(void) { + unblock_all_cpus(); + run_tasks(get_bsp_cpu()); + wait_for_all_cpus(); +} #endif /* KTF_SCHED_H */ diff --git a/tests/test.c b/tests/test.c index 31295511..90ac8d9f 100644 --- a/tests/test.c +++ b/tests/test.c @@ -71,6 +71,8 @@ unsigned long test_main(void *unused) { printk("Running test: %s\n", name); rc = fn(NULL); + execute_tasks(); + printk("Test %s returned: 0x%x\n", name, rc); n++; }