Skip to content
This repository has been archived by the owner on May 31, 2021. It is now read-only.

Commit

Permalink
Let other APs sleep until there's something to schedule
Browse files Browse the repository at this point in the history
  • Loading branch information
klange committed May 27, 2021
1 parent d52bc94 commit 1e464d1
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 0 deletions.
1 change: 1 addition & 0 deletions base/usr/include/kernel/process.h
Original file line number Diff line number Diff line change
Expand Up @@ -216,4 +216,5 @@ extern void arch_set_kernel_stack(uintptr_t);
extern void arch_enter_user(uintptr_t entrypoint, int argc, char * argv[], char * envp[], uintptr_t stack);
__attribute__((noreturn))
extern void arch_enter_signal_handler(uintptr_t,int);
extern void arch_wakeup_others(void);

9 changes: 9 additions & 0 deletions kernel/arch/x86_64/acpi.c
Original file line number Diff line number Diff line change
Expand Up @@ -282,3 +282,12 @@ void acpi_initialize(void) {
}
}

void arch_wakeup_others(void) {
/* Never wake up BSP, don't hit ourselves, easy. */
for (int i = 1; i < processor_count; ++i) {
if (i == this_core->cpu_id) continue;
if (processor_local_data[i].current_process == processor_local_data[i].kernel_idle_task) {
lapic_send_ipi(processor_local_data[i].lapic_id, 0x407E);
}
}
}
4 changes: 4 additions & 0 deletions kernel/sys/process.c
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,7 @@ static void _kidle(void) {

static void _kburn(void) {
while (1) {
arch_pause();
if (((volatile list_t *)process_queue)->head) switch_next();
}
}
Expand Down Expand Up @@ -558,6 +559,8 @@ void make_process_ready(volatile process_t * proc) {
spin_lock(process_queue_lock);
list_append(process_queue, (node_t*)&proc->sched_node);
spin_unlock(process_queue_lock);

arch_wakeup_others();
}

/**
Expand Down Expand Up @@ -866,6 +869,7 @@ int waitpid(int pid, int * status, int options) {
}
int pid = candidate->id;
if (candidate->flags & PROC_FLAG_FINISHED) {
while (*((volatile int *)&candidate->flags) & PROC_FLAG_RUNNING);
process_delete((process_t*)candidate);
}
return pid;
Expand Down

0 comments on commit 1e464d1

Please sign in to comment.