linux-perf-users.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Deepak Surti <Deepak.Surti@arm.com>
To: "peterz@infradead.org" <peterz@infradead.org>
Cc: Ben Gainey <Ben.Gainey@arm.com>,
	"alexander.shishkin@linux.intel.com"
	<alexander.shishkin@linux.intel.com>,
	Mark Barnett <Mark.Barnett@arm.com>,
	James Clark <James.Clark@arm.com>,
	"adrian.hunter@intel.com" <adrian.hunter@intel.com>,
	"ak@linux.intel.com" <ak@linux.intel.com>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
	"linux-perf-users@vger.kernel.org"
	<linux-perf-users@vger.kernel.org>,
	"irogers@google.com" <irogers@google.com>,
	"mingo@redhat.com" <mingo@redhat.com>,
	"will@kernel.org" <will@kernel.org>,
	Mark Rutland <Mark.Rutland@arm.com>,
	"linux-arm-kernel@lists.infradead.org"
	<linux-arm-kernel@lists.infradead.org>,
	"acme@kernel.org" <acme@kernel.org>,
	"jolsa@kernel.org" <jolsa@kernel.org>,
	"namhyung@kernel.org" <namhyung@kernel.org>
Subject: Re: [PATCH v1 1/4] perf: Allow periodic events to alternate between two sample periods
Date: Mon, 25 Nov 2024 17:11:43 +0000	[thread overview]
Message-ID: <026914337fe69ed388e42a59e97d4a838bea6832.camel@arm.com> (raw)
In-Reply-To: <20241114150152.GC39245@noisy.programming.kicks-ass.net>

On Thu, 2024-11-14 at 16:01 +0100, Peter Zijlstra wrote:
> On Thu, Nov 07, 2024 at 04:07:18PM +0000, Deepak Surti wrote:
> > From: Ben Gainey <ben.gainey@arm.com>
> > 
> > This change modifies perf_event_attr to add a second, alternative
> > sample period field, and modifies the core perf overflow handling
> > such that when specified an event will alternate between two sample
> > periods.
> > 
> > Currently, perf does not provide a  mechanism for decoupling the
> > period
> > over which counters are counted from the period between samples.
> > This is
> > problematic for building a tool to measure per-function metrics
> > derived
> > from a sampled counter group. Ideally such a tool wants a very
> > small
> > sample window in order to correctly attribute the metrics to a
> > given
> > function, but prefers a larger sample period that provides
> > representative
> > coverage without excessive probe effect, triggering throttling, or
> > generating excessive amounts of data.
> > 
> > By alternating between a long and short sample_period and
> > subsequently
> > discarding the long samples, tools may decouple the period between
> > samples that the tool cares about from the window of time over
> > which
> > interesting counts are collected.
> 
> Do you have a link to a paper or something that explains this method?

Ben had originally authored this as an internal doc but I can look at
publishing externally. Is there anything in particular about this
method that you are interested in?

> 
> 
> > +	/*
> > +	 * Indicates that the alternative_sample_period is used
> > +	 */
> > +	bool				using_alternative_sample_p
> > eriod;
> 
> I typically prefer variables names that are shorter.

Acknowledged. Will do it in version 2 of the patch.

> 
> 
> > @@ -9822,6 +9825,26 @@ static int __perf_event_overflow(struct
> > perf_event *event,
> >  	    !bpf_overflow_handler(event, data, regs))
> >  		return ret;
> >  
> > +	/*
> > +	 * Swap the sample period to the alternative period
> > +	 */
> > +	if (event->attr.alternative_sample_period) {
> > +		bool using_alt = hwc-
> > >using_alternative_sample_period;
> > +		u64 sample_period = (using_alt ? event-
> > >attr.sample_period
> > +					       : event-
> > >attr.alternative_sample_period);
> > +
> > +		hwc->sample_period = sample_period;
> > +		hwc->using_alternative_sample_period = !using_alt;
> > +
> > +		if (local64_read(&hwc->period_left) > 0) {
> > +			event->pmu->stop(event, PERF_EF_UPDATE);
> > +
> > +			local64_set(&hwc->period_left, 0);
> > +
> > +			event->pmu->start(event, PERF_EF_RELOAD);
> > +		}
> 
> This is quite terrible :-(
> 
> Getting here means we just went through the effort of programming the
> period and you'll pretty much always hit that 'period_left > 0' case.
> 
> Why do we need this case at all? If you don't do this, then the next
> overflow will pick the period you just wrote to hwc->sample_period
> (although you might want to audit all arch implementations).
> 
> Looking at it again, that truncation to 0 is just plain wrong --
> always.
> Why are you doing this?

This was due to Ben's lack of familiarity with the codebase when this
was originally written; this replicates what the IOCTL handler does to
change the sample period.

But you are right this is inefficient; we've tested with this removed
and for SW events and arm pmu events it appears to be fine.

A quick review of the other architecture overflow handlers tend to all
follow the same pattern so it's probably safe, but we will do some more
validation on that before version 2 of the patch.

Thanks,
Deepak
> 
> 
> 


  reply	other threads:[~2024-11-25 17:12 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-11-07 16:07 [PATCH v1 0/4] A mechanism for efficient support for per-function metrics Deepak Surti
2024-11-07 16:07 ` [PATCH v1 1/4] perf: Allow periodic events to alternate between two sample periods Deepak Surti
2024-11-14 15:01   ` Peter Zijlstra
2024-11-25 17:11     ` Deepak Surti [this message]
2024-11-07 16:07 ` [PATCH v1 2/4] perf: Allow adding fixed random jitter to the alternate sampling period Deepak Surti
2024-11-07 16:07 ` [PATCH v1 3/4] tools/perf: Modify event parser to support alt-period term Deepak Surti
2024-11-14  2:10   ` Ian Rogers
2024-11-25 16:02     ` Deepak Surti
2024-11-07 16:07 ` [PATCH v1 4/4] tools/perf: Modify event parser to support alt-period-jitter term Deepak Surti
2024-11-14  2:22 ` [PATCH v1 0/4] A mechanism for efficient support for per-function metrics Ian Rogers
2024-11-14 14:36   ` James Clark
2024-11-25 17:05   ` Deepak Surti

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=026914337fe69ed388e42a59e97d4a838bea6832.camel@arm.com \
    --to=deepak.surti@arm.com \
    --cc=Ben.Gainey@arm.com \
    --cc=James.Clark@arm.com \
    --cc=Mark.Barnett@arm.com \
    --cc=Mark.Rutland@arm.com \
    --cc=acme@kernel.org \
    --cc=adrian.hunter@intel.com \
    --cc=ak@linux.intel.com \
    --cc=alexander.shishkin@linux.intel.com \
    --cc=irogers@google.com \
    --cc=jolsa@kernel.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-perf-users@vger.kernel.org \
    --cc=mingo@redhat.com \
    --cc=namhyung@kernel.org \
    --cc=peterz@infradead.org \
    --cc=will@kernel.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;
as well as URLs for NNTP newsgroup(s).