linux-perf-users.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Arun Sharma <asharma@fb.com>
To: linux-perf-users@vger.kernel.org
Cc: acme@ghostprotocols.net, Peter Zijlstra <peterz@infradead.org>,
	mingo@elte.hu, Stephane Eranian <eranian@google.com>
Subject: Profiling sleep times?
Date: Mon, 3 Oct 2011 12:38:59 -0700	[thread overview]
Message-ID: <4E8A0F53.7020408@fb.com> (raw)


Some of our users want to use perf to profile not just the code that 
consumes cycles, but also the code that ends up waiting for I/O - 
otherwise known as wall clock profiling.

I could not find ways of getting this info from the perf tool as-is. 
Wondering if a software event such as PERF_COUNT_SW_SLEEP_CLOCK below 
makes sense.

The idea is, if a task sleeps for 1ms, it should generate 1000x more 
samples vs a task that sleeps for 1us. Also, the callchain emitted 
should be the user stack.

If such an event is useful to a larger set of users, I could try to work 
out the details of how to get to event->attr.freq in the context switch 
path with low overhead and run some tests to verify that the profile 
that comes out of "perf report" looks sane.

We'll also need ways of combining PERF_COUNT_SW_TASK_CLOCK and 
PERF_COUNT_SW_SLEEP_CLOCK (in userspace?) to get the full picture.

  -Arun


diff --git a/include/linux/perf_event.h b/include/linux/perf_event.h
index c2da40d..a3e2fb4 100644
--- a/include/linux/perf_event.h
+++ b/include/linux/perf_event.h
@@ -106,6 +106,7 @@ enum perf_sw_ids {
         PERF_COUNT_SW_PAGE_FAULTS_MAJ           = 6,
         PERF_COUNT_SW_ALIGNMENT_FAULTS          = 7,
         PERF_COUNT_SW_EMULATION_FAULTS          = 8,
+       PERF_COUNT_SW_SLEEP_CLOCK               = 9,

         PERF_COUNT_SW_MAX,                      /* non-ABI */
  };
diff --git a/kernel/sched_fair.c b/kernel/sched_fair.c
index 7406f36..e973862 100644
--- a/kernel/sched_fair.c
+++ b/kernel/sched_fair.c
@@ -877,8 +877,10 @@ static void enqueue_sleeper(struct cfs_rq *cfs_rq, 
struct sched_entity *se)
                 se->statistics.sum_sleep_runtime += delta;

                 if (tsk) {
+                       u64 freq = 1000000; /* XXX: Use event->attr.freq 
? */
                         account_scheduler_latency(tsk, delta >> 10, 1);
                         trace_sched_stat_sleep(tsk, delta);
+                       perf_sw_event(PERF_COUNT_SW_SLEEP_CLOCK, 
delta/freq, 0, NULL, 0);
                 }
         }
         if (se->statistics.block_start) {

             reply	other threads:[~2011-10-03 19:48 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-10-03 19:38 Arun Sharma [this message]
2011-10-03 20:17 ` Profiling sleep times? Peter Zijlstra
2011-10-03 21:53   ` Arun Sharma
2011-10-04  8:34     ` Peter Zijlstra
2011-10-06 21:56       ` Arun Sharma
2011-10-07  0:05         ` Arun Sharma
2011-10-07  1:30         ` Peter Zijlstra
2011-10-07  5:42           ` avagin
2011-10-07  9:33             ` Peter Zijlstra
2011-10-07 17:58           ` Arun Sharma
2011-10-07 23:16             ` avagin
2011-10-08  1:45         ` avagin
2011-10-10 18:50           ` Arun Sharma
2011-10-12  7:41             ` Ingo Molnar
2011-10-13  5:39               ` Andrew Vagin
2011-10-14 21:19               ` Arun Sharma
2011-10-15 17:00                 ` Ingo Molnar
2011-10-15 19:22                   ` Peter Zijlstra
2011-10-15 19:29                     ` Peter Zijlstra
2011-10-18  1:07                       ` Arun Sharma
2011-10-22 10:49                         ` Frederic Weisbecker
2011-10-22 16:22                           ` Andrew Wagin
2011-10-23  0:27                           ` 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=4E8A0F53.7020408@fb.com \
    --to=asharma@fb.com \
    --cc=acme@ghostprotocols.net \
    --cc=eranian@google.com \
    --cc=linux-perf-users@vger.kernel.org \
    --cc=mingo@elte.hu \
    --cc=peterz@infradead.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).