From: "Jan Beulich" Subject: [PATCH] x86: clean up AMD Fam10 xenoprof IBS code Date: Thu, 04 Nov 2010 14:59:45 +0000 Message-ID: <4CD2D871020000780002095B@vpn.id2.novell.com> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=__Part4D60DE71.0__=" Return-path: List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xensource.com Errors-To: xen-devel-bounces@lists.xensource.com To: "xen-devel@lists.xensource.com" List-Id: xen-devel@lists.xenproject.org This is a MIME message. If you are reading this text, you may want to consider changing to a mail reader or gateway that understands how to properly handle MIME multipart messages. --=__Part4D60DE71.0__= Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: quoted-printable Content-Disposition: inline Arrange for (almost) no code to be generated for x86-32, where the functionality is disabled anyway. Properly __init-annotate the code. Remove some pointless bits. Signed-off-by: Jan Beulich --- a/xen/arch/x86/oprofile/nmi_int.c +++ b/xen/arch/x86/oprofile/nmi_int.c @@ -431,7 +431,7 @@ static int __init nmi_init(void) case 0x10: model =3D &op_athlon_spec; cpu_type =3D "x86-64/family10"; - ibs_caps =3D ibs_init(); + ibs_init(); break; case 0x11: model =3D &op_athlon_spec; --- a/xen/arch/x86/oprofile/op_model_athlon.c +++ b/xen/arch/x86/oprofile/op_model_athlon.c @@ -48,8 +48,12 @@ static unsigned long reset_value[NUM_COU =20 extern char svm_stgi_label[]; =20 +#ifdef CONFIG_X86_64 u32 ibs_caps =3D 0; static u64 ibs_op_ctl; +#else +#define ibs_op_ctl 0 +#endif =20 /* IBS cpuid feature detection */ #define IBS_CPUID_FEATURES 0x8000001b @@ -324,6 +328,7 @@ static int athlon_check_ctrs(unsigned in =20 static inline void start_ibs(void) { +#ifdef CONFIG_X86_64 u64 val =3D 0; =20 if (!ibs_caps) @@ -361,6 +366,7 @@ static inline void start_ibs(void) val =3D op_amd_randomize_ibs_op(ibs_op_ctl); wrmsrl(MSR_AMD64_IBSOPCTL, val); } +#endif } =20 static void athlon_start(struct op_msrs const * const msrs) @@ -407,11 +413,13 @@ static void athlon_stop(struct op_msrs c stop_ibs(); } =20 +#ifdef CONFIG_X86_64 + #define IBSCTL_LVTOFFSETVAL (1 << 8) #define APIC_EILVT_MSG_NMI 0x4 #define APIC_EILVT_LVTOFF_IBS 1 #define APIC_EILVTn(n) (0x500 + 0x10 * n) -static inline void init_ibs_nmi_per_cpu(void *arg) +static inline void __init init_ibs_nmi_per_cpu(void *arg) { unsigned long reg; =20 @@ -422,7 +430,7 @@ static inline void init_ibs_nmi_per_cpu( #define PCI_VENDOR_ID_AMD 0x1022 #define PCI_DEVICE_ID_AMD_10H_NB_MISC 0x1203 #define IBSCTL 0x1cc -static int init_ibs_nmi(void) +static int __init init_ibs_nmi(void) { int bus, dev, func; u32 id, value; @@ -438,10 +446,6 @@ static int init_ibs_nmi(void) for (func =3D 0; func < 8; func++) { id =3D pci_conf_read32(bus, dev, func, = PCI_VENDOR_ID); =20 - if ((id =3D=3D 0xffffffff) || (id =3D=3D = 0x00000000) || - (id =3D=3D 0x0000ffff) || (id = =3D=3D 0xffff0000)) - continue; - vendor_id =3D id & 0xffff; dev_id =3D (id >> 16) & 0xffff; =20 @@ -456,7 +460,7 @@ static int init_ibs_nmi(void) if (value !=3D (IBSCTL_LVTOFFSETVAL= | APIC_EILVT_LVTOFF_IBS)) { printk("Xenoprofile: = Failed to setup IBS LVT offset, " - "IBSCTL =3D = 0x%08x", value); + "IBSCTL =3D = %#08x\n", value); return 1; } nodes++; @@ -466,56 +470,47 @@ static int init_ibs_nmi(void) } =20 if (!nodes) { - printk("Xenoprofile: No CPU node configured for IBS"); + printk("Xenoprofile: No CPU node configured for IBS\n"); return 1; } =20 return 0; } =20 -static u32 get_ibs_caps(void) +static void __init get_ibs_caps(void) { -#ifdef CONFIG_X86_32 - return 0; -#else unsigned int max_level; =20 if (!boot_cpu_has(X86_FEATURE_IBS)) - return 0; + return; =20 /* check IBS cpuid feature flags */ max_level =3D cpuid_eax(0x80000000); - if (max_level < IBS_CPUID_FEATURES) - return IBS_CAPS_AVAIL; - - ibs_caps =3D cpuid_eax(IBS_CPUID_FEATURES); + if (max_level >=3D IBS_CPUID_FEATURES) + ibs_caps =3D cpuid_eax(IBS_CPUID_FEATURES); if (!(ibs_caps & IBS_CAPS_AVAIL)) /* cpuid flags not valid */ - return IBS_CAPS_AVAIL; - - return ibs_caps; -#endif + ibs_caps =3D 0; } =20 -u32 ibs_init(void) +void __init ibs_init(void) { - u32 ibs_caps =3D 0; - - ibs_caps =3D get_ibs_caps(); + get_ibs_caps(); =20 if ( !ibs_caps ) - return 0; + return; =20 if (init_ibs_nmi()) { ibs_caps =3D 0; - return 0; + return; } =20 printk("Xenoprofile: AMD IBS detected (0x%08x)\n", (unsigned)ibs_caps); - return ibs_caps; } =20 +#endif /* CONFIG_X86_64 */ + struct op_x86_model_spec const op_athlon_spec =3D { .num_counters =3D NUM_COUNTERS, .num_controls =3D NUM_CONTROLS, --- a/xen/include/asm-x86/xenoprof.h +++ b/xen/include/asm-x86/xenoprof.h @@ -48,8 +48,13 @@ struct vcpu; struct cpu_user_regs; =20 /* AMD IBS support */ -u32 ibs_init(void); +#ifdef CONFIG_X86_64 +void ibs_init(void); extern u32 ibs_caps; +#else +static inline void ibs_init(void) {} +#define ibs_caps 0 +#endif =20 int xenoprofile_get_mode(struct vcpu *v, struct cpu_user_regs * const = regs); =20 --=__Part4D60DE71.0__= Content-Type: text/plain; name="x86-fam10-oprof.patch" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="x86-fam10-oprof.patch" Arrange for (almost) no code to be generated for x86-32, where the=0Afuncti= onality is disabled anyway. Properly __init-annotate the code.=0ARemove = some pointless bits.=0A=0ASigned-off-by: Jan Beulich = =0A=0A--- a/xen/arch/x86/oprofile/nmi_int.c=0A+++ b/xen/arch/x86/oprofile/n= mi_int.c=0A@@ -431,7 +431,7 @@ static int __init nmi_init(void)=0A = case 0x10:=0A model =3D &op_athlon_spec;= =0A cpu_type =3D "x86-64/family10";=0A- = ibs_caps =3D ibs_init();=0A+ = ibs_init();=0A break;=0A = case 0x11:=0A model =3D &op_athlon_spec;=0A--- = a/xen/arch/x86/oprofile/op_model_athlon.c=0A+++ b/xen/arch/x86/oprofile/op_= model_athlon.c=0A@@ -48,8 +48,12 @@ static unsigned long reset_value[NUM_CO= U=0A =0A extern char svm_stgi_label[];=0A =0A+#ifdef CONFIG_X86_64=0A u32 = ibs_caps =3D 0;=0A static u64 ibs_op_ctl;=0A+#else=0A+#define ibs_op_ctl = 0=0A+#endif=0A =0A /* IBS cpuid feature detection */=0A #define IBS_CPUID_F= EATURES 0x8000001b=0A@@ -324,6 +328,7 @@ static int athlon_che= ck_ctrs(unsigned in=0A =0A static inline void start_ibs(void)=0A {=0A+#ifde= f CONFIG_X86_64=0A u64 val =3D 0;=0A =0A if (!ibs_caps)=0A@@ -361,6 = +366,7 @@ static inline void start_ibs(void)=0A val =3D = op_amd_randomize_ibs_op(ibs_op_ctl);=0A wrmsrl(MSR_AMD64_IB= SOPCTL, val);=0A }=0A+#endif=0A }=0A =0A static void athlon_start(s= truct op_msrs const * const msrs)=0A@@ -407,11 +413,13 @@ static void = athlon_stop(struct op_msrs c=0A stop_ibs();=0A }=0A =0A+#ifdef = CONFIG_X86_64=0A+=0A #define IBSCTL_LVTOFFSETVAL (1 << 8)=0A = #define APIC_EILVT_MSG_NMI 0x4=0A #define APIC_EILVT_LVTOFF_IB= S 1=0A #define APIC_EILVTn(n) (0x500 + 0x10 * = n)=0A-static inline void init_ibs_nmi_per_cpu(void *arg)=0A+static inline = void __init init_ibs_nmi_per_cpu(void *arg)=0A {=0A unsigned long = reg;=0A =0A@@ -422,7 +430,7 @@ static inline void init_ibs_nmi_per_cpu(=0A = #define PCI_VENDOR_ID_AMD 0x1022=0A #define PCI_DEVICE_ID_AMD= _10H_NB_MISC 0x1203=0A #define IBSCTL 0x1cc=0A-s= tatic int init_ibs_nmi(void)=0A+static int __init init_ibs_nmi(void)=0A = {=0A int bus, dev, func;=0A u32 id, value;=0A@@ -438,10 +446,6 @@ = static int init_ibs_nmi(void)=0A for (func =3D 0; = func < 8; func++) {=0A id =3D pci_conf_read32(bus,= dev, func, PCI_VENDOR_ID);=0A =0A- if ((id = =3D=3D 0xffffffff) || (id =3D=3D 0x00000000) ||=0A- = (id =3D=3D 0x0000ffff) || (id =3D=3D 0xffff0000))=0A- = continue;=0A-=0A vendor_id = =3D id & 0xffff;=0A dev_id =3D (id >> 16) & = 0xffff;=0A =0A@@ -456,7 +460,7 @@ static int init_ibs_nmi(void)=0A = if (value !=3D (IBSCTL_LVTOFFSETVAL |=0A = APIC_EILVT_LVTOFF_IBS)) {=0A = printk("Xenoprofile: Failed to setup IBS LVT = offset, "=0A- "IBSCTL = =3D 0x%08x", value);=0A+ = "IBSCTL =3D %#08x\n", value);=0A = return 1;=0A }=0A = nodes++;=0A@@ -466,56 +470,47 @@ static int init_ibs_nmi(void)=0A = }=0A =0A if (!nodes) {=0A- printk("Xenoprofile: No = CPU node configured for IBS");=0A+ printk("Xenoprofile: No = CPU node configured for IBS\n");=0A return 1;=0A }=0A =0A = return 0;=0A }=0A =0A-static u32 get_ibs_caps(void)=0A+static void __init = get_ibs_caps(void)=0A {=0A-#ifdef CONFIG_X86_32=0A- return = 0;=0A-#else=0A unsigned int max_level;=0A =0A if (!boot_cpu_has(X86_FEATU= RE_IBS))=0A- return 0;=0A+ return;=0A =0A /* = check IBS cpuid feature flags */=0A max_level =3D cpuid_eax(0x80000000)= ;=0A- if (max_level < IBS_CPUID_FEATURES)=0A- return IBS_CAPS_AVA= IL;=0A-=0A- ibs_caps =3D cpuid_eax(IBS_CPUID_FEATURES);=0A+ if = (max_level >=3D IBS_CPUID_FEATURES)=0A+ ibs_caps =3D cpuid_eax(IBS_= CPUID_FEATURES);=0A if (!(ibs_caps & IBS_CAPS_AVAIL))=0A /* = cpuid flags not valid */=0A- return IBS_CAPS_AVAIL;=0A-=0A- = return ibs_caps;=0A-#endif=0A+ ibs_caps =3D 0;=0A }=0A =0A-u32 = ibs_init(void)=0A+void __init ibs_init(void)=0A {=0A- u32 ibs_caps =3D = 0;=0A-=0A- ibs_caps =3D get_ibs_caps();=0A+ get_ibs_caps();=0A = =0A if ( !ibs_caps )=0A- return 0;=0A+ return;=0A = =0A if (init_ibs_nmi()) {=0A ibs_caps =3D 0;=0A- = return 0;=0A+ return;=0A }=0A =0A printk("Xenoprofile= : AMD IBS detected (0x%08x)\n",=0A (unsigned)ibs_caps);=0A- = return ibs_caps;=0A }=0A =0A+#endif /* CONFIG_X86_64 */=0A+=0A struct = op_x86_model_spec const op_athlon_spec =3D {=0A .num_counters =3D = NUM_COUNTERS,=0A .num_controls =3D NUM_CONTROLS,=0A--- a/xen/include= /asm-x86/xenoprof.h=0A+++ b/xen/include/asm-x86/xenoprof.h=0A@@ -48,8 = +48,13 @@ struct vcpu;=0A struct cpu_user_regs;=0A =0A /* AMD IBS support = */=0A-u32 ibs_init(void);=0A+#ifdef CONFIG_X86_64=0A+void ibs_init(void);= =0A extern u32 ibs_caps;=0A+#else=0A+static inline void ibs_init(void) = {}=0A+#define ibs_caps 0=0A+#endif=0A =0A int xenoprofile_get_mode(struct = vcpu *v, struct cpu_user_regs * const regs);=0A =0A --=__Part4D60DE71.0__= Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ Xen-devel mailing list Xen-devel@lists.xensource.com http://lists.xensource.com/xen-devel --=__Part4D60DE71.0__=--