x86: amend 'n' debug-key output with SMI count
PATCH v2 1/1 x86: amend 'n' debug-key output with SMI count
... if available only, of course.
---
I don't really like issuing an IPI (and having another cf_check function) here, yet then again this is issued only when the debug key is actually used, and given how simple the handling function is (including that it doesn't use its parameter) it also looks difficult to abuse.
---
v2: Actually read each CPU's SMI count in do_nmi_stats().
xen/arch/x86/cpu/common.c +7 -1
@@ -407,9 +407,15 @@ void __init early_cpu_init(bool verbose) paddr_bits -= (ebx >>6 ) &0x3f ; } -if (!(c->x86_vendor & (X86_VENDOR_AMD |X86_VENDOR_HYGON ))) +if (!(c->x86_vendor & (X86_VENDOR_AMD |X86_VENDOR_HYGON ))) { +uint64_t smi_count; + park_offline_cpus = opt_mce; +if (!verbose && !rdmsr_safe (MSR_SMI_COUNT , smi_count)) +setup_force_cpu_cap (X86_FEATURE_SMI_COUNT ); + } +initialize_cpu_data (0 ); }
xen/arch/x86/include/asm/cpufeatures.h +1 -1
@@ -24,7 +24,7 @@ XEN_CPUFEATURE(APERFMPERF, X86_SY XEN_CPUFEATURE(MFENCE_RDTSC, X86_SYNTH( 9)) /* MFENCE synchronizes RDTSC */ XEN_CPUFEATURE(XEN_SMEP, X86_SYNTH(10)) /* SMEP gets used by Xen itself */ XEN_CPUFEATURE(XEN_SMAP, X86_SYNTH(11)) /* SMAP gets used by Xen itself */ -/* Bit 12 unused. */ +XEN_CPUFEATURE(SMI_COUNT, X86_SYNTH(12)) /* MSR_SMI_COUNT exists */ XEN_CPUFEATURE(IND_THUNK_LFENCE, X86_SYNTH(13)) /* Use IND_THUNK_LFENCE */ XEN_CPUFEATURE(IND_THUNK_JMP, X86_SYNTH(14)) /* Use IND_THUNK_JMP */XEN_CPUFEATURE (SC_NO_BRANCH_HARDEN ,X86_SYNTH (15 ))/* (Disable) Conditional branch hardening */
xen/arch/x86/include/asm/msr-index.h +2 -0
@@ -28,6 +28,8 @@#define TEST_CTRL_SPLITLOCK_DETECT (_AC(1, ULL) << 29)#define TEST_CTRL_SPLITLOCK_DISABLE (_AC(1, ULL) << 31) +#define MSR_SMI_COUNT 0x00000034 +#define MSR_INTEL_CORE_THREAD_COUNT 0x00000035#define MSR_CTC_THREAD_MASK 0x0000ffff#define MSR_CTC_CORE_MASK _AC(0xffff0000, U)
xen/arch/x86/nmi.c +21 -2
@@ -585,15 +585,34 @@ static void cf_check do_nmi_trigger(unsiself_nmi (); } +static DEFINE_PER_CPU(unsigned int, smi_count); + +static void cf_check read_smi_count(void *unused) +{ +unsigned int dummy; + +rdmsr (MSR_SMI_COUNT ,this_cpu (smi_count), dummy); +} + static void cf_check do_nmi_stats(unsigned char key) {const struct vcpu *v;unsigned int cpu;bool pend, mask; -printk ("CPU\tNMI\n" ); +printk ("CPU\tNMI%s\n" ,boot_cpu_has (X86_FEATURE_SMI_COUNT ) ?"\tSMI" :"" ); + +if (boot_cpu_has (X86_FEATURE_SMI_COUNT ) ) +on_each_cpu (read_smi_count,NULL ,1 ); +for_each_online_cpu ( cpu ) - printk("%3u\t%3u\n", cpu, per_cpu(nmi_count, cpu)); + { +printk ("%3u\t%3u" , cpu,per_cpu (nmi_count, cpu)); +if (boot_cpu_has (X86_FEATURE_SMI_COUNT ) ) +printk ("\t%3u\n" ,per_cpu (smi_count, cpu)); +else +printk ("\n" ); + }if ( !hardware_domain || !(v =domain_vcpu (hardware_domain,0 )) )return ;
Quoted 16 lines · Jan Beulich
... if available only, of course.
Signed-off-by Jan Beulich <[email protected]>---
I don't really like issuing an IPI (and having anothercf_checkfunction) here, yet then again this is issued only when the debug key is actually used, and given how simple the handling function is (including that it doesn't use its parameter) it also looks difficult to abuse.
---
v2: Actually read each CPU's SMI count indo_nmi_stats().xen/arch/x86/cpu/common.c +0
-0@@ -407,9 +407,15 @@ void __init early_cpu_init(bool verbose) paddr_bits -= (ebx >>6 ) &0x3f ;
xen/arch/x86/cpu/common.c void __init early_cpu_init(bool verbose) · line 416
Quoted 10 lines
xen/arch/x86/cpu/common.c +5
-1} -if (!(c->x86_vendor & (X86_VENDOR_AMD |X86_VENDOR_HYGON ))) +if (!(c->x86_vendor & (X86_VENDOR_AMD |X86_VENDOR_HYGON ))) { +uint64_t smi_count; + park_offline_cpus = opt_mce; +if (!verbose && !rdmsr_safe (MSR_SMI_COUNT , smi_count)) +setup_force_cpu_cap (X86_FEATURE_SMI_COUNT );
Why make it dependent on !verbose? The call with !verbose is tied to part of the ucode loading being half-functional (for example MCU_CONTROL_DIS_MCU_LOAD not being set) but I don't see that as a signal that SMI count shouldn't be used.
does it need to be part of the early cpu initialization instead of being in the (later) Intel specific init code part of the identify_cpu()?
Quoted 56 lines
xen/arch/x86/cpu/common.c +2
-0+ } +initialize_cpu_data (0 ); }xen/arch/x86/include/asm/cpufeatures.h +1
-1@@ -24,7 +24,7 @@ XEN_CPUFEATURE(APERFMPERF, X86_SY XEN_CPUFEATURE(MFENCE_RDTSC, X86_SYNTH( 9)) /* MFENCE synchronizes RDTSC */ XEN_CPUFEATURE(XEN_SMEP, X86_SYNTH(10)) /* SMEP gets used by Xen itself */ XEN_CPUFEATURE(XEN_SMAP, X86_SYNTH(11)) /* SMAP gets used by Xen itself */ -/* Bit 12 unused. */ +XEN_CPUFEATURE(SMI_COUNT, X86_SYNTH(12)) /* MSR_SMI_COUNT exists */ XEN_CPUFEATURE(IND_THUNK_LFENCE, X86_SYNTH(13)) /* Use IND_THUNK_LFENCE */ XEN_CPUFEATURE(IND_THUNK_JMP, X86_SYNTH(14)) /* Use IND_THUNK_JMP */XEN_CPUFEATURE (SC_NO_BRANCH_HARDEN ,X86_SYNTH (15 ))/* (Disable) Conditional branch hardening */ xen/arch/x86/include/asm/msr-index.h +2
-0@@ -28,6 +28,8 @@#define TEST_CTRL_SPLITLOCK_DETECT (_AC(1, ULL) << 29)#define TEST_CTRL_SPLITLOCK_DISABLE (_AC(1, ULL) << 31) +#define MSR_SMI_COUNT 0x00000034 +#define MSR_INTEL_CORE_THREAD_COUNT 0x00000035#define MSR_CTC_THREAD_MASK 0x0000ffff#define MSR_CTC_CORE_MASK _AC(0xffff0000, U)xen/arch/x86/nmi.c +14
-2@@ -585,15 +585,34 @@ static void cf_check do_nmi_trigger(unsiself_nmi (); } +static DEFINE_PER_CPU(unsigned int, smi_count); + +static void cf_check read_smi_count(void *unused) +{ +unsigned int dummy; + +rdmsr (MSR_SMI_COUNT ,this_cpu (smi_count), dummy); +} + static void cf_check do_nmi_stats(unsigned char key) {const struct vcpu *v;unsigned int cpu;bool pend, mask; -printk ("CPU\tNMI\n" ); +printk ("CPU\tNMI%s\n" ,boot_cpu_has (X86_FEATURE_SMI_COUNT ) ?"\tSMI" :"" ); + +if (boot_cpu_has (X86_FEATURE_SMI_COUNT ) ) +on_each_cpu (read_smi_count,NULL ,1 ); +for_each_online_cpu ( cpu ) - printk("%3u\t%3u\n", cpu, per_cpu(nmi_count, cpu));
xen/arch/x86/nmi.c static void cf_check do_nmi_trigger(unsi · line 618
Quoted 10 lines
xen/arch/x86/nmi.c +7
-0+ { +printk ("%3u\t%3u" , cpu,per_cpu (nmi_count, cpu)); +if (boot_cpu_has (X86_FEATURE_SMI_COUNT ) ) +printk ("\t%3u\n" ,per_cpu (smi_count, cpu)); +else +printk ("\n" ); + }if ( !hardware_domain || !(v =domain_vcpu (hardware_domain,0 )) )return ;
Could you also amend the debug-key help text to mention SMI?
Thanks, Roger.
Quoted 21 lines · Roger Pau Monné
Quoted 4 lines · Jan Beulich
xen/arch/x86/cpu/common.c +0
-0@@ -407,9 +407,15 @@ void __init early_cpu_init(bool verbose) paddr_bits -= (ebx >>6 ) &0x3f ;xen/arch/x86/cpu/common.c void __init early_cpu_init(bool verbose) · line 416
Quoted 10 lines
xen/arch/x86/cpu/common.c +5
-1} -if (!(c->x86_vendor & (X86_VENDOR_AMD |X86_VENDOR_HYGON ))) +if (!(c->x86_vendor & (X86_VENDOR_AMD |X86_VENDOR_HYGON ))) { +uint64_t smi_count; + park_offline_cpus = opt_mce; +if (!verbose && !rdmsr_safe (MSR_SMI_COUNT , smi_count)) +setup_force_cpu_cap (X86_FEATURE_SMI_COUNT );Why make it dependent on !verbose? The call with !verbose is tied to part of the ucode loading being half-functional (for example
MCU_CONTROL_DIS_MCU_LOADnot being set) but I don't see that as a signal that SMI count shouldn't be used.
Quoted 3 lines
does it need to be part of the early cpu initialization instead of being in the (later) Intel specific init code part of the
identify_cpu()?
Yes, the condition was inverted. It could likely also be dropped altogether; not sure which one's better: On one hand avoiding multiple setup_force_cpu_cap() seems desirable (albeit not strictly necessary), while otoh the code would be simpler without.
Quoted 37 lines
Quoted 37 lines
xen/arch/x86/nmi.c +21
-2@@ -585,15 +585,34 @@ static void cf_check do_nmi_trigger(unsiself_nmi (); } +static DEFINE_PER_CPU(unsigned int, smi_count); + +static void cf_check read_smi_count(void *unused) +{ +unsigned int dummy; + +rdmsr (MSR_SMI_COUNT ,this_cpu (smi_count), dummy); +} + static void cf_check do_nmi_stats(unsigned char key) {const struct vcpu *v;unsigned int cpu;bool pend, mask; -printk ("CPU\tNMI\n" ); +printk ("CPU\tNMI%s\n" ,boot_cpu_has (X86_FEATURE_SMI_COUNT ) ?"\tSMI" :"" ); + +if (boot_cpu_has (X86_FEATURE_SMI_COUNT ) ) +on_each_cpu (read_smi_count,NULL ,1 ); +for_each_online_cpu ( cpu ) - printk("%3u\t%3u\n", cpu, per_cpu(nmi_count, cpu)); + { +printk ("%3u\t%3u" , cpu,per_cpu (nmi_count, cpu)); +if (boot_cpu_has (X86_FEATURE_SMI_COUNT ) ) +printk ("\t%3u\n" ,per_cpu (smi_count, cpu)); +else +printk ("\n" ); + }
Quoted 4 lines
xen/arch/x86/nmi.c static void cf_check do_nmi_trigger(unsi · line 618
Quoted 2 lines
xen/arch/x86/nmi.c +0
-0if ( !hardware_domain || !(v =domain_vcpu (hardware_domain,0 )) )return ;Could you also amend the debug-key help text to mention SMI?
Hmm, I had considered that and decided against. I'm uncertain, nevertheless, so could be talked into amending that help text. Just that I can't make it "NMI and SMI statistics" as whether SMI data is available is conditional. Yet "NMI (and maybe SMI) statistics" looks a little clumsy to me ...
Jan