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

From: Peter Zijlstra
Date: Wed Apr 09 2025 - 10:24:40 EST


On Tue, Apr 08, 2025 at 06:15:28PM +0100, mark.barnett@xxxxxxx wrote:
> @@ -10224,6 +10227,19 @@ static int __perf_event_overflow(struct perf_event *event,
> *
> * By ignoring the HF samples, we measure the actual period.
> */
> +
> + /*
> + * Apply optional jitter to the overall sample period
> + */
> + if (hwc->sample_period_state & PERF_SPS_HF_RAND
> + && !(hwc->sample_period_state & PERF_SPS_HF_SAMPLE)) {

Coding style nit: when breaking lines, the operator goes on the end of
the preceding line.

> + struct rnd_state *state = &get_cpu_var(sample_period_jitter_rnd);
> + u64 rand_period = 1 << event->attr.hf_sample_rand;
> +
> + sample_period -= rand_period / 2;
> + sample_period += prandom_u32_state(state) & (rand_period - 1);
> + }
> +
> if (hwc->sample_period_state & PERF_SPS_HF_ON) {
> u64 hf_sample_period = event->attr.hf_sample_period;
>