Re: [PATCH v3 3/5] perf: Allow adding fixed random jitter to the alternate sampling period

From: Peter Zijlstra
Date: Mon Mar 10 2025 - 08:49:07 EST


On Fri, Mar 07, 2025 at 08:22:45PM +0000, mark.barnett@xxxxxxx wrote:
> @@ -9922,7 +9923,10 @@ static int __perf_event_overflow(struct perf_event *event,
> if (event->attr.alt_sample_period) {
> bool using_alt = hwc->using_alt_sample_period;
> u64 sample_period = (using_alt ? event->attr.sample_period
> - : event->attr.alt_sample_period);
> + : event->attr.alt_sample_period)
> + + (event->attr.jitter_alt_period
> + ? get_random_u32_below(2 << event->attr.jitter_alt_period)
> + : 0);

So, ... this here is NMI context, right? Have you looked at the guts of
get_random_u32_below() ?

I would strongly suggest you go do so.

>
> hwc->sample_period = sample_period;
> hwc->using_alt_sample_period = !using_alt;