Make cpu->proc_run_q_count not atomic

This commit is contained in:
2026-02-22 14:03:51 +01:00
parent 85872b856b
commit e69606668d
4 changed files with 16 additions and 7 deletions

View File

@@ -58,13 +58,22 @@ struct cpu* cpu_find_lightest (void) {
struct limine_mp_response* mp = limine_mp_request.response; struct limine_mp_response* mp = limine_mp_request.response;
int start = atomic_fetch_add (&last_cpu_index, 1) % mp->cpu_count; int start = atomic_fetch_add (&last_cpu_index, 1) % mp->cpu_count;
struct cpu* best_cpu = &cpus[start]; struct cpu* best_cpu = &cpus[start];
int best_load = atomic_load (&best_cpu->proc_run_q_count);
spin_lock (&best_cpu->lock);
int best_load = best_cpu->proc_run_q_count;
spin_unlock (&best_cpu->lock);
for (int i = 1; i < (int)mp->cpu_count; i++) { for (int i = 1; i < (int)mp->cpu_count; i++) {
int idx = (start + i) % mp->cpu_count; int idx = (start + i) % mp->cpu_count;
struct cpu* cpu = &cpus[idx]; struct cpu* cpu = &cpus[idx];
int l = atomic_load (&cpu->proc_run_q_count);
spin_lock (&cpu->lock);
int l = cpu->proc_run_q_count;
spin_unlock (&cpu->lock);
if (l < best_load) { if (l < best_load) {
best_load = l; best_load = l;
best_cpu = cpu; best_cpu = cpu;

View File

@@ -32,7 +32,7 @@ struct cpu {
struct list_node_link* proc_run_q; struct list_node_link* proc_run_q;
struct proc* proc_current; struct proc* proc_current;
atomic_int proc_run_q_count; int proc_run_q_count;
}; };
struct cpu* cpu_make (uint64_t lapic_id, uint64_t acpi_id); struct cpu* cpu_make (uint64_t lapic_id, uint64_t acpi_id);

View File

@@ -198,7 +198,7 @@ void proc_register (struct proc* proc, struct cpu* register_cpu, struct reschedu
rbtree_insert (struct proc, &proc_tree, &proc->proc_tree_link, proc_tree_link, pid); rbtree_insert (struct proc, &proc_tree, &proc->proc_tree_link, proc_tree_link, pid);
atomic_fetch_add (&cpu->proc_run_q_count, 1); cpu->proc_run_q_count++;
list_append (cpu->proc_run_q, &proc->cpu_run_q_link); list_append (cpu->proc_run_q, &proc->cpu_run_q_link);
if (cpu->proc_current == NULL) if (cpu->proc_current == NULL)
cpu->proc_current = proc; cpu->proc_current = proc;
@@ -315,7 +315,7 @@ void proc_kill (struct proc* proc, struct reschedule_ctx* rctx) {
proc->cpu = NULL; proc->cpu = NULL;
list_remove (cpu->proc_run_q, &proc->cpu_run_q_link); list_remove (cpu->proc_run_q, &proc->cpu_run_q_link);
atomic_fetch_sub (&cpu->proc_run_q_count, 1); cpu->proc_run_q_count--;
if (cpu->proc_current == proc) if (cpu->proc_current == proc)
cpu->proc_current = NULL; cpu->proc_current = NULL;

View File

@@ -37,7 +37,7 @@ void proc_sq_suspend (struct proc* proc, struct proc_suspension_q* sq, spin_lock
list_append (proc->sq_entries, &sq_entry->proc_link); list_append (proc->sq_entries, &sq_entry->proc_link);
list_remove (cpu->proc_run_q, &proc->cpu_run_q_link); list_remove (cpu->proc_run_q, &proc->cpu_run_q_link);
atomic_fetch_sub (&cpu->proc_run_q_count, 1); cpu->proc_run_q_count--;
if (cpu->proc_current == proc) if (cpu->proc_current == proc)
cpu->proc_current = NULL; cpu->proc_current = NULL;
@@ -73,7 +73,7 @@ void proc_sq_resume (struct proc* proc, struct proc_sq_entry* sq_entry,
atomic_store (&proc->state, PROC_READY); atomic_store (&proc->state, PROC_READY);
list_append (cpu->proc_run_q, &proc->cpu_run_q_link); list_append (cpu->proc_run_q, &proc->cpu_run_q_link);
atomic_fetch_add (&cpu->proc_run_q_count, 1); cpu->proc_run_q_count++;
spin_unlock (&sq->lock); spin_unlock (&sq->lock);
spin_unlock (&proc->lock); spin_unlock (&proc->lock);