watchdog_hld.c 1.2 KB

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