From 0f320c8f07a4fda12b24349bc25db4d4694acadc Mon Sep 17 00:00:00 2001 From: kamkow1 Date: Wed, 18 Mar 2026 23:18:06 +0100 Subject: [PATCH] Simplified RR, cleanup stream function params --- kernel/amd64/intr.c | 26 +++++++++++++------------- kernel/proc/proc.c | 23 +++++++---------------- kernel/proc/stream.c | 6 ++---- kernel/proc/stream.h | 6 ++---- kernel/syscall/syscall.c | 4 ++-- sdutil/sdutil.c | 9 +++------ 6 files changed, 29 insertions(+), 45 deletions(-) diff --git a/kernel/amd64/intr.c b/kernel/amd64/intr.c index c16d3a9..8686c2a 100644 --- a/kernel/amd64/intr.c +++ b/kernel/amd64/intr.c @@ -140,25 +140,25 @@ static void idt_init (void) { /* Handle CPU exception and dump registers. If incoming CS has CPL3, kill the process. */ static void intr_exception (struct saved_regs* regs) { - DEBUG_NOLOCK ("cpu exception %lu (%lu)\n", regs->trap, regs->error); + DEBUG ("cpu exception %lu (%lu)\n", regs->trap, regs->error); uint64_t cr2; __asm__ volatile ("movq %%cr2, %0" : "=r"(cr2)); uint64_t cr3; __asm__ volatile ("movq %%cr3, %0" : "=r"(cr3)); - debugprintf_nolock ("r15=%016lx r14=%016lx r13=%016lx\n" - "r12=%016lx r11=%016lx r10=%016lx\n" - "r9 =%016lx r8 =%016lx rbp=%016lx\n" - "rdi=%016lx rsi=%016lx rdx=%016lx\n" - "rcx=%016lx rax=%016lx trp=%016lx\n" - "err=%016lx rip=%016lx cs =%016lx\n" - "rfl=%016lx rsp=%016lx ss =%016lx\n" - "cr2=%016lx cr3=%016lx rbx=%016lx\n", - regs->r15, regs->r14, regs->r13, regs->r12, regs->r11, regs->r10, regs->r9, - regs->r8, regs->rbp, regs->rdi, regs->rsi, regs->rdx, regs->rcx, regs->rax, - regs->trap, regs->error, regs->rip, regs->cs, regs->rflags, regs->rsp, - regs->ss, cr2, cr3, regs->rbx); + debugprintf ("r15=%016lx r14=%016lx r13=%016lx\n" + "r12=%016lx r11=%016lx r10=%016lx\n" + "r9 =%016lx r8 =%016lx rbp=%016lx\n" + "rdi=%016lx rsi=%016lx rdx=%016lx\n" + "rcx=%016lx rax=%016lx trp=%016lx\n" + "err=%016lx rip=%016lx cs =%016lx\n" + "rfl=%016lx rsp=%016lx ss =%016lx\n" + "cr2=%016lx cr3=%016lx rbx=%016lx\n", + regs->r15, regs->r14, regs->r13, regs->r12, regs->r11, regs->r10, regs->r9, regs->r8, + regs->rbp, regs->rdi, regs->rsi, regs->rdx, regs->rcx, regs->rax, regs->trap, + regs->error, regs->rip, regs->cs, regs->rflags, regs->rsp, regs->ss, cr2, cr3, + regs->rbx); if (regs->cs == (GDT_UCODE | 0x03)) { struct reschedule_ctx rctx; diff --git a/kernel/proc/proc.c b/kernel/proc/proc.c index f4950ff..a5b9b8a 100644 --- a/kernel/proc/proc.c +++ b/kernel/proc/proc.c @@ -49,6 +49,7 @@ struct proc* kproc_create (void) { kproc->lock = SPIN_LOCK_INIT; kproc->flags |= PROC_KPROC; + kproc->state = PROC_READY; kproc->pid = proc_alloc_pid (); kproc->procgroup = procgroup_create (); @@ -58,7 +59,7 @@ struct proc* kproc_create (void) { struct reschedule_ctx rctx; memset (&rctx, 0, sizeof (rctx)); - proc_register (kproc, NULL, &rctx); + proc_register (kproc, thiscpu, &rctx); return kproc; } @@ -228,24 +229,19 @@ void proc_register_partial (struct proc* proc) { static struct proc* proc_find_sched (struct cpu* cpu) { uint64_t fp; + struct list_node_link *current, *start; + if (!cpu->proc_run_q) return NULL; - struct list_node_link *current, *start; - if (cpu->proc_current && cpu->proc_current->cpu_run_q_link.next) current = cpu->proc_current->cpu_run_q_link.next; else current = cpu->proc_run_q; - if (!current) - current = cpu->proc_run_q; - start = current; - bool wrap = false; - - while (current) { + do { struct proc* proc = list_entry (current, struct proc, cpu_run_q_link); spin_lock (&proc->lock, &fp); @@ -261,14 +257,9 @@ static struct proc* proc_find_sched (struct cpu* cpu) { current = current->next; - if (!current && !wrap) { + if (!current) current = cpu->proc_run_q; - wrap = true; - } - - if (wrap && current == start) - break; - } + } while (current != start); return NULL; } diff --git a/kernel/proc/stream.c b/kernel/proc/stream.c index 29b997e..72cc4d9 100644 --- a/kernel/proc/stream.c +++ b/kernel/proc/stream.c @@ -7,8 +7,7 @@ #include #include -void proc_stream_write (struct proc* proc, struct proc_stream* stream, struct reschedule_ctx* rctx, - void* data, size_t data_size) { +void proc_stream_write (struct proc_stream* stream, void* data, size_t data_size) { uint64_t fr, fsq; spin_lock (&stream->resource->lock, &fr); @@ -19,8 +18,7 @@ void proc_stream_write (struct proc* proc, struct proc_stream* stream, struct re spin_unlock (&stream->resource->lock, fr); } -size_t proc_stream_read (struct proc* proc, struct proc_stream* stream, struct reschedule_ctx* rctx, - void* out_data, size_t data_size) { +size_t proc_stream_read (struct proc_stream* stream, void* out_data, size_t data_size) { uint64_t fr; size_t bytes = 0; diff --git a/kernel/proc/stream.h b/kernel/proc/stream.h index e1d2e8f..eb0331d 100644 --- a/kernel/proc/stream.h +++ b/kernel/proc/stream.h @@ -20,10 +20,8 @@ struct proc_stream { void proc_cleanup_resource_stream (struct proc_resource* resource, struct reschedule_ctx* rctx); -void proc_stream_write (struct proc* proc, struct proc_stream* stream, struct reschedule_ctx* rctx, - void* data, size_t data_size); +void proc_stream_write (struct proc_stream* stream, void* data, size_t data_size); -size_t proc_stream_read (struct proc* proc, struct proc_stream* stream, struct reschedule_ctx* rctx, - void* out_data, size_t data_size); +size_t proc_stream_read (struct proc_stream* stream, void* out_data, size_t data_size); #endif // _KERNEL_PROC_STREAM_H diff --git a/kernel/syscall/syscall.c b/kernel/syscall/syscall.c index a0f1ca5..7fd621e 100644 --- a/kernel/syscall/syscall.c +++ b/kernel/syscall/syscall.c @@ -1061,7 +1061,7 @@ DEFINE_SYSCALL (sys_stream_write) { if (stream_resource == NULL) return SYSRESULT (-ST_NOT_FOUND); - proc_stream_write (proc, &stream_resource->u.stream, rctx, buffer, buffer_size); + proc_stream_write (&stream_resource->u.stream, buffer, buffer_size); return SYSRESULT (ST_OK); } @@ -1094,7 +1094,7 @@ DEFINE_SYSCALL (sys_stream_read) { if (stream_resource == NULL) return SYSRESULT (-ST_NOT_FOUND); - return SYSRESULT (proc_stream_read (proc, &stream_resource->u.stream, rctx, buffer, buffer_size)); + return SYSRESULT (proc_stream_read (&stream_resource->u.stream, buffer, buffer_size)); } static syscall_handler_func_t handler_table[] = { diff --git a/sdutil/sdutil.c b/sdutil/sdutil.c index 67726ea..399dcc0 100644 --- a/sdutil/sdutil.c +++ b/sdutil/sdutil.c @@ -11,10 +11,7 @@ void app_main (void) { char commandbuf[COMMAND_MAX]; commandbuf[0] = '\0'; - mprintf ("HELLO!\n"); - - /* if (env_get (process_get_pgid (), "C", (void*)commandbuf, sizeof (commandbuf)) == ST_OK) { */ - /* } */ - - /* mprintf ("C=%s\n", commandbuf); */ + if (env_get (process_get_pgid (), "C", (void*)commandbuf, sizeof (commandbuf)) == ST_OK) { + mprintf ("C=%s\n", commandbuf); + } }