]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
watchdog/perf: Provide function for adjusting the event period
authorYicong Yang <yangyicong@hisilicon.com>
Tue, 1 Jul 2025 11:02:13 +0000 (19:02 +0800)
committerWill Deacon <will@kernel.org>
Fri, 4 Jul 2025 12:17:30 +0000 (13:17 +0100)
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.

Reviewed-by: Douglas Anderson <dianders@chromium.org>
Signed-off-by: Yicong Yang <yangyicong@hisilicon.com>
Link: https://lore.kernel.org/r/20250701110214.27242-2-yangyicong@huawei.com
Signed-off-by: Will Deacon <will@kernel.org>
include/linux/nmi.h
kernel/watchdog_perf.c

index e78fa535f61dd89f3bdf54130e04cfc546e92c02..cf3c6ab408aacac839aec5c4c24a3ad16e032461 100644 (file)
@@ -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(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(u64 period) { }
 #endif
 
 void watchdog_hardlockup_stop(void);
index 75af12ff774e7627e42365c3cd5744dda3fa6cf4..9c58f5b4381d3819e3a99377dff7d6afc663636e 100644 (file)
@@ -186,6 +186,28 @@ void watchdog_hardlockup_disable(unsigned int cpu)
        }
 }
 
+/**
+ * hardlockup_detector_perf_adjust_period - Adjust the event period due
+ *                                          to current cpu frequency change
+ * @period: The target period to be set
+ */
+void hardlockup_detector_perf_adjust_period(u64 period)
+{
+       struct perf_event *event = this_cpu_read(watchdog_ev);
+
+       if (!(watchdog_enabled & WATCHDOG_HARDLOCKUP_ENABLED))
+               return;
+
+       if (!event)
+               return;
+
+       if (event->attr.sample_period == period)
+               return;
+
+       if (perf_event_period(event, period))
+               pr_err("failed to change period to %llu\n", period);
+}
+
 /**
  * hardlockup_detector_perf_stop - Globally stop watchdog events
  *