sched/debug, sys_info: Introduce SYS_INFO_CPU_RUNQUEUES
Subsystems (3)
PATCH v2 1/1 sched/debug, sys_info: Introduce SYS_INFO_CPU_RUNQUEUES
When investigating kernel panics, inspectability of per-CPU runqueues and runnable task states is valuable for diagnosing CPU starvation priority inversion, etc.
While debugfs (/sys/kernel/debug/sched/debug) exposes runqueue metrics to userspace, these details are not captured during an automated kernel panic or crash dump. Capturing per-CPU runqueue state directly into log_buf fills this diagnostic gap for post-mortem crash analysis.
Introduce SYS_INFO_CPU_RUNQUEUES and its corresponding string token "cpu_runqueues" to panic_sys_info. Add sched_show_runqueues(), modelled on print_rq(), to emit per-CPU scheduler diagnostics to the kernel log.
Unlike /sys/kernel/debug/sched/debug which dumps all threads assigned to a CPU, sched_show_runqueues() only emits threads that are actively running or queued on the runqueue (via task_on_rq_queued() and task_current()). This keeps the panic log concise, reflects the true runqueue depth, and prevents overflowing the printk ring buffer on systems with high thread counts.
Additionally, to guarantee deadlock and memory safety in panic context:
- Acquire the runqueue lock using raw_spin_rq_trylock() with READ_ONCE() and rcu_dereference() fallback, marking contended queues with " (contended)"
- Wrap the per-CPU inspection in rcu_read_lock() to protect the sampled current task (comm and PID) against premature release during pr_info() across other callers
- Omit cgroup group-path printing in print_rq() to avoid acquiring cgroup_mutex and traversing kernfs dentries
---
Changes since v1:
- Resolved Sparse __rcu address space warnings by accessing rq->curr via rcu_dereference() in sched_show_runqueues()
- Link to v1: https://lore.kernel.org/lkml/[email protected]/
--- Documentation/admin-guide/sysctl/kernel.rst | 1 + include/linux/sched/debug.h | 1 + include/linux/sys_info.h | 1 + kernel/sched/debug.c | 76 +++++++++++++++++---- lib/sys_info.c | 4 ++ 5 files changed, 70 insertions(+), 13 deletions(-)
Documentation/admin-guide/sysctl/kernel.rst +1 -0
@@ -939,6 +939,7 @@ locks print locks info if CONFIG_LOCKDEP is on ftrace print ftrace buffer all_bt print all CPUs backtrace (if available in the arch) blocked_tasks print only tasks in uninterruptible (blocked) state +cpu_runqueues print per-CPU runqueue depth and runnable tasks ============= ===================================================
include/linux/sched/debug.h +1 -0
@@ -39,6 +39,7 @@ struct seq_file;extern void proc_sched_show_task (struct task_struct *p,struct pid_namespace *ns,struct seq_file *m);extern void proc_sched_set_task (struct task_struct *p); +extern void sched_show_runqueues (void );/* Attach to any functions which should be ignored in wchan output. */ #define __sched __section(".sched.text")
include/linux/sys_info.h +1 -0
@@ -16,6 +16,7 @@#define SYS_INFO_PANIC_CONSOLE_REPLAY 0x00000020#define SYS_INFO_ALL_BT 0x00000040#define SYS_INFO_BLOCKED_TASKS 0x00000080 +#define SYS_INFO_CPU_RUNQUEUES 0x00000100void sys_info (unsigned long si_mask);unsigned long sys_info_parse_param (char *str);
kernel/sched/debug.c +63 -13
127 lines not on this page · raw message
lib/sys_info.c +4 -0
@@ -22,6 +22,7 @@ static const char * const si_names[] = { [ilog2(SYS_INFO_PANIC_CONSOLE_REPLAY)] = "", [ilog2(SYS_INFO_ALL_BT)] = "all_bt", [ilog2(SYS_INFO_BLOCKED_TASKS)] = "blocked_tasks", + [ilog2(SYS_INFO_CPU_RUNQUEUES)] = "cpu_runqueues", };/*
@@ -158,6 +159,9 @@ static void __sys_info(unsigned long si_mask)if (si_mask &SYS_INFO_BLOCKED_TASKS )show_state_filter (TASK_UNINTERRUPTIBLE ); + +if (si_mask &SYS_INFO_CPU_RUNQUEUES ) +sched_show_runqueues (); }void sys_info (unsigned long si_mask)
Signature · 1 line
2.55.0
Quoted 35 lines · Aaron Tomlin
When investigating kernel panics, inspectability of per-CPU runqueues and runnable task states is valuable for diagnosing CPU starvation priority inversion, etc.
While debugfs (
/sys/kernel/debug/sched/debug) exposes runqueue metrics to userspace, these details are not captured during an automated kernel panic or crash dump. Capturing per-CPU runqueue state directly intolog_buffills this diagnostic gap for post-mortem crash analysis.Introduce
SYS_INFO_CPU_RUNQUEUESand its corresponding string token "cpu_runqueues" topanic_sys_info. Addsched_show_runqueues(), modelled onprint_rq(), to emit per-CPU scheduler diagnostics to the kernel log.Unlike
/sys/kernel/debug/sched/debugwhich dumps all threads assigned to a CPU,sched_show_runqueues()only emits threads that are actively running or queued on the runqueue (viatask_on_rq_queued()andtask_current()). This keeps the panic log concise, reflects the true runqueue depth, and prevents overflowing the printk ring buffer on systems with high thread counts.Additionally, to guarantee deadlock and memory safety in panic context:
- Acquire the runqueue lock usingraw_spin_rq_trylock()withREAD_ONCE()andrcu_dereference()fallback, marking contended queues with " (contended)"- Wrap the per-CPU inspection in
rcu_read_lock()to protect the sampled current task (comm and PID) against premature release duringpr_info()across other callers- Omit cgroup group-path printing in
print_rq()to avoid acquiringcgroup_mutexand traversing kernfs dentries
Documentation/admin-guide/sysctl/kernel.rst locks print locks info if CONFIG_LOCKDEP is on · line 942
Quoted 4 lines
Documentation/admin-guide/sysctl/kernel.rst +1
-0@@ -939,6 +939,7 @@ locks print locks info if CONFIG_LOCKDEP is on ftrace print ftrace buffer all_bt print all CPUs backtrace (if available in the arch) blocked_tasks print only tasks in uninterruptible (blocked) state +cpu_runqueues print per-CPU runqueue depth and runnable tasks
I would keep is short and call it "rq".
include/linux/sys_info.h line 19
Quoted 9 lines
Documentation/admin-guide/sysctl/kernel.rst +0
-0============= ===================================================include/linux/sys_info.h +1
-0@@ -16,6 +16,7 @@#define SYS_INFO_PANIC_CONSOLE_REPLAY 0x00000020#define SYS_INFO_ALL_BT 0x00000040#define SYS_INFO_BLOCKED_TASKS 0x00000080 +#define SYS_INFO_CPU_RUNQUEUES 0x00000100
Similar here: SYS_INFO_RQ
Quoted 19 lines
include/linux/sys_info.h +0
-0void sys_info (unsigned long si_mask);unsigned long sys_info_parse_param (char *str);kernel/sched/debug.c +9
-0@@ -1322,6 +1330,48 @@ void sysrq_sched_debug_show(void) } } +void sched_show_runqueues (void ) +{ +int cpu; + +pr_info ("CPU Runqueues:\n" ); +for_each_online_cpu (cpu) { +struct rq *rq =cpu_rq (cpu); +struct task_struct *curr; +unsigned int nr_running;
kernel/sched/debug.c void sysrq_sched_debug_show(void) · line 1351
Quoted 10 lines
kernel/sched/debug.c +10
-0+u64 nr_switches; +unsigned long flags; +bool locked; + +touch_nmi_watchdog (); +touch_all_softlockup_watchdogs (); + +rcu_read_lock (); +local_irq_save (flags); + locked =raw_spin_rq_trylock (rq);
Is the trylock needed for all sys_info() callers or just in panic()? If it is just panic() then I would use it only when oops_in_progress is set and use raw_spin_rq_lock() otherwise.
Quoted 12 lines
kernel/sched/debug.c +12
-0+if (locked) { + nr_running = rq->nr_running; + nr_switches = rq->nr_switches; + curr =rcu_dereference (rq->curr); +raw_spin_rq_unlock (rq); + }else { + nr_running =READ_ONCE (rq->nr_running); + nr_switches =READ_ONCE (rq->nr_switches); + curr =rcu_dereference (rq->curr); + } +local_irq_restore (flags); +
kernel/sched/debug.c void sysrq_sched_debug_show(void) · line 1373
Quoted 10 lines
kernel/sched/debug.c +10
-0+pr_info ("cpu#%d: nr_running:%u switches:%llu curr:%s[%d]%s\n" , + cpu, nr_running, nr_switches, + curr ? curr->comm :"<none>" , + curr ?task_pid_nr (curr) :-1 , + locked ?"" :" (contended)" ); + +print_rq (NULL , rq, cpu, false, true); +rcu_read_unlock (); + } +}
IMHO, it might be a useful feature.
The main question is whether it is acceptable to scheduler maintainers. It adds some churn. Also they would need to keep in mind that it can be called in panic().
Best Regards,
Petr
Peter Zijlstra
maintainerQuoted 8 lines · Aaron Tomlin
When investigating kernel panics, inspectability of per-CPU runqueues and runnable task states is valuable for diagnosing CPU starvation priority inversion, etc.
While debugfs (
/sys/kernel/debug/sched/debug) exposes runqueue metrics to userspace, these details are not captured during an automated kernel panic or crash dump. Capturing per-CPU runqueue state directly intolog_buffills this diagnostic gap for post-mortem crash analysis.
Uh, crash-dump preserves everything.
Quoted 46 lines
kernel/sched/debug.c +25
-2rcu_read_lock ();for_each_process_thread (g, p) {if (task_cpu (p) != rq_cpu)continue ; -print_task (m, rq, p); +if (queued_only && !task_current (rq, p) && !task_on_rq_queued (p)) +continue ; + +print_task (m, rq, p, show_cgroup_path); }rcu_read_unlock (); }@@ -1234,7 +1242,7 @@ do { \print_rt_stats (m, cpu);print_dl_stats (m, cpu); -print_rq (m, rq, cpu); +print_rq (m, rq, cpu, true, false);SEQ_printf (m,"\n" ); }@@ -1322,6 +1330,48 @@ void sysrq_sched_debug_show(void) } } +void sched_show_runqueues (void ) +{ +int cpu; + +pr_info ("CPU Runqueues:\n" ); +for_each_online_cpu (cpu) { +struct rq *rq =cpu_rq (cpu); +struct task_struct *curr; +unsigned int nr_running; +u64 nr_switches; +unsigned long flags; +bool locked; + +touch_nmi_watchdog (); +touch_all_softlockup_watchdogs (); + +rcu_read_lock (); +local_irq_save (flags); + locked =raw_spin_rq_trylock (rq); +if (locked) {
kernel/sched/debug.c void sysrq_sched_debug_show(void) · line 1362
Quoted 10 lines
kernel/sched/debug.c +10
-0+ nr_running = rq->nr_running; + nr_switches = rq->nr_switches; + curr =rcu_dereference (rq->curr); +raw_spin_rq_unlock (rq); + }else { + nr_running =READ_ONCE (rq->nr_running); + nr_switches =READ_ONCE (rq->nr_switches); + curr =rcu_dereference (rq->curr); + } +local_irq_restore (flags);
This seems to want to avoid deadlocking on rq->lock, but then print_rq()->print_cfs_stats() will unconditionally take rq->lock again.
So meh.
Quoted 28 lines
kernel/sched/debug.c +12
-0+ +pr_info ("cpu#%d: nr_running:%u switches:%llu curr:%s[%d]%s\n" , + cpu, nr_running, nr_switches, + curr ? curr->comm :"<none>" , + curr ?task_pid_nr (curr) :-1 , + locked ?"" :" (contended)" ); + +print_rq (NULL , rq, cpu, false, true); +rcu_read_unlock (); + } +} +/* * This iterator needs some explanation. * It returns 1 for the header position. lib/sys_info.c +1
-0@@ -22,6 +22,7 @@ static const char * const si_names[] = { [ilog2(SYS_INFO_PANIC_CONSOLE_REPLAY)] = "", [ilog2(SYS_INFO_ALL_BT)] = "all_bt", [ilog2(SYS_INFO_BLOCKED_TASKS)] = "blocked_tasks", + [ilog2(SYS_INFO_CPU_RUNQUEUES)] = "cpu_runqueues", };/*
lib/sys_info.c static void __sys_info(unsigned long si_mask) · line 165
Quoted 7 lines
lib/sys_info.c +3
-0@@ -158,6 +159,9 @@ static void __sys_info(unsigned long si_mask)if (si_mask &SYS_INFO_BLOCKED_TASKS )show_state_filter (TASK_UNINTERRUPTIBLE ); + +if (si_mask &SYS_INFO_CPU_RUNQUEUES ) +sched_show_runqueues (); }
I really don't know if this is worth the trouble. I have *never* needed this.
Quoted 33 lines · Petr Mladek
Quoted 32 lines · Aaron Tomlin
When investigating kernel panics, inspectability of per-CPU runqueues and runnable task states is valuable for diagnosing CPU starvation priority inversion, etc.
While debugfs (
/sys/kernel/debug/sched/debug) exposes runqueue metrics to userspace, these details are not captured during an automated kernel panic or crash dump. Capturing per-CPU runqueue state directly intolog_buffills this diagnostic gap for post-mortem crash analysis.Introduce
SYS_INFO_CPU_RUNQUEUESand its corresponding string token "cpu_runqueues" topanic_sys_info. Addsched_show_runqueues(), modelled onprint_rq(), to emit per-CPU scheduler diagnostics to the kernel log.Unlike
/sys/kernel/debug/sched/debugwhich dumps all threads assigned to a CPU,sched_show_runqueues()only emits threads that are actively running or queued on the runqueue (viatask_on_rq_queued()andtask_current()). This keeps the panic log concise, reflects the true runqueue depth, and prevents overflowing the printk ring buffer on systems with high thread counts.Additionally, to guarantee deadlock and memory safety in panic context:
- Acquire the runqueue lock usingraw_spin_rq_trylock()withREAD_ONCE()andrcu_dereference()fallback, marking contended queues with " (contended)"- Wrap the per-CPU inspection in
rcu_read_lock()to protect the sampled current task (comm and PID) against premature release duringpr_info()across other callers- Omit cgroup group-path printing in
print_rq()to avoid acquiringcgroup_mutexand traversing kernfs dentries
Quoted 9 lines
Documentation/admin-guide/sysctl/kernel.rst locks print locks info if CONFIG_LOCKDEP is on · line 942
Quoted 7 lines
Documentation/admin-guide/sysctl/kernel.rst +1
-0@@ -939,6 +939,7 @@ locks print locks info if CONFIG_LOCKDEP is on ftrace print ftrace buffer all_bt print all CPUs backtrace (if available in the arch) blocked_tasks print only tasks in uninterruptible (blocked) state +cpu_runqueues print per-CPU runqueue depth and runnable tasksI would keep is short and call it "rq".
Hi Petr,
Thank you for your review.
Acknowledged, fair enough.
Quoted 11 lines
include/linux/sys_info.h line 19
Quoted 9 lines
Documentation/admin-guide/sysctl/kernel.rst +0
-0============= ===================================================include/linux/sys_info.h +1
-0@@ -16,6 +16,7 @@#define SYS_INFO_PANIC_CONSOLE_REPLAY 0x00000020#define SYS_INFO_ALL_BT 0x00000040#define SYS_INFO_BLOCKED_TASKS 0x00000080 +#define SYS_INFO_CPU_RUNQUEUES 0x00000100Similar here:
SYS_INFO_RQ
Acknowledged.
Quoted 10 lines
Quoted 10 lines
include/linux/sys_info.h +0
-0void sys_info (unsigned long si_mask);unsigned long sys_info_parse_param (char *str);kernel/sched/debug.c +0
-0@@ -1322,6 +1330,48 @@ void sysrq_sched_debug_show(void) } }
Quoted 5 lines
kernel/sched/debug.c void sysrq_sched_debug_show(void) · line 1337
Quoted 5 lines
kernel/sched/debug.c +5
-0+void sched_show_runqueues (void ) +{ +int cpu; + +pr_info ("CPU Runqueues:\n" );
I will drop this. In print_rq(), there is often no overarching banner line emitted beforehand.
Quoted 10 lines
Quoted 10 lines
kernel/sched/debug.c +10
-0+for_each_online_cpu (cpu) { +struct rq *rq =cpu_rq (cpu); +struct task_struct *curr; +unsigned int nr_running; +u64 nr_switches; +unsigned long flags; +bool locked; + +touch_nmi_watchdog (); +touch_all_softlockup_watchdogs ();
Quoted 8 lines
kernel/sched/debug.c void sysrq_sched_debug_show(void) · line 1351
Quoted 4 lines
kernel/sched/debug.c +4
-0+ +rcu_read_lock (); +local_irq_save (flags); + locked =raw_spin_rq_trylock (rq);Is the trylock needed for all
sys_info()callers or just inpanic()? If it is justpanic()then I would use it only whenoops_in_progressis set and useraw_spin_rq_lock()otherwise.
Yes, the trylock in sched_show_runqueues() is needed for all callers to __sys_info(), not just panic().
Because __sys_info() is also called from NMI context (hardlockup), hardirq context (softlockup), and khungtaskd, oops_in_progress is 0 in those paths. Using unconditional raw_spin_rq_lock() there risks fatal self-deadlocks if rq->lock is already held on the local CPU. Furthermore, locking arbitrary runqueues in a loop risks AB-BA deadlocks with concurrent scheduler load-balancing.
Using raw_spin_rq_trylock() ensures sched_show_runqueues() remains strictly non-blocking across all __sys_info() contexts, and tagging contended queues with " (contended)" adds useful diagnostic value.
As such, I believe the current implementation is sufficient.
Quoted 26 lines
Quoted 13 lines
kernel/sched/debug.c +12
-0+if (locked) { + nr_running = rq->nr_running; + nr_switches = rq->nr_switches; + curr =rcu_dereference (rq->curr); +raw_spin_rq_unlock (rq); + }else { + nr_running =READ_ONCE (rq->nr_running); + nr_switches =READ_ONCE (rq->nr_switches); + curr =rcu_dereference (rq->curr); + } +local_irq_restore (flags); +kernel/sched/debug.c void sysrq_sched_debug_show(void) · line 1373
Quoted 10 lines
kernel/sched/debug.c +10
-0+pr_info ("cpu#%d: nr_running:%u switches:%llu curr:%s[%d]%s\n" , + cpu, nr_running, nr_switches, + curr ? curr->comm :"<none>" , + curr ?task_pid_nr (curr) :-1 , + locked ?"" :" (contended)" ); + +print_rq (NULL , rq, cpu, false, true); +rcu_read_unlock (); + } +}IMHO, it might be a useful feature.
Quoted 3 lines
The main question is whether it is acceptable to scheduler maintainers. It adds some churn. Also they would need to keep in mind that it can be called in
panic().
Thank you for your feedback.
Indeed. Regarding the scheduler maintainers (Cc'd Ingo Molnar, Peter Zijlstra, Juri Lelli, and Vincent Guittot):
The churn was kept strictly confined to kernel/sched/debug.c:
1. It reuses existing print_rq()/print_task() helpers with two flags; queued_only, to keep output concise and show_cgroup_path, to avoid cgroup_mutex.
2. sched_show_runqueues() is completely read-only and non-blocking (raw_spin_rq_trylock() with READ_ONCE() and rcu_dereference() fallback), so it does not impose locking constraints or latency risks on core scheduler code, even in panic() or NMI/hardirq contexts.
Kind regards,
Signature · 1 line
Aaron Tomlin
Quoted 11 lines · Peter Zijlstra
Quoted 8 lines · Aaron Tomlin
When investigating kernel panics, inspectability of per-CPU runqueues and runnable task states is valuable for diagnosing CPU starvation priority inversion, etc.
While debugfs (
/sys/kernel/debug/sched/debug) exposes runqueue metrics to userspace, these details are not captured during an automated kernel panic or crash dump. Capturing per-CPU runqueue state directly intolog_buffills this diagnostic gap for post-mortem crash analysis.Uh, crash-dump preserves everything.
Hi Peter,
Yes, fair point. The intention here is to preserve this state directly within the kernel log buffer, particularly for scenarios where kdump is not configured, the vmcore was truncated or fails to complete.
In such circumstances, dmesg, whether captured via pstore or serial, is frequently the sole surviving diagnostic artefact.
Quoted 62 lines
Quoted 48 lines
kernel/sched/debug.c +25
-2rcu_read_lock ();for_each_process_thread (g, p) {if (task_cpu (p) != rq_cpu)continue ; -print_task (m, rq, p); +if (queued_only && !task_current (rq, p) && !task_on_rq_queued (p)) +continue ; + +print_task (m, rq, p, show_cgroup_path); }rcu_read_unlock (); }@@ -1234,7 +1242,7 @@ do { \print_rt_stats (m, cpu);print_dl_stats (m, cpu); -print_rq (m, rq, cpu); +print_rq (m, rq, cpu, true, false);SEQ_printf (m,"\n" ); }@@ -1322,6 +1330,48 @@ void sysrq_sched_debug_show(void) } } +void sched_show_runqueues (void ) +{ +int cpu; + +pr_info ("CPU Runqueues:\n" ); +for_each_online_cpu (cpu) { +struct rq *rq =cpu_rq (cpu); +struct task_struct *curr; +unsigned int nr_running; +u64 nr_switches; +unsigned long flags; +bool locked; + +touch_nmi_watchdog (); +touch_all_softlockup_watchdogs (); + +rcu_read_lock (); +local_irq_save (flags); + locked =raw_spin_rq_trylock (rq); +if (locked) {kernel/sched/debug.c void sysrq_sched_debug_show(void) · line 1362
Quoted 10 lines
kernel/sched/debug.c +10
-0+ nr_running = rq->nr_running; + nr_switches = rq->nr_switches; + curr =rcu_dereference (rq->curr); +raw_spin_rq_unlock (rq); + }else { + nr_running =READ_ONCE (rq->nr_running); + nr_switches =READ_ONCE (rq->nr_switches); + curr =rcu_dereference (rq->curr); + } +local_irq_restore (flags);This seems to want to avoid deadlocking on
rq->lock, but then print_rq()->print_cfs_stats() will unconditionally takerq->lockagain.
Quoted 1 line
So meh.
No, print_rq() does not call print_cfs_stats(). It is print_cpu() (i.e. used by debugfs and SysRq) that calls print_cfs_stats() and unconditionally takes rq->lock via print_cfs_rq().
With sched_show_runqueues(), it specifically avoids print_cpu() and only calls print_rq(NULL, rq, cpu, false, true). Inside print_rq(), it merely iterates threads under rcu_read_lock() and calls print_task(), neither of which acquires rq->lock. Hence, rq->lock is never taken again, and the non-blocking guarantee of the trylock remains intact throughout the entire dump.
Quoted 30 lines
Quoted 30 lines
kernel/sched/debug.c +12
-0+ +pr_info ("cpu#%d: nr_running:%u switches:%llu curr:%s[%d]%s\n" , + cpu, nr_running, nr_switches, + curr ? curr->comm :"<none>" , + curr ?task_pid_nr (curr) :-1 , + locked ?"" :" (contended)" ); + +print_rq (NULL , rq, cpu, false, true); +rcu_read_unlock (); + } +} +/* * This iterator needs some explanation. * It returns 1 for the header position. lib/sys_info.c +1
-0@@ -22,6 +22,7 @@ static const char * const si_names[] = { [ilog2(SYS_INFO_PANIC_CONSOLE_REPLAY)] = "", [ilog2(SYS_INFO_ALL_BT)] = "all_bt", [ilog2(SYS_INFO_BLOCKED_TASKS)] = "blocked_tasks", + [ilog2(SYS_INFO_CPU_RUNQUEUES)] = "cpu_runqueues", };/* @@ -158,6 +159,9 @@ static void __sys_info(unsigned long si_mask)
Quoted 9 lines
lib/sys_info.c static void __sys_info(unsigned long si_mask) · line 165
Quoted 6 lines
lib/sys_info.c +3
-0if (si_mask &SYS_INFO_BLOCKED_TASKS )show_state_filter (TASK_UNINTERRUPTIBLE ); + +if (si_mask &SYS_INFO_CPU_RUNQUEUES ) +sched_show_runqueues (); }I really don't know if this is worth the trouble. I have *never* needed this.
I understand. However, the requirement primarily arises in production support. In environments where kdump is not configured or the resulting vmcore is truncated, dmesg is frequently the sole surviving diagnostic artefact.
During an NMI-induced panic, capturing per-CPU runqueue depth in the log is invaluable for identifying CPU starvation, etc. As with the remainder of sys_info, this functionality is strictly opt-in and disabled by default, imposing no overhead on systems that do not require it while providing vital visibility where full memory dumps are unavailable.
Kind regards,
Signature · 1 line
Aaron Tomlin
Peter Zijlstra
maintainerQuoted 13 lines · Aaron Tomlin
Quoted 11 lines · Peter Zijlstra
Quoted 8 lines · Aaron Tomlin
When investigating kernel panics, inspectability of per-CPU runqueues and runnable task states is valuable for diagnosing CPU starvation priority inversion, etc.
While debugfs (
/sys/kernel/debug/sched/debug) exposes runqueue metrics to userspace, these details are not captured during an automated kernel panic or crash dump. Capturing per-CPU runqueue state directly intolog_buffills this diagnostic gap for post-mortem crash analysis.Uh, crash-dump preserves everything.
Quoted 7 lines
Hi Peter,
Yes, fair point. The intention here is to preserve this state directly within the kernel log buffer, particularly for scenarios where kdump is not configured, the vmcore was truncated or fails to complete.
In such circumstances, dmesg, whether captured via pstore or serial, is frequently the sole surviving diagnostic artefact.
Ok. So not crash-dump then ;-)
Quoted 17 lines
Quoted 17 lines
kernel/sched/debug.c void sysrq_sched_debug_show(void) · line 1362
Quoted 13 lines
kernel/sched/debug.c +13
-0+local_irq_save (flags); + locked =raw_spin_rq_trylock (rq); +if (locked) { + nr_running = rq->nr_running; + nr_switches = rq->nr_switches; + curr =rcu_dereference (rq->curr); +raw_spin_rq_unlock (rq); + }else { + nr_running =READ_ONCE (rq->nr_running); + nr_switches =READ_ONCE (rq->nr_switches); + curr =rcu_dereference (rq->curr); + } +local_irq_restore (flags);This seems to want to avoid deadlocking on
rq->lock, but then print_rq()->print_cfs_stats() will unconditionally takerq->lockagain.
Quoted 5 lines
Quoted 1 line
So meh.
No,
print_rq()does not callprint_cfs_stats(). It isprint_cpu()(i.e. used by debugfs and SysRq) that callsprint_cfs_stats()and unconditionally takesrq->lockviaprint_cfs_rq().
Right you are. Clearly I got my wires crossed when looking through that.
Quoted 6 lines
With
sched_show_runqueues(), it specifically avoidsprint_cpu()and only callsprint_rq(NULL, rq, cpu, false, true). Insideprint_rq(), it merely iterates threads underrcu_read_lock()and callsprint_task(), neither of which acquiresrq->lock. Hence,rq->lockis never taken again, and the non-blocking guarantee of the trylock remains intact throughout the entire dump.
OK. So perhaps add a few comments / annotations that these paths should stay clear of rq-lock. It is too easy for it to get added.
Quoted 12 lines
Quoted 6 lines
lib/sys_info.c static void __sys_info(unsigned long si_mask) · line 165
Quoted 3 lines
lib/sys_info.c +2
-0+if (si_mask &SYS_INFO_CPU_RUNQUEUES ) +sched_show_runqueues (); }I really don't know if this is worth the trouble. I have *never* needed this.
I understand. However, the requirement primarily arises in production support. In environments where kdump is not configured or the resulting vmcore is truncated, dmesg is frequently the sole surviving diagnostic artefact.
Quoted 5 lines
During an NMI-induced panic, capturing per-CPU runqueue depth in the log is invaluable for identifying CPU starvation, etc. As with the remainder of
sys_info, this functionality is strictly opt-in and disabled by default, imposing no overhead on systems that do not require it while providing vital visibility where full memory dumps are unavailable.
What is the main thing holding 'you' back from enabling kdump everywhere? AFAIU crash dump can be configured to only dump kernel data structures, which is a lot more economical than a complete memory dump.
Mostly I just worry about death by a thousand cuts and all that. I don't have a very strong objection to this, just wondering if we really need it.
Quoted 7 lines · Peter Zijlstra
Quoted 5 lines
Yes, fair point. The intention here is to preserve this state directly within the kernel log buffer, particularly for scenarios where kdump is not configured, the vmcore was truncated or fails to complete.
In such circumstances, dmesg, whether captured via pstore or serial, is frequently the sole surviving diagnostic artefact.Ok. So not crash-dump then ;-)
Hi Peter,
Yes. Any data emitted by sys_info() that appears on the serial console will also be captured in vmcore-dmesg.txt, even if the resulting vmcore dump to disk is truncated due to insufficient storage.
Quoted 11 lines
Right you are. Clearly I got my wires crossed when looking through that.
Quoted 6 lines
With
sched_show_runqueues(), it specifically avoidsprint_cpu()and only callsprint_rq(NULL, rq, cpu, false, true). Insideprint_rq(), it merely iterates threads underrcu_read_lock()and callsprint_task(), neither of which acquiresrq->lock. Hence,rq->lockis never taken again, and the non-blocking guarantee of the trylock remains intact throughout the entire dump.OK. So perhaps add a few comments / annotations that these paths should stay clear of rq-lock. It is too easy for it to get added.
Understood, will do.
Quoted 18 lines
Quoted 12 lines
Quoted 6 lines
lib/sys_info.c static void __sys_info(unsigned long si_mask) · line 165
Quoted 3 lines
lib/sys_info.c +2
-0+if (si_mask &SYS_INFO_CPU_RUNQUEUES ) +sched_show_runqueues (); }I really don't know if this is worth the trouble. I have *never* needed this.
I understand. However, the requirement primarily arises in production support. In environments where kdump is not configured or the resulting vmcore is truncated, dmesg is frequently the sole surviving diagnostic artefact.
Quoted 5 lines
During an NMI-induced panic, capturing per-CPU runqueue depth in the log is invaluable for identifying CPU starvation, etc. As with the remainder of
sys_info, this functionality is strictly opt-in and disabled by default, imposing no overhead on systems that do not require it while providing vital visibility where full memory dumps are unavailable.
Quoted 7 lines
What is the main thing holding 'you' back from enabling kdump everywhere? AFAIU crash dump can be configured to only dump kernel data structures, which is a lot more economical than a complete memory dump.
Mostly I just worry about death by a thousand cuts and all that. I don't have a very strong objection to this, just wondering if we really need it.
Indeed, filtering via makedumpfile (e.g. -d 31) certainly mitigates dump file size. However, even with kdump configured, our primary motivation is added flexibility, ensuring visibility when a usable vmcore cannot be saved.
Unfortunately, we have encountered a dump target that run out of storage, when prior unpurged vmcores have accumulated. When this occurs, writing /proc/vmcore fails or gets truncated, rendering the dump too incomplete to extract dmesg.
Crucially, kdump extract vmcore-dmesg.txt first. Because it requires only a few megabytes, it routinely succeeds. Capturing SYS_INFO_CPU_RUNQUEUES ensures that runnable task demand and per-CPU runqueue depth remain preserved in vmcore-dmesg.txt (or e.g. serial console) as the sole surviving diagnostic artefact.
Kind regards,
Signature · 1 line
Aaron Tomlin