aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndi Kleen <ak@linux.intel.com>2016-06-09 09:14:38 -0400
committerIngo Molnar <mingo@kernel.org>2016-06-14 05:16:59 -0400
commit2c95afc1e83d93fac3be6923465e1753c2c53b0a (patch)
tree05bfd0397b7d6e9c49e3f7397086e1360c97a5cb
parent281ee056e3f27d925350d65e5eb504b1320d7d5a (diff)
perf/x86/intel, watchdog: Switch NMI watchdog to ref cycles on x86
The NMI watchdog uses either the fixed cycles or a generic cycles counter. This causes a lot of conflicts with users of the PMU who want to run a full group including the cycles fixed counter, for example the --topdown support recently added to perf stat. The code needs to fall back to not use groups, which can cause measurement inaccuracy due to multiplexing errors. This patch switches the NMI watchdog to use reference cycles on Intel systems. This is actually more accurate than cycles, because cycles can tick faster than the measured CPU Frequency due to Turbo mode. The ref cycles always tick at their frequency, or slower when the system is idling. That means the NMI watchdog can never expire too early, unlike with cycles. The reference cycles tick roughly at the frequency of the TSC, so the same period computation can be used. Signed-off-by: Andi Kleen <ak@linux.intel.com> Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org> Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com> Cc: Arnaldo Carvalho de Melo <acme@redhat.com> Cc: Jiri Olsa <jolsa@redhat.com> Cc: Linus Torvalds <torvalds@linux-foundation.org> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Stephane Eranian <eranian@google.com> Cc: Thomas Gleixner <tglx@linutronix.de> Cc: Vince Weaver <vincent.weaver@maine.edu> Cc: acme@kernel.org Cc: jolsa@kernel.org Link: http://lkml.kernel.org/r/1465478079-19993-1-git-send-email-andi@firstfloor.org Signed-off-by: Ingo Molnar <mingo@kernel.org>
-rw-r--r--arch/x86/kernel/apic/hw_nmi.c8
-rw-r--r--include/linux/nmi.h1
-rw-r--r--kernel/watchdog.c7
3 files changed, 16 insertions, 0 deletions
diff --git a/arch/x86/kernel/apic/hw_nmi.c b/arch/x86/kernel/apic/hw_nmi.c
index 7788ce643bf4..016f4263fad4 100644
--- a/arch/x86/kernel/apic/hw_nmi.c
+++ b/arch/x86/kernel/apic/hw_nmi.c
@@ -18,8 +18,16 @@
18#include <linux/nmi.h> 18#include <linux/nmi.h>
19#include <linux/module.h> 19#include <linux/module.h>
20#include <linux/delay.h> 20#include <linux/delay.h>
21#include <linux/perf_event.h>
21 22
22#ifdef CONFIG_HARDLOCKUP_DETECTOR 23#ifdef CONFIG_HARDLOCKUP_DETECTOR
24int hw_nmi_get_event(void)
25{
26 if (boot_cpu_data.x86_vendor == X86_VENDOR_INTEL)
27 return PERF_COUNT_HW_REF_CPU_CYCLES;
28 return PERF_COUNT_HW_CPU_CYCLES;
29}
30
23u64 hw_nmi_get_sample_period(int watchdog_thresh) 31u64 hw_nmi_get_sample_period(int watchdog_thresh)
24{ 32{
25 return (u64)(cpu_khz) * 1000 * watchdog_thresh; 33 return (u64)(cpu_khz) * 1000 * watchdog_thresh;
diff --git a/include/linux/nmi.h b/include/linux/nmi.h
index 4630eeae18e0..79858af27209 100644
--- a/include/linux/nmi.h
+++ b/include/linux/nmi.h
@@ -66,6 +66,7 @@ static inline bool trigger_allbutself_cpu_backtrace(void)
66 66
67#ifdef CONFIG_LOCKUP_DETECTOR 67#ifdef CONFIG_LOCKUP_DETECTOR
68u64 hw_nmi_get_sample_period(int watchdog_thresh); 68u64 hw_nmi_get_sample_period(int watchdog_thresh);
69int hw_nmi_get_event(void);
69extern int nmi_watchdog_enabled; 70extern int nmi_watchdog_enabled;
70extern int soft_watchdog_enabled; 71extern int soft_watchdog_enabled;
71extern int watchdog_user_enabled; 72extern int watchdog_user_enabled;
diff --git a/kernel/watchdog.c b/kernel/watchdog.c
index 9acb29f280ec..8dd30fcd91be 100644
--- a/kernel/watchdog.c
+++ b/kernel/watchdog.c
@@ -315,6 +315,12 @@ static int is_softlockup(unsigned long touch_ts)
315 315
316#ifdef CONFIG_HARDLOCKUP_DETECTOR 316#ifdef CONFIG_HARDLOCKUP_DETECTOR
317 317
318/* Can be overriden by architecture */
319__weak int hw_nmi_get_event(void)
320{
321 return PERF_COUNT_HW_CPU_CYCLES;
322}
323
318static struct perf_event_attr wd_hw_attr = { 324static struct perf_event_attr wd_hw_attr = {
319 .type = PERF_TYPE_HARDWARE, 325 .type = PERF_TYPE_HARDWARE,
320 .config = PERF_COUNT_HW_CPU_CYCLES, 326 .config = PERF_COUNT_HW_CPU_CYCLES,
@@ -604,6 +610,7 @@ static int watchdog_nmi_enable(unsigned int cpu)
604 610
605 wd_attr = &wd_hw_attr; 611 wd_attr = &wd_hw_attr;
606 wd_attr->sample_period = hw_nmi_get_sample_period(watchdog_thresh); 612 wd_attr->sample_period = hw_nmi_get_sample_period(watchdog_thresh);
613 wd_attr->config = hw_nmi_get_event();
607 614
608 /* Try to register using hardware perf events */ 615 /* Try to register using hardware perf events */
609 event = perf_event_create_kernel_counter(wd_attr, cpu, NULL, watchdog_overflow_callback, NULL); 616 event = perf_event_create_kernel_counter(wd_attr, cpu, NULL, watchdog_overflow_callback, NULL);