Skip to content

Commit 27d2fe5

Browse files
Byte-LabKernel Patches Daemon
authored and
Kernel Patches Daemon
committed
sched_ext: Print sched_ext info when dumping stack
It would be useful to see what the sched_ext scheduler state is, and what scheduler is running, when we're dumping a task's stack. This patch therefore adds a new print_scx_info() function that's called in the same context as print_worker_info() and print_stop_info(). An example dump follows. BUG: kernel NULL pointer dereference, address: 0000000000000999 #PF: supervisor write access in kernel mode #PF: error_code(0x0002) - not-present page PGD 0 P4D 0 Oops: 0002 [#1] PREEMPT SMP CPU: 13 PID: 2047 Comm: insmod Tainted: G O 6.6.0-work-10323-gb58d4cae8e99-dirty #34 Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS unknown 2/2/2022 Sched_ext: qmap (enabled+all), task: runnable_at=-17ms RIP: 0010:init_module+0x9/0x1000 [test_module] ... Signed-off-by: David Vernet <[email protected]> Signed-off-by: Tejun Heo <[email protected]>
1 parent 67bee31 commit 27d2fe5

File tree

4 files changed

+49
-0
lines changed

4 files changed

+49
-0
lines changed

include/linux/sched/ext.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -428,10 +428,12 @@ struct sched_ext_entity {
428428
};
429429

430430
void sched_ext_free(struct task_struct *p);
431+
void print_scx_info(const char *log_lvl, struct task_struct *p);
431432

432433
#else /* !CONFIG_SCHED_CLASS_EXT */
433434

434435
static inline void sched_ext_free(struct task_struct *p) {}
436+
static inline void print_scx_info(const char *log_lvl, struct task_struct *p) {}
435437

436438
#endif /* CONFIG_SCHED_CLASS_EXT */
437439
#endif /* _LINUX_SCHED_EXT_H */

kernel/sched/core.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9217,6 +9217,7 @@ void sched_show_task(struct task_struct *p)
92179217

92189218
print_worker_info(KERN_INFO, p);
92199219
print_stop_info(KERN_INFO, p);
9220+
print_scx_info(KERN_INFO, p);
92209221
show_stack(p, NULL, KERN_INFO);
92219222
put_task_stack(p);
92229223
}

kernel/sched/ext.c

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2787,6 +2787,51 @@ static const struct sysrq_key_op sysrq_sched_ext_reset_op = {
27872787
.enable_mask = SYSRQ_ENABLE_RTNICE,
27882788
};
27892789

2790+
/**
2791+
* print_scx_info - print out sched_ext scheduler state
2792+
* @log_lvl: the log level to use when printing
2793+
* @p: target task
2794+
*
2795+
* If a sched_ext scheduler is enabled, print the name and state of the
2796+
* scheduler. If @p is on sched_ext, print further information about the task.
2797+
*
2798+
* This function can be safely called on any task as long as the task_struct
2799+
* itself is accessible. While safe, this function isn't synchronized and may
2800+
* print out mixups or garbages of limited length.
2801+
*/
2802+
void print_scx_info(const char *log_lvl, struct task_struct *p)
2803+
{
2804+
enum scx_ops_enable_state state = scx_ops_enable_state();
2805+
const char *all = READ_ONCE(scx_switching_all) ? "+all" : "";
2806+
char runnable_at_buf[22] = "?";
2807+
struct sched_class *class;
2808+
unsigned long runnable_at;
2809+
2810+
if (state == SCX_OPS_DISABLED)
2811+
return;
2812+
2813+
/*
2814+
* Carefully check if the task was running on sched_ext, and then
2815+
* carefully copy the time it's been runnable, and its state.
2816+
*/
2817+
if (copy_from_kernel_nofault(&class, &p->sched_class, sizeof(class)) ||
2818+
class != &ext_sched_class) {
2819+
printk("%sSched_ext: %s (%s%s)", log_lvl, scx_ops.name,
2820+
scx_ops_enable_state_str[state], all);
2821+
return;
2822+
}
2823+
2824+
if (!copy_from_kernel_nofault(&runnable_at, &p->scx.runnable_at,
2825+
sizeof(runnable_at)))
2826+
scnprintf(runnable_at_buf, sizeof(runnable_at_buf), "%+lldms",
2827+
(s64)(runnable_at - jiffies) * (HZ / MSEC_PER_SEC));
2828+
2829+
/* Print everything onto one line to conserve console spce. */
2830+
printk("%sSched_ext: %s (%s%s), task: runnable_at=%s",
2831+
log_lvl, scx_ops.name, scx_ops_enable_state_str[state], all,
2832+
runnable_at_buf);
2833+
}
2834+
27902835
void __init init_sched_ext_class(void)
27912836
{
27922837
int cpu;

lib/dump_stack.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ void dump_stack_print_info(const char *log_lvl)
6868

6969
print_worker_info(log_lvl, current);
7070
print_stop_info(log_lvl, current);
71+
print_scx_info(log_lvl, current);
7172
}
7273

7374
/**

0 commit comments

Comments
 (0)