Skip to contentSkip to conversation

sched/debug: schedstats bug fix and improvement

PATCH In review Josh Poimboeuf 3 participants 8 messages Jun 3, 2016 – Jun 8, 2016 Scheduler

lore
Share & tools
lore
#0 lore raw

v2 cover sched/debug: schedstats bug fix and improvement

v2:
- fixed !SCHEDSTATS build for patch 1 using new schedstat_val() macro
- dropped patch 3

A schedstats-related bug fix and improvement.

Josh Poimboeuf (2):
sched/debug: fix /proc/sched_debug regression
sched/debug: always show nr_migrations

 kernel/sched/debug.c | 17 +++++------------
 kernel/sched/stats.h |  3 +++
 2 files changed, 8 insertions(+), 12 deletions(-)
Signature · 1 line
2.4.11
#1 lore raw

PATCH v2 1/2 sched/debug: fix /proc/sched_debug regression

Commit cb2517653fcc ("sched/debug: Make schedstats a runtime tunable that is disabled by default") introduced a bug when CONFIG_SCHEDSTATS is enabled and the runtime tunable is disabled (which is the default). The wait-time, sum-exec, and sum-sleep fields are missing from the /proc/sched_debug file in the runnable_tasks section.

Fix it with a new schedstat_val() macro which returns the field value when schedstats is enabled and zero otherwise. The macro works with both SCHEDSTATS and !SCHEDSTATS. I put the macro in stats.h since it might end up being useful in other places.

Fixes cb2517653fcc ("sched/debug: Make schedstats a runtime tunable that is disabled by default")
---
 kernel/sched/debug.c | 15 ++++-----------
 kernel/sched/stats.h |  3 +++
 2 files changed, 7 insertions(+), 11 deletions(-)
kernel/sched/debug.c +4 -11
index cf905f6..0368c39 100644
@@ -427,19 +427,12 @@ print_task(struct seq_file *m, struct rq *rq, struct task_struct *p)
 		SPLIT_NS(p->se.vruntime),
 		(long long)(p->nvcsw + p->nivcsw),
 		p->prio);
-#ifdef CONFIG_SCHEDSTATS
-	if (schedstat_enabled()) {
-		SEQ_printf(m, "%9Ld.%06ld %9Ld.%06ld %9Ld.%06ld",
-			SPLIT_NS(p->se.statistics.wait_sum),
-			SPLIT_NS(p->se.sum_exec_runtime),
-			SPLIT_NS(p->se.statistics.sum_sleep_runtime));
-	}
-#else
+
 	SEQ_printf(m, "%9Ld.%06ld %9Ld.%06ld %9Ld.%06ld",
-		0LL, 0L,
+		SPLIT_NS(schedstat_val(p, se.statistics.wait_sum)),
 		SPLIT_NS(p->se.sum_exec_runtime),
-		0LL, 0L);
-#endif
+		SPLIT_NS(schedstat_val(p, se.statistics.sum_sleep_runtime)));
+
 #ifdef CONFIG_NUMA_BALANCING
 	SEQ_printf(m, " %d %d", task_node(p), task_numa_group_id(p));
 #endif
kernel/sched/stats.h +3 -0
index 70b3b6a..78955cb 100644
@@ -33,6 +33,8 @@ rq_sched_info_dequeued(struct rq *rq, unsigned long long delta)
 # define schedstat_inc(rq, field)	do { if (schedstat_enabled()) { (rq)->field++; } } while (0)
 # define schedstat_add(rq, field, amt)	do { if (schedstat_enabled()) { (rq)->field += (amt); } } while (0)
 # define schedstat_set(var, val)	do { if (schedstat_enabled()) { var = (val); } } while (0)
+# define schedstat_val(rq, field)	((schedstat_enabled()) ? (rq)->field : 0)
+
 #else /* !CONFIG_SCHEDSTATS */
 static inline void
 rq_sched_info_arrive(struct rq *rq, unsigned long long delta)
@@ -47,6 +49,7 @@ rq_sched_info_depart(struct rq *rq, unsigned long long delta)
 # define schedstat_inc(rq, field)	do { } while (0)
 # define schedstat_add(rq, field, amt)	do { } while (0)
 # define schedstat_set(var, val)	do { } while (0)
+# define schedstat_val(rq, field)	0
 #endif
 
 #ifdef CONFIG_SCHED_INFO
