tools/xen-cpuid: switch to use cpu-policy defined names
PATCH v2 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 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 +++--------------------- xen/tools/gen-cpuid.py | 26 ++ 3 files changed, 68 insertions(+), 282 deletions(-)
tools/include/xen-tools/common-macros.h +4 -0
@@ -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
xen/tools/gen-cpuid.py +26 -0
@@ -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
Quoted 9 lines · Roger Pau Monne
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_NAMESwould require iterating over the array elements until a match with the expected bit position is found.
Quoted 4 lines
Note that leaf names need to be kept, as the current auto-generated data doesn't contain the leaf names.
Signed-off-by Roger Pau Monné <[email protected]>
except that ...
Quoted 7 lines
xen/tools/gen-cpuid.py +1
-0@@ -475,6 +475,32 @@ def write_results(state): state.output.write( """} +""")
xen/tools/gen-cpuid.py def write_results(state): · line 488
Quoted 10 lines
xen/tools/gen-cpuid.py +10
-0+ + state.output.write( +""" +#define INIT_FEATURE_NAME_ARRAY { \\ +""") + + try: + _tmp = state.names.iteritems() + except AttributeError: + _tmp = state.names.items()
... can't figure what this try/except is needed for. Hopefully someone with better Python foo than mine can take a look.
Jan
Quoted 10 lines · Jan Beulich
Quoted 9 lines · Roger Pau Monne
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_NAMESwould require iterating over the array elements until a match with the expected bit position is found.
Quoted 7 lines
Quoted 4 lines
Note that leaf names need to be kept, as the current auto-generated data doesn't contain the leaf names.
Signed-off-by Roger Pau Monné <[email protected]>Reviewed-by Jan Beulich <[email protected]>except that ...
Thanks.
Quoted 7 lines
Quoted 7 lines
xen/tools/gen-cpuid.py +0
-0@@ -475,6 +475,32 @@ def write_results(state): state.output.write( """}
Quoted 14 lines
xen/tools/gen-cpuid.py def write_results(state): · line 488
Quoted 11 lines
xen/tools/gen-cpuid.py +11
-0+""") + + state.output.write( +""" +#define INIT_FEATURE_NAME_ARRAY { \\ +""") + + try: + _tmp = state.names.iteritems() + except AttributeError: + _tmp = state.names.items()... can't figure what this try/except is needed for. Hopefully someone with better Python foo than mine can take a look.
If I understood this correctly (which I might have not, I know very little Python), iteritems() method was removed in Python 3, and what used to be iteritems() in Python 2 is items() on Python 3.
Regards, Roger.
Quoted 10 lines · Jan Beulich
Quoted 9 lines · Roger Pau Monne
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_NAMESwould require iterating over the array elements until a match with the expected bit position is found.
Quoted 6 lines
Quoted 4 lines
Note that leaf names need to be kept, as the current auto-generated data doesn't contain the leaf names.
Signed-off-by Roger Pau Monné <[email protected]>Reviewed-by Jan Beulich <[email protected]>
Oleksii, now that Jan has provided a Reviewed-by, can you provide a release-ack for this to go in?
Thanks, Roger.
Quoted 21 lines · Roger Pau Monné
Quoted 20 lines · Jan Beulich
Quoted 19 lines · Roger Pau Monne
Like it was done recently for libxl, switch to using the auto- generated feature
names by the processing ofcpufeatureset.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 existingINIT_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.
Quoted 6 lines
Quoted 3 lines
Quoted 1 line
Signed-off-by Roger Pau Monné <[email protected]>Reviewed-by Jan Beulich <[email protected]>Oleksii, now that Jan has provided a Reviewed-by, can you provide a release-ack for this to go in?
Based that it is reviewed, I will be happy to have this in 4.19:
~ Oleksii
Quoted 5 lines · Roger Pau Monne
tools/include/xen-tools/common-macros.h +0
-0
tools/include/xen-tools/common-macros.h line 92
Quoted 10 lines
tools/include/xen-tools/common-macros.h +4
-0@@ -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)); \
This hunk needs a matching:
(quoted diff) +0 -0
b/tools/tests/x86_emulator/x86-emulate.h
index 8f8accfe3e70..a702c9faf207 100644
tools/tests/x86_emulator/x86-emulate.h +0 -0
@@ -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)
~Andrew