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

Peter Zijlstra peterz at infradead.org
Wed Apr 9 07:24:17 PDT 2025


On Tue, Apr 08, 2025 at 06:15:28PM +0100, mark.barnett at arm.com 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;
>  



More information about the linux-arm-kernel mailing list