Skip to contentSkip to conversation

scheduler: enhancement to show_state_filter

PATCH Superseded Yafang Shao 2 participants 9 messages Aug 8, 2017

Subsystems (2)

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

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
index 3ffc1ce..86db51b 100644
@@ -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
index 8337e2d..318f149 100644
@@ -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
index e0eaee5..c844689 100644
@@ -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
index 0869b20..f9b9529 100644
@@ -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
maintainer
#1 lore raw
Quoted 11 lines · Yafang Shao

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.

It reads like magic and I really don't see the point.

#2 lore raw

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_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.

It reads like magic and I really don't see the point.

maintainer
#3 lore raw
Quoted 7 lines · Yafang Shao

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.

But the patch doesn't introduce any of that. It just makes the existing code unreadable.

#4 lore raw

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_RUNNING is 0, that will dump all tasks.

Under some circumstance, we need this to dump only tasks in TASK_RUNNING state.

But the patch doesn't introduce any of that. It just makes the existing code unreadable.

maintainer
#5 lore raw
Quoted 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.

#6 lore raw

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.

maintainer
#7 lore raw

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:

#8 lore raw

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