Skip to contentSkip to conversation

replace cpuid_*features fields with a featue word array (v2)

PATCH In review Eduardo Habkost 3 participants 21 messages Dec 12, 2012 – Dec 14, 2012

lore
Share & tools
lore
#0 lore raw

cover replace cpuid_*features fields with a featue word array (v2)

Changes in v2:
- Rebased on top of:
Subject: [PATCH 0/2] target-i386: move CPU object creation to cpu.c (v2)
- Wrote a sed script that can be used to reproduce exactly the same changes from patch 3:
https://gist.github.com/4271991

Git tree for testing:
git://github.com/ehabkost/qemu-hacks.git x86-cpu-feature-array.v2
https://github.com/ehabkost/qemu-hacks/tree/x86-cpu-feature-array.v2

Original description:

I was planning to implement this only after we finished the rest of the work, the changes are a bit intrusive. But now it looks like the CPUID feature bits are getting into our way (e.g. the feature word array will allow us to simplify the -cpu host and -cpu check/enforce code a lot, making it easier to convert that code to use CPU subclasses), so I decided to submit it now.

Eduardo Habkost (3):
target-i386: add EXT2_PPRO_FEATURES #define target-i386/cpu.c: coding style fix
target-i386: replace cpuid_*features fields with a feature word array

 hw/kvm/clock.c            |   2 +-
 linux-user/elfload.c      |   2 +-
 linux-user/main.c         |   4 +-
 target-i386/cpu.c         | 582 +++++++++++++++++++++++-----------------------
 target-i386/cpu.h         |  30 +--
 target-i386/helper.c      |   4 +-
 target-i386/kvm.c         |   5 +-
 target-i386/misc_helper.c |  14 +-
 target-i386/translate.c   |  10 +-
 9 files changed, 334 insertions(+), 319 deletions(-)
Signature · 1 line
1.7.11.7
#1 lore raw

PATCH 1/3 target-i386: add EXT2_PPRO_FEATURES #define

Instead of repeating the (PPRO_FEATURES & CPUID_EXT2_AMD_ALIASES) expression everywhere, use EXT2_PPRO_FEATURES.

---
 target-i386/cpu.c | 13 +++++++------
 1 file changed, 7 insertions(+), 6 deletions(-)
target-i386/cpu.c +7 -6
index 546c86a..a2ee8bb 100644
@@ -303,6 +303,7 @@ typedef struct x86_def_t {
           CPUID_MSR | CPUID_MCE | CPUID_CX8 | CPUID_PGE | CPUID_CMOV | \
           CPUID_PAT | CPUID_FXSR | CPUID_MMX | CPUID_SSE | CPUID_SSE2 | \
           CPUID_PAE | CPUID_SEP | CPUID_APIC)
+#define EXT2_PPRO_FEATURES (PPRO_FEATURES & CPUID_EXT2_AMD_ALIASES)
 
 #define TCG_FEATURES (CPUID_FP87 | CPUID_PSE | CPUID_TSC | CPUID_MSR | \
           CPUID_PAE | CPUID_MCE | CPUID_CX8 | CPUID_APIC | CPUID_SEP | \