Signature · 1 line
2.4.11
Acked-by on v2 1/2
#2 lore raw

Re: [PATCH v2 1/2] sched/debug: fix /proc/sched_debug regression

Quoted 6 lines · Josh Poimboeuf

Commit cb2517653fcc ("sched/debug: Make schedstats a runtime tunable that is disabled by default") introduced a bug when CONFIG_SCHEDSTATS is enabled and the runtime tunable is disabled (which is the default). The wait-time, sum-exec, and sum-sleep fields are missing from the /proc/sched_debug file in the runnable_tasks section.

I take it that this breaks userspace parsing?

Quoted 8 lines

Fix it with a new schedstat_val() macro which returns the field value when schedstats is enabled and zero otherwise. The macro works with both SCHEDSTATS and !SCHEDSTATS. I put the macro in stats.h since it might end up being useful in other places.

Fixes cb2517653fcc ("sched/debug: Make schedstats a runtime tunable that is disabled by default")
Signature · 2 lines
Mel Gorman
SUSE Labs
#3 lore raw

Re: [PATCH v2 1/2] sched/debug: fix /proc/sched_debug regression

Quoted 9 lines · Mel Gorman
Quoted 6 lines · Josh Poimboeuf

Commit cb2517653fcc ("sched/debug: Make schedstats a runtime tunable that is disabled by default") introduced a bug when CONFIG_SCHEDSTATS is enabled and the runtime tunable is disabled (which is the default). The wait-time, sum-exec, and sum-sleep fields are missing from the /proc/sched_debug file in the runnable_tasks section.

I take it that this breaks userspace parsing?

In theory, yes, though I don't know if there are any tools out there which parse it.

Quoted 10 lines
Quoted 8 lines

Fix it with a new schedstat_val() macro which returns the field value when schedstats is enabled and zero otherwise. The macro works with both SCHEDSTATS and !SCHEDSTATS. I put the macro in stats.h since it might end up being useful in other places.

Fixes cb2517653fcc ("sched/debug: Make schedstats a runtime tunable that is disabled by default")

Thanks!

Signature · 1 line
Josh
#4 lore raw

[tip:sched/core] sched/debug: Fix /proc/sched_debug regression

In reply to Josh Poimboeuf
sched/debug: Fix /proc/sched_debug regression
Commit-ID:  9c57259117b9c25472a3fa6d5a14d6bb3b647e87
Gitweb:     http://git.kernel.org/tip/9c57259117b9c25472a3fa6d5a14d6bb3b647e87
Author:     Josh Poimboeuf <[email protected]>
AuthorDate: Fri, 3 Jun 2016 17:58:40 -0500
Committer:  Ingo Molnar <[email protected]>
CommitDate: Wed, 8 Jun 2016 14:31:58 +0200

sched/debug: Fix /proc/sched_debug regression

Commit:

cb2517653fcc ("sched/debug: Make schedstats a runtime tunable that is disabled by default")

... introduced a bug when CONFIG_SCHEDSTATS is enabled and the runtime tunable is disabled (which is the default).

The wait-time, sum-exec, and sum-sleep fields are missing from the /proc/sched_debug file in the runnable_tasks section.

Fix it with a new schedstat_val() macro which returns the field value when schedstats is enabled and zero otherwise. The macro works with both SCHEDSTATS and !SCHEDSTATS. I put the macro in stats.h since it might end up being useful in other places.

Cc Linus Torvalds <[email protected]>
Cc Matt Fleming <[email protected]>
Cc Peter Zijlstra <[email protected]>
Cc Srikar Dronamraju <[email protected]>
Cc Thomas Gleixner <[email protected]>
Fixes cb2517653fcc ("sched/debug: Make schedstats a runtime tunable that is disabled by default")
---
 kernel/sched/debug.c | 15 ++++-----------
 kernel/sched/stats.h |  3 +++
 2 files changed, 7 insertions(+), 11 deletions(-)
kernel/sched/debug.c +4 -11
index cf905f6..0368c39 100644
@@ -427,19 +427,12 @@ print_task(struct seq_file *m, struct rq *rq, struct task_struct *p)
 		SPLIT_NS(p->se.vruntime),
 		(long long)(p->nvcsw + p->nivcsw),
 		p->prio);
