i386/x86-64 Add nmi watchdog support for new Intel CPUs
PATCH 1/1 i386/x86-64 Add nmi watchdog support for new Intel CPUs
[Sorry if this is a duplicate. I tried sending this mail two days back and I don't see it on the mailing list yet. So, resending it.]
Intel now has support for Architectural Performance Monitoring Counters ( Refer to IA-32 Intel Architecture Software Developer's Manual
http://www.intel.com/design/pentium4/manuals/253669.htm ). This feature is present starting from Intel Core Duo and Intel Core Solo processors.
What this means is, the performance monitoring counters and some performance monitoring events are now defined in an architectural way (using cpuid). And there will be no need to check for family/model etc for these architectural events.
Below is the patch to use this performance counters in nmi watchdog driver. Patch handles both i386 and x86-64 kernels.
arch/i386/kernel/cpu/intel.c +6 -0
@@ -122,6 +122,12 @@ static void __cpuinit init_intel(structselect_idle_routine (c); l2 =init_intel_cacheinfo (c); +if (c->cpuid_level >9 ) { +unsigned eax =cpuid_eax (10 ); +/* Check for version and the number of counters */ +if ((eax &0xff ) && (((eax>>8 ) &0xff ) >1 )) +set_bit (X86_FEATURE_ARCH_PERFMON , c->x86_capability); + }/* SEP CPUID bug: Pentium Pro reports SEP but doesn't have it until model 3 mask 3 */ if ((c->x86<<8 | c->x86_model<<4 | c->x86_mask) <0x633 )
arch/i386/kernel/nmi.c +64 -1
107 lines not on this page · raw message
arch/x86_64/kernel/nmi.c +76 -5
130 lines not on this page · raw message
arch/x86_64/kernel/setup.c +7 -0
@@ -1065,6 +1065,13 @@ static void __cpuinit init_intel(structunsigned n;init_intel_cacheinfo (c); +if (c->cpuid_level >9 ) { +unsigned eax =cpuid_eax (10 ); +/* Check for version and the number of counters */ +if ((eax &0xff ) && (((eax>>8 ) &0xff ) >1 )) +set_bit (X86_FEATURE_ARCH_PERFMON , &c->x86_capability); + } + n = c->extended_cpuid_level;if (n >=0x80000008 ) {unsigned eax =cpuid_eax (0x80000008 );
include/asm-i386/cpufeature.h +1 -0
@@ -72,6 +72,7 @@#define X86_FEATURE_CONSTANT_TSC (3*32+ 8)/* TSC ticks at a constant rate */ #define X86_FEATURE_UP (3*32+ 9)/* smp kernel running on up */ #define X86_FEATURE_FXSAVE_LEAK (3*32+10)/* FXSAVE leaks FOP/FIP/FOP */ +#define X86_FEATURE_ARCH_PERFMON (3*32+11)/* Intel Architectural PerfMon */ /* Intel-defined CPU features, CPUID level 0x00000001 (ecx), word 4 */ #define X86_FEATURE_XMM3 (4*32+ 0)/* Streaming SIMD Extensions-3 */
include/asm-i386/intel_arch_perfmon.h +19 -0
@@ -0,0 +1,19 @@ +#ifndef X86_INTEL_ARCH_PERFMON_H +#define X86_INTEL_ARCH_PERFMON_H 1 + +#define MSR_ARCH_PERFMON_PERFCTR0 0xc1 +#define MSR_ARCH_PERFMON_PERFCTR1 0xc2 + +#define MSR_ARCH_PERFMON_EVENTSEL0 0x186 +#define MSR_ARCH_PERFMON_EVENTSEL1 0x187 + +#define ARCH_PERFMON_EVENTSEL0_ENABLE (1 << 22) +#define ARCH_PERFMON_EVENTSEL_INT (1 << 20) +#define ARCH_PERFMON_EVENTSEL_OS (1 << 17) +#define ARCH_PERFMON_EVENTSEL_USR (1 << 16) + +#define ARCH_PERFMON_UNHALTED_CORE_CYCLES_SEL (0x3c) +#define ARCH_PERFMON_UNHALTED_CORE_CYCLES_UMASK (0x00 << 8) +#define ARCH_PERFMON_UNHALTED_CORE_CYCLES_PRESENT (1 << 0) + +#endif /* X86_INTEL_ARCH_PERFMON_H */
include/asm-x86_64/cpufeature.h +1 -0
@@ -65,6 +65,7 @@#define X86_FEATURE_CONSTANT_TSC (3*32+5)/* TSC runs at constant rate */ #define X86_FEATURE_SYNC_RDTSC (3*32+6)/* RDTSC syncs CPU core */ #define X86_FEATURE_FXSAVE_LEAK (3*32+7)/* FIP/FOP/FDP leaks through FXSAVE */ +#define X86_FEATURE_ARCH_PERFMON (3*32+8)/* Intel Architectural PerfMon */ /* Intel-defined CPU features, CPUID level 0x00000001 (ecx), word 4 */ #define X86_FEATURE_XMM3 (4*32+ 0)/* Streaming SIMD Extensions-3 */
include/asm-x86_64/intel_arch_perfmon.h +19 -0
@@ -0,0 +1,19 @@ +#ifndef X86_64_INTEL_ARCH_PERFMON_H +#define X86_64_INTEL_ARCH_PERFMON_H 1 + +#define MSR_ARCH_PERFMON_PERFCTR0 0xc1 +#define MSR_ARCH_PERFMON_PERFCTR1 0xc2 + +#define MSR_ARCH_PERFMON_EVENTSEL0 0x186 +#define MSR_ARCH_PERFMON_EVENTSEL1 0x187 + +#define ARCH_PERFMON_EVENTSEL0_ENABLE (1 << 22) +#define ARCH_PERFMON_EVENTSEL_INT (1 << 20) +#define ARCH_PERFMON_EVENTSEL_OS (1 << 17) +#define ARCH_PERFMON_EVENTSEL_USR (1 << 16) + +#define ARCH_PERFMON_UNHALTED_CORE_CYCLES_SEL (0x3c) +#define ARCH_PERFMON_UNHALTED_CORE_CYCLES_UMASK (0x00 << 8) +#define ARCH_PERFMON_UNHALTED_CORE_CYCLES_PRESENT (1 << 0) + +#endif /* X86_64_INTEL_ARCH_PERFMON_H */
Quoted 7 lines · Venkatesh Pallipadi
---
linux-2.6.17-rc4/arch/i386/kernel/nmi.c2006-05-11 17:23:13.000000000 -0700
+++linux-2.6.17-rc4-nmi/arch/i386/kernel/nmi.c2006-05-12 17:47:48.000000000 -0700...
+static void
disable_intel_arch_watchdog(void)
Should this code be moved to arch/i386/kernel/cpu/intel.c?
Quoted 10 lines · Andrew Morton
Quoted 7 lines · Venkatesh Pallipadi
---
linux-2.6.17-rc4/arch/i386/kernel/nmi.c2006-05-11 17:23:13.000000000 -0700
+++linux-2.6.17-rc4-nmi/arch/i386/kernel/nmi.c2006-05-12 17:47:48.000000000 -0700...
+static void
disable_intel_arch_watchdog(void)Should this code be moved to
arch/i386/kernel/cpu/intel.c?
I am not sure. The other watchdog setup functions p3, p4, k7 are all in nmi.c file and thats the reason I kept the new function in the same file too. Also, as this is specific to watchdog event, it won't be called by anyone else.
If you are thinking of putting these disable and enable functions in same place so that we can share it across i386/x86_64, we can put it in intel_cacheinfo or create a new file for this. There is one line difference between i386 and x86_64 enable functions due to a macro getting used in i386 version. So, we will have to workaround that to make this code shared.
Thanks,
Venki
Quoted 5 lines · Venkatesh Pallipadi
Intel now has support for Architectural Performance Monitoring Counters ( Refer to IA-32 Intel Architecture Software Developer's Manual
http://www.intel.com/design/pentium4/manuals/253669.htm ). This feature is present starting from Intel Core Duo and Intel Core Solo processors.
Nice!
Quoted 7 lines
What this means is, the performance monitoring counters and some performance monitoring events are now defined in an architectural way (using cpuid). And there will be no need to check for family/model etc for these architectural events.
Below is the patch to use this performance counters in nmi watchdog driver. Patch handles both i386 and x86-64 kernels.
Can you regenerate it against the latest firstfloor tree please? With Don's x86-64 NMI changes there are a zillion rejects.
-Andi
Quoted 4 lines · Andi Kleen
Can you regenerate it against the latest firstfloor tree please? With Don's x86-64 NMI changes there are a zillion rejects.
Below is the updated patch, to apply over Don's changes.
Intel now has support for Architectural Performance Monitoring Counters ( Refer to IA-32 Intel Architecture Software Developer's Manual
http://www.intel.com/design/pentium4/manuals/253669.htm ). This feature is present starting from Intel Core Duo and Intel Core Solo processors.
What this means is, the performance monitoring counters and some performance monitoring events are now defined in an architectural way (using cpuid). And there will be no need to check for family/model etc for these architectural events.
Below is the patch to use this performance counters in nmi watchdog driver. Patch handles both i386 and x86-64 kernels.
arch/i386/kernel/cpu/intel.c +6 -0
@@ -122,6 +122,12 @@ static void __cpuinit init_intel(structselect_idle_routine (c); l2 =init_intel_cacheinfo (c); +if (c->cpuid_level >9 ) { +unsigned eax =cpuid_eax (10 ); +/* Check for version and the number of counters */ +if ((eax &0xff ) && (((eax>>8 ) &0xff ) >1 )) +set_bit (X86_FEATURE_ARCH_PERFMON , c->x86_capability); + }/* SEP CPUID bug: Pentium Pro reports SEP but doesn't have it until model 3 mask 3 */ if ((c->x86<<8 | c->x86_model<<4 | c->x86_mask) <0x633 )
arch/i386/kernel/nmi.c +121 -5
182 lines not on this page · raw message
arch/x86_64/kernel/nmi.c +125 -5
183 lines not on this page · raw message
wrmsrl(wd->perfctr_msr, -((u64)cpu_khz * 1000 / nmi_hz));
rc = 1;
} else if (nmi_watchdog == NMI_IO_APIC) {
/* don't know how to accurately check for this.
arch/x86_64/kernel/setup.c +7 -0
@@ -997,6 +997,13 @@ static void __cpuinit init_intel(structunsigned n;init_intel_cacheinfo (c); +if (c->cpuid_level >9 ) { +unsigned eax =cpuid_eax (10 ); +/* Check for version and the number of counters */ +if ((eax &0xff ) && (((eax>>8 ) &0xff ) >1 )) +set_bit (X86_FEATURE_ARCH_PERFMON , &c->x86_capability); + } + n = c->extended_cpuid_level;if (n >=0x80000008 ) {unsigned eax =cpuid_eax (0x80000008 );
include/asm-i386/cpufeature.h +1 -0
@@ -72,6 +72,7 @@#define X86_FEATURE_CONSTANT_TSC (3*32+ 8)/* TSC ticks at a constant rate */ #define X86_FEATURE_UP (3*32+ 9)/* smp kernel running on up */ #define X86_FEATURE_FXSAVE_LEAK (3*32+10)/* FXSAVE leaks FOP/FIP/FOP */ +#define X86_FEATURE_ARCH_PERFMON (3*32+11)/* Intel Architectural PerfMon */ /* Intel-defined CPU features, CPUID level 0x00000001 (ecx), word 4 */ #define X86_FEATURE_XMM3 (4*32+ 0)/* Streaming SIMD Extensions-3 */
include/asm-i386/intel_arch_perfmon.h new file +31 -0
@@ -0,0 +1,31 @@ +#ifndef X86_INTEL_ARCH_PERFMON_H +#define X86_INTEL_ARCH_PERFMON_H 1 + +#define MSR_ARCH_PERFMON_PERFCTR0 0xc1 +#define MSR_ARCH_PERFMON_PERFCTR1 0xc2 + +#define MSR_ARCH_PERFMON_EVENTSEL0 0x186 +#define MSR_ARCH_PERFMON_EVENTSEL1 0x187 + +#define ARCH_PERFMON_EVENTSEL0_ENABLE (1 << 22) +#define ARCH_PERFMON_EVENTSEL_INT (1 << 20) +#define ARCH_PERFMON_EVENTSEL_OS (1 << 17) +#define ARCH_PERFMON_EVENTSEL_USR (1 << 16) + +#define ARCH_PERFMON_UNHALTED_CORE_CYCLES_SEL (0x3c) +#define ARCH_PERFMON_UNHALTED_CORE_CYCLES_UMASK (0x00 << 8) +#define ARCH_PERFMON_UNHALTED_CORE_CYCLES_INDEX (0) +#define ARCH_PERFMON_UNHALTED_CORE_CYCLES_PRESENT \ + (1 << (ARCH_PERFMON_UNHALTED_CORE_CYCLES_INDEX)) + +union cpuid10_eax { +struct { +unsigned int version_id:8 ; +unsigned int num_counters:8 ; +unsigned int bit_width:8 ; +unsigned int mask_length:8 ; + } split; +unsigned int full; +}; + +#endif /* X86_INTEL_ARCH_PERFMON_H */
include/asm-x86_64/cpufeature.h +1 -0
@@ -66,6 +66,7 @@#define X86_FEATURE_SYNC_RDTSC (3*32+6)/* RDTSC syncs CPU core */ #define X86_FEATURE_FXSAVE_LEAK (3*32+7)/* FIP/FOP/FDP leaks through FXSAVE */ #define X86_FEATURE_UP (3*32+8)/* SMP kernel running on UP */ +#define X86_FEATURE_ARCH_PERFMON (3*32+9)/* Intel Architectural PerfMon */ /* Intel-defined CPU features, CPUID level 0x00000001 (ecx), word 4 */
include/asm-x86_64/intel_arch_perfmon.h new file +31 -0
@@ -0,0 +1,31 @@ +#ifndef X86_64_INTEL_ARCH_PERFMON_H +#define X86_64_INTEL_ARCH_PERFMON_H 1 + +#define MSR_ARCH_PERFMON_PERFCTR0 0xc1 +#define MSR_ARCH_PERFMON_PERFCTR1 0xc2 + +#define MSR_ARCH_PERFMON_EVENTSEL0 0x186 +#define MSR_ARCH_PERFMON_EVENTSEL1 0x187 + +#define ARCH_PERFMON_EVENTSEL0_ENABLE (1 << 22) +#define ARCH_PERFMON_EVENTSEL_INT (1 << 20) +#define ARCH_PERFMON_EVENTSEL_OS (1 << 17) +#define ARCH_PERFMON_EVENTSEL_USR (1 << 16) + +#define ARCH_PERFMON_UNHALTED_CORE_CYCLES_SEL (0x3c) +#define ARCH_PERFMON_UNHALTED_CORE_CYCLES_UMASK (0x00 << 8) +#define ARCH_PERFMON_UNHALTED_CORE_CYCLES_INDEX (0) +#define ARCH_PERFMON_UNHALTED_CORE_CYCLES_PRESENT \ + (1 << (ARCH_PERFMON_UNHALTED_CORE_CYCLES_INDEX)) + +union cpuid10_eax { +struct { +unsigned int version_id:8 ; +unsigned int num_counters:8 ; +unsigned int bit_width:8 ; +unsigned int mask_length:8 ; + } split; +unsigned int full; +}; + +#endif /* X86_64_INTEL_ARCH_PERFMON_H */
Quoted 8 lines · Venkatesh Pallipadi
Quoted 4 lines · Andi Kleen
Can you regenerate it against the latest firstfloor tree please? With Don's x86-64 NMI changes there are a zillion rejects.
Below is the updated patch, to apply over Don's changes.
Applied thanks
-Andi
Quoted 11 lines · Venkatesh Pallipadi
[Sorry if this is a duplicate. I tried sending this mail two days back and I don't see it on the mailing list yet. So, resending it.]
Intel now has support for Architectural Performance Monitoring Counters ( Refer to IA-32 Intel Architecture Software Developer's Manual
http://www.intel.com/design/pentium4/manuals/253669.htm ). This feature is present starting from Intel Core Duo and Intel Core Solo processors.
Quoted 7 lines
What this means is, the performance monitoring counters and some performance monitoring events are now defined in an architectural way (using cpuid). And there will be no need to check for family/model etc for these architectural events.
Below is the patch to use this performance counters in nmi watchdog driver. Patch handles both i386 and x86-64 kernels.
FYI - i went back to this old patch again because I temporarily dropped the NMI rework for 2.6.18. Please let me know if it misses any changes that you added in later kernels (except for the merge with the newer code base)
-Andi