public inbox for linux-kernel@vger.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: Wed, 20 Oct 2010 13:13:16 +0200	[thread overview]
Message-ID: <1287573196.3488.2.camel@twins> (raw)
In-Reply-To: <AANLkTimjabS1MEkheJ0z2keceH=0eEfC_NbyCjZ-Ltxz@mail.gmail.com>

On Tue, 2010-10-19 at 21:03 +0200, Stephane Eranian wrote:

> >> 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 don't get that. Could you give an example?

Take update_context_time(), it has:

now = perf_clock();
ctx->time += now - ctx->timestamp;
ctx->timestamp = now;

If you interleave two of those you get:

 ctx->timestamp = T0;


 now = perf_clock(); /* T1 */
 ctx->time += now - ctx->timestamp;
					now = perf_clock(); /* T2 */
					ctx->time += now - ctx->timestamp;
					ctx->timestamp = now;
 ctx->timestamp = now;


So at this point you would expect timestamp = T2 and time += T2-T0.

Except that: time += T1 - T0 + T2 - T0 != T2 - T0 and
             timestamp = T1

You can of course write it as something like x86_perf_event_update(),
but then there's trying to keep total_time_running and
total_time_enabled in sync.


> > Not sure, but barring 64bit atomics for all these, 32bit archs and NMI
> > are going to be 'interesting'
> >
> 
> Every sample needs to be correct, otherwise you run the risk of introducing
> bias.
> 
> I think if the tradeoffs is correctness vs. speed, I'd choose correctness.

Well, yes, but it sucks, esp. since its only relevant to
PERF_SAMPLE_READ.

  parent reply	other threads:[~2010-10-20 11:13 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
2010-10-19 19:03       ` Stephane Eranian
2010-10-20 11:00         ` Peter Zijlstra
2010-10-20 11:13         ` Peter Zijlstra [this message]
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=1287573196.3488.2.camel@twins \
    --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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox