[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Xen-devel] [PATCH RFC 16/31] x86: Automatically generate known_features



Use the new gen-feature-deps.py infrastructure to automatically generate
known_features[], rather than requiring people to patch two places to add a
new feature for hypervisor use.

Signed-off-by: Andrew Cooper <andrew.cooper3@xxxxxxxxxx>
---
CC: Jan Beulich <JBeulich@xxxxxxxx>

TODO: Probably move the introduction of gen-feature-deps.py earier in the
series, so "xen/x86: Mask out unknown features from Xen's capabilities" uses
the automatically generated known_features[].
---
 xen/arch/x86/cpuid/cpuid.c             | 115 ---------------------------------
 xen/arch/x86/cpuid/gen-feature-deps.py |  23 ++++++-
 2 files changed, 20 insertions(+), 118 deletions(-)

diff --git a/xen/arch/x86/cpuid/cpuid.c b/xen/arch/x86/cpuid/cpuid.c
index 20c36f7..c1f3e22 100644
--- a/xen/arch/x86/cpuid/cpuid.c
+++ b/xen/arch/x86/cpuid/cpuid.c
@@ -1,120 +1,5 @@
 #include "cpuid-private.h"
 
-const uint32_t known_features[XEN_NR_FEATURESET_ENTRIES] =
-{
-    [cpufeat_word(X86_FEATURE_FPU)] = (SHARED_1d                           |
-                                       cpufeat_mask(X86_FEATURE_SEP)       |
-                                       cpufeat_mask(X86_FEATURE_PN)        |
-                                       cpufeat_mask(X86_FEATURE_CLFLSH)    |
-                                       cpufeat_mask(X86_FEATURE_DS)        |
-                                       cpufeat_mask(X86_FEATURE_ACPI)      |
-                                       cpufeat_mask(X86_FEATURE_XMM)       |
-                                       cpufeat_mask(X86_FEATURE_XMM2)      |
-                                       cpufeat_mask(X86_FEATURE_SELFSNOOP) |
-                                       cpufeat_mask(X86_FEATURE_HT)        |
-                                       cpufeat_mask(X86_FEATURE_ACC)       |
-                                       cpufeat_mask(X86_FEATURE_IA64)      |
-                                       cpufeat_mask(X86_FEATURE_PBE)),
-
-    [cpufeat_word(X86_FEATURE_XMM3)] = (cpufeat_mask(X86_FEATURE_XMM3)         
|
-                                        cpufeat_mask(X86_FEATURE_PCLMULQDQ)    
|
-                                        cpufeat_mask(X86_FEATURE_DTES64)       
|
-                                        cpufeat_mask(X86_FEATURE_MWAIT)        
|
-                                        cpufeat_mask(X86_FEATURE_DSCPL)        
|
-                                        cpufeat_mask(X86_FEATURE_VMXE)         
|
-                                        cpufeat_mask(X86_FEATURE_SMXE)         
|
-                                        cpufeat_mask(X86_FEATURE_EST)          
|
-                                        cpufeat_mask(X86_FEATURE_TM2)          
|
-                                        cpufeat_mask(X86_FEATURE_SSSE3)        
|
-                                        cpufeat_mask(X86_FEATURE_CID)          
|
-                                        cpufeat_mask(X86_FEATURE_FMA)          
|
-                                        cpufeat_mask(X86_FEATURE_CX16)         
|
-                                        cpufeat_mask(X86_FEATURE_XTPR)         
|
-                                        cpufeat_mask(X86_FEATURE_PDCM)         
|
-                                        cpufeat_mask(X86_FEATURE_PCID)         
|
-                                        cpufeat_mask(X86_FEATURE_DCA)          
|
-                                        cpufeat_mask(X86_FEATURE_SSE4_1)       
|
-                                        cpufeat_mask(X86_FEATURE_SSE4_2)       
|
-                                        cpufeat_mask(X86_FEATURE_X2APIC)       
|
-                                        cpufeat_mask(X86_FEATURE_MOVBE)        
|
-                                        cpufeat_mask(X86_FEATURE_POPCNT)       
|
-                                        cpufeat_mask(X86_FEATURE_TSC_DEADLINE) 
|
-                                        cpufeat_mask(X86_FEATURE_AES)          
|
-                                        cpufeat_mask(X86_FEATURE_XSAVE)        
|
-                                        cpufeat_mask(X86_FEATURE_OSXSAVE)      
|
-                                        cpufeat_mask(X86_FEATURE_AVX)          
|
-                                        cpufeat_mask(X86_FEATURE_F16C)         
|
-                                        cpufeat_mask(X86_FEATURE_RDRAND)       
|
-                                        cpufeat_mask(X86_FEATURE_HYPERVISOR)),
-
-    [cpufeat_word(X86_FEATURE_SYSCALL)] = (SHARED_1d                          |
-                                           cpufeat_mask(X86_FEATURE_SYSCALL)  |
-                                           cpufeat_mask(X86_FEATURE_MP)       |
-                                           cpufeat_mask(X86_FEATURE_NX)       |
-                                           cpufeat_mask(X86_FEATURE_MMXEXT)   |
-                                           cpufeat_mask(X86_FEATURE_FFXSR)    |
-                                           cpufeat_mask(X86_FEATURE_PAGE1GB)  |
-                                           cpufeat_mask(X86_FEATURE_RDTSCP)   |
-                                           cpufeat_mask(X86_FEATURE_LM)       |
-                                           cpufeat_mask(X86_FEATURE_3DNOWEXT) |
-                                           cpufeat_mask(X86_FEATURE_3DNOW)),
-
-    [cpufeat_word(X86_FEATURE_LAHF_LM)] = (cpufeat_mask(X86_FEATURE_LAHF_LM)   
    |
-                                           
cpufeat_mask(X86_FEATURE_CMP_LEGACY)    |
-                                           cpufeat_mask(X86_FEATURE_SVM)       
    |
-                                           cpufeat_mask(X86_FEATURE_EXTAPIC)   
    |
-                                           
cpufeat_mask(X86_FEATURE_CR8_LEGACY)    |
-                                           cpufeat_mask(X86_FEATURE_ABM)       
    |
-                                           cpufeat_mask(X86_FEATURE_SSE4A)     
    |
-                                           
cpufeat_mask(X86_FEATURE_MISALIGNSSE)   |
-                                           
cpufeat_mask(X86_FEATURE_3DNOWPREFETCH) |
-                                           cpufeat_mask(X86_FEATURE_OSVW)      
    |
-                                           cpufeat_mask(X86_FEATURE_IBS)       
    |
-                                           cpufeat_mask(X86_FEATURE_XOP)       
    |
-                                           cpufeat_mask(X86_FEATURE_SKINIT)    
    |
-                                           cpufeat_mask(X86_FEATURE_WDT)       
    |
-                                           cpufeat_mask(X86_FEATURE_LWP)       
    |
-                                           cpufeat_mask(X86_FEATURE_FMA4)      
    |
-                                           
cpufeat_mask(X86_FEATURE_NODEID_MSR)    |
-                                           cpufeat_mask(X86_FEATURE_TBM)       
    |
-                                           cpufeat_mask(X86_FEATURE_TOPOEXT)   
    |
-                                           cpufeat_mask(X86_FEATURE_DBEXT)     
    |
-                                           cpufeat_mask(X86_FEATURE_MWAITX)),
-
-    [cpufeat_word(X86_FEATURE_XSAVEOPT)] = (cpufeat_mask(X86_FEATURE_XSAVEOPT) 
|
-                                            cpufeat_mask(X86_FEATURE_XSAVEC)   
|
-                                            cpufeat_mask(X86_FEATURE_XGETBV1)  
|
-                                            cpufeat_mask(X86_FEATURE_XSAVES)),
-
-    [cpufeat_word(X86_FEATURE_FSGSBASE)] = (cpufeat_mask(X86_FEATURE_FSGSBASE) 
  |
-                                            
cpufeat_mask(X86_FEATURE_TSC_ADJUST) |
-                                            cpufeat_mask(X86_FEATURE_BMI1)     
  |
-                                            cpufeat_mask(X86_FEATURE_HLE)      
  |
-                                            cpufeat_mask(X86_FEATURE_AVX2)     
  |
-                                            cpufeat_mask(X86_FEATURE_SMEP)     
  |
-                                            cpufeat_mask(X86_FEATURE_BMI2)     
  |
-                                            cpufeat_mask(X86_FEATURE_ERMS)     
  |
-                                            cpufeat_mask(X86_FEATURE_INVPCID)  
  |
-                                            cpufeat_mask(X86_FEATURE_RTM)      
  |
-                                            cpufeat_mask(X86_FEATURE_CMT)      
  |
-                                            cpufeat_mask(X86_FEATURE_FPU_SEL)  
  |
-                                            cpufeat_mask(X86_FEATURE_MPX)      
  |
-                                            cpufeat_mask(X86_FEATURE_CAT)      
  |
-                                            cpufeat_mask(X86_FEATURE_RDSEED)   
  |
-                                            cpufeat_mask(X86_FEATURE_ADX)      
  |
-                                            cpufeat_mask(X86_FEATURE_SMAP)     
  |
-                                            cpufeat_mask(X86_FEATURE_PCOMMIT)  
  |
-                                            
cpufeat_mask(X86_FEATURE_CLFLUSHOPT) |
-                                            cpufeat_mask(X86_FEATURE_CLWB)     
  |
-                                            cpufeat_mask(X86_FEATURE_SHA)),
-
-    [cpufeat_word(X86_FEATURE_PREFETCHWT1)] = 
(cpufeat_mask(X86_FEATURE_PREFETCHWT1)),
-
-    [cpufeat_word(X86_FEATURE_ITSC)] = (cpufeat_mask(X86_FEATURE_ITSC)),
-
-    [cpufeat_word(X86_FEATURE_CLZERO)] = (cpufeat_mask(X86_FEATURE_CLZERO)),
-};
-
 const uint32_t inverted_features[XEN_NR_FEATURESET_ENTRIES] =
 {
     [cpufeat_word(X86_FEATURE_FPU_SEL)] = cpufeat_mask(X86_FEATURE_FPU_SEL),
diff --git a/xen/arch/x86/cpuid/gen-feature-deps.py 
b/xen/arch/x86/cpuid/gen-feature-deps.py
index f0ecbba..1b61542 100755
--- a/xen/arch/x86/cpuid/gen-feature-deps.py
+++ b/xen/arch/x86/cpuid/gen-feature-deps.py
@@ -42,6 +42,15 @@ with open(path.join(os.environ["XEN_ROOT"],
         # Construct a reverse mapping of value to name
         names[val] = name
 
+# Features shared between 1d and e1d.
+shared_1d = (FPU, VME, DE, PSE, TSC, MSR, PAE, MCE, CX8, APIC,
+             MTRR, PGE, MCA, CMOV, PAT, PSE36, MMX, FXSR)
+
+# All defined features, other than shared ones.
+all_features = []
+
+for f in (x for x in names.keys() if not x in shared_1d):
+    all_features.append(f)
 
 # Dependences specified as a dictionary of tuples: The feature in the key
 # is a direct dependency of each of the features in the tuple.
@@ -95,7 +104,7 @@ for feat in deep_features:
 
     deep_deps[feat] = seen[1:]
 
-def format_featurset(fs):
+def format_featurset(fs, shared = False):
 
     words = {}
     res = "\n"
@@ -112,7 +121,11 @@ def format_featurset(fs):
     for w in sorted(words.keys()):
         wf = sorted(words[w])
 
-        res += "        [cpufeat_word(X86_FEATURE_%s)] = (\n" % (names[wf[0]], 
)
+        if shared and wf[0] in (SEP, SYSCALL):
+            res += "        [cpufeat_word(X86_FEATURE_%s)] = (SHARED_1d |\n" \
+                   % (names[wf[0]], )
+        else:
+            res += "        [cpufeat_word(X86_FEATURE_%s)] = (\n" % 
(names[wf[0]], )
 
         res += " |\n".join(
             "            cpufeat_mask(X86_FEATURE_%s)" %
@@ -130,8 +143,12 @@ with open(path.join(os.environ["XEN_ROOT"],
  */
 #include "cpuid-private.h"
 
+const uint32_t known_features[XEN_NR_FEATURESET_ENTRIES] =
+{%s
+};
+
 const struct tagged_featureset deep_deps[] =
-{""" % (sys.argv[0],))
+{""" % (sys.argv[0], format_featurset(all_features, True)))
 
     for d in sorted(deep_deps.keys()):
         f.write("""
-- 
2.1.4


_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxx
http://lists.xen.org/xen-devel


 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.