Implement waiting for process, CE add command cancelation, rctx many cpus
All checks were successful
Build documentation / build-and-deploy (push) Successful in 2m27s

This commit is contained in:
2026-03-01 22:59:04 +01:00
parent 858e55118b
commit 9043c4f9ec
18 changed files with 308 additions and 89 deletions

View File

@@ -37,6 +37,8 @@ void proc_mutexes_cleanup (struct proc* proc, struct reschedule_ctx* rctx) {
proc_mutex_unlock (proc, &resource->u.mutex, rctx);
}
spin_unlock (&resource->lock);
}
spin_unlock (&proc->procgroup->lock);

View File

@@ -198,10 +198,7 @@ void proc_register (struct proc* proc, struct cpu* register_cpu, struct reschedu
spin_unlock (&cpu->lock);
spin_unlock (&proc_tree_lock);
if (rctx != NULL) {
rctx->reschedule = true;
rctx->cpu = cpu;
}
rctx_insert_cpu (rctx, cpu);
}
/* caller holds cpu->lock */
@@ -225,11 +222,15 @@ static struct proc* proc_find_sched (struct cpu* cpu) {
struct proc* proc = list_entry (current, struct proc, cpu_run_q_link);
spin_lock (&proc->lock);
int state = proc->state;
spin_unlock (&proc->lock);
if (state == PROC_READY)
int state = proc->state;
if (state == PROC_READY) {
spin_unlock (&proc->lock);
return proc;
}
spin_unlock (&proc->lock);
current = current->next ? current->next : cpu->proc_run_q;
} while (current != start);
@@ -278,7 +279,7 @@ static void proc_reap (struct reschedule_ctx* rctx) {
void proc_sched (void) {
int s_cycles = atomic_fetch_add (&sched_cycles, 1);
struct reschedule_ctx rctx = {.reschedule = false, .cpu = NULL};
struct reschedule_ctx rctx = {0};
if (s_cycles % SCHED_REAP_FREQ == 0)
proc_reap (&rctx);
@@ -321,14 +322,24 @@ void proc_kill (struct proc* proc, struct reschedule_ctx* rctx) {
spin_unlock (&proc->lock);
spin_unlock (&cpu->lock);
rctx->reschedule = true;
rctx->cpu = cpu;
rctx_insert_cpu (rctx, cpu);
DEBUG ("killed PID %d\n", proc->pid);
}
void proc_wait_for (struct proc* proc, struct reschedule_ctx* rctx, struct proc* wait_proc) {
proc_sq_suspend (proc, &wait_proc->done_sq, NULL, rctx);
}
static void proc_irq_sched (void* arg, void* regs, struct reschedule_ctx* rctx) {
(void)arg, (void)regs;
#if defined(__x86_64__)
struct saved_regs* sr = regs;
if (sr->cs != (GDT_UCODE | 0x3))
return;
#endif
proc_sched ();
}
@@ -338,14 +349,14 @@ void proc_init (void) {
irq_attach (&proc_irq_sched, NULL, CPU_REQUEST_SCHED);
#endif
struct reschedule_ctx rctx = {.cpu = NULL, .reschedule = false};
struct reschedule_ctx rctx = {0};
struct proc* spin_proc = proc_from_file (VFS_KERNEL, "RD", "/spin", &rctx);
proc_register (spin_proc, thiscpu, NULL);
proc_register (spin_proc, thiscpu, &rctx);
struct proc* init = proc_from_file (VFS_KERNEL, "RD", "/init", &rctx);
init->procgroup->capabilities |= (PROC_CAP_TERMINAL | PROC_CAP_KB);
proc_register (init, thiscpu, NULL);
proc_register (init, thiscpu, &rctx);
spin_lock (&spin_proc->cpu->lock);
do_sched (spin_proc, &spin_proc->cpu->lock);

View File

@@ -47,6 +47,7 @@ struct proc {
void* mail_recv_buffer;
size_t mail_recv_size;
char cwv[VOLUME_MAX];
struct proc_suspension_q done_sq;
};
void proc_sched (void);
@@ -68,6 +69,8 @@ int proc_alloc_pid (void);
void proc_pid_alloc_init (void);
void proc_wait_for (struct proc* proc, struct reschedule_ctx* rctx, struct proc* wait_proc);
void proc_init (void);
#endif // _KERNEL_PROC_PROC_H

View File

@@ -6,8 +6,24 @@
#include <sys/smp.h>
struct reschedule_ctx {
bool reschedule;
struct cpu* cpu;
struct cpu* cpus[CPUS_MAX];
};
#define rctx_insert_cpu(rctx, cpu) \
do { \
bool __found = false; \
for (size_t __i = 0; __i < CPUS_MAX; __i++) { \
if ((rctx)->cpus[__i] == (cpu)) \
__found = true; \
} \
if (!__found) { \
for (size_t __i = 0; __i < CPUS_MAX; __i++) { \
if ((rctx)->cpus[__i] == NULL) { \
(rctx)->cpus[__i] = (cpu); \
break; \
} \
} \
} \
} while (0)
#endif // _KERNEL_PROC_RESCHEDULE_H

View File

@@ -15,7 +15,8 @@ void proc_sq_suspend (struct proc* proc, struct proc_suspension_q* sq, spin_lock
struct proc_sq_entry* sq_entry = malloc (sizeof (*sq_entry));
if (!sq_entry) {
spin_unlock (resource_lock);
if (resource_lock != NULL)
spin_unlock (resource_lock);
return;
}
@@ -26,7 +27,8 @@ void proc_sq_suspend (struct proc* proc, struct proc_suspension_q* sq, spin_lock
spin_lock (&proc->lock);
spin_lock (&sq->lock);
spin_unlock (resource_lock);
if (resource_lock != NULL)
spin_unlock (resource_lock);
proc->state = PROC_SUSPENDED;
@@ -48,8 +50,7 @@ void proc_sq_suspend (struct proc* proc, struct proc_suspension_q* sq, spin_lock
spin_unlock (&proc->lock);
spin_unlock (&cpu->lock);
rctx->reschedule = true;
rctx->cpu = cpu;
rctx_insert_cpu (rctx, cpu);
}
void proc_sq_resume (struct proc* proc, struct proc_sq_entry* sq_entry,
@@ -81,8 +82,7 @@ void proc_sq_resume (struct proc* proc, struct proc_sq_entry* sq_entry,
free (sq_entry);
rctx->reschedule = true;
rctx->cpu = cpu;
rctx_insert_cpu (rctx, cpu);
}
void proc_sqs_cleanup (struct proc* proc) {