Skip to contentSkip to conversation

tools/xen-cpuid: switch to use cpu-policy defined names

PATCH New Roger Pau Monne 1 participant 1 message May 13, 2024

lore
Share & tools
lore
#0 lore raw

PATCH v3 1/1 tools/xen-cpuid: switch to use cpu-policy defined names

Like it was done recently for libxl, switch to using the auto-generated feature names by the processing of cpufeatureset.h, this allows removing the open-coded feature names, and unifies the feature naming with libxl and the hypervisor.

Introduce a newly auto-generated array that contains the feature names indexed at featureset bit position, otherwise using the existing INIT_FEATURE_NAMES would require iterating over the array elements until a match with the expected bit position is found.

Note that leaf names need to be kept, as the current auto-generated data doesn't contain the leaf names.

---
Changes since v2:
- Remove __maybe_unused definition from the emulator harness.

Changes since v1:
- Modify gen-cpuid.py to generate an array of strings with the feature names.
- Introduce and use __maybe_unused.

---
 tools/include/xen-tools/common-macros.h |   4 +
 tools/misc/xen-cpuid.c                  | 320 +++---------------------
 tools/tests/x86_emulator/x86-emulate.h  |   1 -
 xen/tools/gen-cpuid.py                  |  26 ++
 4 files changed, 68 insertions(+), 283 deletions(-)
tools/include/xen-tools/common-macros.h +4 -0
index 60912225cb7a..560528dbc638 100644
@@ -83,6 +83,10 @@
 #define __packed __attribute__((__packed__))
 #endif
 
+#ifndef __maybe_unused
+# define __maybe_unused __attribute__((__unused__))
+#endif
+
 #define container_of(ptr, type, member) ({              \
     typeof(((type *)0)->member) *mptr__ = (ptr);        \
     (type *)((char *)mptr__ - offsetof(type, member));  \
tools/misc/xen-cpuid.c +38 -282

357 lines not on this page · raw message

tools/tests/x86_emulator/x86-emulate.h +0 -1
index 8f8accfe3e70..a702c9faf207 100644
@@ -50,7 +50,6 @@
 #define this_cpu(var) per_cpu_##var
 
 #define __init
-#define __maybe_unused __attribute__((__unused__))
 
 #define likely(x)   __builtin_expect(!!(x), true)
 #define unlikely(x) __builtin_expect(!!(x), false)
xen/tools/gen-cpuid.py +26 -0
index 380b9d973a67..c0caa3bdebef 100755
@@ -475,6 +475,32 @@ def write_results(state):
     state.output.write(
 """}
 
+""")
+
+    state.output.write(
+"""
+#define INIT_FEATURE_NAME_ARRAY { \\
+""")
+
+    try:
+        _tmp = state.names.iteritems()
+    except AttributeError:
+        _tmp = state.names.items()
+
+    for bit, name in sorted(_tmp):
+        state.output.write(
+            '    [%s] = "%s",\\\n' % (bit, name.lower().replace("_", "-"))
+            )
+
+    # Ensure array size matches featureset size.
+    if not state.names.get(state.nr_entries * 32 - 1, ""):
+        state.output.write(
+            '    [%s] = NULL,\\\n' % (state.nr_entries * 32 - 1)
+            )
+
+    state.output.write(
+"""}
+
 """)
 
     for idx, text in enumerate(state.bitfields):
Signature · 1 line
2.44.0