scheduler: enhancement to show_state_filter
Subsystems (2)
PATCH v2 1/1 scheduler: enhancement to show_state_filter
Sometimes we want to get tasks in TASK_RUNNING sepcifically, instead of dump all tasks.
For example, when the loadavg are high, we want to dump tasks in TASK_RUNNING and TASK_UNINTERRUPTIBLE, which contribute to system load. But mostly there're lots of tasks in Sleep state, which occupies almost all of the kernel log buffer, even overflows it, that causes the useful messages get lost. Although we can enlarge the kernel log buffer, but that's not a good idea.
So I made this change to make the show_state_filter more flexible, and then we can dump the tasks in TASK_RUNNING specifically.
--- drivers/tty/sysrq.c | 2 +- include/linux/sched.h | 1 + include/linux/sched/debug.h | 6 ++++-- kernel/sched/core.c | 7 ++++--- 4 files changed, 10 insertions(+), 6 deletions(-)
drivers/tty/sysrq.c +1 -1
@@ -291,7 +291,7 @@ static void sysrq_handle_showstate(int key)static void sysrq_handle_showstate_blocked (int key) { -show_state_filter (TASK_UNINTERRUPTIBLE ); +show_state_filter (TASK_UNINTERRUPTIBLE <<1 ); }static struct sysrq_key_op sysrq_showstate_blocked_op = { .handler = sysrq_handle_showstate_blocked,
include/linux/sched.h +1 -0
@@ -82,6 +82,7 @@#define TASK_NOLOAD 1024#define TASK_NEW 2048#define TASK_STATE_MAX 4096 +#define TASK_ALL_BITS ((TASK_STATE_MAX << 1) - 1)#define TASK_STATE_TO_CHAR_STR "RSDTtXZxKWPNn"
include/linux/sched/debug.h +4 -2
@@ -1,6 +1,8 @@#ifndef _LINUX_SCHED_DEBUG_H#define _LINUX_SCHED_DEBUG_H +#include <linux/sched.h> +/* * Various scheduler/task debugging interfaces: */
@@ -10,13 +12,13 @@extern void dump_cpu_task (int cpu);/* -* Only dump TASK_* tasks. (0 for all tasks) +* Only dump TASK_* tasks. (TASK_ALL_BITS for all tasks) */ extern void show_state_filter (unsigned long state_filter);static inline void show_state (void ) { -show_state_filter (0 ); +show_state_filter (TASK_ALL_BITS ); }struct pt_regs ;
kernel/sched/core.c +4 -3
@@ -5161,19 +5161,20 @@ void show_state_filter(unsigned long state_filter)*/ touch_nmi_watchdog ();touch_all_softlockup_watchdogs (); -if (!state_filter || (p->state & state_filter)) +/* in case we want to set TASK_RUNNING specifically */ +if ((p->state !=TASK_RUNNING ? p->state <<1 :1 ) & state_filter)sched_show_task (p); }#ifdef CONFIG_SCHED_DEBUG -if (!state_filter) +if (state_filter ==TASK_ALL_BITS )sysrq_sched_debug_show ();#endif rcu_read_unlock ();/* * Only show locks if all tasks are dumped: */ -if (!state_filter) +if (state_filter ==TASK_ALL_BITS )debug_show_all_locks (); }
Signature · 1 line
1.8.3.1
Peter Zijlstra
maintainerQuoted 11 lines · Yafang Shao
Sometimes we want to get tasks in
TASK_RUNNINGsepcifically, instead of dump all tasks.
For example, when the loadavg are high, we want to dump tasks inTASK_RUNNINGandTASK_UNINTERRUPTIBLE, which contribute to system load. But mostly there're lots of tasks in Sleep state, which occupies almost all of the kernel log buffer, even overflows it, that causes the useful messages get lost. Although we can enlarge the kernel log buffer, but that's not a good idea.So I made this change to make the
show_state_filtermore flexible, and then we can dump the tasks inTASK_RUNNINGspecifically.
It reads like magic and I really don't see the point.
Hi Peter,
The point is we call use it as bellow,
show_state_filter(TASK_RUNNING);
because TASK_RUNNING is 0, that will dump all tasks.
Under some circumstance, we need this to dump only tasks in TASK_RUNNING state.
Thanks
Yafang
2017-08-08 16:30 GMT+08:00 Peter Zijlstra <[email protected]>:
Quoted 14 lines · Yafang Shao
Quoted 11 lines
Sometimes we want to get tasks in
TASK_RUNNINGsepcifically, instead of dump all tasks.
For example, when the loadavg are high, we want to dump tasks inTASK_RUNNINGandTASK_UNINTERRUPTIBLE, which contribute to system load. But mostly there're lots of tasks in Sleep state, which occupies almost all of the kernel log buffer, even overflows it, that causes the useful messages get lost. Although we can enlarge the kernel log buffer, but that's not a good idea.So I made this change to make the
show_state_filtermore flexible, and then we can dump the tasks inTASK_RUNNINGspecifically.It reads like magic and I really don't see the point.
Peter Zijlstra
maintainerQuoted 7 lines · Yafang Shao
Hi Peter,
The point is we call use it as bellow,
show_state_filter(TASK_RUNNING);because
TASK_RUNNINGis 0, that will dump all tasks.Under some circumstance, we need this to dump only tasks in
TASK_RUNNINGstate.
But the patch doesn't introduce any of that. It just makes the existing code unreadable.
Hi Peter,
In oder to make it readable, I have comment in the patch why this change is made,
- if (!state_filter || (p->state & state_filter))
+ /* in case we want to set TASK_RUNNING specifically */
+ if ((p->state != TASK_RUNNING ? p->state << 1 : 1)
& state_filter)
sched_show_task(p);show_state_filter() is only used in SysRq, in which we can dump all tasks (with the key 't'), or uninterruptible tasks(with the key 'w'). I think we should also dump only running tasks (with a new key, or something else).
But in order to introduce the new key, we should made this change first.
After this change got approved, I will try to make some changes in SysRq.
Thanks
Yafang
2017-08-08 18:24 GMT+08:00 Peter Zijlstra <[email protected]>:
Quoted 11 lines · Yafang Shao
Quoted 7 lines
Hi Peter,
The point is we call use it as bellow,
show_state_filter(TASK_RUNNING);because
TASK_RUNNINGis 0, that will dump all tasks.Under some circumstance, we need this to dump only tasks in
TASK_RUNNINGstate.But the patch doesn't introduce any of that. It just makes the existing code unreadable.
Peter Zijlstra
maintainerQuoted 1 line · Yafang Shao
After this change got approved, I will try to make some changes in SysRq.
No, that's not how it works. Show the whole work.
Okay.
I will submit the whole work in a new patch later.
2017-08-08 19:04 GMT+08:00 Peter Zijlstra <[email protected]>:
Quoted 4 lines · Yafang Shao
Quoted 1 line
After this change got approved, I will try to make some changes in SysRq.
No, that's not how it works. Show the whole work.
Peter Zijlstra
maintainerA: Because it messes up the order in which people normally read text.
Q: Why is top-posting such a bad thing?
A: Top-posting.
Q: What is the most annoying thing in e-mail?On Tue, Aug 08, 2017 at 07:07:26PM +0800, Yafang Shao wrote:
2017-08-08 19:24 GMT+08:00 Peter Zijlstra <[email protected]>:
Quoted 4 lines
A: Because it messes up the order in which people normally read text.
Q: Why is top-posting such a bad thing?
A: Top-posting.
Q: What is the most annoying thing in e-mail?On Tue, Aug 08, 2017 at 07:07:26PM +0800, Yafang Shao wrote:
Thanks for your correction.
I will bottom-posting afterwards:)
Thanks
Yafang