The Linux Kernel Mailing List
 help / color / mirror / Atom feed
From: Ingo Molnar <mingo@kernel.org>
To: Gregg Leventhal <gleventhal@janestreet.com>
Cc: linux-perf-users@vger.kernel.org,
	Peter Zijlstra <peterz@infradead.org>,
	Ingo Molnar <mingo@redhat.com>,
	Arnaldo Carvalho de Melo <acme@kernel.org>,
	Namhyung Kim <namhyung@kernel.org>,
	Mark Rutland <mark.rutland@arm.com>,
	Alexander Shishkin <alexander.shishkin@linux.intel.com>,
	Jiri Olsa <jolsa@kernel.org>, Ian Rogers <irogers@google.com>,
	Adrian Hunter <adrian.hunter@intel.com>,
	James Clark <james.clark@linaro.org>,
	Mark Barnett <mark.barnett@arm.com>,
	linux-kernel@vger.kernel.org,
	Jay Hilton <jahilton@janestreet.com>,
	Andrew Delgadillo <adelgadillo@janestreet.com>,
	Eric Hagberg <ehagberg@janestreet.com>
Subject: Re: [PATCH] perf/core: Use the elapsed period for frequency-mode period adjustment
Date: Fri, 27 Nov 2026 10:40:41 +0100	[thread overview]
Message-ID: <awlQGVla7eMls7V5@gmail.com> (raw)
In-Reply-To: <20261117152351.1294050-1-gleventhal@janestreet.com>


* Gregg Leventhal <gleventhal@janestreet.com> wrote:

> From: Jay Hilton <jahilton@janestreet.com>
> 
> In frequency mode, __perf_event_account_interrupt() estimates the event
> rate from hwc->last_period and the time since the previous overflow,
> and passes it to perf_adjust_period().
> 
> The PMU drivers re-arm the counter before they call
> perf_event_overflow(), and re-arming sets hwc->last_period to the
> period of the next interval. The estimator therefore divides the next
> period by the time the previous one took. While the period ramps up
> from its initial value, each period is much larger than the previous
> one, so the rate is overestimated by that ratio and the period
> overshoots its target.
> 
> On an AMD EPYC 9655P running v7.3, sampling user-mode cycles at 11 Hz,
> the period jumped from 21.9M to 2.3G cycles, 5.6x the target, and the
> next sample arrived after 544 ms instead of 91 ms. When the overshoot
> exceeds 8x, the next tick's perf_adjust_period() resets period_left,
> and the cycles counted before the reset are not attributed to any
> sample (145M in that run). Intel and AMD IBS show the same overshoot.
> On Intel, intel_pmu_freq_start_period() hides it for the default
> hardware events, but not for raw events.
> 
> Since commit 1734d98fbcce ("perf/arch: Record sample last_period before
> updating on the x86 and PowerPC platforms"), the PMU drivers record the
> elapsed period in data->period before re-arming. Pass that to the
> estimator instead of hwc->last_period. perf_event_account_interrupt(),
> which has no sample data, keeps using hwc->last_period.

Thank you - I've applied this fix to tip:perf/urgent for a v7.4 merge,
with a Cc: stable tag.

> The Intel PEBS error path runs before re-arming and
> is fine. We haven't measured the IBS discard case; if it's worth
> fixing, those callers could pass the elapsed period too, in a
> follow-up.

Yeah, I think it's worth fixing, even if the effect is minor.

Note that I merged your post-commit description with the commit
message, both are interesting & relevant.

Thanks,

	Ingo

  reply	other threads:[~2026-11-27  9:40 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-12 19:17 Subject: [BUG] perf/core: frequency-mode period overshoots during ramp-up Gregg Leventhal
2026-11-17 20:23 ` [PATCH] perf/core: Use the elapsed period for frequency-mode period adjustment Gregg Leventhal
2026-11-27  9:40   ` Ingo Molnar [this message]
2026-11-27  9:49   ` [tip: perf/urgent] " tip-bot2 for Jay Hilton

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=awlQGVla7eMls7V5@gmail.com \
    --to=mingo@kernel.org \
    --cc=acme@kernel.org \
    --cc=adelgadillo@janestreet.com \
    --cc=adrian.hunter@intel.com \
    --cc=alexander.shishkin@linux.intel.com \
    --cc=ehagberg@janestreet.com \
    --cc=gleventhal@janestreet.com \
    --cc=irogers@google.com \
    --cc=jahilton@janestreet.com \
    --cc=james.clark@linaro.org \
    --cc=jolsa@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-perf-users@vger.kernel.org \
    --cc=mark.barnett@arm.com \
    --cc=mark.rutland@arm.com \
    --cc=mingo@redhat.com \
    --cc=namhyung@kernel.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