From 76221c214ec6907ecd52cf57232fa063e2f937d3 Mon Sep 17 00:00:00 2001 From: dzwdz Date: Thu, 21 Apr 2022 17:52:18 +0200 Subject: kernel: `shutdown()`; temporarily print process states on shutdown --- src/kernel/main.c | 11 +++++++++++ src/kernel/main.h | 2 ++ src/kernel/proc.c | 12 +++--------- src/kernel/proc.h | 1 + 4 files changed, 17 insertions(+), 9 deletions(-) (limited to 'src') diff --git a/src/kernel/main.c b/src/kernel/main.c index 19cc970..9188370 100644 --- a/src/kernel/main.c +++ b/src/kernel/main.c @@ -30,3 +30,14 @@ void kmain(struct kmain_info info) { kprintf("loading init...\n"); run_init(&info); } + +void shutdown(void) { + size_t states[PS_LAST] = {0}; + for (struct process *p = process_first; p; p = process_next(p)) + states[p->state]++; + for (size_t i = 0; i < sizeof(states) / sizeof(*states); i++) + kprintf("state 0x%x: 0x%x\n", i, states[i]); + + mem_debugprint(); + cpu_shutdown(); +} diff --git a/src/kernel/main.h b/src/kernel/main.h index 9c78786..e4ead31 100644 --- a/src/kernel/main.h +++ b/src/kernel/main.h @@ -10,3 +10,5 @@ struct kmain_info { }; void kmain(struct kmain_info); + +void shutdown(void); diff --git a/src/kernel/proc.c b/src/kernel/proc.c index b2a022f..611fd81 100644 --- a/src/kernel/proc.c +++ b/src/kernel/proc.c @@ -1,4 +1,5 @@ #include +#include #include #include #include @@ -100,10 +101,7 @@ _Noreturn void process_idle(void) { struct process *procs[16]; size_t len = process_find_multiple(PS_WAITS4IRQ, procs, 16); - if (len == 0) { - mem_debugprint(); - cpu_shutdown(); - } + if (len == 0) shutdown(); for (;;) { for (size_t i = 0; i < len; i++) { @@ -210,11 +208,7 @@ void process_kill(struct process *proc, int ret) { process_transition(proc, PS_DEAD); proc->death_msg = ret; process_try2collect(proc); - if (proc == process_first) { - kprintf("init killed, quitting..."); - mem_debugprint(); - cpu_shutdown(); - } + if (proc == process_first) shutdown(); } int process_try2collect(struct process *dead) { diff --git a/src/kernel/proc.h b/src/kernel/proc.h index c844f91..f0bae50 100644 --- a/src/kernel/proc.h +++ b/src/kernel/proc.h @@ -12,6 +12,7 @@ enum process_state { PS_WAITS4FS, PS_WAITS4REQUEST, PS_WAITS4IRQ, // set by root vfs + PS_LAST, }; struct process { -- cgit v1.2.3