All of lore.kernel.org
 help / color / mirror / Atom feed
* [RFC] panic: reduce CPU consumption when finished handling panic
@ 2025-03-17 22:01 Carlos Bilbao
  2025-03-18 12:09 ` Carlos Bilbao
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: Carlos Bilbao @ 2025-03-17 22:01 UTC (permalink / raw)
  To: pmladek, Andrew Morton, jani.nikula, open list,
	Greg Kroah-Hartman, Thomas Gleixner, takakura, john.ogness

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@kernel.org>
---
 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


^ permalink raw reply related	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2025-03-26 15:10 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-03-17 22:01 [RFC] panic: reduce CPU consumption when finished handling panic Carlos Bilbao
2025-03-18 12:09 ` Carlos Bilbao
2025-03-21 13:01 ` Carlos Bilbao
2025-03-21 19:03 ` Thomas Gleixner
2025-03-26 15:10   ` Carlos Bilbao

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.