@@ -350,7 +351,7 @@ static x86_def_t builtin_x86_defs[] = {
             CPUID_MTRR | CPUID_CLFLUSH | CPUID_MCA |
             CPUID_PSE36,
         .ext_features = CPUID_EXT_SSE3 | CPUID_EXT_CX16 | CPUID_EXT_POPCNT,
-        .ext2_features = (PPRO_FEATURES & CPUID_EXT2_AMD_ALIASES) |
+        .ext2_features = EXT2_PPRO_FEATURES |
             CPUID_EXT2_LM | CPUID_EXT2_SYSCALL | CPUID_EXT2_NX,
         .ext3_features = CPUID_EXT3_LAHF_LM | CPUID_EXT3_SVM |
             CPUID_EXT3_ABM | CPUID_EXT3_SSE4A,
@@ -370,7 +371,7 @@ static x86_def_t builtin_x86_defs[] = {
             CPUID_PSE36 | CPUID_VME | CPUID_HT,
         .ext_features = CPUID_EXT_SSE3 | CPUID_EXT_MONITOR | CPUID_EXT_CX16 |
             CPUID_EXT_POPCNT,
-        .ext2_features = (PPRO_FEATURES & CPUID_EXT2_AMD_ALIASES) |
+        .ext2_features = EXT2_PPRO_FEATURES |
             CPUID_EXT2_LM | CPUID_EXT2_SYSCALL | CPUID_EXT2_NX |
             CPUID_EXT2_3DNOW | CPUID_EXT2_3DNOWEXT | CPUID_EXT2_MMXEXT |
             CPUID_EXT2_FFXSR | CPUID_EXT2_PDPE1GB | CPUID_EXT2_RDTSCP,
@@ -421,7 +422,7 @@ static x86_def_t builtin_x86_defs[] = {
         /* Missing: CPUID_EXT_POPCNT, CPUID_EXT_MONITOR */
         .ext_features = CPUID_EXT_SSE3 | CPUID_EXT_CX16,
         /* Missing: CPUID_EXT2_PDPE1GB, CPUID_EXT2_RDTSCP */
-        .ext2_features = (PPRO_FEATURES & CPUID_EXT2_AMD_ALIASES) |
+        .ext2_features = EXT2_PPRO_FEATURES |
             CPUID_EXT2_LM | CPUID_EXT2_SYSCALL | CPUID_EXT2_NX,
         /* Missing: CPUID_EXT3_LAHF_LM, CPUID_EXT3_CMP_LEG, CPUID_EXT3_EXTAPIC,
                     CPUID_EXT3_CR8LEG, CPUID_EXT3_ABM, CPUID_EXT3_SSE4A,
@@ -456,7 +457,7 @@ static x86_def_t builtin_x86_defs[] = {
         .features = PPRO_FEATURES |
             CPUID_MTRR | CPUID_CLFLUSH | CPUID_MCA | CPUID_PSE36,
         .ext_features = CPUID_EXT_SSE3,
-        .ext2_features = PPRO_FEATURES & CPUID_EXT2_AMD_ALIASES,
+        .ext2_features = EXT2_PPRO_FEATURES,
         .ext3_features = 0,
         .xlevel = 0x80000008,
         .model_id = "Common 32-bit KVM processor"
@@ -538,7 +539,7 @@ static x86_def_t builtin_x86_defs[] = {
         .stepping = 3,
         .features = PPRO_FEATURES | CPUID_PSE36 | CPUID_VME | CPUID_MTRR |
             CPUID_MCA,
-        .ext2_features = (PPRO_FEATURES & CPUID_EXT2_AMD_ALIASES) |
+        .ext2_features = EXT2_PPRO_FEATURES |
             CPUID_EXT2_MMXEXT | CPUID_EXT2_3DNOW | CPUID_EXT2_3DNOWEXT,
         .xlevel = 0x80000008,
     },
@@ -558,7 +559,7 @@ static x86_def_t builtin_x86_defs[] = {
             /* Some CPUs got no CPUID_SEP */
         .ext_features = CPUID_EXT_SSE3 | CPUID_EXT_MONITOR | CPUID_EXT_SSSE3 |
             CPUID_EXT_DSCPL | CPUID_EXT_EST | CPUID_EXT_TM2 | CPUID_EXT_XTPR,
-        .ext2_features = (PPRO_FEATURES & CPUID_EXT2_AMD_ALIASES) |
+        .ext2_features = EXT2_PPRO_FEATURES |
             CPUID_EXT2_NX,
         .ext3_features = CPUID_EXT3_LAHF_LM,
         .xlevel = 0x8000000A,
Signature · 1 line
1.7.11.7
Reviewed-by on v1 1/3
#2 lore raw

Re: [Qemu-devel] [PATCH 1/3] target-i386: add EXT2_PPRO_FEATURES #define

Quoted 7 lines · On Wed, 12 Dec 2012 20:22:24 -0200 Eduardo Habkost <[email protected]> wrote:

Instead of repeating the (PPRO_FEATURES & CPUID_EXT2_AMD_ALIASES) expression everywhere, use EXT2_PPRO_FEATURES.

---
 target-i386/cpu.c | 13 +++++++------
 1 file changed, 7 insertions(+), 6 deletions(-)
Quoted 71 lines
target-i386/cpu.c +7 -6
index 546c86a..a2ee8bb 100644
@@ -303,6 +303,7 @@ typedef struct x86_def_t {
           CPUID_MSR | CPUID_MCE | CPUID_CX8 | CPUID_PGE | CPUID_CMOV | \
           CPUID_PAT | CPUID_FXSR | CPUID_MMX | CPUID_SSE | CPUID_SSE2 | \
           CPUID_PAE | CPUID_SEP | CPUID_APIC)
+#define EXT2_PPRO_FEATURES (PPRO_FEATURES & CPUID_EXT2_AMD_ALIASES)
 
 #define TCG_FEATURES (CPUID_FP87 | CPUID_PSE | CPUID_TSC | CPUID_MSR | \
           CPUID_PAE | CPUID_MCE | CPUID_CX8 | CPUID_APIC | CPUID_SEP | \
@@ -350,7 +351,7 @@ static x86_def_t builtin_x86_defs[] = {
             CPUID_MTRR | CPUID_CLFLUSH | CPUID_MCA |
             CPUID_PSE36,
         .ext_features = CPUID_EXT_SSE3 | CPUID_EXT_CX16 | CPUID_EXT_POPCNT,
-        .ext2_features = (PPRO_FEATURES & CPUID_EXT2_AMD_ALIASES) |
+        .ext2_features = EXT2_PPRO_FEATURES |
             CPUID_EXT2_LM | CPUID_EXT2_SYSCALL | CPUID_EXT2_NX,
         .ext3_features = CPUID_EXT3_LAHF_LM | CPUID_EXT3_SVM |
             CPUID_EXT3_ABM | CPUID_EXT3_SSE4A,
@@ -370,7 +371,7 @@ static x86_def_t builtin_x86_defs[] = {
             CPUID_PSE36 | CPUID_VME | CPUID_HT,
         .ext_features = CPUID_EXT_SSE3 | CPUID_EXT_MONITOR | CPUID_EXT_CX16 |
             CPUID_EXT_POPCNT,
-        .ext2_features = (PPRO_FEATURES & CPUID_EXT2_AMD_ALIASES) |
+        .ext2_features = EXT2_PPRO_FEATURES |
             CPUID_EXT2_LM | CPUID_EXT2_SYSCALL | CPUID_EXT2_NX |
             CPUID_EXT2_3DNOW | CPUID_EXT2_3DNOWEXT | CPUID_EXT2_MMXEXT |
             CPUID_EXT2_FFXSR | CPUID_EXT2_PDPE1GB | CPUID_EXT2_RDTSCP,
@@ -421,7 +422,7 @@ static x86_def_t builtin_x86_defs[] = {
         /* Missing: CPUID_EXT_POPCNT, CPUID_EXT_MONITOR */
         .ext_features = CPUID_EXT_SSE3 | CPUID_EXT_CX16,
         /* Missing: CPUID_EXT2_PDPE1GB, CPUID_EXT2_RDTSCP */
-        .ext2_features = (PPRO_FEATURES & CPUID_EXT2_AMD_ALIASES) |
+        .ext2_features = EXT2_PPRO_FEATURES |
             CPUID_EXT2_LM | CPUID_EXT2_SYSCALL | CPUID_EXT2_NX,
         /* Missing: CPUID_EXT3_LAHF_LM, CPUID_EXT3_CMP_LEG, CPUID_EXT3_EXTAPIC,
                     CPUID_EXT3_CR8LEG, CPUID_EXT3_ABM, CPUID_EXT3_SSE4A,
@@ -456,7 +457,7 @@ static x86_def_t builtin_x86_defs[] = {
         .features = PPRO_FEATURES |
             CPUID_MTRR | CPUID_CLFLUSH | CPUID_MCA | CPUID_PSE36,
         .ext_features = CPUID_EXT_SSE3,
-        .ext2_features = PPRO_FEATURES & CPUID_EXT2_AMD_ALIASES,
+        .ext2_features = EXT2_PPRO_FEATURES,
         .ext3_features = 0,
         .xlevel = 0x80000008,
         .model_id = "Common 32-bit KVM processor"
@@ -538,7 +539,7 @@ static x86_def_t builtin_x86_defs[] = {
         .stepping = 3,
         .features = PPRO_FEATURES | CPUID_PSE36 | CPUID_VME | CPUID_MTRR |
             CPUID_MCA,
-        .ext2_features = (PPRO_FEATURES & CPUID_EXT2_AMD_ALIASES) |
+        .ext2_features = EXT2_PPRO_FEATURES |
             CPUID_EXT2_MMXEXT | CPUID_EXT2_3DNOW | CPUID_EXT2_3DNOWEXT,
         .xlevel = 0x80000008,
     },
@@ -558,7 +559,7 @@ static x86_def_t builtin_x86_defs[] = {
             /* Some CPUs got no CPUID_SEP */
         .ext_features = CPUID_EXT_SSE3 | CPUID_EXT_MONITOR | CPUID_EXT_SSSE3 |
             CPUID_EXT_DSCPL | CPUID_EXT_EST | CPUID_EXT_TM2 | CPUID_EXT_XTPR,
-        .ext2_features = (PPRO_FEATURES & CPUID_EXT2_AMD_ALIASES) |
+        .ext2_features = EXT2_PPRO_FEATURES |
             CPUID_EXT2_NX,
         .ext3_features = CPUID_EXT3_LAHF_LM,
         .xlevel = 0x8000000A,
Signature · 1 line
1.7.11.7
Signature · 2 lines
Regards,
  Igor
#3 lore raw

Re: [Qemu-devel] [PATCH 1/3] target-i386: add EXT2_PPRO_FEATURES #define

In reply to Eduardo Habkost

Am 12.12.2012 23:22, schrieb Eduardo Habkost:

Quoted 4 lines

Instead of repeating the (PPRO_FEATURES & CPUID_EXT2_AMD_ALIASES) expression everywhere, use EXT2_PPRO_FEATURES.

Technically this patch looks fine. My dislike for these defines aside, I have doubts about the semantics: This is masking out "AMD_ALIASES" (whatever that is exactly I still need to look up) - doesn't that rather call for EXT2_PPRO_INTEL_FEATURES or so? (But then again the Pentium Pro was an Intel chip so AMD sounds confusing...) Or does no AMD model actually inherit those AMD aliases? This at least deserves a mention in the commit message (no need to resend then).

Andreas

Signature · 2 lines
SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany
GF: Jeff Hawn, Jennifer Guild, Felix Imendörffer; HRB 16746 AG Nürnberg
#4 lore raw

Re: [Qemu-devel] [PATCH 1/3] target-i386: add EXT2_PPRO_FEATURES #define

Quoted 6 lines · Andreas Färber

Am 12.12.2012 23:22, schrieb Eduardo Habkost:

Quoted 4 lines

Instead of repeating the (PPRO_FEATURES & CPUID_EXT2_AMD_ALIASES) expression everywhere, use EXT2_PPRO_FEATURES.

Quoted 7 lines

Technically this patch looks fine. My dislike for these defines aside, I have doubts about the semantics: This is masking out "AMD_ALIASES" (whatever that is exactly I still need to look up) - doesn't that rather call for EXT2_PPRO_INTEL_FEATURES or so? (But then again the Pentium Pro was an Intel chip so AMD sounds confusing...) Or does no AMD model actually inherit those AMD aliases? This at least deserves a mention in the commit message (no need to resend then).

The code is not masking out AMD_ALIASES, it is is the opposite: it's keeping only the AMD_ALIASES bits. CPUID_EXT2_AMD_ALIASES are the bits in cpuid_ext2_features that have to be directly duplicated from cpuid_features, but only on AMD CPUs. Intel CPUs don't have those bit aliases.

Anyway, you have a point: I think the #define could be named PPRO_EXT2_FEATURES_AMD instead, to make it clear that those bits make sense only on AMD CPU models.

Also: on the models that actually have vendor=AMD, we can probably remove those bits entirely from the table, as we now have code that makes sure the feature aliases on cpuid_ext2_features are consistent with cpuid_features. But we still have a few exceptions that have vendor=Intel (kvm64, kvm32, and n270), that have to be (carefully) fixed later.

The main reason I sent this change was to make it easier to automatically line-wrap the feature lists in the code to 80-columns on patch 3/3. I think I will reorder and send the feature-array patch first, and fix the CPUID_EXT2_AMD_ALIASES mess later.

Signature · 1 line
Eduardo
#5 lore raw

PATCH 2/3 target-i386/cpu.c: coding style fix

In reply to Eduardo Habkost
---
 target-i386/cpu.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
target-i386/cpu.c +3 -2
index a2ee8bb..25f7500 100644
@@ -1865,10 +1865,11 @@ void cpu_x86_cpuid(CPUX86State *env, uint32_t index, uint32_t count,
 /* XXX: The physical address space is limited to 42 bits in exec.c. */
             *eax = 0x00003028;	/* 48 bits virtual, 40 bits physical */
         } else {
-            if (env->cpuid_features & CPUID_PSE36)
+            if (env->cpuid_features & CPUID_PSE36) {
                 *eax = 0x00000024; /* 36 bits physical */
-            else
+            } else {
                 *eax = 0x00000020; /* 32 bits physical */
+            }
         }
         *ebx = 0;
         *ecx = 0;
Signature · 1 line
1.7.11.7
#6 lore raw

Re: [Qemu-devel] [PATCH 2/3] target-i386/cpu.c: coding style fix

On Wed, 12 Dec 2012 20:22:25 -0200
Eduardo Habkost <[email protected]> wrote:

While at it, could you remove the last <TAB> as well?

Quoted 26 lines
---
 target-i386/cpu.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
target-i386/cpu.c +3 -2
index a2ee8bb..25f7500 100644
@@ -1865,10 +1865,11 @@ void cpu_x86_cpuid(CPUX86State *env, uint32_t index, uint32_t count,
 /* XXX: The physical address space is limited to 42 bits in exec.c. */
             *eax = 0x00003028;	/* 48 bits virtual, 40 bits physical */
         } else {
-            if (env->cpuid_features & CPUID_PSE36)
+            if (env->cpuid_features & CPUID_PSE36) {
                 *eax = 0x00000024; /* 36 bits physical */
-            else
+            } else {
                 *eax = 0x00000020; /* 32 bits physical */
+            }
         }
         *ebx = 0;
         *ecx = 0;
Signature · 1 line
1.7.11.7
Signature · 2 lines
Regards,
  Igor
#7 lore raw

Re: [Qemu-devel] [PATCH 2/3] target-i386/cpu.c: coding style fix

Quoted 4 lines · Igor Mammedov

On Wed, 12 Dec 2012 20:22:25 -0200
Eduardo Habkost <[email protected]> wrote:

While at it, could you remove the last <TAB> as well?

I didn't even notice it was there.

I will do that in case I have to resubmit this series, or send a separate patch to qemu-trivial later, in case this version gets included.

Quoted 31 lines
Quoted 26 lines
---
 target-i386/cpu.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
target-i386/cpu.c +3 -2
index a2ee8bb..25f7500 100644
@@ -1865,10 +1865,11 @@ void cpu_x86_cpuid(CPUX86State *env, uint32_t index, uint32_t count,
 /* XXX: The physical address space is limited to 42 bits in exec.c. */
             *eax = 0x00003028;	/* 48 bits virtual, 40 bits physical */
         } else {
-            if (env->cpuid_features & CPUID_PSE36)
+            if (env->cpuid_features & CPUID_PSE36) {
                 *eax = 0x00000024; /* 36 bits physical */
-            else
+            } else {
                 *eax = 0x00000020; /* 32 bits physical */
+            }
         }
         *ebx = 0;
         *ecx = 0;
Signature · 1 line
1.7.11.7
Signature · 2 lines
Regards,
  Igor
Signature · 1 line
Eduardo
#8 lore raw

PATCH 3/3 target-i386: replace cpuid_*features fields with a feature word array

In reply to Eduardo Habkost

This replaces the feature-bit fields on both X86CPU and x86_def_t structs with an array.

With this, we will be able to simplify code that simply does the same operation on all feature words (e.g. kvm_check_features_against_host(), filter_features_for_kvm(), add_flagname_to_bitmaps(), and CPU feature-bit property lookup/registration).

---
This patch was created solely using a sed script and no manual changes, to try to avoid mistakes while converting the code, and make it easier to rebase if necessary. The sed script can be seen at:
https://gist.github.com/4271991

---
 hw/kvm/clock.c            |   2 +-
 linux-user/elfload.c      |   2 +-
 linux-user/main.c         |   4 +-
 target-i386/cpu.c         | 578 +++++++++++++++++++++++-----------------------
 target-i386/cpu.h         |  30 +--
 target-i386/helper.c      |   4 +-
 target-i386/kvm.c         |   5 +-
 target-i386/misc_helper.c |  14 +-
 target-i386/translate.c   |  10 +-
 9 files changed, 331 insertions(+), 318 deletions(-)
hw/kvm/clock.c +1 -1
index 824b978..11af665 100644
@@ -129,7 +129,7 @@ static TypeInfo kvmclock_info = {
 void kvmclock_create(void)
 {
     if (kvm_enabled() &&
-        first_cpu->cpuid_kvm_features & ((1ULL << KVM_FEATURE_CLOCKSOURCE) |
+        first_cpu->features[FEAT_KVM] & ((1ULL << KVM_FEATURE_CLOCKSOURCE) |
                                          (1ULL << KVM_FEATURE_CLOCKSOURCE2))) {
         sysbus_create_simple("kvmclock", -1, NULL);
     }
linux-user/elfload.c +1 -1
index 1d8bcb4..71156af 100644
@@ -130,7 +130,7 @@ static const char *get_elf_platform(void)
 
 static uint32_t get_elf_hwcap(void)
 {
-    return thread_env->cpuid_features;
+    return thread_env->features[FEAT_1_EDX];
 }
 
 #ifdef TARGET_X86_64
linux-user/main.c +2 -2
index 25e35cd..5e847dd 100644
@@ -3625,13 +3625,13 @@ int main(int argc, char **argv, char **envp)
 
     env->cr[0] = CR0_PG_MASK | CR0_WP_MASK | CR0_PE_MASK;
     env->hflags |= HF_PE_MASK;
-    if (env->cpuid_features & CPUID_SSE) {
+    if (env->features[FEAT_1_EDX] & CPUID_SSE) {
         env->cr[4] |= CR4_OSFXSR_MASK;
         env->hflags |= HF_OSFXSR_MASK;
     }
 #ifndef TARGET_ABI32
     /* enable 64 bit mode if possible */
-    if (!(env->cpuid_ext2_features & CPUID_EXT2_LM)) {
+    if (!(env->features[FEAT_80000001_EDX] & CPUID_EXT2_LM)) {
         fprintf(stderr, "The selected x86 CPU does not support 64 bit mode\n");
         exit(1);
     }
target-i386/cpu.c +293 -285

903 lines not on this page · raw message

target-i386/cpu.h +17 -13
index 8ce9b9f..76f0d27 100644
@@ -694,6 +694,21 @@ typedef enum TPRAccess {
     TPR_ACCESS_WRITE,
 } TPRAccess;
 
+typedef enum X86CPUFeatureWord {
+    FEAT_1_EDX,         /* CPUID[1].EDX */
+    FEAT_1_ECX,         /* CPUID[1].ECX */
+    FEAT_7_0_EBX,       /* CPUID[EAX=7,ECX=0].EBX */
+    FEAT_80000001_EDX,  /* CPUID[8000_0001].EDX */
+    FEAT_80000001_ECX,  /* CPUID[8000_0001].ECX */
+    FEAT_C0000001_EDX,  /* CPUID[C000_0001].EDX */
+    FEAT_KVM,           /* CPUID[4000_0001].EAX (KVM_CPUID_FEATURES) */
+    FEAT_SVM,           /* CPUID[8000_000A].EDX */
+    FEATURE_WORDS,      /* Size of the features arrays */
+} FeatureWord;
+
+/* An array of feature words */
+typedef uint32_t X86CPUFeatureWords[FEATURE_WORDS];
+
 typedef struct CPUX86State {
     /* standard registers */
     target_ulong regs[CPU_NB_REGS];
@@ -800,24 +815,15 @@ typedef struct CPUX86State {
     uint64_t pat;
 
     /* processor features (e.g. for CPUID insn) */
-    uint32_t cpuid_level;
+    uint32_t cpuid_level, cpuid_xlevel, cpuid_xlevel2;
+    X86CPUFeatureWords features;
     uint32_t cpuid_vendor1;
     uint32_t cpuid_vendor2;
     uint32_t cpuid_vendor3;
     uint32_t cpuid_version;
-    uint32_t cpuid_features;
-    uint32_t cpuid_ext_features;
-    uint32_t cpuid_xlevel;
     uint32_t cpuid_model[12];
-    uint32_t cpuid_ext2_features;
-    uint32_t cpuid_ext3_features;
     uint32_t cpuid_apic_id;
     int cpuid_vendor_override;
-    /* Store the results of Centaur's CPUID instructions */
-    uint32_t cpuid_xlevel2;
-    uint32_t cpuid_ext4_features;
-    /* Flags from CPUID[EAX=7,ECX=0].EBX */
-    uint32_t cpuid_7_0_ebx_features;
 
     /* MTRRs */
     uint64_t mtrr_fixed[11];
@@ -831,8 +837,6 @@ typedef struct CPUX86State {
     uint8_t soft_interrupt;
     uint8_t has_error_code;
     uint32_t sipi_vector;
-    uint32_t cpuid_kvm_features;
-    uint32_t cpuid_svm_features;
     bool tsc_valid;
     int tsc_khz;
     void *kvm_xsave_buf;
target-i386/helper.c +2 -2
index dafa666..a1b25b6 100644
@@ -450,7 +450,7 @@ void cpu_x86_update_cr4(CPUX86State *env, uint32_t new_cr4)
         tlb_flush(env, 1);
     }
     /* SSE handling */
-    if (!(env->cpuid_features & CPUID_SSE)) {
+    if (!(env->features[FEAT_1_EDX] & CPUID_SSE)) {
         new_cr4 &= ~CR4_OSFXSR_MASK;
     }
     env->hflags &= ~HF_OSFXSR_MASK;
@@ -458,7 +458,7 @@ void cpu_x86_update_cr4(CPUX86State *env, uint32_t new_cr4)
         env->hflags |= HF_OSFXSR_MASK;
     }
 
-    if (!(env->cpuid_7_0_ebx_features & CPUID_7_0_EBX_SMAP)) {
+    if (!(env->features[FEAT_7_0_EBX] & CPUID_7_0_EBX_SMAP)) {
         new_cr4 &= ~CR4_SMAP_MASK;
     }
     env->hflags &= ~HF_SMAP_MASK;
target-i386/kvm.c +3 -2
index f669281..5b614fa 100644
@@ -438,7 +438,7 @@ int kvm_arch_init_vcpu(CPUX86State *env)
     c = &cpuid_data.entries[cpuid_i++];
     memset(c, 0, sizeof(*c));
     c->function = KVM_CPUID_FEATURES;
-    c->eax = env->cpuid_kvm_features;
+    c->eax = env->features[FEAT_KVM];
 
     if (hyperv_enabled()) {
         memcpy(signature, "Hv#1\0\0\0\0\0\0\0\0", 12);
@@ -573,7 +573,8 @@ int kvm_arch_init_vcpu(CPUX86State *env)
     cpuid_data.cpuid.nent = cpuid_i;
 
     if (((env->cpuid_version >> 8)&0xF) >= 6
-        && (env->cpuid_features&(CPUID_MCE|CPUID_MCA)) == (CPUID_MCE|CPUID_MCA)
+        && (env->features[FEAT_1_EDX] & (CPUID_MCE|CPUID_MCA)) ==
+            (CPUID_MCE|CPUID_MCA)
         && kvm_check_extension(env->kvm_state, KVM_CAP_MCE) > 0) {
         uint64_t mcg_cap;
         int banks;
target-i386/misc_helper.c +7 -7
index a020379..546b8b9 100644
@@ -291,22 +291,22 @@ void helper_wrmsr(CPUX86State *env)
             uint64_t update_mask;
 
             update_mask = 0;
-            if (env->cpuid_ext2_features & CPUID_EXT2_SYSCALL) {
+            if (env->features[FEAT_80000001_EDX] & CPUID_EXT2_SYSCALL) {
                 update_mask |= MSR_EFER_SCE;
             }
-            if (env->cpuid_ext2_features & CPUID_EXT2_LM) {
+            if (env->features[FEAT_80000001_EDX] & CPUID_EXT2_LM) {
                 update_mask |= MSR_EFER_LME;
             }
-            if (env->cpuid_ext2_features & CPUID_EXT2_FFXSR) {
+            if (env->features[FEAT_80000001_EDX] & CPUID_EXT2_FFXSR) {
                 update_mask |= MSR_EFER_FFXSR;
             }
-            if (env->cpuid_ext2_features & CPUID_EXT2_NX) {
+            if (env->features[FEAT_80000001_EDX] & CPUID_EXT2_NX) {
                 update_mask |= MSR_EFER_NXE;
             }
-            if (env->cpuid_ext3_features & CPUID_EXT3_SVM) {
+            if (env->features[FEAT_80000001_ECX] & CPUID_EXT3_SVM) {
                 update_mask |= MSR_EFER_SVME;
             }
-            if (env->cpuid_ext2_features & CPUID_EXT2_FFXSR) {
+            if (env->features[FEAT_80000001_EDX] & CPUID_EXT2_FFXSR) {
                 update_mask |= MSR_EFER_FFXSR;
             }
             cpu_load_efer(env, (env->efer & ~update_mask) |
@@ -513,7 +513,7 @@ void helper_rdmsr(CPUX86State *env)
         val = env->mtrr_deftype;
         break;
     case MSR_MTRRcap:
-        if (env->cpuid_features & CPUID_MTRR) {
+        if (env->features[FEAT_1_EDX] & CPUID_MTRR) {
             val = MSR_MTRRcap_VCNT | MSR_MTRRcap_FIXRANGE_SUPPORT |
                 MSR_MTRRcap_WC_SUPPORTED;
         } else {
target-i386/translate.c +5 -5
index f394ea6..8ff4af9 100644
@@ -7926,11 +7926,11 @@ static inline void gen_intermediate_code_internal(CPUX86State *env,
     if (flags & HF_SOFTMMU_MASK) {
         dc->mem_index = (cpu_mmu_index(env) + 1) << 2;
     }
-    dc->cpuid_features = env->cpuid_features;
-    dc->cpuid_ext_features = env->cpuid_ext_features;
-    dc->cpuid_ext2_features = env->cpuid_ext2_features;
-    dc->cpuid_ext3_features = env->cpuid_ext3_features;
-    dc->cpuid_7_0_ebx_features = env->cpuid_7_0_ebx_features;
+    dc->cpuid_features = env->features[FEAT_1_EDX];
+    dc->cpuid_ext_features = env->features[FEAT_1_ECX];
+    dc->cpuid_ext2_features = env->features[FEAT_80000001_EDX];
+    dc->cpuid_ext3_features = env->features[FEAT_80000001_ECX];
+    dc->cpuid_7_0_ebx_features = env->features[FEAT_7_0_EBX];
 #ifdef TARGET_X86_64
     dc->lma = (flags >> HF_LMA_SHIFT) & 1;
     dc->code64 = (flags >> HF_CS64_SHIFT) & 1;
Signature · 1 line
1.7.11.7
#9 lore raw

Re: [Qemu-devel] [PATCH 3/3] target-i386: replace cpuid_*features fields with a feature word array

Quoted 8 lines · On Wed, 12 Dec 2012 20:22:26 -0200 Eduardo Habkost <[email protected]> wrote:

This replaces the feature-bit fields on both X86CPU and x86_def_t structs with an array.

With this, we will be able to simplify code that simply does the same operation on all feature words (e.g. kvm_check_features_against_host(), filter_features_for_kvm(), add_flagname_to_bitmaps(), and CPU feature-bit property lookup/registration).

do you have a patch that simplifies kvm_check_features_against_host() using this?

Quoted 3 lines
Signature · 1 line
1.7.11.7
Signature · 2 lines
Regards,
  Igor
#10 lore raw

Re: [Qemu-devel] [PATCH 3/3] target-i386: replace cpuid_*features fields with a feature word array

Quoted 6 lines · Igor Mammedov
Quoted 3 lines · On Wed, 12 Dec 2012 20:22:26 -0200 Eduardo Habkost <[email protected]> wrote:

This replaces the feature-bit fields on both X86CPU and x86_def_t structs with an array.

Quoted 8 lines
Quoted 5 lines

With this, we will be able to simplify code that simply does the same operation on all feature words (e.g. kvm_check_features_against_host(), filter_features_for_kvm(), add_flagname_to_bitmaps(), and CPU feature-bit property lookup/registration).

do you have a patch that simplifies kvm_check_features_against_host() using this?

I have a very old one, based on an older (and more complex) version of this series:
https://github.com/ehabkost/qemu-hacks/commit/eb01d374baecf6df26fd6f0d0bb23f2e1547f499

It's in the work/cpuid-refactor-v0.22-2012-08-31 branch in my git repository.

That branch also has some patches to merge kvm_check_features_against_host() and filter_features_for_kvm() (because the purpose of kvm_check_features_against_host() is simply to check if anything is going to be filtered out by filter_features_for_kvm()).

If people are happy with the approach in this series, I plan to write and submit cleanups for kvm_cpu_fill_host(), kvm_check_features_against_host(), filter_features_for_kvm(), add_flagname_to_bitmaps(), and the cpudef -> CPU feature copying code.

There's so much code that could be cleaned up using the array, that I am afraid that it would cause too much conflicts in the CPU properties work. So I can wait until the CPU properties series are submitted before making the cleanups, if necessary.

Signature · 1 line
Eduardo
#11 lore raw

Re: [Qemu-devel] [PATCH 3/3] target-i386: replace cpuid_*features fields with a feature word array

Quoted 33 lines · On Fri, 14 Dec 2012 10:27:34 -0200 Eduardo Habkost <[email protected]> wrote:
Quoted 6 lines · Igor Mammedov
Quoted 3 lines · On Wed, 12 Dec 2012 20:22:26 -0200 Eduardo Habkost <[email protected]> wrote:

This replaces the feature-bit fields on both X86CPU and x86_def_t structs with an array.

Quoted 8 lines
Quoted 5 lines

With this, we will be able to simplify code that simply does the same operation on all feature words (e.g. kvm_check_features_against_host(), filter_features_for_kvm(), add_flagname_to_bitmaps(), and CPU feature-bit property lookup/registration).

do you have a patch that simplifies kvm_check_features_against_host() using this?

I have a very old one, based on an older (and more complex) version of this series:
https://github.com/ehabkost/qemu-hacks/commit/eb01d374baecf6df26fd6f0d0bb23f2e1547f499

It's in the work/cpuid-refactor-v0.22-2012-08-31 branch in my git repository.

That branch also has some patches to merge kvm_check_features_against_host() and filter_features_for_kvm() (because the purpose of kvm_check_features_against_host() is simply to check if anything is going to be filtered out by filter_features_for_kvm()).

If people are happy with the approach in this series, I plan to write and submit cleanups for kvm_cpu_fill_host(), kvm_check_features_against_host(), filter_features_for_kvm(), add_flagname_to_bitmaps(), and the cpudef -> CPU feature copying code.

Quoted 4 lines

There's so much code that could be cleaned up using the array, that I am afraid that it would cause too much conflicts in the CPU properties work. So I can wait until the CPU properties series are submitted before making the cleanups, if necessary.

with cpu properties and subclasses in place, kvm_check_features_against_host() could be expressed as simple subtraction of host subclass features list from guest cpu features list. Which won't require access to feature words at all. Just iterating over properties of both to build lists and then do subtraction and print difference if any, it could be eventially generalized to other kvm supported targets since it won't use any x86 specific fields.

Quoted 3 lines
Signature · 1 line
Eduardo
Signature · 2 lines
Regards,
  Igor
#12 lore raw

Re: [Qemu-devel] [PATCH 3/3] target-i386: replace cpuid_*features fields with a feature word array

Quoted 40 lines · Igor Mammedov
Quoted 33 lines · On Fri, 14 Dec 2012 10:27:34 -0200 Eduardo Habkost <[email protected]> wrote:
Quoted 6 lines · Igor Mammedov
Quoted 3 lines · On Wed, 12 Dec 2012 20:22:26 -0200 Eduardo Habkost <[email protected]> wrote:

This replaces the feature-bit fields on both X86CPU and x86_def_t structs with an array.

Quoted 8 lines
Quoted 5 lines

With this, we will be able to simplify code that simply does the same operation on all feature words (e.g. kvm_check_features_against_host(), filter_features_for_kvm(), add_flagname_to_bitmaps(), and CPU feature-bit property lookup/registration).

do you have a patch that simplifies kvm_check_features_against_host() using this?

I have a very old one, based on an older (and more complex) version of this series:
https://github.com/ehabkost/qemu-hacks/commit/eb01d374baecf6df26fd6f0d0bb23f2e1547f499

It's in the work/cpuid-refactor-v0.22-2012-08-31 branch in my git repository.

That branch also has some patches to merge kvm_check_features_against_host() and filter_features_for_kvm() (because the purpose of kvm_check_features_against_host() is simply to check if anything is going to be filtered out by filter_features_for_kvm()).

If people are happy with the approach in this series, I plan to write and submit cleanups for kvm_cpu_fill_host(), kvm_check_features_against_host(), filter_features_for_kvm(), add_flagname_to_bitmaps(), and the cpudef -> CPU feature copying code.

Quoted 4 lines

There's so much code that could be cleaned up using the array, that I am afraid that it would cause too much conflicts in the CPU properties work. So I can wait until the CPU properties series are submitted before making the cleanups, if necessary.

Quoted 7 lines

with cpu properties and subclasses in place, kvm_check_features_against_host() could be expressed as simple subtraction of host subclass features list from guest cpu features list. Which won't require access to feature words at all. Just iterating over properties of both to build lists and then do subtraction and print difference if any, it could be eventially generalized to other kvm supported targets since it won't use any x86 specific fields.

Once we have the CPU properties code, maybe we could do that. I find the idea a bit confusing (I would like to avoid coupling the "check" code to the "host" CPU class directly), but may be doeable.

We also have one problem: the host class class_init method may be called before KVM is initialized, so I don't know if we can really use the class instrospection system to find out which flags are supported by the host by looking at the "host" class.

Considering the complexity of what you suggest, I think there's value in cleaning up that code first (and use the array to allow us to clean up other code as well), and try to use the solution you suggest later, after we actually have working CPU properties and subclasses.

Signature · 1 line
Eduardo
#13 lore raw

Re: [Qemu-devel] [PATCH 3/3] target-i386: replace cpuid_*features fields with a feature word array

In reply to Eduardo Habkost

Am 14.12.2012 13:27, schrieb Eduardo Habkost:

Quoted 33 lines · Igor Mammedov
Quoted 6 lines
Quoted 3 lines · On Wed, 12 Dec 2012 20:22:26 -0200 Eduardo Habkost <[email protected]> wrote:

This replaces the feature-bit fields on both X86CPU and x86_def_t structs with an array.

Quoted 8 lines
Quoted 5 lines

With this, we will be able to simplify code that simply does the same operation on all feature words (e.g. kvm_check_features_against_host(), filter_features_for_kvm(), add_flagname_to_bitmaps(), and CPU feature-bit property lookup/registration).

do you have a patch that simplifies kvm_check_features_against_host() using this?

I have a very old one, based on an older (and more complex) version of this series:
https://github.com/ehabkost/qemu-hacks/commit/eb01d374baecf6df26fd6f0d0bb23f2e1547f499

It's in the work/cpuid-refactor-v0.22-2012-08-31 branch in my git repository.

That branch also has some patches to merge kvm_check_features_against_host() and filter_features_for_kvm() (because the purpose of kvm_check_features_against_host() is simply to check if anything is going to be filtered out by filter_features_for_kvm()).

If people are happy with the approach in this series, I plan to write and submit cleanups for kvm_cpu_fill_host(), kvm_check_features_against_host(), filter_features_for_kvm(), add_flagname_to_bitmaps(), and the cpudef -> CPU feature copying code.

Quoted 4 lines

There's so much code that could be cleaned up using the array, that I am afraid that it would cause too much conflicts in the CPU properties work. So I can wait until the CPU properties series are submitted before making the cleanups, if necessary.

As stated elsewhere, for me a proper way to define new CPU models has higher priority than feature properties, especially now that we're headed for a class_init based approach where properties cannot be used for original initialization.

As suggested with my RFC I would like to take a quick, simplistic route to subclasses where no major refactoring of data fields happens. If we prepend a couple coding style and function movement patches, that's fine with me. But if we do large functional refactorings > 10 patches that change history will be clobbered by the touch-all conversion and we need to do intensive functional testing, for which I don't see sufficient time before the Soft Freeze, given the holidays.

When the feature bits are stored in the classes, setting them via properties in instance_init seems like overkill (visitor overhead); we no longer dump them in -cpu ?foo; only +feature/-feature would benefit. Thus I assume them to mainly conflict where function signatures change and trivially where def changes to env, making them rather orthogonal to each other.

Regards,
Andreas

Signature · 2 lines
SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany
GF: Jeff Hawn, Jennifer Guild, Felix Imendörffer; HRB 16746 AG Nürnberg
#14 lore raw

Re: [Qemu-devel] [PATCH 3/3] target-i386: replace cpuid_*features fields with a feature word array

Quoted 39 lines · Andreas Färber

Am 14.12.2012 13:27, schrieb Eduardo Habkost:

Quoted 33 lines · Igor Mammedov
Quoted 6 lines
Quoted 3 lines · On Wed, 12 Dec 2012 20:22:26 -0200 Eduardo Habkost <[email protected]> wrote:

This replaces the feature-bit fields on both X86CPU and x86_def_t structs with an array.

Quoted 8 lines
Quoted 5 lines

With this, we will be able to simplify code that simply does the same operation on all feature words (e.g. kvm_check_features_against_host(), filter_features_for_kvm(), add_flagname_to_bitmaps(), and CPU feature-bit property lookup/registration).

do you have a patch that simplifies kvm_check_features_against_host() using this?

I have a very old one, based on an older (and more complex) version of this series:
https://github.com/ehabkost/qemu-hacks/commit/eb01d374baecf6df26fd6f0d0bb23f2e1547f499

It's in the work/cpuid-refactor-v0.22-2012-08-31 branch in my git repository.

That branch also has some patches to merge kvm_check_features_against_host() and filter_features_for_kvm() (because the purpose of kvm_check_features_against_host() is simply to check if anything is going to be filtered out by filter_features_for_kvm()).

If people are happy with the approach in this series, I plan to write and submit cleanups for kvm_cpu_fill_host(), kvm_check_features_against_host(), filter_features_for_kvm(), add_flagname_to_bitmaps(), and the cpudef -> CPU feature copying code.

Quoted 4 lines

There's so much code that could be cleaned up using the array, that I am afraid that it would cause too much conflicts in the CPU properties work. So I can wait until the CPU properties series are submitted before making the cleanups, if necessary.

Quoted 4 lines

As stated elsewhere, for me a proper way to define new CPU models has higher priority than feature properties, especially now that we're headed for a class_init based approach where properties cannot be used for original initialization.

We can go that way. But then I still strongly suggest we add the feature array before doing that, because it will help a lot to simplify the "host" CPU subclass code, and kvm_check_features_against_host() and kvm_cpu_fill_host().

(The main change I see is that kvm_check_features_against_host() won't need to fill a full x86_def_t struct from the host, just a local in-stack feature array. Also, kvm_check_features_against_host() and filter_features_for_kvm() could be unified as well)

(Maybe I can work around the lack of feature array by keeping an embedded x86_def_t struct inside CPUClass (so kvm_cpu_fill_host() don't need a full CPUClass struct like in your RFC). I will try and see what's possible)

Quoted 8 lines

As suggested with my RFC I would like to take a quick, simplistic route to subclasses where no major refactoring of data fields happens. If we prepend a couple coding style and function movement patches, that's fine with me. But if we do large functional refactorings > 10 patches that change history will be clobbered by the touch-all conversion and we need to do intensive functional testing, for which I don't see sufficient time before the Soft Freeze, given the holidays.

I thought we would be in the "we can't introduce major changes" mode _after_ the soft freeze, not before the soft freeze. ;-)

So, are we already in soft freeze in practice?

Quoted 3 lines

When the feature bits are stored in the classes, setting them via properties in instance_init seems like overkill (visitor overhead);

If performance is an issue (I doubt it would be), we could still keep the array inside the model/class, and copy it on instance_init. But we still need a per-instance array as well, in addition to the per-model data (see below).

Quoted 5 lines

we
no longer dump them in -cpu ?foo; only +feature/-feature would benefit. Thus I assume them to mainly conflict where function signatures change and trivially where def changes to env, making them rather orthogonal to each other.

We can't just change "env" to "def", because "def" is static and "env" contains the result of the "<model>,+feature,-feature" parsing.

We could try to go through a route where there's no def->env copy in the code, but then I believe this would be the opposite of the quick simplistic route you're trying to take.

Signature · 1 line
Eduardo
#15 lore raw

Re: [Qemu-devel] [PATCH 3/3] target-i386: replace cpuid_*features fields with a feature word array

In reply to Eduardo Habkost

Am 12.12.2012 23:22, schrieb Eduardo Habkost:

Quoted 14 lines

This replaces the feature-bit fields on both X86CPU and x86_def_t structs with an array.

With this, we will be able to simplify code that simply does the same operation on all feature words (e.g. kvm_check_features_against_host(), filter_features_for_kvm(), add_flagname_to_bitmaps(), and CPU feature-bit property lookup/registration).

---
This patch was created solely using a sed script and no manual changes, to try to avoid mistakes while converting the code, and make it easier to rebase if necessary. The sed script can be seen at:
https://gist.github.com/4271991

Quoted 11 lines
---
 hw/kvm/clock.c            |   2 +-
 linux-user/elfload.c      |   2 +-
 linux-user/main.c         |   4 +-
 target-i386/cpu.c         | 578 +++++++++++++++++++++++-----------------------
 target-i386/cpu.h         |  30 +--
 target-i386/helper.c      |   4 +-
 target-i386/kvm.c         |   5 +-
 target-i386/misc_helper.c |  14 +-
 target-i386/translate.c   |  10 +-
 9 files changed, 331 insertions(+), 318 deletions(-)

I wonder, if we're touching all these lines anyway, can't we place the new feature array directly into X86CPU? As far as I see the features are never changed at runtime, so the only reason to have them in the instance is the command-line-supplied overrides.

The clock code using first_cpu looks solvable; what about CR4 and MSR helpers, how performance-sensitive are they? (if they're not yet using X86CPU for something else)

With the proposed variable change env -> cpu it would not be fully sed'able, but as a maintainer I need to review the whole patch anyway.

Either way since this change affects not just the core CPU that I have started to maintain I feel I should give other target-i386 stakeholders (Blue, Aurélien, malc, ...) sufficient time to object, so not before Christmas realistically.

Regards,
Andreas

Signature · 2 lines
SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany
GF: Jeff Hawn, Jennifer Guild, Felix Imendörffer; HRB 16746 AG Nürnberg
#16 lore raw

Re: [Qemu-devel] [PATCH 3/3] target-i386: replace cpuid_*features fields with a feature word array

Quoted 27 lines · Andreas Färber

Am 12.12.2012 23:22, schrieb Eduardo Habkost:

Quoted 14 lines

This replaces the feature-bit fields on both X86CPU and x86_def_t structs with an array.

With this, we will be able to simplify code that simply does the same operation on all feature words (e.g. kvm_check_features_against_host(), filter_features_for_kvm(), add_flagname_to_bitmaps(), and CPU feature-bit property lookup/registration).

---
This patch was created solely using a sed script and no manual changes, to try to avoid mistakes while converting the code, and make it easier to rebase if necessary. The sed script can be seen at:
https://gist.github.com/4271991

Quoted 11 lines
---
 hw/kvm/clock.c            |   2 +-
 linux-user/elfload.c      |   2 +-
 linux-user/main.c         |   4 +-
 target-i386/cpu.c         | 578 +++++++++++++++++++++++-----------------------
 target-i386/cpu.h         |  30 +--
 target-i386/helper.c      |   4 +-
 target-i386/kvm.c         |   5 +-
 target-i386/misc_helper.c |  14 +-
 target-i386/translate.c   |  10 +-
 9 files changed, 331 insertions(+), 318 deletions(-)
Quoted 4 lines

I wonder, if we're touching all these lines anyway, can't we place the new feature array directly into X86CPU? As far as I see the features are never changed at runtime, so the only reason to have them in the instance is the command-line-supplied overrides.

You mean directly into X86CPUClass? No, we can't: the features are changed at the CPU instance at runtime, when based in the +feature,-feature feature string. We also do some extra filtering based on KVM capabilities at filter_features_for_kvm().

I believe we're moving towards another direction: making the feature bits live only in the X86CPU object, and they will be initialized based on the default property values of each CPU class. Probably we won't do that in the first version of CPU subclasses/properties, but we are trying to reach that point.

Quoted 4 lines

The clock code using first_cpu looks solvable; what about CR4 and MSR helpers, how performance-sensitive are they? (if they're not yet using X86CPU for something else)

I guess any CPU-state code inside QEMU is not performance-sensitive, as it woud already require switching between KVM kernelspace and QEMU userspace.

Quoted 3 lines

With the proposed variable change env -> cpu it would not be fully sed'able, but as a maintainer I need to review the whole patch anyway.

On the other hand, this cleanup will allow us to easily convert some code to deal with the feature array only (not requiring the full X86CPU or x86_def_t struct), making it easier to have only one feature array, in only one place, in the future.

Quoted 5 lines

Either way since this change affects not just the core CPU that I have started to maintain I feel I should give other target-i386 stakeholders (Blue, Aurélien, malc, ...) sufficient time to object, so not before Christmas realistically.

OK.

Signature · 1 line
Eduardo
#17 lore raw

Re: [Qemu-devel] [PATCH 3/3] target-i386: replace cpuid_*features fields with a feature word array

Am 14.12.2012 17:52, schrieb Eduardo Habkost:

Quoted 28 lines · Andreas Färber
Quoted 27 lines

Am 12.12.2012 23:22, schrieb Eduardo Habkost:

Quoted 25 lines

This replaces the feature-bit fields on both X86CPU and x86_def_t structs with an array.

With this, we will be able to simplify code that simply does the same operation on all feature words (e.g. kvm_check_features_against_host(), filter_features_for_kvm(), add_flagname_to_bitmaps(), and CPU feature-bit property lookup/registration).

---
This patch was created solely using a sed script and no manual changes, to try to avoid mistakes while converting the code, and make it easier to rebase if necessary. The sed script can be seen at:
https://gist.github.com/4271991

---
 hw/kvm/clock.c            |   2 +-
 linux-user/elfload.c      |   2 +-
 linux-user/main.c         |   4 +-
 target-i386/cpu.c         | 578 +++++++++++++++++++++++-----------------------
 target-i386/cpu.h         |  30 +--
 target-i386/helper.c      |   4 +-
 target-i386/kvm.c         |   5 +-
 target-i386/misc_helper.c |  14 +-
 target-i386/translate.c   |  10 +-
 9 files changed, 331 insertions(+), 318 deletions(-)
Quoted 6 lines
Quoted 4 lines

I wonder, if we're touching all these lines anyway, can't we place the new feature array directly into X86CPU? As far as I see the features are never changed at runtime, so the only reason to have them in the instance is the command-line-supplied overrides.

You mean directly into X86CPUClass? [...]

No, I literally meant X86CPU rather than CPUX86State (i.e., the place within the instance).

Quoted 7 lines
Quoted 3 lines

The clock code using first_cpu looks solvable; what about CR4 and MSR helpers, how performance-sensitive are they? (if they're not yet using X86CPU for something else)

I guess any CPU-state code inside QEMU is not performance-sensitive, as it woud already require switching between KVM kernelspace and QEMU userspace.

I mean target-i386/[misc_]helper.c and thus TCG, IIUC. :)

Quoted 4 lines

On the other hand, this cleanup will allow us to easily convert some code to deal with the feature array only (not requiring the full X86CPU or x86_def_t struct), making it easier to have only one feature array, in only one place, in the future.

The alternative line of thought is whether to group KVM stuff together. Tying it into an array makes that harder. But personally I'm not opposed to this array proposal.

Andreas

Signature · 2 lines
SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany
GF: Jeff Hawn, Jennifer Guild, Felix Imendörffer; HRB 16746 AG Nürnberg
#18 lore raw

Re: [Qemu-devel] [PATCH 3/3] target-i386: replace cpuid_*features fields with a feature word array

Quoted 34 lines · Andreas Färber

Am 14.12.2012 17:52, schrieb Eduardo Habkost:

Quoted 33 lines · Andreas Färber
Quoted 31 lines

Am 12.12.2012 23:22, schrieb Eduardo Habkost:

Quoted 14 lines

This replaces the feature-bit fields on both X86CPU and x86_def_t structs with an array.

With this, we will be able to simplify code that simply does the same operation on all feature words (e.g. kvm_check_features_against_host(), filter_features_for_kvm(), add_flagname_to_bitmaps(), and CPU feature-bit property lookup/registration).

---
This patch was created solely using a sed script and no manual changes, to try to avoid mistakes while converting the code, and make it easier to rebase if necessary. The sed script can be seen at:
https://gist.github.com/4271991

Quoted 11 lines
---
 hw/kvm/clock.c            |   2 +-
 linux-user/elfload.c      |   2 +-
 linux-user/main.c         |   4 +-
 target-i386/cpu.c         | 578 +++++++++++++++++++++++-----------------------
 target-i386/cpu.h         |  30 +--
 target-i386/helper.c      |   4 +-
 target-i386/kvm.c         |   5 +-
 target-i386/misc_helper.c |  14 +-
 target-i386/translate.c   |  10 +-
 9 files changed, 331 insertions(+), 318 deletions(-)

I wonder, if we're touching all these lines anyway, can't we place the new feature array directly into X86CPU? As far as I see the features are never changed at runtime, so the only reason to have them in the instance is the command-line-supplied overrides.

Quoted 4 lines
Quoted 1 line

You mean directly into X86CPUClass? [...]

No, I literally meant X86CPU rather than CPUX86State (i.e., the place within the instance).

OK. That makes sense. I believe that moving fields to X86CPU would be much easier if we change the code that will actually use those fields to use the QOM CPU class.

Quoted 10 lines
Quoted 8 lines
Quoted 4 lines

The clock code using first_cpu looks solvable; what about CR4 and MSR helpers, how performance-sensitive are they? (if they're not yet using X86CPU for something else)

I guess any CPU-state code inside QEMU is not performance-sensitive, as it woud already require switching between KVM kernelspace and QEMU userspace.

I mean target-i386/[misc_]helper.c and thus TCG, IIUC. :)

Oh, right. I wonder how much performance impact it would have, if people are already using TCG.

Anyway, would this really have any impact at all? I mean:
ENV_GET_CPU(env) is basically subtracing an constant offset from 'env'. So I expect similar code to be generated, just using a different offset from 'env' to get the cpuid_features field.

Quoted 9 lines
Quoted 5 lines

On the other hand, this cleanup will allow us to easily convert some code to deal with the feature array only (not requiring the full X86CPU or x86_def_t struct), making it easier to have only one feature array, in only one place, in the future.

The alternative line of thought is whether to group KVM stuff together. Tying it into an array makes that harder. But personally I'm not opposed to this array proposal.

I don't think we would gain much from grouping KVM stuff together. It would just force us to add KVM special-cases to code that deal with feature bits. KVM feature bits are CPUID bits that work like all others.

Signature · 1 line
Eduardo
#19 lore raw

Re: [Qemu-devel] [PATCH 3/3] target-i386: replace cpuid_*features fields with a feature word array

Quoted 4 lines · On Fri, 14 Dec 2012 15:36:22 -0200 Eduardo Habkost <[email protected]> wrote:
Quoted 3 lines · Andreas Färber

Am 14.12.2012 17:52, schrieb Eduardo Habkost:

Quoted 2 lines · Andreas Färber
Quoted 1 line

Am 12.12.2012 23:22, schrieb Eduardo Habkost:

[...]

Quoted 11 lines
Quoted 10 lines
Quoted 8 lines
Quoted 4 lines

The clock code using first_cpu looks solvable; what about CR4 and MSR helpers, how performance-sensitive are they? (if they're not yet using X86CPU for something else)

I guess any CPU-state code inside QEMU is not performance-sensitive, as it woud already require switching between KVM kernelspace and QEMU userspace.

I mean target-i386/[misc_]helper.c and thus TCG, IIUC. :)

Quoted 7 lines

Oh, right. I wonder how much performance impact it would have, if people are already using TCG.

Anyway, would this really have any impact at all? I mean:
ENV_GET_CPU(env) is basically subtracing an constant offset from 'env'. So I expect similar code to be generated, just using a different offset from 'env' to get the cpuid_features field.

ENV_GET_CPU(env) does dynamic_cast which is expensive.

Quoted 3 lines
Signature · 2 lines
-- 
Eduardo
Signature · 2 lines
Regards,
  Igor
#20 lore raw

Re: [Qemu-devel] [PATCH 3/3] target-i386: replace cpuid_*features fields with a feature word array

Quoted 19 lines · Igor Mammedov
Quoted 4 lines · On Fri, 14 Dec 2012 15:36:22 -0200 Eduardo Habkost <[email protected]> wrote:
Quoted 3 lines · Andreas Färber

Am 14.12.2012 17:52, schrieb Eduardo Habkost:

Quoted 2 lines · Andreas Färber
Quoted 1 line

Am 12.12.2012 23:22, schrieb Eduardo Habkost:

[...]

Quoted 11 lines
Quoted 10 lines
Quoted 8 lines
Quoted 4 lines

The clock code using first_cpu looks solvable; what about CR4 and MSR helpers, how performance-sensitive are they? (if they're not yet using X86CPU for something else)

I guess any CPU-state code inside QEMU is not performance-sensitive, as it woud already require switching between KVM kernelspace and QEMU userspace.

I mean target-i386/[misc_]helper.c and thus TCG, IIUC. :)

Quoted 8 lines
Quoted 7 lines

Oh, right. I wonder how much performance impact it would have, if people are already using TCG.

Anyway, would this really have any impact at all? I mean:
ENV_GET_CPU(env) is basically subtracing an constant offset from 'env'. So I expect similar code to be generated, just using a different offset from 'env' to get the cpuid_features field.

ENV_GET_CPU(env) does dynamic_cast which is expensive.

Oh, I didn't notice that. So the alternatives I see are:
- Use ENV_GET_CPU() and risk performance problems;
- Write a FAST_ENV_GET_CPU() macro for performance-sensitive code, that doesn't use dynamic_cast;
- Keep the fields on CPUX86State and move them only after we change the TCG code to use the QOM CPU object.

Personally, I prefer the third option. Moving fields from CPUArchState before making most code use the CPU QOM objects instead of CPUArchState sounds like a painful task.

Signature · 1 line
Eduardo