Skip to contentSkip to conversation

x86/cpu: Store extended cpuid level in cpuinfo_x86

PATCH In review Andrew Cooper 2 participants 2 messages Feb 25, 2014

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 x86/cpu: Store extended cpuid level in cpuinfo_x86

To save finding it repeatedly with cpuid instructions. The name "extended_cpuid_level" is chosen to match Linux.

CC Keir Fraser <[email protected]>
CC Jan Beulich <[email protected]>
CC Boris Ostrovsky <[email protected]>
CC Suravee Suthikulpanit <[email protected]>
---
 xen/arch/x86/cpu/amd.c                  |    4 ++--
 xen/arch/x86/cpu/common.c               |   22 ++++++++++------------
 xen/arch/x86/hvm/svm/svm.c              |    2 +-
 xen/arch/x86/oprofile/op_model_athlon.c |    5 +----
 xen/include/asm-x86/processor.h         |    1 +
 5 files changed, 15 insertions(+), 19 deletions(-)
xen/arch/x86/cpu/amd.c +2 -2
index 44087fa..904ad2e 100644
@@ -419,11 +419,11 @@ static void __devinit init_amd(struct cpuinfo_x86 *c)
 
 	display_cacheinfo(c);
 
-	if (cpuid_eax(0x80000000) >= 0x80000008) {
+	if (c->extended_cpuid_level >= 0x80000008) {
 		c->x86_max_cores = (cpuid_ecx(0x80000008) & 0xff) + 1;
 	}
 
-	if (cpuid_eax(0x80000000) >= 0x80000007) {
+	if (c->extended_cpuid_level >= 0x80000007) {
 		c->x86_power = cpuid_edx(0x80000007);
 		if (c->x86_power & (1<<8)) {
 			set_bit(X86_FEATURE_CONSTANT_TSC, c->x86_capability);
xen/arch/x86/cpu/common.c +10 -12
index 32ca458..2c128e5 100644
@@ -74,7 +74,7 @@ int __cpuinit get_model_name(struct cpuinfo_x86 *c)
 	unsigned int *v;
 	char *p, *q;
 
-	if (cpuid_eax(0x80000000) < 0x80000004)
+	if (c->extended_cpuid_level < 0x80000004)
 		return 0;
 
 	v = (unsigned int *) c->x86_model_id;
@@ -101,11 +101,9 @@ int __cpuinit get_model_name(struct cpuinfo_x86 *c)
 
 void __cpuinit display_cacheinfo(struct cpuinfo_x86 *c)
 {
-	unsigned int n, dummy, ecx, edx, l2size;
+	unsigned int dummy, ecx, edx, l2size;
 
-	n = cpuid_eax(0x80000000);
-
-	if (n >= 0x80000005) {
+	if (c->extended_cpuid_level >= 0x80000005) {
 		cpuid(0x80000005, &dummy, &dummy, &ecx, &edx);
 		if (opt_cpu_info)
 			printk("CPU: L1 I cache %dK (%d bytes/line),"
@@ -114,7 +112,7 @@ void __cpuinit display_cacheinfo(struct cpuinfo_x86 *c)
 		c->x86_cache_size=(ecx>>24)+(edx>>24);	
 	}
 
-	if (n < 0x80000006)	/* Some chips just has a large L1. */
+	if (c->extended_cpuid_level < 0x80000006)	/* Some chips just has a large L1. */
 		return;
 
 	ecx = cpuid_ecx(0x80000006);
@@ -195,7 +193,7 @@ static void __init early_cpu_detect(void)
 
 static void __cpuinit generic_identify(struct cpuinfo_x86 *c)
 {
-	u32 tfms, xlvl, capability, excap, ebx;
+	u32 tfms, capability, excap, ebx;
 
 	/* Get vendor name */
 	cpuid(0x00000000, &c->cpuid_level,
@@ -222,15 +220,15 @@ static void __cpuinit generic_identify(struct cpuinfo_x86 *c)
 		c->x86_clflush_size = ((ebx >> 8) & 0xff) * 8;
 
 	/* AMD-defined flags: level 0x80000001 */
-	xlvl = cpuid_eax(0x80000000);
-	if ( (xlvl & 0xffff0000) == 0x80000000 ) {
-		if ( xlvl >= 0x80000001 ) {
+	c->extended_cpuid_level = cpuid_eax(0x80000000);
+	if ( (c->extended_cpuid_level & 0xffff0000) == 0x80000000 ) {
+		if ( c->extended_cpuid_level >= 0x80000001 ) {
 			c->x86_capability[1] = cpuid_edx(0x80000001);
 			c->x86_capability[6] = cpuid_ecx(0x80000001);
 		}
-		if ( xlvl >= 0x80000004 )
+		if ( c->extended_cpuid_level >= 0x80000004 )
 			get_model_name(c); /* Default name */
-		if ( xlvl >= 0x80000008 )
+		if ( c->extended_cpuid_level >= 0x80000008 )
 			paddr_bits = cpuid_eax(0x80000008) & 0xff;
 	}
 
xen/arch/x86/hvm/svm/svm.c +1 -1
index 406d394..61b1ec8 100644
@@ -1251,7 +1251,7 @@ const struct hvm_function_table * __init start_svm(void)
 
     setup_vmcb_dump();
 
-    svm_feature_flags = ((cpuid_eax(0x80000000) >= 0x8000000A) ?
+    svm_feature_flags = (current_cpu_data.extended_cpuid_level >= 0x8000000A ?
                          cpuid_edx(0x8000000A) : 0);
 
     printk("SVM: Supported advanced features:\n");
xen/arch/x86/oprofile/op_model_athlon.c +1 -4
index e784018..ad84768 100644
@@ -497,14 +497,11 @@ static int __init init_ibs_nmi(void)
 
 static void __init get_ibs_caps(void)
 {
-	unsigned int max_level;
-
 	if (!boot_cpu_has(X86_FEATURE_IBS))
 		return;
 
     /* check IBS cpuid feature flags */
-	max_level = cpuid_eax(0x80000000);
-	if (max_level >= IBS_CPUID_FEATURES)
+	if (current_cpu_data.extended_cpuid_level >= IBS_CPUID_FEATURES)
 		ibs_caps = cpuid_eax(IBS_CPUID_FEATURES);
 	if (!(ibs_caps & IBS_CAPS_AVAIL))
 		/* cpuid flags not valid */
xen/include/asm-x86/processor.h +1 -0
index c120460..f1cccff 100644
@@ -162,6 +162,7 @@ struct cpuinfo_x86 {
     __u8 x86_model;
     __u8 x86_mask;
     int  cpuid_level;    /* Maximum supported CPUID level, -1=no CPUID */
+    __u32 extended_cpuid_level; /* Maximum supported CPUID extended level */
     unsigned int x86_capability[NCAPINTS];
     char x86_vendor_id[16];
     char x86_model_id[64];
Signature · 1 line
1.7.10.4
#1 lore raw
Quoted 80 lines · Andrew Cooper

To save finding it repeatedly with cpuid instructions. The name "extended_cpuid_level" is chosen to match Linux.

CC Keir Fraser <[email protected]>
CC Jan Beulich <[email protected]>
CC Boris Ostrovsky <[email protected]>
CC Suravee Suthikulpanit <[email protected]>
---
  xen/arch/x86/cpu/amd.c                  |    4 ++--
  xen/arch/x86/cpu/common.c               |   22 ++++++++++------------
  xen/arch/x86/hvm/svm/svm.c              |    2 +-
  xen/arch/x86/oprofile/op_model_athlon.c |    5 +----
  xen/include/asm-x86/processor.h         |    1 +
  5 files changed, 15 insertions(+), 19 deletions(-)
xen/arch/x86/cpu/amd.c +2 -2
index 44087fa..904ad2e 100644
@@ -419,11 +419,11 @@ static void __devinit init_amd(struct cpuinfo_x86 *c)
 
  	display_cacheinfo(c);
 
-	if (cpuid_eax(0x80000000) >= 0x80000008) {
+	if (c->extended_cpuid_level >= 0x80000008) {
  		c->x86_max_cores = (cpuid_ecx(0x80000008) & 0xff) + 1;
  	}
 
-	if (cpuid_eax(0x80000000) >= 0x80000007) {
+	if (c->extended_cpuid_level >= 0x80000007) {
  		c->x86_power = cpuid_edx(0x80000007);
  		if (c->x86_power & (1<<8)) {
  			set_bit(X86_FEATURE_CONSTANT_TSC, c->x86_capability);
xen/arch/x86/cpu/common.c +5 -7
index 32ca458..2c128e5 100644
@@ -74,7 +74,7 @@ int __cpuinit get_model_name(struct cpuinfo_x86 *c)
  	unsigned int *v;
  	char *p, *q;
 
-	if (cpuid_eax(0x80000000) < 0x80000004)
+	if (c->extended_cpuid_level < 0x80000004)
  		return 0;
 
  	v = (unsigned int *) c->x86_model_id;
@@ -101,11 +101,9 @@ int __cpuinit get_model_name(struct cpuinfo_x86 *c)
 
  void __cpuinit display_cacheinfo(struct cpuinfo_x86 *c)
  {
-	unsigned int n, dummy, ecx, edx, l2size;
+	unsigned int dummy, ecx, edx, l2size;
 
-	n = cpuid_eax(0x80000000);
-
-	if (n >= 0x80000005) {
+	if (c->extended_cpuid_level >= 0x80000005) {
  		cpuid(0x80000005, &dummy, &dummy, &ecx, &edx);
  		if (opt_cpu_info)
  			printk("CPU: L1 I cache %dK (%d bytes/line),"
@@ -114,7 +112,7 @@ void __cpuinit display_cacheinfo(struct cpuinfo_x86 *c)
  		c->x86_cache_size=(ecx>>24)+(edx>>24);	
  	}
 
-	if (n < 0x80000006)	/* Some chips just has a large L1. */
+	if (c->extended_cpuid_level < 0x80000006)	/* Some chips just has a large L1. */
  		return;
 
  	ecx = cpuid_ecx(0x80000006);
@@ -195,7 +193,7 @@ static void __init early_cpu_detect(void)
 
  static void __cpuinit generic_identify(struct cpuinfo_x86 *c)
  {
-	u32 tfms, xlvl, capability, excap, ebx;
+	u32 tfms, capability, excap, ebx;
 
  	/* Get vendor name */
  	cpuid(0x00000000, &c->cpuid_level,

xen/arch/x86/cpu/common.c static void __cpuinit generic_identify(struct cpuinfo_x86 *c) · line 223

Quoted 7 lines
xen/arch/x86/cpu/common.c +1 -3
@@ -222,15 +220,15 @@ static void __cpuinit generic_identify(struct cpuinfo_x86 *c)
  		c->x86_clflush_size = ((ebx >> 8) & 0xff) * 8;
 
  	/* AMD-defined flags: level 0x80000001 */
-	xlvl = cpuid_eax(0x80000000);
-	if ( (xlvl & 0xffff0000) == 0x80000000 ) {
-		if ( xlvl >= 0x80000001 ) {
+	c->extended_cpuid_level = cpuid_eax(0x80000000);

This should probably be moved from under AMD-specific comment as it is common with Intel. (And Linux apparently makes the same mistake).

I also see a couple more instances that might be replaced --- efi_start() and mtrr_top_of_ram() (although the latter is probably more trouble than it's worth).

-boris

Quoted 58 lines
xen/arch/x86/cpu/common.c +4 -2
+	if ( (c->extended_cpuid_level & 0xffff0000) == 0x80000000 ) {
+		if ( c->extended_cpuid_level >= 0x80000001 ) {
  			c->x86_capability[1] = cpuid_edx(0x80000001);
  			c->x86_capability[6] = cpuid_ecx(0x80000001);
  		}
-		if ( xlvl >= 0x80000004 )
+		if ( c->extended_cpuid_level >= 0x80000004 )
  			get_model_name(c); /* Default name */
-		if ( xlvl >= 0x80000008 )
+		if ( c->extended_cpuid_level >= 0x80000008 )
  			paddr_bits = cpuid_eax(0x80000008) & 0xff;
  	}
 
xen/arch/x86/hvm/svm/svm.c +1 -1
index 406d394..61b1ec8 100644
@@ -1251,7 +1251,7 @@ const struct hvm_function_table * __init start_svm(void)
 
      setup_vmcb_dump();
 
-    svm_feature_flags = ((cpuid_eax(0x80000000) >= 0x8000000A) ?
+    svm_feature_flags = (current_cpu_data.extended_cpuid_level >= 0x8000000A ?
                           cpuid_edx(0x8000000A) : 0);
 
      printk("SVM: Supported advanced features:\n");
xen/arch/x86/oprofile/op_model_athlon.c +1 -4
index e784018..ad84768 100644
@@ -497,14 +497,11 @@ static int __init init_ibs_nmi(void)
 
  static void __init get_ibs_caps(void)
  {
-	unsigned int max_level;
-
  	if (!boot_cpu_has(X86_FEATURE_IBS))
  		return;
 
      /* check IBS cpuid feature flags */
-	max_level = cpuid_eax(0x80000000);
-	if (max_level >= IBS_CPUID_FEATURES)
+	if (current_cpu_data.extended_cpuid_level >= IBS_CPUID_FEATURES)
  		ibs_caps = cpuid_eax(IBS_CPUID_FEATURES);
  	if (!(ibs_caps & IBS_CAPS_AVAIL))
  		/* cpuid flags not valid */
xen/include/asm-x86/processor.h +1 -0
index c120460..f1cccff 100644
@@ -162,6 +162,7 @@ struct cpuinfo_x86 {
      __u8 x86_model;
      __u8 x86_mask;
      int  cpuid_level;    /* Maximum supported CPUID level, -1=no CPUID */
+    __u32 extended_cpuid_level; /* Maximum supported CPUID extended level */
      unsigned int x86_capability[NCAPINTS];
      char x86_vendor_id[16];
      char x86_model_id[64];