Re: [PATCH 2/2] perf: Don't throttle based on NMI watchdog events
From: Calvin Owens
Date: Tue Mar 31 2026 - 13:48:09 EST
On Tuesday 03/31 at 10:22 -0700, Calvin Owens wrote:
> On Tuesday 03/31 at 08:25 -0700, Calvin Owens wrote:
> > @@ -663,6 +666,17 @@ void perf_sample_event_took(u64 sample_len_ns)
> > if (avg_len <= max_len)
> > return;
> >
> > + /*
> > + * Very infrequent events like the perf counter hard watchdog
> > + * can trigger spurious throttling: skip throttling if the prior
> > + * NMI got here more than one second before this NMI began.
> > + */
> > + now = local_clock();
> > + delta = now - __this_cpu_read(last_throttle_clock);
> > + __this_cpu_write(last_throttle_clock, now);
> > + if (delta - sample_len_ns > NSEC_PER_SEC)
> > + return;
Apologies for replying twice in a row...
Sashiko made a second useful observation:
>> There appears to be no upper bound on sample_len_ns itself. If an
>> event takes 5 seconds to run but is configured to fire only once every
>> 7 seconds, the idle time will be 2 seconds.
>>
>> Because 2 seconds is > NSEC_PER_SEC, the throttling logic is skipped
>> entirely. This defeats the sysctl_perf_cpu_time_max_percent safeguard
>> and allows an event to monopolize the CPU in NMI/IRQ context for
>> seconds at a time without ever being throttled.
I'm skeptical that would ever actually happen, but I think I can address
that by adding:
&& sample_len_ns < NSEC_PER_SEC
...to the skip throttle condition?
In fairness to the LLM skeptics, the feedback Sashiko gave on patch 1/2
is absolute nonsense.
Thanks,
Calvin