mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Andrew Vagin <avagin@openvz.org>
To: unlisted-recipients:; (no To-header on input)
Cc: Arun Sharma <asharma@fb.com>, Oleg Strikov <OSTRIKOV@nvidia.com>,
	Steven Rostedt <rostedt@goodmis.org>,
	Frederic Weisbecker <fweisbec@gmail.com>,
	Ingo Molnar <mingo@redhat.com>,
	Peter Zijlstra <a.p.zijlstra@chello.nl>,
	linux-kernel@vger.kernel.org
Subject: [PATCH 3/5] sched: save a previous state on task_struct
Date: Mon,  4 Jun 2012 12:09:40 +0400	[thread overview]
Message-ID: <1338797382-287275-4-git-send-email-avagin@openvz.org> (raw)
In-Reply-To: <1338797382-287275-1-git-send-email-avagin@openvz.org>

prev_state is a state of task, when it stops executing on cpu.

It's needed for filtering sched:sched_switch_finish.
For example If we want to track when a task is sleeping:

./perf record -e sched:sched_switch -g --filter 'prev_state == 1' \
	-e sched:sched_switch_finish --filter 'state == 1' -P  foo

The previous state is set in sched:sched_switch, so it works when
both events sched:sched_switch and sched:sched_switch_finish are
enabled.

Signed-off-by: Andrew Vagin <avagin@openvz.org>
---
 include/linux/sched.h        |    3 +++
 include/trace/events/sched.h |   12 +++++++++++-
 2 files changed, 14 insertions(+), 1 deletions(-)

diff --git a/include/linux/sched.h b/include/linux/sched.h
index f45c0b2..172bbe3 100644
--- a/include/linux/sched.h
+++ b/include/linux/sched.h
@@ -1576,6 +1576,9 @@ struct task_struct {
 	struct uprobe_task *utask;
 	int uprobe_srcu_id;
 #endif
+#ifdef CONFIG_EVENT_TRACING
+	volatile long prev_state;
+#endif
 };
 
 /* Future-safe accessor for struct task_struct's cpus_allowed. */
diff --git a/include/trace/events/sched.h b/include/trace/events/sched.h
index b2219d8..c1b70b1 100644
--- a/include/trace/events/sched.h
+++ b/include/trace/events/sched.h
@@ -133,6 +133,7 @@ TRACE_EVENT(sched_switch,
 		__entry->prev_pid	= prev->pid;
 		__entry->prev_prio	= prev->prio;
 		__entry->prev_state	= __trace_sched_switch_state(prev);
+		prev->prev_state	= __trace_sched_switch_state(prev);
 		memcpy(__entry->prev_comm, prev->comm, TASK_COMM_LEN);
 		__entry->next_pid	= next->pid;
 		__entry->next_prio	= next->prio;
@@ -158,14 +159,23 @@ TRACE_EVENT(sched_switch_finish,
 	TP_STRUCT__entry(
 		__array(	char,	comm,	TASK_COMM_LEN	)
 		__field(	pid_t,	pid			)
+		__field(	long,	state			)
 	),
 
 	TP_fast_assign(
 		__entry->pid	= p->pid;
+		__entry->state	= p->prev_state;
 		memcpy(__entry->comm, p->comm, TASK_COMM_LEN);
 	),
 
-	TP_printk("comm=%s pid=%d", __entry->comm, __entry->pid)
+	TP_printk("comm=%s pid=%d state=%s%s",
+		__entry->comm, __entry->pid,
+		__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, "W" }) : "R",
+		__entry->state & TASK_STATE_MAX ? "+" : "")
 );
 
 /*
-- 
1.7.1


  parent reply	other threads:[~2012-06-04  8:10 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-06-04  8:09 [RFC] [PATCH 0/5] Teach perf tool to profile sleep times (V4) Andrew Vagin
2012-06-04  8:09 ` [PATCH 1/5] sched: event: add trace events when a task starts executing on a cpu Andrew Vagin
2012-06-04  8:09 ` [PATCH 2/5] sched: send the event sched_switch before perf_event_task_sched_out Andrew Vagin
2012-06-04  8:09 ` Andrew Vagin [this message]
2012-06-04  8:09 ` [PATCH 4/5] perf: teach "perf inject" to work with files Andrew Vagin
2012-06-04  8:09 ` [PATCH 5/5] perf: teach perf inject to merge sched_switch* events for profiling sleep times Andrew Vagin
2012-06-04 12:40 ` [RFC] [PATCH 0/5] Teach perf tool to profile sleep times (V4) Peter Zijlstra
2012-06-04 12:50   ` Peter Zijlstra
2012-06-04 13:46   ` Steven Rostedt
2012-06-04 17:01   ` Arun Sharma
2012-06-04 20:52     ` Peter Zijlstra
2012-06-06  8:32   ` Ingo Molnar
2012-06-12 13:15   ` Andrew Wagin
2012-06-12 17:46     ` Peter Zijlstra
2012-06-04 17:03 ` Arun Sharma

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=1338797382-287275-4-git-send-email-avagin@openvz.org \
    --to=avagin@openvz.org \
    --cc=OSTRIKOV@nvidia.com \
    --cc=a.p.zijlstra@chello.nl \
    --cc=asharma@fb.com \
    --cc=fweisbec@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@redhat.com \
    --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

all inboxes | Powered by JetHome®