Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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>

authored by

Rik van Riel and committed by
Linus Torvalds
5045bcae 6e574195

+48
+2
Documentation/sysrq.txt
··· 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
+46
drivers/char/sysrq.c
··· 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(); ··· 382 340 &sysrq_kill_op, /* i */ 383 341 NULL, /* j */ 384 342 &sysrq_SAK_op, /* k */ 343 + #ifdef CONFIG_SMP 344 + &sysrq_showallcpus_op, /* l */ 345 + #else 385 346 NULL, /* l */ 347 + #endif 386 348 &sysrq_showmem_op, /* m */ 387 349 &sysrq_unrt_op, /* n */ 388 350 /* o: This will often be registered as 'Off' at init time */