Add runnability info to query-cpu-definitions
PATCH v3 4/5 qmp: Add runnability information to query-cpu-definitions
In reply to Eduardo HabkostAdd a new optional field to query-cpu-definitions schema:
"unavailable-features". It will contain a list of QOM properties that prevent the CPU model from running in the current host.
---
Changes v2 -> v3:
* Small documentation reword
* Suggested-by: Markus Armbruster <[email protected]>
Changes v1 -> v2:
* Remove @runnable field, non-empty @unavailable-features is enough to report CPU model as not runnable.
* Documentation updates:
* Changed to "(since 2.7)";
* Add more details about the exact meaning of unavailable-features, and what it would mean to see read-only QOM properties in the list, and that implementations can return "type" if there's no extra information available;
--- qapi-schema.json | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-)
qapi-schema.json +22 -1
@@ -3111,10 +3111,31 @@ # QEMU version, machine type, machine options and accelerator options. # A static model is always migration-safe. (since 2.8) # +# @unavailable-features: #optional List of properties that prevent +# the CPU model from running in the current +# host. (since 2.7) +# +# @unavailable-features is a list of QOM property names that +# represent CPU model attributes that prevent the CPU from running. +# If the QOM property is read-only, that means there's no known +# way to make the CPU model run in the current host. Implementations +# that choose not to provide specific information return the +# property name "type". +# If the property is read-write, it means that it MAY be possible +# to run the CPU model in the current host if that property is +# changed. Management software can use it as hints to suggest or +# choose an alternative for the user, or just to generate meaningful +# error messages explaining why the CPU model can't be used. +# If @unavailable-features is an empty list, the CPU model is +# runnable using the current host and machine-type. +# If @unavailable-features is not present, runnability +# information for the CPU is not available. +# # Since: 1.2.0 ## { 'struct': 'CpuDefinitionInfo', - 'data': { 'name': 'str', '*migration-safe': 'bool', 'static': 'bool' } } + 'data': { 'name': 'str', '*migration-safe': 'bool', 'static': 'bool', + '*unavailable-features': [ 'str' ] } } ## # @query-cpu-definitions:
Signature · 1 line
2.7.4
PATCH v3 5/5 target-i386: Return runnability information on query-cpu-definitions
In reply to Eduardo HabkostFill the "unavailable-features" field on the x86 implementation of query-cpu-definitions.
---
Changes v2 -> v3:
* Create a x86_cpu_feature_name() function, to
isolate the code that returns the property name
Changes v1 -> v2:
* Updated to the new schema: no @runnable field, and always report @unavailable-features as present
--- target-i386/cpu.c | 55 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+)
target-i386/cpu.c +55 -0
@@ -1987,6 +1987,24 @@ static inline void feat2prop(char *s) } } +/* Return the feature property name for a feature flag bit */ +static char *x86_cpu_feature_name (FeatureWord w,int bitnr) +{ +char **parts, *r; + +/*TODO: This can be simplified later, by: +* 1) Moving the aliases outside the feat_names array +* (making g_strsplit() unnecessary) +* 2) Replacing "_" with "-" on all entries +* (making feat2prop() unnecessary) +*/ + parts =g_strsplit (feature_word_info[w].feat_names[bitnr],"|" ,2 ); + r =g_strdup (parts[0 ]); +feat2prop (r); +g_strfreev (parts); +return r; +} +/* Compatibily hack to maintain legacy +-feat semantic, * where +-feat overwrites any feature set by * feat=on|feat even if the later is parsed after +-feat
@@ -2105,6 +2123,41 @@ static void x86_cpu_report_filtered_features(X86CPU *cpu) } } +/* Check for missing features that may prevent the CPU class from +* running using the current machine and accelerator. +*/ +static void x86_cpu_class_check_missing_features (X86CPUClass *xcc, +strList **missing_feats) +{ +X86CPU *xc; +FeatureWord w; + +if (xcc->kvm_required && !kvm_enabled ()) { +strList *new =g_new0 (strList,1 ); + new->value =g_strdup ("kvm" );; + *missing_feats = new; +return ; + } + + xc =X86_CPU (object_new (object_class_get_name (OBJECT_CLASS (xcc)))); +if (x86_cpu_filter_features (xc)) { +for (w =0 ; w <FEATURE_WORDS ; w++) { +uint32_t filtered = xc->filtered_features[w]; +int i; +for (i =0 ; i <32 ; i++) { +if (filtered & (1UL << i)) { +strList *new =g_new0 (strList,1 ); + new->value =x86_cpu_feature_name (w, i); + new->next = *missing_feats; + *missing_feats = new; + } + } + } + } + +object_unref (OBJECT (xc)); +} +/* Print all cpuid feature names in featureset */ static void listflags (FILE *f,fprintf_function print,const char **featureset)
@@ -2197,6 +2250,8 @@ static void x86_cpu_definition_entry(gpointer data, gpointer user_data) info =g_malloc0 (sizeof (*info)); info->name =x86_cpu_class_get_model_name (cc); +x86_cpu_class_check_missing_features (cc, &info->unavailable_features); + info->has_unavailable_features = true; entry =g_malloc0 (sizeof (*entry)); entry->value = info;
Signature · 1 line
2.7.4
PATCH v3 2/5 target-i386: Move warning code outside x86_cpu_filter_features()
In reply to Eduardo Habkostx86_cpu_filter_features() will be reused by code that shouldn't print any warning. Move the warning code to a new x86_cpu_report_filtered_features() function, and call it from x86_cpu_realizefn().
--- target-i386/cpu.c | 28 +++++++++++++++++++--------- 1 file changed, 19 insertions(+), 9 deletions(-)
target-i386/cpu.c +19 -9
@@ -2218,9 +2218,6 @@ static int x86_cpu_filter_features(X86CPU *cpu) env->features[w] &= host_feat; cpu->filtered_features[w] = requested_features & ~env->features[w];if (cpu->filtered_features[w]) { -if (cpu->check_cpuid || cpu->enforce_cpuid) { -report_unavailable_features (w, cpu->filtered_features[w]); - } rv =1 ; } }
@@ -2228,6 +2225,15 @@ static int x86_cpu_filter_features(X86CPU *cpu)return rv; } +static void x86_cpu_report_filtered_features (X86CPU *cpu) +{ +FeatureWord w; + +for (w =0 ; w <FEATURE_WORDS ; w++) { +report_unavailable_features (w, cpu->filtered_features[w]); + } +} +static void x86_cpu_apply_props (X86CPU *cpu,PropValue *props) {PropValue *pv;
@@ -3042,12 +3048,16 @@ static void x86_cpu_realizefn(DeviceState *dev, Error **errp) env->cpuid_level =7 ; } -if (x86_cpu_filter_features (cpu) && cpu->enforce_cpuid) { -error_setg (&local_err, -kvm_enabled () ? -"Host doesn't support requested features" : -"TCG doesn't support requested features" ); - goto out; +if (x86_cpu_filter_features (cpu) && + (cpu->check_cpuid || cpu->enforce_cpuid)) { +x86_cpu_report_filtered_features (cpu); +if (cpu->enforce_cpuid) { +error_setg (&local_err, +kvm_enabled () ? +"Host doesn't support requested features" : +"TCG doesn't support requested features" ); + goto out; + } }/* On AMD CPUs, some CPUID[8000_0001].EDX bits must match the bits on
Signature · 1 line
2.7.4
PATCH v3 3/5 target-i386: Define CPUID filtering functions before x86_cpu_list()
In reply to Eduardo HabkostJust move code to another place so the it can be reused by the query-cpu-definitions code.
--- target-i386/cpu.c | 68 +++++++++++++++++++++++++++---------------------------- 1 file changed, 34 insertions(+), 34 deletions(-)
target-i386/cpu.c +34 -34
@@ -2071,6 +2071,40 @@ static void x86_cpu_parse_featurestr(const char *typename, char *features, } } +/* +* Filters CPU feature words based on host availability of each feature. +* +* Returns: 0 if all flags are supported by the host, non-zero otherwise. +*/ +static int x86_cpu_filter_features (X86CPU *cpu) +{ +CPUX86State *env = &cpu->env; +FeatureWord w; +int rv =0 ; + +for (w =0 ; w <FEATURE_WORDS ; w++) { +uint32_t host_feat = +x86_cpu_get_supported_feature_word (w, cpu->migratable); +uint32_t requested_features = env->features[w]; + env->features[w] &= host_feat; + cpu->filtered_features[w] = requested_features & ~env->features[w]; +if (cpu->filtered_features[w]) { + rv =1 ; + } + } + +return rv; +} + +static void x86_cpu_report_filtered_features (X86CPU *cpu) +{ +FeatureWord w; + +for (w =0 ; w <FEATURE_WORDS ; w++) { +report_unavailable_features (w, cpu->filtered_features[w]); + } +} +/* Print all cpuid feature names in featureset */ static void listflags (FILE *f,fprintf_function print,const char **featureset)
@@ -2200,40 +2234,6 @@ static uint32_t x86_cpu_get_supported_feature_word(FeatureWord w,return r; } -/* -* Filters CPU feature words based on host availability of each feature. -* -* Returns: 0 if all flags are supported by the host, non-zero otherwise. -*/ -static int x86_cpu_filter_features (X86CPU *cpu) -{ -CPUX86State *env = &cpu->env; -FeatureWord w; -int rv =0 ; - -for (w =0 ; w <FEATURE_WORDS ; w++) { -uint32_t host_feat = -x86_cpu_get_supported_feature_word (w, cpu->migratable); -uint32_t requested_features = env->features[w]; - env->features[w] &= host_feat; - cpu->filtered_features[w] = requested_features & ~env->features[w]; -if (cpu->filtered_features[w]) { - rv =1 ; - } - } - -return rv; -} - -static void x86_cpu_report_filtered_features (X86CPU *cpu) -{ -FeatureWord w; - -for (w =0 ; w <FEATURE_WORDS ; w++) { -report_unavailable_features (w, cpu->filtered_features[w]); - } -} -static void x86_cpu_apply_props (X86CPU *cpu,PropValue *props) {PropValue *pv;
Signature · 1 line
2.7.4
v3 cover Add runnability info to query-cpu-definitions
This series extends query-cpu-definitions to include an extra
field: "unavailable-features". The new field can be used to find out reasons that prevent the CPU model from running in the current host.
This will return information based on the current machine and accelerator only. In the future we may extend these mechanisms to allow querying other machines and other accelerators without restarting QEMU, but it will require some reorganization of QEMU's main code.
Changes v2 -> v3:
* Small documentation reword
* Suggested-by: Markus Armbruster <[email protected]>
* Create a x86_cpu_feature_name() function, to isolate the code that returns the property name
Changes v1 -> v2:
* Fixed documentation to say "(since 2.7)"
* Removed @runnable field, improved documentation
Example command output:
{ "return": [
{
"unavailable-features": [],
"static": false,
"name": "host"
},
{
"unavailable-features": [],
"static": false,
"name": "qemu64"
},
{
"unavailable-features": [],
"static": false,
"name": "qemu32"
},
{
"unavailable-features": ["npt", "sse4a", "3dnow", "3dnowext", "fxsr-opt", "mmxext"],
"static": false,
"name": "phenom"
},
{
"unavailable-features": [],
"static": false,
"name": "pentium3"
},
{
"unavailable-features": [],
"static": false,
"name": "pentium2"
},
{
"unavailable-features": [],
"static": false,
"name": "pentium"
},
{
"unavailable-features": [],
"static": false,
"name": "n270"
},
{
"unavailable-features": [],
"static": false,
"name": "kvm64"
},
{
"unavailable-features": [],
"static": false,
"name": "kvm32"
},
{
"unavailable-features": [],
"static": false,
"name": "coreduo"
},
{
"unavailable-features": [],
"static": false,
"name": "core2duo"
},
{
"unavailable-features": ["3dnow", "3dnowext", "mmxext"],
"static": false,
"name": "athlon"
},
{
"unavailable-features": [],
"static": false,
"name": "Westmere"
},
{
"unavailable-features": ["xgetbv1", "xsavec", "3dnowprefetch", "smap", "adx", "rdseed", "mpx", "rtm", "hle"],
"static": false,
"name": "Skylake-Client"
},
{
"unavailable-features": [],
"static": false,
"name": "SandyBridge"
},
{
"unavailable-features": [],
"static": false,
"name": "Penryn"
},
{
"unavailable-features": ["tbm", "fma4", "xop", "3dnowprefetch", "misalignsse", "sse4a"],
"static": false,
"name": "Opteron_G5"
},
{
"unavailable-features": ["fma4", "xop", "3dnowprefetch", "misalignsse", "sse4a"],
"static": false,
"name": "Opteron_G4"
},
{
"unavailable-features": ["misalignsse", "sse4a"],
"static": false,
"name": "Opteron_G3"
},
{
"unavailable-features": [],
"static": false,
"name": "Opteron_G2"
},
{
"unavailable-features": [],
"static": false,
"name": "Opteron_G1"
},
{
"unavailable-features": [],
"static": false,
"name": "Nehalem"
},
{
"unavailable-features": [],
"static": false,
"name": "IvyBridge"
},
{
"unavailable-features": ["rtm", "hle"],
"static": false,
"name": "Haswell"
},
{
"unavailable-features": [],
"static": false,
"name": "Haswell-noTSX"
},
{
"unavailable-features": [],
"static": false,
"name": "Conroe"
},
{
"unavailable-features": ["3dnowprefetch", "smap", "adx", "rdseed", "rtm", "hle"],
"static": false,
"name": "Broadwell"
},
{
"unavailable-features": ["3dnowprefetch", "smap", "adx", "rdseed"],
"static": false,
"name": "Broadwell-noTSX"
},
{
"unavailable-features": [],
"static": false,
"name": "486"
}
]}Eduardo Habkost (5):
target-i386: List CPU models using subclass list
target-i386: Move warning code outside x86_cpu_filter_features()
target-i386: Define CPUID filtering functions before x86_cpu_list()
qmp: Add runnability information to query-cpu-definitions
target-i386: Return runnability information on query-cpu-definitions
qapi-schema.json | 23 ++++- target-i386/cpu-qom.h | 4 + target-i386/cpu.c | 236 ++++++++++++++++++++++++++++++++++++-------------- 3 files changed, 199 insertions(+), 64 deletions(-)
Signature · 1 line
2.7.4
PATCH v3 1/5 target-i386: List CPU models using subclass list
Instead of using the builtin_x86_defs array, use the QOM subclass list to list CPU models on "-cpu ?" and "query-cpu-definitions".
[ehabkost: copied code from a patch by Andreas:
"target-i386: QOM'ify CPU", from March 2012]
--- target-i386/cpu-qom.h | 4 ++ target-i386/cpu.c | 103 ++++++++++++++++++++++++++++++++++++-------------- 2 files changed, 78 insertions(+), 29 deletions(-)
target-i386/cpu-qom.h +4 -0
@@ -63,6 +63,10 @@ typedef struct X86CPUClass {bool kvm_required; +/* Optional description of CPU model. +* If unavailable, cpu_def->model_id is used */ +const char *model_description; +DeviceRealize parent_realize;void (*parent_reset)(CPUState *cpu); } X86CPUClass;
target-i386/cpu.c +74 -29
129 lines not on this page · raw message
Signature · 1 line
2.7.4
Your series failed automatic build test. Please find the testing commands and their output below. If you have docker installed, you can probably reproduce it locally.
Hi,
Your series failed automatic build test. Please find the testing commands and their output below. If you have docker installed, you can probably reproduce it locally.
Subject: [libvirt] [PATCH v3 0/5] Add runnability info to query-cpu-definitions
Message-id: [email protected]
Type: series
=== TEST SCRIPT BEGIN ===
#!/bin/bash
set -e
git submodule update --init dtc
make J=8 docker-test-quick@centos6
make J=8 docker-test-mingw@fedora
=== TEST SCRIPT END ===
Updating 3c8cf5a9c21ff8782164d1def7f44bd888713384
From https://github.com/patchew-project/qemu
* [new tag] patchew/[email protected] -> patchew/[email protected]
* [new tag] patchew/[email protected] -> patchew/[email protected]
Switched to a new branch 'test'
43f49c7 target-i386: Return runnability information on query-cpu-definitions 17a9434 qmp: Add runnability information to query-cpu-definitions 405e270 target-i386: Define CPUID filtering functions before x86_cpu_list() dc099e7 target-i386: Move warning code outside x86_cpu_filter_features() 21da10b target-i386: List CPU models using subclass list
=== OUTPUT BEGIN ===
Submodule 'dtc' (git://git.qemu-project.org/dtc.git) registered for path 'dtc' Cloning into 'dtc'...
Submodule path 'dtc': checked out '65cc4d2748a2c2e6f27f1cf39e07a5dbabd80ebf'
BUILD centos6
=== OUTPUT END ===
Abort: command timeout (>3600 seconds)
---
Email generated automatically by Patchew [http://patchew.org/].
Please send your feedback to [email protected]
Re: [Qemu-devel] [libvirt] [PATCH v3 4/5] qmp: Add runnability information to query-cpu-definitions
In reply to Eduardo HabkostQuoted 15 lines · Eduardo Habkost
Add a new optional field to query-cpu-definitions schema:
"unavailable-features". It will contain a list of QOM properties that prevent the CPU model from running in the current host.Cc David Hildenbrand <[email protected]>Cc Michael Mueller <[email protected]>Cc Christian Borntraeger <[email protected]>Cc Cornelia Huck <[email protected]>Cc Jiri Denemark <[email protected]>Signed-off-by Eduardo Habkost <[email protected]>---
+++
b/qapi-schema.json
qapi-schema.json line 3116
Quoted 6 lines
qapi-schema.json +3
-0@@ -3111,10 +3111,31 @@ # QEMU version, machine type, machine options and accelerator options. # A static model is always migration-safe. (since 2.8) # +# @unavailable-features: #optional List of properties that prevent +# the CPU model from running in the current +# host. (since 2.7)
We've missed 2.7; this should probably be 2.8. Otherwise reads okay to me;
Signature · 2 lines
Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org
Re: [Qemu-devel] [libvirt] [PATCH v3 4/5] qmp: Add runnability information to query-cpu-definitions
Quoted 25 lines · Eric Blake
Quoted 15 lines · Eduardo Habkost
Add a new optional field to query-cpu-definitions schema:
"unavailable-features". It will contain a list of QOM properties that prevent the CPU model from running in the current host.Cc David Hildenbrand <[email protected]>Cc Michael Mueller <[email protected]>Cc Christian Borntraeger <[email protected]>Cc Cornelia Huck <[email protected]>Cc Jiri Denemark <[email protected]>Signed-off-by Eduardo Habkost <[email protected]>---
+++
b/qapi-schema.jsonqapi-schema.json line 3116
Quoted 6 lines
qapi-schema.json +3
-0@@ -3111,10 +3111,31 @@ # QEMU version, machine type, machine options and accelerator options. # A static model is always migration-safe. (since 2.8) # +# @unavailable-features: #optional List of properties that prevent +# the CPU model from running in the current +# host. (since 2.7)We've missed 2.7; this should probably be 2.8. Otherwise reads okay to me;
Quoted 1 line
Reviewed-by Eric Blake <[email protected]>
Oops! I will fix it before merging. Thanks for spotting!
Signature · 1 line
Eduardo