mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Stephane Eranian <eranian@google.com>
To: Peter Zijlstra <peterz@infradead.org>
Cc: LKML <linux-kernel@vger.kernel.org>,
	mingo@elte.hu, "Frédéric Weisbecker" <fweisbec@gmail.com>,
	"Paul Mackerras" <paulus@samba.org>,
	"David S. Miller" <davem@davemloft.net>
Subject: Re: perf_events: question about __perf_event_read()
Date: Fri, 21 Jan 2011 19:25:43 +0100	[thread overview]
Message-ID: <AANLkTima4Bfe-wRewbEkbrF9MGJmW1D0Cd3B4KynntSk@mail.gmail.com> (raw)
In-Reply-To: <1295633925.28776.308.camel@laptop>

On Fri, Jan 21, 2011 at 7:18 PM, Peter Zijlstra <peterz@infradead.org> wrote:
> On Fri, 2011-01-21 at 19:06 +0100, Stephane Eranian wrote:
>> Hi,
>>
>> I think the code below still has a problem in case of a per-cpu event.
>>
>> If you issue a read() on a different CPU, then you IPI to the event's cpu.
>> By the time you get there, the event may be de-scheduled in which
>> case you don't want to issue event->pmu_read() nor update context
>> timings. The function has a test but it seems to be checking the per-cpu
>> case only.
>>
>> I have seen panics on P4 with this code because it goes all the way
>> down to rdmsrl() with a bogus counter index (like -1).
>>
>> Am I missing something here?
>>
>> static void __perf_event_read(void *info)
>> {
>>         struct perf_event *event = info;
>>         struct perf_event_context *ctx = event->ctx;
>>         struct perf_cpu_context *cpuctx = __get_cpu_context(ctx);
>>
>>         /*
>>          * If this is a task context, we need to check whether it is
>>          * the current task context of this cpu.  If not it has been
>>          * scheduled out before the smp call arrived.  In that case
>>          * event->count would have been updated to a recent sample
>>          * when the event was scheduled out.
>>          */
>>         if (ctx->task && cpuctx->task_ctx != ctx)
>>                 return;
>>
>>         raw_spin_lock(&ctx->lock);
>
> Shouldn't we re-check event->state once we hold this lock?
>
I remember checking this about a month ago and tip-x86 had
some checks in this routine, but now the're gone.

I think you need something like:

+	if (ctx->is_active)
+		update_context_time(ctx);

+	if (event->state == PERF_EVENT_STATE_ACTIVE)
+		event->pmu->read(event);

>>         update_context_time(ctx);
>>         update_event_times(event);
>>         raw_spin_unlock(&ctx->lock);
>>
>>         event->pmu->read(event);
>> }
>
>
>

  reply	other threads:[~2011-01-21 18:25 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-01-21 18:06 Stephane Eranian
2011-01-21 18:18 ` Peter Zijlstra
2011-01-21 18:25   ` Stephane Eranian [this message]
2011-01-26 14:40     ` Peter Zijlstra
2011-01-26 14:50       ` Stephane Eranian

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=AANLkTima4Bfe-wRewbEkbrF9MGJmW1D0Cd3B4KynntSk@mail.gmail.com \
    --to=eranian@google.com \
    --cc=davem@davemloft.net \
    --cc=fweisbec@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@elte.hu \
    --cc=paulus@samba.org \
    --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

all inboxes | Powered by JetHome®