2019-03-07 11:21:16

by Yafang Shao

[permalink] [raw]
Subject: [PATCH v2] sched: fair: fix missed CONFIG_SCHEDSTATS

When I'm using trace_sched_stat_{iowait, blocked, wait, sleep} to
measure how long the processes are stalled, there's always no output
from
trace_pipe while there're really some tasks in uninterruptible sleep
state. That makes me confused, so I try to investigate why.
Finally I find the reason is that CONFIG_SCHEDSTATS is not set.

To avoid such kind of confusion, we should not expose these tracepoints
if CONFIG_SCHEDSTATS is not set.

Signed-off-by: Yafang Shao <[email protected]>
---
include/trace/events/sched.h | 24 +++++++++++++++++++++++-
1 file changed, 23 insertions(+), 1 deletion(-)

diff --git a/include/trace/events/sched.h b/include/trace/events/sched.h
index 9a4bdfa..f060940 100644
--- a/include/trace/events/sched.h
+++ b/include/trace/events/sched.h
@@ -241,7 +241,6 @@ static inline long __trace_sched_switch_state(bool preempt, struct task_struct *
DEFINE_EVENT(sched_process_template, sched_process_free,
TP_PROTO(struct task_struct *p),
TP_ARGS(p));
-

/*
* Tracepoint for a task exiting:
@@ -336,6 +335,7 @@ static inline long __trace_sched_switch_state(bool preempt, struct task_struct *
__entry->pid, __entry->old_pid)
);

+#ifdef CONFIG_SCHEDSTATS
/*
* XXX the below sched_stat tracepoints only apply to SCHED_OTHER/BATCH/IDLE
* adding sched_stat support to SCHED_FIFO/RR would be welcome.
@@ -395,6 +395,28 @@ static inline long __trace_sched_switch_state(bool preempt, struct task_struct *
TP_PROTO(struct task_struct *tsk, u64 delay),
TP_ARGS(tsk, delay));

+#else
+
+#ifndef DEFINE_EVENT_NONE
+#define DEFINE_EVENT_NONE(name, var) \
+ static inline void trace_##name(var) \
+ { \
+ }
+
+DEFINE_EVENT_NONE(sched_stat_wait,
+ TP_PROTO(struct task_struct *tsk, u64 delay))
+
+DEFINE_EVENT_NONE(sched_stat_sleep,
+ TP_PROTO(struct task_struct *tsk, u64 delay))
+
+DEFINE_EVENT_NONE(sched_stat_iowait,
+ TP_PROTO(struct task_struct *tsk, u64 delay))
+
+DEFINE_EVENT_NONE(sched_stat_blocked,
+ TP_PROTO(struct task_struct *tsk, u64 delay))
+#endif
+#endif
+
/*
* Tracepoint for accounting runtime (time the task is executing
* on a CPU).
--
1.8.3.1