summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordzwdz2022-04-21 17:52:18 +0200
committerdzwdz2022-04-21 17:52:18 +0200
commit76221c214ec6907ecd52cf57232fa063e2f937d3 (patch)
tree03fc614432e51fb280c737324e49d021dab94dce
parente07fba53d972cfd4cf13c2e025200e40958f013d (diff)
kernel: `shutdown()`; temporarily print process states on shutdown
-rw-r--r--src/kernel/main.c11
-rw-r--r--src/kernel/main.h2
-rw-r--r--src/kernel/proc.c12
-rw-r--r--src/kernel/proc.h1
4 files changed, 17 insertions, 9 deletions
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 <kernel/arch/generic.h>
+#include <kernel/main.h>
#include <kernel/mem/alloc.h>
#include <kernel/mem/virt.h>
#include <kernel/panic.h>
@@ -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 {