From: Cong Wang <xiyou.wangcong@gmail.com>
To: linux-kernel@vger.kernel.org
Cc: Cong Wang <xiyou.wangcong@gmail.com>,
Steven Rostedt <rostedt@goodmis.org>,
Ingo Molnar <mingo@redhat.com>,
Peter Zijlstra <peterz@infradead.org>,
Cong Wang <cwang@twopensource.com>
Subject: [PATCH] sched: split sched_switch trace event into two
Date: Wed, 24 Jun 2015 16:19:33 -0700 [thread overview]
Message-ID: <1435187973-23931-1-git-send-email-xiyou.wangcong@gmail.com> (raw)
Currently we only have one sched_switch trace event
for task switching, which is generated very early during
task switch. When we try to monitor per-container events,
this is not what we expect.
For example, we have a process A which is in the cgroup
we monitor, and process B which isn't, when kernel switches
from B to A, the sched_switch event is not recorded for this
cgroup since it belongs to B (current process is still B
util we finish the switch), but we require this event to
signal that process A in this cgroup gets scheduled. This is
crucial for calculating schedule latency.
So split the sched_switch event into two: sched_in event
before we perform the switch, and sched_out event after we
perform the switch.
For compatibility, the sched_switch event is not touched.
Cc: Steven Rostedt <rostedt@goodmis.org>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Signed-off-by: Cong Wang <xiyou.wangcong@gmail.com>
Signed-off-by: Cong Wang <cwang@twopensource.com>
---
include/trace/events/sched.h | 51 +++++++++++++++++++++++++++++++++++++++++++-
kernel/sched/core.c | 2 ++
2 files changed, 52 insertions(+), 1 deletion(-)
diff --git a/include/trace/events/sched.h b/include/trace/events/sched.h
index d57a575..c31f1e0 100644
--- a/include/trace/events/sched.h
+++ b/include/trace/events/sched.h
@@ -112,8 +112,57 @@ static inline long __trace_sched_switch_state(struct task_struct *p)
#endif /* CREATE_TRACE_POINTS */
/*
- * Tracepoint for task switches, performed by the scheduler:
+ * Tracepoints for task switches, performed by the scheduler:
*/
+TRACE_EVENT(sched_out,
+
+ TP_PROTO(struct task_struct *curr),
+
+ TP_ARGS(curr),
+
+ TP_STRUCT__entry(
+ __array( char, comm, TASK_COMM_LEN )
+ __field( int, prio )
+ __field( long, state )
+ ),
+
+ TP_fast_assign(
+ __entry->prio = curr->prio;
+ __entry->state = __trace_sched_switch_state(curr);
+ memcpy(__entry->comm, curr->comm, TASK_COMM_LEN);
+ ),
+
+ TP_printk("comm=%s prio=%d state=%s%s",
+ __entry->comm, __entry->prio,
+ __entry->state & (TASK_STATE_MAX-1) ?
+ __print_flags(__entry->state & (TASK_STATE_MAX-1), "|",
+ { 1, "S"} , { 2, "D" }, { 4, "T" }, { 8, "t" },
+ { 16, "Z" }, { 32, "X" }, { 64, "x" },
+ { 128, "K" }, { 256, "W" }, { 512, "P" },
+ { 1024, "N" }) : "R",
+ __entry->state & TASK_STATE_MAX ? "+" : "")
+);
+
+TRACE_EVENT(sched_in,
+
+ TP_PROTO(struct task_struct *next),
+
+ TP_ARGS(next),
+
+ TP_STRUCT__entry(
+ __array( char, comm, TASK_COMM_LEN )
+ __field( int, prio )
+ ),
+
+ TP_fast_assign(
+ memcpy(__entry->comm, next->comm, TASK_COMM_LEN);
+ __entry->prio = next->prio;
+ ),
+
+ TP_printk("comm=%s prio=%d",
+ __entry->comm, __entry->prio)
+);
+
TRACE_EVENT(sched_switch,
TP_PROTO(struct task_struct *prev,
diff --git a/kernel/sched/core.c b/kernel/sched/core.c
index c86935a..681fc50 100644
--- a/kernel/sched/core.c
+++ b/kernel/sched/core.c
@@ -2219,6 +2219,7 @@ prepare_task_switch(struct rq *rq, struct task_struct *prev,
struct task_struct *next)
{
trace_sched_switch(prev, next);
+ trace_sched_out(prev);
sched_info_switch(rq, prev, next);
perf_event_task_sched_out(prev, next);
fire_sched_out_preempt_notifiers(prev, next);
@@ -2288,6 +2289,7 @@ static struct rq *finish_task_switch(struct task_struct *prev)
}
tick_nohz_task_switch(current);
+ trace_sched_in(current);
return rq;
}
--
1.8.3.1
next reply other threads:[~2015-06-24 23:19 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-06-24 23:19 Cong Wang [this message]
2015-06-25 1:05 ` [PATCH] sched: split sched_switch trace event into two Steven Rostedt
2015-06-25 17:04 ` Cong Wang
2015-06-25 7:48 ` Peter Zijlstra
2015-06-25 17:17 ` Cong Wang
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1435187973-23931-1-git-send-email-xiyou.wangcong@gmail.com \
--to=xiyou.wangcong@gmail.com \
--cc=cwang@twopensource.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@redhat.com \
--cc=peterz@infradead.org \
--cc=rostedt@goodmis.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).