[RESEND PATCH v2 1/2] watchdog/perf: Provide function for adjusting the event period

Will Deacon will at kernel.org
Fri Jun 27 08:35:06 PDT 2025


On Thu, Jun 19, 2025 at 07:48:04PM +0800, Yicong Yang wrote:
> From: Yicong Yang <yangyicong at hisilicon.com>
> 
> Architecture's using perf events for hard lockup detection needs to
> convert the watchdog_thresh to the event's period, some architecture
> for example arm64 perform this conversion using the CPU's maximum
> frequency which will be acquired by cpufreq. However by the time
> the lockup detector's initialized the cpufreq driver may not be
> initialized, thus launch a watchdog with inaccurate period. Provide
> a function hardlockup_detector_perf_adjust_period() to allowing
> adjust the event period. Then architecture can update with more
> accurate period if cpufreq is initialized.
> 
> Signed-off-by: Yicong Yang <yangyicong at hisilicon.com>
> ---
>  include/linux/nmi.h    |  2 ++
>  kernel/watchdog_perf.c | 23 +++++++++++++++++++++++
>  2 files changed, 25 insertions(+)
> 
> diff --git a/include/linux/nmi.h b/include/linux/nmi.h
> index e78fa535f61d..0a6d8a8d2d5b 100644
> --- a/include/linux/nmi.h
> +++ b/include/linux/nmi.h
> @@ -103,10 +103,12 @@ void watchdog_hardlockup_check(unsigned int cpu, struct pt_regs *regs);
>  extern void hardlockup_detector_perf_stop(void);
>  extern void hardlockup_detector_perf_restart(void);
>  extern void hardlockup_config_perf_event(const char *str);
> +extern void hardlockup_detector_perf_adjust_period(int cpu, u64 period);
>  #else
>  static inline void hardlockup_detector_perf_stop(void) { }
>  static inline void hardlockup_detector_perf_restart(void) { }
>  static inline void hardlockup_config_perf_event(const char *str) { }
> +static inline void hardlockup_detector_perf_adjust_period(int cpu, u64 period) { }
>  #endif
>  
>  void watchdog_hardlockup_stop(void);
> diff --git a/kernel/watchdog_perf.c b/kernel/watchdog_perf.c
> index 75af12ff774e..41c299e63fab 100644
> --- a/kernel/watchdog_perf.c
> +++ b/kernel/watchdog_perf.c
> @@ -186,6 +186,29 @@ void watchdog_hardlockup_disable(unsigned int cpu)
>  	}
>  }
>  
> +/**
> + * hardlockup_detector_perf_adjust_period - Adjust the event period due
> + *                                          to cpu frequency change
> + * @cpu: The CPU whose event period will be adjusted
> + * @period: The target period to be set
> + */
> +void hardlockup_detector_perf_adjust_period(int cpu, u64 period)
> +{
> +	struct perf_event *event = per_cpu(watchdog_ev, cpu);

Given that this is always called in the context of the current CPU (and
has to be to avoid the race you describe in the next patch), why not
drop the 'cpu' argument and use this_cpu_ptr() here instead?

Will



More information about the linux-arm-kernel mailing list