From a83f7ddb45ffb012e1b7f91026c96505ef963fa4 Mon Sep 17 00:00:00 2001 From: Mark Date: Sun, 5 Jan 2020 02:41:31 +0200 Subject: [PATCH] Collect debug information about thread queues --- sys/amd64/sys/sched.c | 19 +++++++++++++++++++ usr/init.c | 4 ++++ 2 files changed, 23 insertions(+) diff --git a/sys/amd64/sys/sched.c b/sys/amd64/sys/sched.c index c54b5ed..b1816fb 100644 --- a/sys/amd64/sys/sched.c +++ b/sys/amd64/sys/sched.c @@ -365,6 +365,25 @@ static uint64_t debug_last_tick = 0; static void debug_stats(void) { kdebug("--- STATS ---\n"); kdebug("syscalls/s: %lu\n", syscall_count); + + kdebug("CPU queues:\n"); + for (size_t i = 0; i < sched_ncpus; ++i) { + debugf(DEBUG_DEFAULT, " cpu%d [ ", i); + for (struct thread *it = sched_queue_heads[i]; it; it = it->next) { + if (it->flags & THREAD_KERNEL) { + // Kernel threads have no pids, lol + debugs(DEBUG_DEFAULT, "K?"); + } else { + debugf(DEBUG_DEFAULT, "%d", it->pid); + } + + if (it->next) { + debugs(DEBUG_DEFAULT, ", "); + } + } + debugs(DEBUG_DEFAULT, " ]\n"); + } + kdebug("--- ----- ---\n"); syscall_count = 0; diff --git a/usr/init.c b/usr/init.c index f036675..adb0012 100644 --- a/usr/init.c +++ b/usr/init.c @@ -387,6 +387,10 @@ static int cmd_exec(const char *line) { } int main(int argc, char **argv) { + if (getpid() != 1) { + printf("Won't work if PID is not 1\n"); + return -1; + } char linebuf[512]; char c; size_t l = 0;