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,
	vincent.weaver@maine.edu, jolsa@redhat.com, ak@linux.intel.com
Subject: Re: [PATCH v2] perf,x86: Fix shared register mutual exclusion enforcement
Date: Mon, 24 Jun 2013 09:46:56 +0200	[thread overview]
Message-ID: <20130624074656.GG28407@twins.programming.kicks-ass.net> (raw)
In-Reply-To: <20130620164254.GA3556@quad>

On Thu, Jun 20, 2013 at 06:42:54PM +0200, Stephane Eranian wrote:
> 
> This patch fixes a problem with the shared registers mutual
> exclusion code and incremental event scheduling by the
> generic perf_event code.
> 
> There was a bug whereby the mutual exclusion on the shared
> registers was not enforced because of incremental scheduling
> abort due to event constraints. As an example on Intel
> Nehalem, consider the following events:
> 
> group1= L1D_CACHE_LD:E_STATE,OFFCORE_RESPONSE_0:PF_RFO,L1D_CACHE_LD:I_STATE
> group2= L1D_CACHE_LD:I_STATE
> 
> The L1D_CACHE_LD event can only be measured by 2 counters. Yet, there
> are 3 instances here. The first group can be scheduled and is committed.
> Then, the generic code tries to schedule group2 and this fails (because
> there is no more counter to support the 3rd instance of L1D_CACHE_LD).
> But in x86_schedule_events() error path, put_event_contraints() is invoked
> on ALL the events and not just the ones that just failed. That causes the
> "lock" on the shared offcore_response MSR to be released. Yet the first group
> is actually scheduled and is exposed to reprogramming of that shared msr by
> the sibling HT thread. In other words, there is no guarantee on what is
> measured.
> 
> This patch fixes the problem by tagging committed events with the
> PERF_X86_EVENT_COMMITTED tag. In the error path of x86_schedule_events(),
> only the events NOT tagged have their constraint released. The tag
> is eventually removed when the event in descheduled.
> 
> Signed-off-by: Stephane Eranian <eranian@google.com>

OK, so I 'accidentally' read the patch again; and noticed something.

In your case above; the get/put constraints are still fully matched.
That is; the first group, which was successful, will not have done a put
yet. So a subsequent get+put should still leave us with a positive 'ref'
count and not undo things.

Only once these events pass through x86_pmu_del() will they get a final
put and the 'ref' count will drop to 0.

Now the problem seems to be the get/put things don't actually count
properly.

However, if we look at __intel_shared_reg_{get,put}_constraints() there
is a refcount in there; namely era->ref; however we don't appear to
clear reg->alloc based on it.

Should we?

  reply	other threads:[~2013-06-24  7:47 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-06-20 16:42 [PATCH v2] perf,x86: Fix shared register mutual exclusion enforcement Stephane Eranian
2013-06-24  7:46 ` Peter Zijlstra [this message]
2013-06-24  8:01   ` Stephane Eranian
2013-06-24 15:48     ` Peter Zijlstra
2013-06-25  9:54       ` Stephane Eranian
2013-06-27  9:01 ` [tip:perf/core] perf/x86: " tip-bot for 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=20130624074656.GG28407@twins.programming.kicks-ass.net \
    --to=peterz@infradead.org \
    --cc=ak@linux.intel.com \
    --cc=eranian@google.com \
    --cc=jolsa@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@elte.hu \
    --cc=vincent.weaver@maine.edu \
    /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.