-#ifdef CONFIG_SCHEDSTATS
-	if (schedstat_enabled()) {
-		SEQ_printf(m, "%9Ld.%06ld %9Ld.%06ld %9Ld.%06ld",
-			SPLIT_NS(p->se.statistics.wait_sum),
-			SPLIT_NS(p->se.sum_exec_runtime),
-			SPLIT_NS(p->se.statistics.sum_sleep_runtime));
-	}
-#else
+
 	SEQ_printf(m, "%9Ld.%06ld %9Ld.%06ld %9Ld.%06ld",
-		0LL, 0L,
+		SPLIT_NS(schedstat_val(p, se.statistics.wait_sum)),
 		SPLIT_NS(p->se.sum_exec_runtime),
-		0LL, 0L);
-#endif
+		SPLIT_NS(schedstat_val(p, se.statistics.sum_sleep_runtime)));
+
 #ifdef CONFIG_NUMA_BALANCING
 	SEQ_printf(m, " %d %d", task_node(p), task_numa_group_id(p));
 #endif
kernel/sched/stats.h +3 -0
index 70b3b6a..78955cb 100644
@@ -33,6 +33,8 @@ rq_sched_info_dequeued(struct rq *rq, unsigned long long delta)
 # define schedstat_inc(rq, field)	do { if (schedstat_enabled()) { (rq)->field++; } } while (0)
 # define schedstat_add(rq, field, amt)	do { if (schedstat_enabled()) { (rq)->field += (amt); } } while (0)
 # define schedstat_set(var, val)	do { if (schedstat_enabled()) { var = (val); } } while (0)
+# define schedstat_val(rq, field)	((schedstat_enabled()) ? (rq)->field : 0)
+
 #else /* !CONFIG_SCHEDSTATS */
 static inline void
 rq_sched_info_arrive(struct rq *rq, unsigned long long delta)
@@ -47,6 +49,7 @@ rq_sched_info_depart(struct rq *rq, unsigned long long delta)
 # define schedstat_inc(rq, field)	do { } while (0)
 # define schedstat_add(rq, field, amt)	do { } while (0)
 # define schedstat_set(var, val)	do { } while (0)
+# define schedstat_val(rq, field)	0
 #endif
 
 #ifdef CONFIG_SCHED_INFO
#5 lore raw

PATCH v2 2/2 sched/debug: always show nr_migrations

In reply to Josh Poimboeuf

The nr_migrations field is updated independently of CONFIG_SCHEDSTATS, so it can be displayed regardless.

---
 kernel/sched/debug.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
kernel/sched/debug.c +1 -1
index 0368c39..2a0a999 100644
@@ -879,9 +879,9 @@ void proc_sched_show_task(struct task_struct *p, struct seq_file *m)
 
 	nr_switches = p->nvcsw + p->nivcsw;
 
-#ifdef CONFIG_SCHEDSTATS
 	P(se.nr_migrations);
 
+#ifdef CONFIG_SCHEDSTATS
 	if (schedstat_enabled()) {
 		u64 avg_atom, avg_per_cpu;
 
Signature · 1 line
2.4.11
#7 lore raw

[tip:sched/core] sched/debug: Always show 'nr_migrations'

In reply to Josh Poimboeuf
sched/debug: Always show 'nr_migrations'
Commit-ID:  03c041c5bf6ed584dff36b7cd509e0146a124277
Gitweb:     http://git.kernel.org/tip/03c041c5bf6ed584dff36b7cd509e0146a124277
Author:     Josh Poimboeuf <[email protected]>
AuthorDate: Fri, 3 Jun 2016 17:58:41 -0500
Committer:  Ingo Molnar <[email protected]>
CommitDate: Wed, 8 Jun 2016 14:34:49 +0200

sched/debug: Always show 'nr_migrations'

The nr_migrations field is updated independently of CONFIG_SCHEDSTATS, so it can be displayed regardless.

---
 kernel/sched/debug.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
kernel/sched/debug.c +1 -1
index 0368c39..2a0a999 100644
@@ -879,9 +879,9 @@ void proc_sched_show_task(struct task_struct *p, struct seq_file *m)
 
 	nr_switches = p->nvcsw + p->nivcsw;
 
-#ifdef CONFIG_SCHEDSTATS
 	P(se.nr_migrations);
 
+#ifdef CONFIG_SCHEDSTATS
 	if (schedstat_enabled()) {
 		u64 avg_atom, avg_per_cpu;