Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
sched: add simple CPU task execution synchronization barrier
Browse files Browse the repository at this point in the history
All AP CPUs after empting their task_queue get into blocked state, which
makes run_tasks() wait on them until they get unblocked. The BSP is
never waited on as it is supposed to unblock the AP CPUs.
After an unblock, run_tasks() sets the CPU into unfinished state, before
executing any tasks from the task_queue.

That way BSP controls when all APs start executing their tasks and when
they are finished with it.

Signed-off-by: Pawel Wieczorkiewicz <wipawel@grsecurity.net>
wipawel committed Jul 21, 2023
1 parent 21ed829 commit 8e8bbe1
Showing 2 changed files with 6 additions and 4 deletions.
6 changes: 5 additions & 1 deletion common/sched.c
Original file line number Diff line number Diff line change
@@ -217,7 +217,9 @@ void wait_for_task_group(const cpu_t *cpu, task_group_t group) {
void run_tasks(cpu_t *cpu) {
task_t *task, *safe;

wait_cpu_unblocked(cpu);
if (!cpu->bsp)
wait_cpu_unblocked(cpu);
set_cpu_unfinished(cpu);

do {
list_for_each_entry_safe (task, safe, &cpu->task_queue, list) {
@@ -238,5 +240,7 @@ void run_tasks(cpu_t *cpu) {
}
} while (!list_is_empty(&cpu->task_queue));

if (!cpu->bsp)
set_cpu_blocked(cpu);
set_cpu_finished(cpu);
}
4 changes: 1 addition & 3 deletions smp/smp.c
Original file line number Diff line number Diff line change
@@ -64,10 +64,8 @@ void __noreturn ap_startup(void) {
if (opt_fpu)
enable_fpu();

run_tasks(cpu);

while (true)
halt();
run_tasks(cpu);

UNREACHABLE();
}

0 comments on commit 8e8bbe1

Please sign in to comment.