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: eranian@gmail.com, linux-kernel@vger.kernel.org, mingo@elte.hu,
	paulus@samba.org, perfmon2-devel@lists.sf.net,
	"David S. Miller" <davem@davemloft.net>
Subject: Re: [PATCH] perf_events: improve Intel event scheduling
Date: Mon, 21 Dec 2009 20:31:09 +0100	[thread overview]
Message-ID: <1261423869.4314.198.camel@laptop> (raw)
In-Reply-To: <bd4cb8900912211100n419ef5b1w5322656b034f909e@mail.gmail.com>

On Mon, 2009-12-21 at 20:00 +0100, Stephane Eranian wrote:

> >  perf_disable() <-- shut down the full pmu
> >
> >  pmu->disable() <-- hey someone got removed (easy free the reg)
> >  pmu->enable()  <-- hey someone got added (harder, check constraints)
> >
> >  hw_perf_group_sched_in() <-- hey a full group got added
> >                              (better than multiple ->enable)
> >
> >  perf_enable() <-- re-enable pmu
> >
> >
> > So ->disable() is used to track freeing, ->enable is used to add
> > individual counters, check constraints etc..
> >
> > hw_perf_group_sched_in() is used to optimize the full group enable.
> >
> 
> Does that mean that after a disable() I can assume that there won't
> be an enable() without a group_sched_in()?
> 
> I suspect not. In fact, there is a counter-example in perf_ctx_adjust_freq().

Why would that be a problem?

A perf_disable() will simply disable the pmu, but not alter its
configuration, perf_enable() will program the pmu and re-enable it (with
the obvious optimization that if the current state and the new state
match we can skip the actual programming).

If a ->disable() was observed between it will simply not re-enable that
particular counter, that is it will remove that counters' config, and
perf_enable() can do a smart reprogram by simply no re-enabling that
counter.

If an ->enable() or hw_perf_group_sched_in() was observed in between,
you have to recompute the full state in order to validate the
availability, if that fails, no state change, if it succeeds you have a
new pmu state and perf_enable() will program that.

In the case of perf_ctx_adjust_freq():

	if (!interrupts) {
		perf_disable();
		event->pmu->disable(event);
		atomic64_set(&hwc->period_left, 0);
		event->pmu->enable(event);
		perf_enable();
	}

You'll very likely end up with the same state you had before, but if not
who cares -- its supposed to be an unlikely case.

That is, the ->disable() will clear the cpu_hw_events::used_mask bit.
The ->enable() will want to place the counter on its last know reg,
which (not so very surprisingly) will be available, hence it will
trivially succeed, depending on its smarts it might or might not find
that the 'new' counter's config is identical to the current hw state, if
not it might set a cpu_hw_event::reprogram state.

perf_enable() will, when it sees cpu_hw_event::reprogram, re-write the
pmu config and re-enable the whole thing (global ctrl reg, or iterate
individual EN bits).




  reply	other threads:[~2009-12-21 19:32 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-10-19 15:03 [PATCH] perf_events: improve Intel event scheduling Stephane Eranian
2009-11-18 16:32 ` Peter Zijlstra
2009-12-11 11:00   ` stephane eranian
2009-12-11 11:59     ` stephane eranian
2009-12-21 15:40       ` Peter Zijlstra
2009-12-21 19:00         ` Stephane Eranian
2009-12-21 19:31           ` Peter Zijlstra [this message]
2009-12-21 20:59             ` Stephane Eranian
2009-12-21 21:18               ` Peter Zijlstra
2009-12-22  1:09               ` Paul Mackerras
2009-12-22  1:02         ` Paul Mackerras
2009-12-29 14:47           ` Stephane Eranian
2010-01-07  4:13             ` Paul Mackerras
2010-01-07  8:54               ` Peter Zijlstra
2010-01-07  9:00               ` Peter Zijlstra
2010-01-07  9:54                 ` Stephane Eranian
2010-01-07 10:01                   ` Peter Zijlstra
2009-12-22  0:57       ` Paul Mackerras
2009-12-11 14:38     ` 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=1261423869.4314.198.camel@laptop \
    --to=peterz@infradead.org \
    --cc=davem@davemloft.net \
    --cc=eranian@gmail.com \
    --cc=eranian@google.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@elte.hu \
    --cc=paulus@samba.org \
    --cc=perfmon2-devel@lists.sf.net \
    /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