From: "Jan Beulich" Subject: [PATCH] x86/AMD: fold redundant parameters of cpu_has_amd_erratum() Date: Fri, 16 Dec 2011 15:23:45 +0000 Message-ID: <4EEB70910200007800068852@nat28.tlf.novell.com> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=__Part3E119691.1__=" 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" Cc: wei.huang2@amd.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. --=__Part3E119691.1__= Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: quoted-printable Content-Disposition: inline The boolean 'osvw' indicator and 'osvw_id' can be folded - the function can as well distinguish the non-OSVW case by checking for a negative 'osvw_id'. That way the whole variable argument list processing is only needed on the legacy code path. Signed-off-by: Jan Beulich --- a/xen/arch/x86/cpu/amd.c +++ b/xen/arch/x86/cpu/amd.c @@ -186,7 +186,7 @@ static void __devinit set_cpuidmask(cons * Check for the presence of an AMD erratum. Arguments are defined in = amd.h=20 * for each known erratum. Return 1 if erratum is found. */ -int cpu_has_amd_erratum(const struct cpuinfo_x86 *cpu, int osvw, ...)=20 +int cpu_has_amd_erratum(const struct cpuinfo_x86 *cpu, int osvw_id, ...) { va_list ap; u32 range; @@ -195,27 +195,24 @@ int cpu_has_amd_erratum(const struct cpu if (cpu->x86_vendor !=3D X86_VENDOR_AMD) return 0; =20 - va_start(ap, osvw); + if (osvw_id >=3D 0 && cpu_has(cpu, X86_FEATURE_OSVW)) { + u64 osvw_len; =20 - if (osvw) { - u16 osvw_id =3D va_arg(ap, int); + rdmsrl(MSR_AMD_OSVW_ID_LENGTH, osvw_len); =20 - if (cpu_has(cpu, X86_FEATURE_OSVW)) { - u64 osvw_len; - rdmsrl(MSR_AMD_OSVW_ID_LENGTH, osvw_len); - - if (osvw_id < osvw_len) { - u64 osvw_bits; - rdmsrl(MSR_AMD_OSVW_STATUS + (osvw_id >> = 6),=20 - osvw_bits); + if (osvw_id < osvw_len) { + u64 osvw_bits; =20 - va_end(ap); - return (osvw_bits >> (osvw_id & 0x3f)) & = 0x01; - } + rdmsrl(MSR_AMD_OSVW_STATUS + (osvw_id >> 6), + osvw_bits); + + return (osvw_bits >> (osvw_id & 0x3f)) & 1; } } =20 /* OSVW unavailable or ID unknown, match family-model-stepping = range */ + va_start(ap, osvw_id); + ms =3D (cpu->x86_model << 4) | cpu->x86_mask; while ((range =3D va_arg(ap, int))) { if ((cpu->x86 =3D=3D AMD_MODEL_RANGE_FAMILY(range)) && --- a/xen/include/asm-x86/amd.h +++ b/xen/include/asm-x86/amd.h @@ -119,8 +119,8 @@ * =20 */ =20 -#define AMD_LEGACY_ERRATUM(...) 0 /* legacy */, __VA_ARGS__, 0 -#define AMD_OSVW_ERRATUM(osvw_id, ...) 1 /* osvw */, osvw_id, __VA_ARGS__= , 0 +#define AMD_LEGACY_ERRATUM(...) -1 /* legacy */, __VA_ARGS__, 0 +#define AMD_OSVW_ERRATUM(osvw_id, ...) osvw_id, __VA_ARGS__, 0 #define AMD_MODEL_RANGE(f, m_start, s_start, m_end, s_end) \ ((f << 24) | (m_start << 16) | (s_start << 12) | (m_end << 4) | = (s_end)) #define AMD_MODEL_RANGE_FAMILY(range) (((range) >> 24) & 0xff) --=__Part3E119691.1__= Content-Type: text/plain; name="amd-errata-redundant-param.patch" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="amd-errata-redundant-param.patch" x86/AMD: fold redundant parameters of cpu_has_amd_erratum()=0A=0AThe = boolean 'osvw' indicator and 'osvw_id' can be folded - the function=0Acan = as well distinguish the non-OSVW case by checking for a negative=0A'osvw_id= '. That way the whole variable argument list processing is only=0Aneeded = on the legacy code path.=0A=0ASigned-off-by: Jan Beulich =0A=0A--- a/xen/arch/x86/cpu/amd.c=0A+++ b/xen/arch/x86/cpu/amd.c=0A@@ = -186,7 +186,7 @@ static void __devinit set_cpuidmask(cons=0A * Check for = the presence of an AMD erratum. Arguments are defined in amd.h =0A * for = each known erratum. Return 1 if erratum is found.=0A */=0A-int cpu_has_amd= _erratum(const struct cpuinfo_x86 *cpu, int osvw, ...) =0A+int cpu_has_amd_= erratum(const struct cpuinfo_x86 *cpu, int osvw_id, ...)=0A {=0A = va_list ap;=0A u32 range;=0A@@ -195,27 +195,24 @@ int cpu_has_amd_erratum(= const struct cpu=0A if (cpu->x86_vendor !=3D X86_VENDOR_AMD)=0A = return 0;=0A =0A- va_start(ap, osvw);=0A+ if (osvw_id >=3D 0 && = cpu_has(cpu, X86_FEATURE_OSVW)) {=0A+ u64 osvw_len;=0A =0A- if = (osvw) {=0A- u16 osvw_id =3D va_arg(ap, int);=0A+ = rdmsrl(MSR_AMD_OSVW_ID_LENGTH, osvw_len);=0A =0A- if = (cpu_has(cpu, X86_FEATURE_OSVW)) {=0A- u64 osvw_len;=0A- = rdmsrl(MSR_AMD_OSVW_ID_LENGTH, osvw_len);=0A-=0A- = if (osvw_id < osvw_len) {=0A- u64 = osvw_bits;=0A- rdmsrl(MSR_AMD_OSVW_STATUS + = (osvw_id >> 6), =0A- osvw_bits);=0A+ = if (osvw_id < osvw_len) {=0A+ u64 osvw_bits;=0A =0A- = va_end(ap);=0A- return (osvw_bits = >> (osvw_id & 0x3f)) & 0x01;=0A- }=0A+ = rdmsrl(MSR_AMD_OSVW_STATUS + (osvw_id >> 6),=0A+ = osvw_bits);=0A+=0A+ return (osvw_bits >> (osvw_id & = 0x3f)) & 1;=0A }=0A }=0A =0A /* OSVW unavailable or ID = unknown, match family-model-stepping range */=0A+ va_start(ap, = osvw_id);=0A+=0A ms =3D (cpu->x86_model << 4) | cpu->x86_mask;=0A = while ((range =3D va_arg(ap, int))) {=0A if ((cpu->x86 = =3D=3D AMD_MODEL_RANGE_FAMILY(range)) &&=0A--- a/xen/include/asm-x86/amd.h= =0A+++ b/xen/include/asm-x86/amd.h=0A@@ -119,8 +119,8 @@=0A * =0A = */=0A =0A-#define AMD_LEGACY_ERRATUM(...) 0 /* legacy */, = __VA_ARGS__, 0=0A-#define AMD_OSVW_ERRATUM(osvw_id, ...) 1 /* osvw */, = osvw_id, __VA_ARGS__, 0=0A+#define AMD_LEGACY_ERRATUM(...) -1 /* = legacy */, __VA_ARGS__, 0=0A+#define AMD_OSVW_ERRATUM(osvw_id, ...) = osvw_id, __VA_ARGS__, 0=0A #define AMD_MODEL_RANGE(f, m_start, s_start, = m_end, s_end) \=0A ((f << 24) | (m_start << 16) | = (s_start << 12) | (m_end << 4) | (s_end))=0A #define AMD_MODEL_RANGE_FAMILY= (range) (((range) >> 24) & 0xff)=0A --=__Part3E119691.1__= 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 --=__Part3E119691.1__=--