1// SPDX-License-Identifier: GPL-2.0
2#include <linux/nmi.h>
3#include <linux/cpufreq.h>
4#include <linux/perf/arm_pmu.h>
5
6/*
7 * Safe maximum CPU frequency in case a particular platform doesn't implement
8 * cpufreq driver. Although, architecture doesn't put any restrictions on
9 * maximum frequency but 5 GHz seems to be safe maximum given the available
10 * Arm CPUs in the market which are clocked much less than 5 GHz. On the other
11 * hand, we can't make it much higher as it would lead to a large hard-lockup
12 * detection timeout on parts which are running slower (eg. 1GHz on
13 * Developerbox) and doesn't possess a cpufreq driver.
14 */
15#define SAFE_MAX_CPU_FREQ 5000000000UL // 5 GHz
16u64 hw_nmi_get_sample_period(int watchdog_thresh)
17{
18 unsigned int cpu = smp_processor_id();
19 unsigned long max_cpu_freq;
20
21 max_cpu_freq = cpufreq_get_hw_max_freq(cpu) * 1000UL;
22 if (!max_cpu_freq)
23 max_cpu_freq = SAFE_MAX_CPU_FREQ;
24
25 return (u64)max_cpu_freq * watchdog_thresh;
26}
27
28bool __init arch_perf_nmi_is_available(void)
29{
30 /*
31 * hardlockup_detector_perf_init() will success even if Pseudo-NMI turns off,
32 * however, the pmu interrupts will act like a normal interrupt instead of
33 * NMI and the hardlockup detector would be broken.
34 */
35 return arm_pmu_irq_is_nmi();
36}
37

source code of linux/arch/arm64/kernel/watchdog_hld.c