All of lore.kernel.org
 help / color / mirror / Atom feed
From: Peter Zijlstra <peterz@infradead.org>
To: Stephane Eranian <eranian@google.com>
Cc: linux-kernel@vger.kernel.org, mingo@elte.hu, paulus@samba.org,
	davem@davemloft.net, fweisbec@gmail.com,
	perfmon2-devel@lists.sf.net, eranian@gmail.com,
	robert.richter@amd.com
Subject: Re: [PATCH] perf_events: fix time tracking in samples
Date: Tue, 19 Oct 2010 19:09:47 +0200	[thread overview]
Message-ID: <1287508187.1998.3445.camel@laptop> (raw)
In-Reply-To: <AANLkTik5_h1hVfX=1chezE6z25r4KV6GfzQZ+JvD8J_p@mail.gmail.com>

On Tue, 2010-10-19 at 19:01 +0200, Stephane Eranian wrote:
> On Tue, Oct 19, 2010 at 6:52 PM, Peter Zijlstra <peterz@infradead.org> wrote:
> > On Tue, 2010-10-19 at 18:47 +0200, Stephane Eranian wrote:
> >> This patch corrects time tracking in samples. Without this patch
> >> both time_enabled and time_running may be reported as zero when
> >> user asks for PERF_SAMPLE_READ.
> >>
> >> You use PERF_SAMPLE_READ when you want to sample the values of
> >> other counters in each sample. Because of multiplexing, it is
> >> necessary to know both time_enable, time_running to be able
> >> to scale counts correctly.
> >>
> >> We defer updating timing until we know it is really needed, i.e.,
> >> only when we have PERF_SAMPLE_READ.
> >>
> >> With this patch, the libpfm4 example task_smpl now reports
> >> correct counts (shown on 2.4GHz Core 2):
> >>
> >> $ task_smpl -p 2400000000 -e unhalted_core_cycles:u,instructions_retired:u,baclears  noploop 5
> >> noploop for 5 seconds
> >> IIP:0x000000004006d6 PID:5596 TID:5596 TIME:466,210,211,430 STREAM_ID:33 PERIOD:2,400,000,000 ENA=1,010,157,814 RUN=1,010,157,814 NR=3
> >>       2,400,000,254 unhalted_core_cycles:u (33)
> >>       2,399,273,744 instructions_retired:u (34)
> >>       53,340 baclears (35)
> >>
> >> Signed-off-by: Stephane Eranian <eranian@google.com>
> >>
> >> ---
> >>
> >> diff --git a/kernel/perf_event.c b/kernel/perf_event.c
> >> index f309e80..04611dd 100644
> >> --- a/kernel/perf_event.c
> >> +++ b/kernel/perf_event.c
> >> @@ -3494,6 +3494,9 @@ static void perf_output_read_group(struct perf_output_handle *handle,
> >>  static void perf_output_read(struct perf_output_handle *handle,
> >>                            struct perf_event *event)
> >>  {
> >> +     update_context_time(event->ctx);
> >> +     update_event_times(event);
> >> +
> >>       if (event->attr.read_format & PERF_FORMAT_GROUP)
> >>               perf_output_read_group(handle, event);
> >>       else
> >
> >
> > Right, except that this can actually corrupt the time measurements... :/
> >
> > Usually context times are updated under ctx->lock, and this is called
> > from NMI context, which can interrupt ctx->lock..
> >
> Ok, I missed that. But I don't understand why you need the lock to
> udpate the time. The lower-level clock is lockless if I recall. Can't you
> use an atomic ops in update_context_time()?

atomic ops would slow down those code paths, also, I don't think you can
fully get the ordering between ->tstamp_$foo and ->total_time_$foo just
right.

> > I was thinking about updating a local copy of the times, in that case
> > you can only get funny times from samples, but it won't corrupt the
> > actual running data.
> >
> You want time to be correct in every sample How would you detect
> bogus timing?

Not sure, but barring 64bit atomics for all these, 32bit archs and NMI
are going to be 'interesting'

  reply	other threads:[~2010-10-19 17:10 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-10-19 16:47 [PATCH] perf_events: fix time tracking in samples Stephane Eranian
2010-10-19 16:52 ` Peter Zijlstra
2010-10-19 17:01   ` Stephane Eranian
2010-10-19 17:09     ` Peter Zijlstra [this message]
2010-10-19 19:03       ` Stephane Eranian
2010-10-20 11:00         ` Peter Zijlstra
2010-10-20 11:13         ` Peter Zijlstra
2010-10-20 12:42           ` Stephane Eranian
2010-10-20 13:04             ` Peter Zijlstra

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=1287508187.1998.3445.camel@laptop \
    --to=peterz@infradead.org \
    --cc=davem@davemloft.net \
    --cc=eranian@gmail.com \
    --cc=eranian@google.com \
    --cc=fweisbec@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@elte.hu \
    --cc=paulus@samba.org \
    --cc=perfmon2-devel@lists.sf.net \
    --cc=robert.richter@amd.com \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.