[RFC] panic: reduce CPU consumption when finished handling panic
From: Carlos Bilbao
Date: Mon Mar 17 2025 - 18:01:33 EST
After the kernel has finished handling a panic, it enters a busy-wait loop.
But, this unnecessarily consumes CPU power and electricity. Plus, in VMs,
this negatively impacts the throughput of other VM guests running on the
same hypervisor.
I propose introducing a function cpu_halt_end_panic() to halt the CPU
during this state while still allowing interrupts to be processed. See my
commit below.
Thanks in advance!
Signed-off-by: Carlos Bilbao <carlos.bilbao@xxxxxxxxxx>
---
kernel/panic.c | 17 ++++++++++++++++-
1 file changed, 16 insertions(+), 1 deletion(-)
diff --git a/kernel/panic.c b/kernel/panic.c
index fbc59b3b64d0..c00ccaa698d5 100644
--- a/kernel/panic.c
+++ b/kernel/panic.c
@@ -276,6 +276,21 @@ static void panic_other_cpus_shutdown(bool crash_kexec)
crash_smp_send_stop();
}
+static void cpu_halt_end_panic(void)
+{
+#ifdef CONFIG_X86
+ native_safe_halt();
+#elif defined(CONFIG_ARM)
+ cpu_do_idle();
+#else
+ /*
+ * Default to a simple busy-wait if no architecture-specific halt is
+ * defined above
+ */
+ mdelay(PANIC_TIMER_STEP);
+#endif
+}
+
/**
* panic - halt the system
* @fmt: The text string to print
@@ -474,7 +489,7 @@ void panic(const char *fmt, ...)
i += panic_blink(state ^= 1);
i_next = i + 3600 / PANIC_BLINK_SPD;
}
- mdelay(PANIC_TIMER_STEP);
+ cpu_halt_end_panic();
}
}
--
2.47.1