Commit 5045bcae0fb466a1dbb6af0036e56901fd7aafb7

Authored by Rik van Riel
Committed by Linus Torvalds
1 parent 6e574195b7

sysrq: add show-backtrace-on-all-cpus function

SysRQ-P is not always useful on SMP systems, since it usually ends up showing
the backtrace of a CPU that is doing just fine, instead of the backtrace of
the CPU that is having problems.

This patch adds SysRQ show-all-cpus(L), which shows the backtrace of every
active CPU in the system.  It skips idle CPUs because some SMP systems are
just too large and we already know what the backtrace of the idle task looks
like.

[akpm@linux-foundation.org: coding-style fixes]
Signed-off-by: Rik van Riel <riel@redhat.com>
Randy Dunlap <randy.dunlap@oracle.com>
Cc: <lwoodman@redhat.com>
Cc: Ingo Molnar <mingo@elte.hu>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>

Showing 2 changed files with 48 additions and 0 deletions Side-by-side Diff

Documentation/sysrq.txt
... ... @@ -85,6 +85,8 @@
85 85 'k' - Secure Access Key (SAK) Kills all programs on the current virtual
86 86 console. NOTE: See important comments below in SAK section.
87 87  
  88 +'l' - Shows a stack backtrace for all active CPUs.
  89 +
88 90 'm' - Will dump current memory info to your console.
89 91  
90 92 'n' - Used to make RT tasks nice-able
drivers/char/sysrq.c
... ... @@ -196,6 +196,48 @@
196 196 #define sysrq_showlocks_op (*(struct sysrq_key_op *)0)
197 197 #endif
198 198  
  199 +#ifdef CONFIG_SMP
  200 +static DEFINE_SPINLOCK(show_lock);
  201 +
  202 +static void showacpu(void *dummy)
  203 +{
  204 + unsigned long flags;
  205 +
  206 + /* Idle CPUs have no interesting backtrace. */
  207 + if (idle_cpu(smp_processor_id()))
  208 + return;
  209 +
  210 + spin_lock_irqsave(&show_lock, flags);
  211 + printk(KERN_INFO "CPU%d:\n", smp_processor_id());
  212 + show_stack(NULL, NULL);
  213 + spin_unlock_irqrestore(&show_lock, flags);
  214 +}
  215 +
  216 +static void sysrq_showregs_othercpus(struct work_struct *dummy)
  217 +{
  218 + smp_call_function(showacpu, NULL, 0, 0);
  219 +}
  220 +
  221 +static DECLARE_WORK(sysrq_showallcpus, sysrq_showregs_othercpus);
  222 +
  223 +static void sysrq_handle_showallcpus(int key, struct tty_struct *tty)
  224 +{
  225 + struct pt_regs *regs = get_irq_regs();
  226 + if (regs) {
  227 + printk(KERN_INFO "CPU%d:\n", smp_processor_id());
  228 + show_regs(regs);
  229 + }
  230 + schedule_work(&sysrq_showallcpus);
  231 +}
  232 +
  233 +static struct sysrq_key_op sysrq_showallcpus_op = {
  234 + .handler = sysrq_handle_showallcpus,
  235 + .help_msg = "aLlcpus",
  236 + .action_msg = "Show backtrace of all active CPUs",
  237 + .enable_mask = SYSRQ_ENABLE_DUMP,
  238 +};
  239 +#endif
  240 +
199 241 static void sysrq_handle_showregs(int key, struct tty_struct *tty)
200 242 {
201 243 struct pt_regs *regs = get_irq_regs();
202 244  
... ... @@ -340,7 +382,11 @@
340 382 &sysrq_kill_op, /* i */
341 383 NULL, /* j */
342 384 &sysrq_SAK_op, /* k */
  385 +#ifdef CONFIG_SMP
  386 + &sysrq_showallcpus_op, /* l */
  387 +#else
343 388 NULL, /* l */
  389 +#endif
344 390 &sysrq_showmem_op, /* m */
345 391 &sysrq_unrt_op, /* n */
346 392 /* o: This will often be registered as 'Off' at init time */