Simplify reschedule points, mail works now!
All checks were successful
Build documentation / build-and-deploy (push) Successful in 2m55s

This commit is contained in:
2026-02-19 18:25:47 +01:00
parent a1730dfdc2
commit 4472ad5bb3
13 changed files with 45 additions and 143 deletions

View File

@@ -54,7 +54,7 @@ void bootmain (void) {
vfs_init ();
struct device* ramdisk_device = device_find (RAMDISK_DEVICE);
struct reschedule_ctx rctx = {.entries = NULL, .lock = SPIN_LOCK_INIT};
struct reschedule_ctx rctx = {.cpu = thiscpu, .reschedule = false};
int ret = vfs_create_mountpoint ("ramdisk", VFS_TARFS, ramdisk_device, NULL, &rctx);
if (ret < 0) {

View File

@@ -26,13 +26,9 @@ static bool amd64_debug_serial_tx_empty (void) {
/* Write a single character to serial */
static void amd64_debug_serial_write (char x) {
spin_lock (&serial_lock);
while (!amd64_debug_serial_tx_empty ())
;
amd64_io_outb (PORT_COM1, (uint8_t)x);
spin_unlock (&serial_lock);
}
/*
@@ -54,10 +50,14 @@ void debugprintf (const char* fmt, ...) {
const char* p = buffer;
spin_lock (&serial_lock);
while (*p) {
amd64_debug_serial_write (*p);
p++;
}
spin_unlock (&serial_lock);
}
/* Initialize serial */

View File

@@ -157,35 +157,13 @@ static void amd64_intr_exception (struct saved_regs* regs) {
regs->rbx);
if (regs->cs == (GDT_UCODE | 0x03)) {
struct reschedule_ctx rctx = {.entries = NULL, .lock = SPIN_LOCK_INIT};
struct reschedule_ctx rctx = {.reschedule = false, .cpu = NULL};
proc_kill (thiscpu->proc_current, &rctx);
bool reschedule_thiscpu = false;
spin_lock (&rctx.lock);
struct list_node_link *node, *tmp;
list_foreach (rctx.entries, node, tmp) {
struct reschedule_entry* entry = list_entry (node, struct reschedule_entry, link);
struct cpu* cpu = entry->cpu;
if (cpu != thiscpu) {
cpu_request_sched (cpu);
} else {
reschedule_thiscpu = true;
}
list_remove (rctx.entries, &entry->link);
free (entry);
}
spin_unlock (&rctx.lock);
if (reschedule_thiscpu) {
proc_sched ();
}
if (rctx.reschedule)
cpu_request_sched (rctx.cpu);
} else {
__asm__ volatile ("cli");
spin ();
}
}
@@ -215,33 +193,11 @@ void amd64_intr_handler (void* stack_ptr) {
if (irq == NULL)
return;
struct reschedule_ctx rctx = {.entries = NULL, .lock = SPIN_LOCK_INIT};
struct reschedule_ctx rctx = {.reschedule = false, .cpu = NULL};
irq->func (irq->arg, stack_ptr, &rctx);
bool reschedule_thiscpu = false;
spin_lock (&rctx.lock);
struct list_node_link *node, *tmp;
list_foreach (rctx.entries, node, tmp) {
struct reschedule_entry* entry = list_entry (node, struct reschedule_entry, link);
struct cpu* cpu = entry->cpu;
if (cpu != thiscpu) {
cpu_request_sched (cpu);
} else {
reschedule_thiscpu = true;
}
list_remove (rctx.entries, &entry->link);
free (entry);
}
spin_unlock (&rctx.lock);
if (reschedule_thiscpu) {
proc_sched ();
}
if (rctx.reschedule)
cpu_request_sched (rctx.cpu);
}
}

View File

@@ -37,7 +37,7 @@ uintptr_t amd64_syscall_dispatch (void* stack_ptr) {
return -ST_SYSCALL_NOT_FOUND;
}
struct reschedule_ctx rctx = {.entries = NULL, .lock = SPIN_LOCK_INIT};
struct reschedule_ctx rctx = {.reschedule = false, .cpu = NULL};
uintptr_t r =
func (caller, regs, &rctx, regs->rdi, regs->rsi, regs->rdx, regs->r10, regs->r8, regs->r9);
@@ -50,30 +50,8 @@ uintptr_t amd64_syscall_dispatch (void* stack_ptr) {
spin_unlock (&caller->lock);
}
bool reschedule_thiscpu = false;
spin_lock (&rctx.lock);
struct list_node_link *node, *tmp;
list_foreach (rctx.entries, node, tmp) {
struct reschedule_entry* entry = list_entry (node, struct reschedule_entry, link);
struct cpu* cpu = entry->cpu;
if (cpu != thiscpu) {
cpu_request_sched (cpu);
} else {
reschedule_thiscpu = true;
}
list_remove (rctx.entries, &entry->link);
free (entry);
}
spin_unlock (&rctx.lock);
if (reschedule_thiscpu) {
proc_sched ();
}
if (rctx.reschedule)
cpu_request_sched (rctx.cpu);
return r;
}