The Linux Kernel Mailing List
 help / color / mirror / Atom feed
From: Carlos Bilbao <carlos.bilbao.osdev@gmail.com>
To: pmladek@suse.com, Andrew Morton <akpm@linux-foundation.org>,
	jani.nikula@intel.com, open list <linux-kernel@vger.kernel.org>,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	Thomas Gleixner <tglx@linutronix.de>,
	takakura@valinux.co.jp, john.ogness@linutronix.de
Subject: [RFC] panic: reduce CPU consumption when finished handling panic
Date: Mon, 17 Mar 2025 17:01:22 -0500	[thread overview]
Message-ID: <f2272f04-510e-4c92-be5e-fedcbb445eb0@gmail.com> (raw)

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


             reply	other threads:[~2025-03-17 22:01 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-03-17 22:01 Carlos Bilbao [this message]
2025-03-18 12:09 ` [RFC] panic: reduce CPU consumption when finished handling panic Carlos Bilbao
2025-03-21 13:01 ` Carlos Bilbao
2025-03-21 19:03 ` Thomas Gleixner
2025-03-26 15:10   ` Carlos Bilbao

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=f2272f04-510e-4c92-be5e-fedcbb445eb0@gmail.com \
    --to=carlos.bilbao.osdev@gmail.com \
    --cc=akpm@linux-foundation.org \
    --cc=gregkh@linuxfoundation.org \
    --cc=jani.nikula@intel.com \
    --cc=john.ogness@linutronix.de \
    --cc=linux-kernel@vger.kernel.org \
    --cc=pmladek@suse.com \
    --cc=takakura@valinux.co.jp \
    --cc=tglx@linutronix.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox