Redesign reschedule points, allow one operation to reschedule many cpus at once
All checks were successful
Build documentation / build-and-deploy (push) Successful in 2m12s

This commit is contained in:
2026-02-18 23:16:03 +01:00
parent ae0a6024da
commit f103bdd739
39 changed files with 376 additions and 223 deletions

View File

@@ -15,6 +15,7 @@
#include <proc/capability.h>
#include <proc/proc.h>
#include <proc/procgroup.h>
#include <proc/reschedule.h>
#include <proc/resource.h>
#include <sync/spin_lock.h>
#include <sys/debug.h>
@@ -160,8 +161,8 @@ struct proc* proc_find_pid (int pid) {
return proc;
}
bool proc_register (struct proc* proc, struct cpu** reschedule_cpu) {
struct cpu* cpu = *reschedule_cpu != NULL ? *reschedule_cpu : cpu_find_lightest ();
void proc_register (struct proc* proc, struct cpu* register_cpu, struct reschedule_ctx* rctx) {
struct cpu* cpu = register_cpu != NULL ? register_cpu : cpu_find_lightest ();
spin_lock (&proc_tree_lock);
spin_lock (&cpu->lock);
@@ -180,9 +181,8 @@ bool proc_register (struct proc* proc, struct cpu** reschedule_cpu) {
spin_unlock (&cpu->lock);
spin_unlock (&proc_tree_lock);
*reschedule_cpu = cpu;
return PROC_NEED_RESCHEDULE;
if (rctx != NULL)
reschedule_list_append (rctx, cpu);
}
/* caller holds cpu->lock */
@@ -214,7 +214,7 @@ static struct proc* proc_find_sched (struct cpu* cpu) {
return NULL;
}
static void proc_reap (void) {
static void proc_reap (struct reschedule_ctx* rctx) {
struct proc* proc = NULL;
struct list_node_link* reap_list = NULL;
@@ -246,15 +246,16 @@ static void proc_reap (void) {
list_remove (reap_list, &proc->reap_link);
DEBUG ("cleanup PID %d\n", proc->pid);
proc_cleanup (proc);
proc_cleanup (proc, rctx);
}
}
void proc_sched (void) {
int s_cycles = atomic_fetch_add (&sched_cycles, 1);
struct reschedule_ctx rctx = {.entries = NULL, .lock = SPIN_LOCK_INIT};
if (s_cycles % SCHED_REAP_FREQ == 0)
proc_reap ();
proc_reap (&rctx);
struct proc* next = NULL;
struct cpu* cpu = thiscpu;
@@ -275,7 +276,7 @@ void proc_sched (void) {
}
}
bool proc_kill (struct proc* proc, struct cpu** reschedule_cpu) {
void proc_kill (struct proc* proc, struct reschedule_ctx* rctx) {
spin_lock (&proc->lock);
struct cpu* cpu = proc->cpu;
spin_unlock (&proc->lock);
@@ -294,17 +295,14 @@ bool proc_kill (struct proc* proc, struct cpu** reschedule_cpu) {
spin_unlock (&proc->lock);
spin_unlock (&cpu->lock);
reschedule_list_append (rctx, cpu);
DEBUG ("killed PID %d\n", proc->pid);
*reschedule_cpu = cpu;
return PROC_NEED_RESCHEDULE;
}
static bool proc_irq_sched (struct cpu** reschedule_cpu, void* arg, void* regs) {
(void)arg, (void)regs, (void)reschedule_cpu;
static void proc_irq_sched (void* arg, void* regs, struct reschedule_ctx* rctx) {
(void)arg, (void)regs;
proc_sched ();
return PROC_NO_RESCHEDULE;
}
void proc_init (void) {
@@ -314,13 +312,11 @@ void proc_init (void) {
#endif
struct proc* spin_proc = proc_from_file (NULL, "ramdisk", "/spin");
struct cpu* spin_cpu = thiscpu;
proc_register (spin_proc, &spin_cpu);
proc_register (spin_proc, thiscpu, NULL);
struct proc* init = proc_from_file (NULL, "ramdisk", "/init");
init->procgroup->capabilities |= (PROC_CAP_TERMINAL | PROC_CAP_KB);
struct cpu* init_cpu = thiscpu;
proc_register (init, &init_cpu);
proc_register (init, thiscpu, NULL);
spin_lock (&spin_proc->cpu->lock);
do_sched (spin_proc, &spin_proc->cpu->lock);