From d0c34f93310e6d764daee66f72a9eff9b49bb562 Mon Sep 17 00:00:00 2001 From: Augustin Cavalier Date: Sat, 23 Sep 2023 14:07:17 -0400 Subject: [PATCH] kernel/debug: Invoke cpu_pause in trap_cpu_in_kdl. This is the loop that runs on all CPUs besides the one actually running the kernel debugger. It's functionally a spin-loop around a few different variables, and so it should be safe to use cpu_pause() here, just as real spinlocks do. (cpu_pause() just runs a "pause" or equivalent instruction, it doesn't use the CPU-idle modules, which indeed may be unsafe to use in KDL.) A glance at FreeBSD seems to indicate they also do this when their kernel debugger is active. Seriously improves power consumption while KDL is active: even running in a VM with only a few cores, there would be obvious fan spin-up when entering KDL. After this change, there's barely any at all (while overall CPU usage % remains basically identical.) --- src/system/kernel/debug/debug.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/system/kernel/debug/debug.cpp b/src/system/kernel/debug/debug.cpp index 1481079949..52a0db3837 100644 --- a/src/system/kernel/debug/debug.cpp +++ b/src/system/kernel/debug/debug.cpp @@ -1811,6 +1811,8 @@ debug_trap_cpu_in_kdl(int32 cpu, bool returnIfHandedOver) sCPUTrapped[cpu] = true; while (sInDebugger != 0) { + cpu_pause(); + if (sHandOverKDL && sHandOverKDLToCPU == cpu) { if (returnIfHandedOver) break;