s390 cpu model implementation
v6 cover s390 cpu model implementation
This patch set in combination with its kernel kvm patch set proposes an implementation of S390 CPU models. The origin of this item is to provide a means for management interfaces like libvirt to draw decisions if life guest migration to a target hypervisor is reasonable.
A migration constraint is that a target hypervisor is capable to run a guest with the same CPU model as the source hypervisor does. To verify this condition, the administration interface employes the existing QMP command "query-cpu-definitions" which returns a list of all currently supported CPU models of a given host system. Together with the extension of QMP command "query-cpus", the current CPU model of a guest is retrievable and a conclusion can be drawn if a migration is possible.
A S390 CPU model is defined as a triple of machine type, CPU facility set and IBC value. Each historic, current and future triple receives a name composed of the machine type and its general availability counter. This name forms the CPU model name (e.g.: "2817-ga2".)
With means of the Instruction Blocking Control feature (IBC), the instruction set available to a given guest is limitable.
Examples:
{"execute":"query-cpus"} {"return":[{"current":true,"CPU":0,"model":"2094-ga3","halted":false,
"accel":"kvm","thread_id":57423},...]}
{"execute":"query-cpu-definitions","arguments":{"accel":"kvm",
"machine":"s390-ccw-virtio"}}
{"return":[{"order":3345,"name":"2964-ga1","live-migration-safe":true},
{"name":"zBC12","runnable":true},
{"name":"2828","runnable":true},
{"order":3105,"name":"2828-ga1","runnable":true,"live-migration-safe":true},
{"name":"host","runnable":true},
{"name":"zEC12","runnable":true},
{"name":"2827","runnable":true},
{"order":3090,"name":"2827-ga2","runnable":true,"live-migration-safe":true",
"is-default":true},
...
{"name":"none","runnable":true}]}A comment to the optional "order" attribute in the answer of query-cpu-definitions is welcomed as well.
Thanks a lot
Michael
v5-v6:
- git am reported whitespace issues fixed
- facility bit 74 added to S390Facility enumeration and comment adjusted
- comment for get_machine_props_fallback() added in patch description
- cpu_model_get/set/() arguments now use void pointers instead of uint64_t
- zPCI related facility definitions merged into series
- Christian's ACKs added to series
v4-v5:
- common code patches moved to begin of series
- linux header related patch dropped as changes are already upstream
- ibc_range renamed to ibc and fac_list_mask renamed to fac_mask to correspond with struct fields in linux header
- test for NULL skipped after strdup_s390_cpu_name()
- strdup_cpu_name() now also handles none cpu model case
- s390_cpu_compare_name() now uses strdup_cpu_name() as well
- omit runnable and is-default field from query-cpu-definitions answer when they are false
- global variable cpu_models_used and routine s390_cpu_models_used() dropped
- routine query-cpu-definitions has a common code path now
- CPU model none is always runnable and presented in answer of command query-cpu-definitions
- live-migration-safe field added to QAPI type CpuDefinitionInfo
- cpu model aliases presented in query-cpu-definitions answer
- CPUState field accel_id added to represent the used accelerator (ACCEL_ID) and initialized in cpu_generic_init()
- CPUState field model_name added to represent the used cpu model, initialized in arch specific init function s390_cpu_initfn()
- QMP command query-cpus extended to display accelerator and CPU model name of all CPUs
- QMP command query-cpu-model dropped in favor to query-cpus
- HMP command info cpus now displays CPU model and accelerator
- optional order field added to query-cpu-definitions
v3-v4:
- qemu probe mode is gone now
- optional parameters 'accel' and 'machine' added to QMP query-cpu-definitions
- z13 related facilities added
- private build directory issue fixed
v2-v3:
- using GTK-Doc style format now for function descriptions
- typo fixed (2/16)
- gen-facilties now used to generate cpu model specific facility lists and the qemu side facility mask during build time (5/16)
- gen-facilities added to make magic (5/16)
- element of struct S390CPUMachineProps now statically in cpu class (6/16)
- element of struct S390CPUProcessorProps now statically in cpu class (6/16)
- facility list also static now (6/16)
- typo fixed (7/16)
- zBC12-ga1 model now active on zEC12-ga2 host (11/16)
- operations on facility lists use QEMU bitmap API now (11/16)
- routine s390_cpu_model_init() introduced, called during cpu object realization to prepare the current accelarator (12/16) if a cpu model was selected
- missing comment added in description of CpuModelInfo type (13/16)
- accelerator field now mandatory for "query-cpu-model" (13/16)
- sorted list related comment to "query-cpu-definitions" dropped in commit message (13/16)
- comment for AccelCpuInfo type updated (13/16)
- routine s390_facility_test() factored out (15/16)
v1-v2:
- QEMU-side facility list mask introduced: this allows to enable guest facilities that are handled by instruction interception handlers implemented on qemu side. Similar to the facilities enabled by means of the KVM side facility list mask which are handled by kvm/kernel.
- Concept of soft facilities has been dropped
- Result type of QMP command query-cpu-definitions extended to hold additional information beside the cpu model name including which cpu model is runnable in current accelerator and machine context.
Michael Mueller (17):
Introduce stub routine cpu_desc_avail
Add accelerator id and model name to CPUState
Extend QMP command query-cpus to return accelerator id and model name Extend HMP command info cpus to display accelerator id and model name Add optional parameters to QMP command query-cpu-definitions
target-s390x: Introduce S390 CPU facilities
target-s390x: Generate facility defines per S390 CPU model
target-s390x: Introduce S390 CPU models
target-s390x: Define S390 CPU model specific facility lists
target-s390x: Add S390 CPU model alias definition routines
target-s390x: Add KVM VM attribute interface for S390 CPU models
target-s390x: Add S390 CPU class initialization routines
target-s390x: Prepare accelerator during S390 CPU object realization
target-s390x: Initialize S390 CPU model name in CPUState
target-s390x: Extend arch specific QMP command query-cpu-definitions
target-s390x: Introduce S390 CPU facility test routine
target-s390x: Enable S390 CPU model usage
Makefile.target | 2 +- cpus.c | 4 + hmp.c | 7 + hw/s390x/s390-virtio.c | 12 +- include/qemu-common.h | 2 + include/qom/cpu.h | 5 + include/sysemu/arch_init.h | 7 +- qapi-schema.json | 44 ++- qmp-commands.hx | 2 +- qmp.c | 11 +- qom/cpu.c | 14 + rules.mak | 1 + stubs/Makefile.objs | 1 + stubs/arch-query-cpu-def.c | 6 +- stubs/cpu-desc-avail.c | 6 + target-arm/helper.c | 6 +- target-i386/cpu.c | 6 +- target-ppc/translate_init.c | 6 +- target-s390x/Makefile.objs | 21 ++ target-s390x/cpu-facilities.h | 86 +++++ target-s390x/cpu-models.c | 746 ++++++++++++++++++++++++++++++++++++++++++ target-s390x/cpu-models.h | 168 ++++++++++ target-s390x/cpu-qom.h | 49 +++ target-s390x/cpu.c | 149 ++++++++- target-s390x/gen-facilities.c | 424 ++++++++++++++++++++++++ target-s390x/helper.c | 9 +- target-s390x/kvm.c | 129 ++++++++ trace-events | 3 + vl.c | 2 +- 29 files changed, 1898 insertions(+), 30 deletions(-) create mode 100644 stubs/cpu-desc-avail.c create mode 100644 target-s390x/cpu-facilities.h create mode 100644 target-s390x/cpu-models.c create mode 100644 target-s390x/cpu-models.h create mode 100644 target-s390x/gen-facilities.c
Signature · 1 line
1.8.3.1
PATCH v6 1/17 Introduce stub routine cpu_desc_avail
This patch introduces the function cpu_desc_avail() which returns by default true if not architecture specific implemented. Its intention is to indicate if the cpu model description is available for display by list_cpus(). This change allows cpu model descriptions to become dynamically created by evaluating the runtime context instead of putting static cpu model information at display.
--- include/qemu-common.h | 2 ++ stubs/Makefile.objs | 1 + stubs/cpu-desc-avail.c | 6 ++++++ vl.c | 2 +- 4 files changed, 10 insertions(+), 1 deletion(-) create mode 100644 stubs/cpu-desc-avail.c
include/qemu-common.h +2 -0
@@ -484,4 +484,6 @@ int parse_debug_env(const char *name, int max, int initial);const char *qemu_ether_ntoa (const MACAddr *mac); +bool cpu_desc_avail (void ); +#endif
stubs/Makefile.objs +1 -0
@@ -39,3 +39,4 @@ stub-obj-$(CONFIG_WIN32) += fd-register.o stub-obj-y += cpus.o stub-obj-y += kvm.o stub-obj-y += qmp_pc_dimm_device_list.o +stub-obj-y += cpu-desc-avail.o
stubs/cpu-desc-avail.c new file +6 -0
@@ -0,0 +1,6 @@ +#include "qemu-common.h" + +bool cpu_desc_avail (void ) +{ +return true; +}
vl.c +1 -1
@@ -3820,7 +3820,7 @@ int main(int argc, char **argv, char **envp)*/ cpudef_init (); -if (cpu_model &&is_help_option (cpu_model)) { +if (cpu_model &&cpu_desc_avail () &&is_help_option (cpu_model)) {list_cpus (stdout, &fprintf, cpu_model);exit (0 ); }
Signature · 1 line
1.8.3.1
Re: [Qemu-devel] [PATCH v6 01/17] Introduce stub routine cpu_desc_avail
Quoted 6 lines · Michael Mueller
This patch introduces the function
cpu_desc_avail()which returns by default true if not architecture specific implemented. Its intention is to indicate if the cpu model description is available for display bylist_cpus(). This change allows cpu model descriptions to become dynamically created by evaluating the runtime context instead of putting static cpu model information at display.
Why are you deliberately breaking "-cpu ?" when cpu_desc_avail() is false?
What exactly could cause cpu_desc_avail() to be false? If CPU model information is not yet available when cpu_list() is called, it is a bug.
Quoted 60 lines
Signed-off-by Michael Mueller <[email protected]>Reviewed-by Thomas Huth <[email protected]>--- include/qemu-common.h | 2 ++ stubs/Makefile.objs | 1 + stubs/cpu-desc-avail.c | 6 ++++++ vl.c | 2 +- 4 files changed, 10 insertions(+), 1 deletion(-) create mode 100644 stubs/cpu-desc-avail.cinclude/qemu-common.h +2
-0@@ -484,4 +484,6 @@ int parse_debug_env(const char *name, int max, int initial);const char *qemu_ether_ntoa (const MACAddr *mac); +bool cpu_desc_avail (void ); +#endif stubs/Makefile.objs +1
-0@@ -39,3 +39,4 @@ stub-obj-$(CONFIG_WIN32) += fd-register.o stub-obj-y += cpus.o stub-obj-y += kvm.o stub-obj-y += qmp_pc_dimm_device_list.o +stub-obj-y += cpu-desc-avail.ostubs/cpu-desc-avail.c new file +6
-0@@ -0,0 +1,6 @@ +#include "qemu-common.h" + +bool cpu_desc_avail (void ) +{ +return true; +}vl.c +1
-1@@ -3820,7 +3820,7 @@ int main(int argc, char **argv, char **envp)*/ cpudef_init (); -if (cpu_model &&is_help_option (cpu_model)) { +if (cpu_model &&cpu_desc_avail () &&is_help_option (cpu_model)) {list_cpus (stdout, &fprintf, cpu_model);exit (0 ); }Signature · 1 line
1.8.3.1
Signature · 1 line
Eduardo
Re: [Qemu-devel] [PATCH v6 01/17] Introduce stub routine cpu_desc_avail
Quoted 10 lines · On Tue, 5 May 2015 10:55:47 -0300 Eduardo Habkost <[email protected]> wrote:
Quoted 6 lines · Michael Mueller
This patch introduces the function
cpu_desc_avail()which returns by default true if not architecture specific implemented. Its intention is to indicate if the cpu model description is available for display bylist_cpus(). This change allows cpu model descriptions to become dynamically created by evaluating the runtime context instead of putting static cpu model information at display.Why are you deliberately breaking "-cpu ?" when
cpu_desc_avail()is false?
In the s390x case cpu_desc_avail() is per se false in this code section of vl.c:
/* Init CPU def lists, based on config
* - Must be called after all the qemu_read_config_file() calls
* - Must be called before list_cpu()
* - Must be called before machine->init()
*/
cpudef_init();
if (cpu_model && cpu_desc_avail() && is_help_option(cpu_model)) {
list_cpus(stdout, &fprintf, cpu_model);
exit(0);
}That is because the output does not solely depend on static definitions but also on runtime context. Here the host machine type this instance of QEMU is running on, at least for the KVM case.
Once the accelerator has been initialized AND the S390 cpu classes have been setup by means of the following code:
static void kvm_setup_cpu_classes(KVMState *s)
{
S390MachineProps mach;
if (!kvm_s390_get_machine_props(s, &mach)) {
s390_setup_cpu_classes(ACCEL_CURRENT, &mach,
s390_current_fac_list_mask());
s390_setup_cpu_aliases();
cpu_classes_initialized = true;
}
}cpu_desc_avail() becomes true. In case the selceted mode was "?" the list_cpu() is now done right before the cpu model is used as part of the cpu initialization (hw/s390-virtio.c):
void s390_init_cpus(const char *cpu_model, uint8_t *storage_keys)
{
int i;
if (cpu_model == NULL) {
cpu_model = "none";
}
if (is_help_option(cpu_model)) {
list_cpus(stdout, &fprintf, cpu_model);
exit(0);
}
...
for (i = 0; i < smp_cpus; i++) {
...
cpu = cpu_s390x_init(cpu_model);
...
}
}Quoted 4 lines
What exactly could cause
cpu_desc_avail()to be false? If CPU model information is not yet available whencpu_list()is called, it is a bug.
Here an example output that shows only runnable cpu models:
$ ./s390x-softmmu/qemu-system-s390x -machine s390,accel=kvm -cpu ? s390 none s390 2064-ga1 IBM zSeries 900 GA1 s390 2064-ga2 IBM zSeries 900 GA2 s390 2064-ga3 IBM zSeries 900 GA3 s390 2064 (alias for 2064-ga3) s390 z900 (alias for 2064-ga3) s390 2066-ga1 IBM zSeries 800 GA1 s390 2066 (alias for 2066-ga1) s390 z800 (alias for 2066-ga1) s390 2084-ga1 IBM zSeries 990 GA1 s390 2084-ga2 IBM zSeries 990 GA2 s390 2084-ga3 IBM zSeries 990 GA3 s390 2084-ga4 IBM zSeries 990 GA4 s390 2084-ga5 IBM zSeries 990 GA5 s390 2084 (alias for 2084-ga5) s390 z990 (alias for 2084-ga5) s390 2086-ga1 IBM zSeries 890 GA1 s390 2086-ga2 IBM zSeries 890 GA2 s390 2086-ga3 IBM zSeries 890 GA3 s390 2086 (alias for 2086-ga3) s390 z890 (alias for 2086-ga3) s390 2094-ga1 IBM System z9 EC GA1 s390 z9-109 (alias for 2094-ga1) s390 2094-ga2 IBM System z9 EC GA2 s390 2094-ga3 IBM System z9 EC GA3 s390 2094 (alias for 2094-ga3) s390 z9 (alias for 2094-ga3) s390 z9-ec (alias for 2094-ga3) s390 2096-ga1 IBM System z9 BC GA1 s390 2096-ga2 IBM System z9 BC GA2 s390 2096 (alias for 2096-ga2) s390 z9-bc (alias for 2096-ga2) s390 2097-ga1 IBM System z10 EC GA1 s390 2097-ga2 IBM System z10 EC GA2 s390 2097-ga3 IBM System z10 EC GA3 s390 2097 (alias for 2097-ga3) s390 z10 (alias for 2097-ga3) s390 z10-ec (alias for 2097-ga3) s390 2098-ga1 IBM System z10 BC GA1 s390 2098-ga2 IBM System z10 BC GA2 s390 2098 (alias for 2098-ga2) s390 z10-bc (alias for 2098-ga2) s390 2817-ga1 IBM zEnterprise 196 GA1 s390 2817-ga2 IBM zEnterprise 196 GA2 s390 2817 (alias for 2817-ga2) s390 z196 (alias for 2817-ga2) s390 2818-ga1 IBM zEnterprise 114 GA1 s390 2818 (alias for 2818-ga1) s390 z114 (alias for 2818-ga1) s390 2827-ga1 IBM zEnterprise EC12 GA1 s390 2827-ga2 IBM zEnterprise EC12 GA2 s390 2827 (alias for 2827-ga2) s390 zEC12 (alias for 2827-ga2) s390 host (alias for 2827-ga2) s390 2828-ga1 IBM zEnterprise BC12 GA1 s390 2828 (alias for 2828-ga1) s390 zBC12 (alias for 2828-ga1)
Quoted 61 lines
Quoted 60 lines
Signed-off-by Michael Mueller <[email protected]>Reviewed-by Thomas Huth <[email protected]>--- include/qemu-common.h | 2 ++ stubs/Makefile.objs | 1 + stubs/cpu-desc-avail.c | 6 ++++++ vl.c | 2 +- 4 files changed, 10 insertions(+), 1 deletion(-) create mode 100644 stubs/cpu-desc-avail.cinclude/qemu-common.h +2
-0@@ -484,4 +484,6 @@ int parse_debug_env(const char *name, int max, int initial);const char *qemu_ether_ntoa (const MACAddr *mac); +bool cpu_desc_avail (void ); +#endif stubs/Makefile.objs +1
-0@@ -39,3 +39,4 @@ stub-obj-$(CONFIG_WIN32) += fd-register.o stub-obj-y += cpus.o stub-obj-y += kvm.o stub-obj-y += qmp_pc_dimm_device_list.o +stub-obj-y += cpu-desc-avail.ostubs/cpu-desc-avail.c new file +6
-0@@ -0,0 +1,6 @@ +#include "qemu-common.h" + +bool cpu_desc_avail (void ) +{ +return true; +}vl.c +1
-1@@ -3820,7 +3820,7 @@ int main(int argc, char **argv, char **envp)*/ cpudef_init (); -if (cpu_model &&is_help_option (cpu_model)) { +if (cpu_model &&cpu_desc_avail () &&is_help_option (cpu_model)) {list_cpus (stdout, &fprintf, cpu_model);exit (0 ); }Signature · 1 line
1.8.3.1
Re: [Qemu-devel] [PATCH v6 01/17] Introduce stub routine cpu_desc_avail
Quoted 14 lines · Michael Mueller
Quoted 10 lines · On Tue, 5 May 2015 10:55:47 -0300 Eduardo Habkost <[email protected]> wrote:
Quoted 6 lines · Michael Mueller
This patch introduces the function
cpu_desc_avail()which returns by default true if not architecture specific implemented. Its intention is to indicate if the cpu model description is available for display bylist_cpus(). This change allows cpu model descriptions to become dynamically created by evaluating the runtime context instead of putting static cpu model information at display.Why are you deliberately breaking "-cpu ?" when
cpu_desc_avail()is false?
Quoted 7 lines
In the s390x case
cpu_desc_avail()is per se false in this code section ofvl.c:/* Init CPU def lists, based on config
* - Must be called after all theqemu_read_config_file()calls
* - Must be called beforelist_cpu()
* - Must be called beforemachine->init()
*/
(Side note: I believe the above outdated, I will send a patch to update it.)
Quoted 10 lines
cpudef_init(); if (cpu_model && cpu_desc_avail() && is_help_option(cpu_model)) { list_cpus(stdout, &fprintf, cpu_model); exit(0); }That is because the output does not solely depend on static definitions but also on runtime context. Here the host machine type this instance of QEMU is running on, at least for the KVM case.
Is this a required feature? I would prefer to have the main() code simple even if it means not having runnable information in "-cpu ?" by now (about possible ways to implement this without cpu_desc_avail(), see below).
Quoted 33 lines
Once the accelerator has been initialized AND the S390 cpu classes have been setup by means of the following code:
static void
kvm_setup_cpu_classes(KVMState *s){ S390MachineProps mach; if (!kvm_s390_get_machine_props(s, &mach)) { s390_setup_cpu_classes(ACCEL_CURRENT, &mach, s390_current_fac_list_mask()); s390_setup_cpu_aliases(); cpu_classes_initialized = true; } }
cpu_desc_avail()becomes true. In case the selceted mode was "?" thelist_cpu()is now done right before the cpu model is used as part of the cpu initialization (hw/s390-virtio.c):void
s390_init_cpus(const char *cpu_model, uint8_t *storage_keys){ int i; if (cpu_model == NULL) { cpu_model = "none"; } if (is_help_option(cpu_model)) { list_cpus(stdout, &fprintf, cpu_model); exit(0); }
Quoted 7 lines
...
for (i = 0; i < smp_cpus; i++) {
...
cpu = cpu_s390x_init(cpu_model);
...
}
}In other words, you just need to ensure that s390_cpu_list() run after kvm_setup_cpu_classes().
Can't you simply call s390_setup_cpu_classes(ACCEL_TEMP) inside s390_init_cpus(), just like arch_query_cpu_definitions()? You could even share code between both functions.
(In the future, we should be able to implement "-cpu ?" by simply calling the query-cpu-definitions implementation.)
Quoted 68 lines
Quoted 5 lines
What exactly could cause
cpu_desc_avail()to be false? If CPU model information is not yet available whencpu_list()is called, it is a bug.Here an example output that shows only runnable cpu models:
$ ./s390x-softmmu/qemu-system-s390x -machine s390,accel=kvm -cpu ? s390 none s390 2064-ga1 IBM zSeries 900 GA1 s390 2064-ga2 IBM zSeries 900 GA2 s390 2064-ga3 IBM zSeries 900 GA3 s390 2064 (alias for 2064-ga3) s390 z900 (alias for 2064-ga3) s390 2066-ga1 IBM zSeries 800 GA1 s390 2066 (alias for 2066-ga1) s390 z800 (alias for 2066-ga1) s390 2084-ga1 IBM zSeries 990 GA1 s390 2084-ga2 IBM zSeries 990 GA2 s390 2084-ga3 IBM zSeries 990 GA3 s390 2084-ga4 IBM zSeries 990 GA4 s390 2084-ga5 IBM zSeries 990 GA5 s390 2084 (alias for 2084-ga5) s390 z990 (alias for 2084-ga5) s390 2086-ga1 IBM zSeries 890 GA1 s390 2086-ga2 IBM zSeries 890 GA2 s390 2086-ga3 IBM zSeries 890 GA3 s390 2086 (alias for 2086-ga3) s390 z890 (alias for 2086-ga3) s390 2094-ga1 IBM System z9 EC GA1 s390 z9-109 (alias for 2094-ga1) s390 2094-ga2 IBM System z9 EC GA2 s390 2094-ga3 IBM System z9 EC GA3 s390 2094 (alias for 2094-ga3) s390 z9 (alias for 2094-ga3) s390 z9-ec (alias for 2094-ga3) s390 2096-ga1 IBM System z9 BC GA1 s390 2096-ga2 IBM System z9 BC GA2 s390 2096 (alias for 2096-ga2) s390 z9-bc (alias for 2096-ga2) s390 2097-ga1 IBM System z10 EC GA1 s390 2097-ga2 IBM System z10 EC GA2 s390 2097-ga3 IBM System z10 EC GA3 s390 2097 (alias for 2097-ga3) s390 z10 (alias for 2097-ga3) s390 z10-ec (alias for 2097-ga3) s390 2098-ga1 IBM System z10 BC GA1 s390 2098-ga2 IBM System z10 BC GA2 s390 2098 (alias for 2098-ga2) s390 z10-bc (alias for 2098-ga2) s390 2817-ga1 IBM zEnterprise 196 GA1 s390 2817-ga2 IBM zEnterprise 196 GA2 s390 2817 (alias for 2817-ga2) s390 z196 (alias for 2817-ga2) s390 2818-ga1 IBM zEnterprise 114 GA1 s390 2818 (alias for 2818-ga1) s390 z114 (alias for 2818-ga1) s390 2827-ga1 IBM zEnterprise EC12 GA1 s390 2827-ga2 IBM zEnterprise EC12 GA2 s390 2827 (alias for 2827-ga2) s390 zEC12 (alias for 2827-ga2) s390 host (alias for 2827-ga2) s390 2828-ga1 IBM zEnterprise BC12 GA1 s390 2828 (alias for 2828-ga1) s390 zBC12 (alias for 2828-ga1)
[...]
Signature · 1 line
Eduardo
Re: [Qemu-devel] [PATCH v6 01/17] Introduce stub routine cpu_desc_avail
Quoted 17 lines · On Tue, 5 May 2015 14:41:01 -0300 Eduardo Habkost <[email protected]> wrote:
Quoted 16 lines · Michael Mueller
Quoted 10 lines · On Tue, 5 May 2015 10:55:47 -0300 Eduardo Habkost <[email protected]> wrote:
Quoted 6 lines · Michael Mueller
This patch introduces the function
cpu_desc_avail()which returns by default true if not architecture specific implemented. Its intention is to indicate if the cpu model description is available for display bylist_cpus(). This change allows cpu model descriptions to become dynamically created by evaluating the runtime context instead of putting static cpu model information at display.Why are you deliberately breaking "-cpu ?" when
cpu_desc_avail()is false?In the s390x case
cpu_desc_avail()is per se false in this code section ofvl.c:
Quoted 8 lines
Quoted 5 lines
/* Init CPU def lists, based on config
* - Must be called after all theqemu_read_config_file()calls
* - Must be called beforelist_cpu()
* - Must be called beforemachine->init()
*/(Side note: I believe the above outdated, I will send a patch to update it.)
Will be interesting to see what the change is, master is currently showing this code.
Quoted 8 lines
Quoted 8 lines
cpudef_init(); if (cpu_model && cpu_desc_avail() && is_help_option(cpu_model)) { list_cpus(stdout, &fprintf, cpu_model); exit(0); }
Quoted 8 lines
Quoted 3 lines
That is because the output does not solely depend on static definitions but also on runtime context. Here the host machine type this instance of QEMU is running on, at least for the KVM case.
Is this a required feature? I would prefer to have the
main()code simple even if it means not having runnable information in "-cpu ?" by now (about possible ways to implement this withoutcpu_desc_avail(), see below).
I think it is more than a desired feature because one might end up with a failed CPU object instantiation although the help screen claims to CPU model to be valid.
Quoted 44 lines
Quoted 35 lines
Once the accelerator has been initialized AND the S390 cpu classes have been setup by means of the following code:
static void
kvm_setup_cpu_classes(KVMState *s){ S390MachineProps mach; if (!kvm_s390_get_machine_props(s, &mach)) { s390_setup_cpu_classes(ACCEL_CURRENT, &mach, s390_current_fac_list_mask()); s390_setup_cpu_aliases(); cpu_classes_initialized = true; } }
cpu_desc_avail()becomes true. In case the selceted mode was "?" thelist_cpu()is now done right before the cpu model is used as part of the cpu initialization (hw/s390-virtio.c):void
s390_init_cpus(const char *cpu_model, uint8_t *storage_keys){ int i; if (cpu_model == NULL) { cpu_model = "none"; } if (is_help_option(cpu_model)) { list_cpus(stdout, &fprintf, cpu_model); exit(0); }Quoted 7 lines
... for (i = 0; i < smp_cpus; i++) { ... cpu = cpu_s390x_init(cpu_model); ... } }
Quoted 2 lines
In other words, you just need to ensure that
s390_cpu_list()run afterkvm_setup_cpu_classes().
... which is part of the KVM/accel init process but it could of course make use of the ACCEL_TMP use case as query-cpu-definitions does.
Quoted 4 lines
Can't you simply call
s390_setup_cpu_classes(ACCEL_TEMP)insides390_init_cpus(), just likearch_query_cpu_definitions()? You could even share code between both functions.
That would not help with the current placement of list_cpus() in main() as it happens way to early. Not s390_init_cpus() is the issue, the context information has been processed already at that time. Currently I just kind of delay the list_cpus() until all required information is available.
Quoted 3 lines
(In the future, we should be able to implement "-cpu ?" by simply calling the query-cpu-definitions implementation.)
Right but the -machine <name>,accel=<accel> options have to be processed already.
Quoted 71 lines
Quoted 69 lines
Quoted 6 lines
What exactly could cause
cpu_desc_avail()to be false? If CPU model information is not yet available whencpu_list()is called, it is a bug.Here an example output that shows only runnable cpu models:
$ ./s390x-softmmu/qemu-system-s390x -machine s390,accel=kvm -cpu ? s390 none s390 2064-ga1 IBM zSeries 900 GA1 s390 2064-ga2 IBM zSeries 900 GA2 s390 2064-ga3 IBM zSeries 900 GA3 s390 2064 (alias for 2064-ga3) s390 z900 (alias for 2064-ga3) s390 2066-ga1 IBM zSeries 800 GA1 s390 2066 (alias for 2066-ga1) s390 z800 (alias for 2066-ga1) s390 2084-ga1 IBM zSeries 990 GA1 s390 2084-ga2 IBM zSeries 990 GA2 s390 2084-ga3 IBM zSeries 990 GA3 s390 2084-ga4 IBM zSeries 990 GA4 s390 2084-ga5 IBM zSeries 990 GA5 s390 2084 (alias for 2084-ga5) s390 z990 (alias for 2084-ga5) s390 2086-ga1 IBM zSeries 890 GA1 s390 2086-ga2 IBM zSeries 890 GA2 s390 2086-ga3 IBM zSeries 890 GA3 s390 2086 (alias for 2086-ga3) s390 z890 (alias for 2086-ga3) s390 2094-ga1 IBM System z9 EC GA1 s390 z9-109 (alias for 2094-ga1) s390 2094-ga2 IBM System z9 EC GA2 s390 2094-ga3 IBM System z9 EC GA3 s390 2094 (alias for 2094-ga3) s390 z9 (alias for 2094-ga3) s390 z9-ec (alias for 2094-ga3) s390 2096-ga1 IBM System z9 BC GA1 s390 2096-ga2 IBM System z9 BC GA2 s390 2096 (alias for 2096-ga2) s390 z9-bc (alias for 2096-ga2) s390 2097-ga1 IBM System z10 EC GA1 s390 2097-ga2 IBM System z10 EC GA2 s390 2097-ga3 IBM System z10 EC GA3 s390 2097 (alias for 2097-ga3) s390 z10 (alias for 2097-ga3) s390 z10-ec (alias for 2097-ga3) s390 2098-ga1 IBM System z10 BC GA1 s390 2098-ga2 IBM System z10 BC GA2 s390 2098 (alias for 2098-ga2) s390 z10-bc (alias for 2098-ga2) s390 2817-ga1 IBM zEnterprise 196 GA1 s390 2817-ga2 IBM zEnterprise 196 GA2 s390 2817 (alias for 2817-ga2) s390 z196 (alias for 2817-ga2) s390 2818-ga1 IBM zEnterprise 114 GA1 s390 2818 (alias for 2818-ga1) s390 z114 (alias for 2818-ga1) s390 2827-ga1 IBM zEnterprise EC12 GA1 s390 2827-ga2 IBM zEnterprise EC12 GA2 s390 2827 (alias for 2827-ga2) s390 zEC12 (alias for 2827-ga2) s390 host (alias for 2827-ga2) s390 2828-ga1 IBM zEnterprise BC12 GA1 s390 2828 (alias for 2828-ga1) s390 zBC12 (alias for 2828-ga1)[...]
Re: [Qemu-devel] [PATCH v6 01/17] Introduce stub routine cpu_desc_avail
Quoted 26 lines · Michael Mueller
Quoted 23 lines · On Tue, 5 May 2015 14:41:01 -0300 Eduardo Habkost <[email protected]> wrote:
Quoted 21 lines · Michael Mueller
Quoted 10 lines · On Tue, 5 May 2015 10:55:47 -0300 Eduardo Habkost <[email protected]> wrote:
Quoted 6 lines · Michael Mueller
This patch introduces the function
cpu_desc_avail()which returns by default true if not architecture specific implemented. Its intention is to indicate if the cpu model description is available for display bylist_cpus(). This change allows cpu model descriptions to become dynamically created by evaluating the runtime context instead of putting static cpu model information at display.Why are you deliberately breaking "-cpu ?" when
cpu_desc_avail()is false?In the s390x case
cpu_desc_avail()is per se false in this code section ofvl.c:/* Init CPU def lists, based on config
* - Must be called after all theqemu_read_config_file()calls
* - Must be called beforelist_cpu()
* - Must be called beforemachine->init()
*/
Quoted 4 lines
Quoted 2 lines
(Side note: I believe the above outdated, I will send a patch to update it.)
Will be interesting to see what the change is, master is currently showing this code.
We don't (and shouldn't) have the qemu_read_config_file() requirement, as CPU models are not loaded from config files anymore.
And we should be able to eliminate cpudef_init() completely, soon. I think the only user of cpudef_init() is x86.
Quoted 13 lines
Quoted 13 lines
Quoted 12 lines
cpudef_init(); if (cpu_model && cpu_desc_avail() && is_help_option(cpu_model)) { list_cpus(stdout, &fprintf, cpu_model); exit(0); }That is because the output does not solely depend on static definitions but also on runtime context. Here the host machine type this instance of QEMU is running on, at least for the KVM case.
Quoted 7 lines
Quoted 4 lines
Is this a required feature? I would prefer to have the
main()code simple even if it means not having runnable information in "-cpu ?" by now (about possible ways to implement this withoutcpu_desc_avail(), see below).I think it is more than a desired feature because one might end up with a failed CPU object instantiation although the help screen claims to CPU model to be valid.
I think you are more likely to confuse users by not showing information on "-cpu ?" when -machine is not present. I believe most people use "-cpu ?" with no other arguments, to see what the QEMU binary is capable of.
Anyway, whatever we decide to do, I believe we should start with something simple to get things working, and after that we can look for ways improve the help output with "runnable" info.
Quoted 45 lines
Quoted 45 lines
Quoted 43 lines
Once the accelerator has been initialized AND the S390 cpu classes have been setup by means of the following code:
static void
kvm_setup_cpu_classes(KVMState *s){ S390MachineProps mach; if (!kvm_s390_get_machine_props(s, &mach)) { s390_setup_cpu_classes(ACCEL_CURRENT, &mach, s390_current_fac_list_mask()); s390_setup_cpu_aliases(); cpu_classes_initialized = true; } }
cpu_desc_avail()becomes true. In case the selceted mode was "?" thelist_cpu()is now done right before the cpu model is used as part of the cpu initialization (hw/s390-virtio.c):void
s390_init_cpus(const char *cpu_model, uint8_t *storage_keys){ int i; if (cpu_model == NULL) { cpu_model = "none"; } if (is_help_option(cpu_model)) { list_cpus(stdout, &fprintf, cpu_model); exit(0); } ... for (i = 0; i < smp_cpus; i++) { ... cpu = cpu_s390x_init(cpu_model); ... } }
Quoted 5 lines
Quoted 2 lines
In other words, you just need to ensure that
s390_cpu_list()run afterkvm_setup_cpu_classes().... which is part of the KVM/accel init process but it could of course make use of the
ACCEL_TMPuse case as query-cpu-definitions does.
Exactly. I don't see a reason to not share code between query-cpu-definitions and "-cpu ?".
Quoted 10 lines
Quoted 5 lines
Can't you simply call
s390_setup_cpu_classes(ACCEL_TEMP)insides390_init_cpus(), just likearch_query_cpu_definitions()? You could even share code between both functions.That would not help with the current placement of
list_cpus()inmain()as it happens way to early. Nots390_init_cpus()is the issue, the context information has been processed already at that time. Currently I just kind of delay thelist_cpus()until all required information is available.
I understand you are just delaying it. But it is requiring a hack inside generic main() code that could be avoided. About the actual reasons to delay it, see below.
Quoted 6 lines
Quoted 4 lines
(In the future, we should be able to implement "-cpu ?" by simply calling the query-cpu-definitions implementation.)
Right but the -machine <name>,accel=<accel> options have to be processed already.
About query-cpu-definitions: its code shouldn't depend on -machine options to work. Maybe it can use current_machine to get the default accel and machine argument, but it should always output the same data for a machine+accel combination even if you use "-machine none".
About "-cpu ?": do we really want it to depend on -machine processing? Today, help output shows what the QEMU binary is capable of, not just what the host system and -machine option are capable of.
If we decide to change that assumption, let's do it in a generic way and not as a arch-specific hack. The options I see are:
1) Continue with the current policy where "-cpu ?" does not depend on -machine arguments, and show all CPU models on "-cpu ?".
2) Deciding that, yes, it is OK to make "-cpu ?" depend on -machine arguments, and move the list_cpus() call after machine initialization inside generic main() code for all arches.
2.1) We could delay the list_cpus() call inside main() on all cases. 2.2) We could delay the list_cpus() call inside main() only if
an explicit -machine option is present.
I prefer (1) and my second choice would be (2.2), but the main point is that none of the options above require making s390 special and introducing cpu_desc_avail().
Signature · 1 line
Eduardo
Re: [Qemu-devel] [PATCH v6 01/17] Introduce stub routine cpu_desc_avail
Quoted 30 lines · On Wed, 6 May 2015 08:23:32 -0300 Eduardo Habkost <[email protected]> wrote:
Quoted 29 lines · Michael Mueller
Quoted 25 lines · On Tue, 5 May 2015 14:41:01 -0300 Eduardo Habkost <[email protected]> wrote:
Quoted 14 lines · Michael Mueller
Quoted 10 lines · On Tue, 5 May 2015 10:55:47 -0300 Eduardo Habkost <[email protected]> wrote:
Quoted 6 lines · Michael Mueller
This patch introduces the function
cpu_desc_avail()which returns by default true if not architecture specific implemented. Its intention is to indicate if the cpu model description is available for display bylist_cpus(). This change allows cpu model descriptions to become dynamically created by evaluating the runtime context instead of putting static cpu model information at display.Why are you deliberately breaking "-cpu ?" when
cpu_desc_avail()is false?Quoted 7 lines
In the s390x case
cpu_desc_avail()is per se false in this code section ofvl.c:/* Init CPU def lists, based on config
* - Must be called after all theqemu_read_config_file()calls
* - Must be called beforelist_cpu()
* - Must be called beforemachine->init()
*/(Side note: I believe the above outdated, I will send a patch to update it.)
Quoted 7 lines
Quoted 1 line
Will be interesting to see what the change is, master is currently showing this code.
We don't (and shouldn't) have the
qemu_read_config_file()requirement, as CPU models are not loaded from config files anymore.And we should be able to eliminate
cpudef_init()completely, soon. I think the only user ofcpudef_init()is x86.
right.
Quoted 19 lines
Quoted 19 lines
Quoted 18 lines
Quoted 10 lines
cpudef_init(); if (cpu_model && cpu_desc_avail() && is_help_option(cpu_model)) { list_cpus(stdout, &fprintf, cpu_model); exit(0); }Quoted 3 lines
That is because the output does not solely depend on static definitions but also on runtime context. Here the host machine type this instance of QEMU is running on, at least for the KVM case.
Is this a required feature? I would prefer to have the
main()code simple even if it means not having runnable information in "-cpu ?" by now (about possible ways to implement this withoutcpu_desc_avail(), see below).
Quoted 7 lines
Quoted 2 lines
I think it is more than a desired feature because one might end up with a failed CPU object instantiation although the help screen claims to CPU model to be valid.
I think you are more likely to confuse users by not showing information on "-cpu ?" when -machine is not present. I believe most people use "-cpu ?" with no other arguments, to see what the QEMU binary is capable of.
I don't disagree with that, both cases are to some extend confusing... But the accelerator makes a big difference and a tended user should really be aware of that.
Also that TCG is the default:
$ ./s390x-softmmu/qemu-system-s390x -cpu ? s390 host
And I don't see a way to make a user belief that all the defined CPU models are available to a TCG user in the S390 case where most of the CPU facilities are not implemented.
Quoted 4 lines
Anyway, whatever we decide to do, I believe we should start with something simple to get things working, and after that we can look for ways improve the help output with "runnable" info.
I don't see how to solve this without cpu_desc_avail() or some other comparable mechanism, the aliases e.g. are also dynamic...
Quoted 75 lines
Quoted 46 lines
Quoted 46 lines
Quoted 44 lines
Once the accelerator has been initialized AND the S390 cpu classes have been setup by means of the following code:
static void
kvm_setup_cpu_classes(KVMState *s){ S390MachineProps mach; if (!kvm_s390_get_machine_props(s, &mach)) { s390_setup_cpu_classes(ACCEL_CURRENT, &mach, s390_current_fac_list_mask()); s390_setup_cpu_aliases(); cpu_classes_initialized = true; } }
cpu_desc_avail()becomes true. In case the selceted mode was "?" thelist_cpu()is now done right before the cpu model is used as part of the cpu initialization (hw/s390-virtio.c):void
s390_init_cpus(const char *cpu_model, uint8_t *storage_keys){ int i; if (cpu_model == NULL) { cpu_model = "none"; } if (is_help_option(cpu_model)) { list_cpus(stdout, &fprintf, cpu_model); exit(0); } ... for (i = 0; i < smp_cpus; i++) { ... cpu = cpu_s390x_init(cpu_model); ... } }Quoted 5 lines
Quoted 2 lines
In other words, you just need to ensure that
s390_cpu_list()run afterkvm_setup_cpu_classes().... which is part of the KVM/accel init process but it could of course make use of the
ACCEL_TMPuse case as query-cpu-definitions does.Exactly. I don't see a reason to not share code between query-cpu-definitions and "-cpu ?".
Quoted 10 lines
Quoted 5 lines
Can't you simply call
s390_setup_cpu_classes(ACCEL_TEMP)insides390_init_cpus(), just likearch_query_cpu_definitions()? You could even share code between both functions.That would not help with the current placement of
list_cpus()inmain()as it happens way to early. Nots390_init_cpus()is the issue, the context information has been processed already at that time. Currently I just kind of delay thelist_cpus()until all required information is available.I understand you are just delaying it. But it is requiring a hack inside generic
main()code that could be avoided. About the actual reasons to delay it, see below.Quoted 5 lines
Quoted 4 lines
(In the future, we should be able to implement "-cpu ?" by simply calling the query-cpu-definitions implementation.)
Quoted 6 lines
Quoted 1 line
Right but the -machine <name>,accel=<accel> options have to be processed already.
About query-cpu-definitions: its code shouldn't depend on -machine options to work. Maybe it can use
current_machineto get the default accel and machine argument, but it should always output the same data for a machine+accel combination even if you use "-machine none".
No it should not but it takes the same parameters.
Quoted 4 lines
About "-cpu ?": do we really want it to depend on -machine processing? Today, help output shows what the QEMU binary is capable of, not just what the host system and -machine option are capable of.
I think we have to take it into account because the available CPU models might deviate substantially as in the case for S390 for KVM and TCG.
Quoted 3 lines
If we decide to change that assumption, let's do it in a generic way and not as a arch-specific hack. The options I see are:
welcome
Quoted 10 lines
1) Continue with the current policy where "-cpu ?" does not depend on -machine arguments, and show all CPU models on "-cpu ?".
2) Deciding that, yes, it is OK to make "-cpu ?" depend on -machine arguments, and move thelist_cpus()call after machine initialization inside genericmain()code for all arches.
2.1) We could delay thelist_cpus()call insidemain()on all cases. 2.2) We could delay thelist_cpus()call insidemain()only if
an explicit -machine option is present.
Quoted 3 lines
I prefer (1) and my second choice would be (2.2), but the main point is that none of the options above require making s390 special and introducing
cpu_desc_avail().
My take here is 2.1 because omitting option -machine is a decision to some defaults for machine type and accelerator type already.
Quoted 1 line
Re: [Qemu-devel] [PATCH v6 01/17] Introduce stub routine cpu_desc_avail
Quoted 2 lines · Michael Mueller
On Wed, 6 May 2015 08:23:32 -0300
Eduardo Habkost <[email protected]> wrote:
[...]
Quoted 28 lines
Quoted 16 lines
Quoted 16 lines
Quoted 15 lines
Quoted 10 lines
cpudef_init(); if (cpu_model && cpu_desc_avail() && is_help_option(cpu_model)) { list_cpus(stdout, &fprintf, cpu_model); exit(0); }That is because the output does not solely depend on static definitions but also on runtime context. Here the host machine type this instance of QEMU is running on, at least for the KVM case.
Is this a required feature? I would prefer to have the
main()code simple even if it means not having runnable information in "-cpu ?" by now (about possible ways to implement this withoutcpu_desc_avail(), see below).Quoted 7 lines
Quoted 2 lines
I think it is more than a desired feature because one might end up with a failed CPU object instantiation although the help screen claims to CPU model to be valid.
I think you are more likely to confuse users by not showing information on "-cpu ?" when -machine is not present. I believe most people use "-cpu ?" with no other arguments, to see what the QEMU binary is capable of.
I don't disagree with that, both cases are to some extend confusing... But the accelerator makes a big difference and a tended user should really be aware of that.
Quoted 7 lines
Also that TCG is the default:
$ ./s390x-softmmu/qemu-system-s390x -cpu ? s390 hostAnd I don't see a way to make a user belief that all the defined CPU models are available to a TCG user in the S390 case where most of the CPU facilities are not implemented.
Well, we could simply add a "KVM required" note (maybe just an asterisk beside the CPU model description). But maybe we have a reasonable alternative below:
Quoted 8 lines
Quoted 5 lines
Anyway, whatever we decide to do, I believe we should start with something simple to get things working, and after that we can look for ways improve the help output with "runnable" info.
I don't see how to solve this without
cpu_desc_avail()or some other comparable mechanism, the aliases e.g. are also dynamic...
What bothers me in cpu_desc_avail() is that it depends on global state that is non-trivial (one needs to follow the whole KVM initialization path to find out if cpu_desc_avail() will be true or false).
We could instead simply skip the cpu_list() call unconditionally on s390. e.g.:
target-s390x/cpu.h:
/* Delete the existing cpu_list macro */
cpus.c:
int list_cpus(FILE *f, fprintf_function cpu_fprintf, const char *optarg)
{
#if defined(cpu_list)
cpu_list(f, cpu_fprintf);
return 1;
#else
return 0;
#endif
}vl.c:
if (cpu_model && is_help_option(cpu_model)) {
/* zero list_cpus() return value means "-cpu ?" will be
* handled later by machine initialization code */
if (list_cpus(stdout, &fprintf, cpu_model)) {
exit(0);
}
}[...]
Quoted 7 lines
Quoted 4 lines
About "-cpu ?": do we really want it to depend on -machine processing? Today, help output shows what the QEMU binary is capable of, not just what the host system and -machine option are capable of.
I think we have to take it into account because the available CPU models might deviate substantially as in the case for S390 for KVM and TCG.
That's true, on s390 the set of available CPU models is very different on both cases. It breaks assumptions in the existing "-cpu ?" handling code in main().
Quoted 17 lines
Quoted 4 lines
If we decide to change that assumption, let's do it in a generic way and not as a arch-specific hack. The options I see are:
welcome
Quoted 10 lines
1) Continue with the current policy where "-cpu ?" does not depend on -machine arguments, and show all CPU models on "-cpu ?".
2) Deciding that, yes, it is OK to make "-cpu ?" depend on -machine arguments, and move thelist_cpus()call after machine initialization inside genericmain()code for all arches.
2.1) We could delay thelist_cpus()call insidemain()on all cases. 2.2) We could delay thelist_cpus()call insidemain()only if
an explicit -machine option is present.
Quoted 6 lines
Quoted 3 lines
I prefer (1) and my second choice would be (2.2), but the main point is that none of the options above require making s390 special and introducing
cpu_desc_avail().My take here is 2.1 because omitting option -machine is a decision to some defaults for machine type and accelerator type already.
The problem with 2.1 is that some machine init functions require that additional command-line parameters are set and will abort (e.g. mips machines). So we can't do that unconditionally for all architectures.
The proposal above is like 2.1, but conditional: it will delay "-cpu ?" handling only on architectures that don't define cpu_list().
Signature · 1 line
Eduardo
Re: [Qemu-devel] [PATCH v6 01/17] Introduce stub routine cpu_desc_avail
Quoted 72 lines · On Wed, 6 May 2015 14:06:16 -0300 Eduardo Habkost <[email protected]> wrote:
Quoted 2 lines · Michael Mueller
On Wed, 6 May 2015 08:23:32 -0300
Eduardo Habkost <[email protected]> wrote:[...]
Quoted 28 lines
Quoted 16 lines
Quoted 16 lines
Quoted 15 lines
Quoted 10 lines
cpudef_init(); if (cpu_model && cpu_desc_avail() && is_help_option(cpu_model)) { list_cpus(stdout, &fprintf, cpu_model); exit(0); }That is because the output does not solely depend on static definitions but also on runtime context. Here the host machine type this instance of QEMU is running on, at least for the KVM case.
Is this a required feature? I would prefer to have the
main()code simple even if it means not having runnable information in "-cpu ?" by now (about possible ways to implement this withoutcpu_desc_avail(), see below).Quoted 7 lines
Quoted 2 lines
I think it is more than a desired feature because one might end up with a failed CPU object instantiation although the help screen claims to CPU model to be valid.
I think you are more likely to confuse users by not showing information on "-cpu ?" when -machine is not present. I believe most people use "-cpu ?" with no other arguments, to see what the QEMU binary is capable of.
I don't disagree with that, both cases are to some extend confusing... But the accelerator makes a big difference and a tended user should really be aware of that.
Quoted 7 lines
Also that TCG is the default:
$ ./s390x-softmmu/qemu-system-s390x -cpu ? s390 hostAnd I don't see a way to make a user belief that all the defined CPU models are available to a TCG user in the S390 case where most of the CPU facilities are not implemented.
Well, we could simply add a "KVM required" note (maybe just an asterisk beside the CPU model description). But maybe we have a reasonable alternative below:
Quoted 8 lines
Quoted 5 lines
Anyway, whatever we decide to do, I believe we should start with something simple to get things working, and after that we can look for ways improve the help output with "runnable" info.
I don't see how to solve this without
cpu_desc_avail()or some other comparable mechanism, the aliases e.g. are also dynamic...What bothers me in
cpu_desc_avail()is that it depends on global state that is non-trivial (one needs to follow the whole KVM initialization path to find out ifcpu_desc_avail()will be true or false).We could instead simply skip the
cpu_list()call unconditionally on s390. e.g.:
target-s390x/cpu.h:/* Delete the existing cpu_list macro */
cpus.c:int list_cpus(FILE *f, fprintf_function cpu_fprintf, const char *optarg) { #if defined(cpu_list) cpu_list(f, cpu_fprintf); return 1; #else return 0; #endif }
Quoted 8 lines
vl.c:if (cpu_model && is_help_option(cpu_model)) { /* zero list_cpus() return value means "-cpu ?" will be * handled later by machine initialization code */ if (list_cpus(stdout, &fprintf, cpu_model)) { exit(0); } }
That approach is will do the job as well. I will prepare a patch for the next version.
Thanks!
Quoted 37 lines
[...]
Quoted 7 lines
Quoted 4 lines
About "-cpu ?": do we really want it to depend on -machine processing? Today, help output shows what the QEMU binary is capable of, not just what the host system and -machine option are capable of.
I think we have to take it into account because the available CPU models might deviate substantially as in the case for S390 for KVM and TCG.
That's true, on s390 the set of available CPU models is very different on both cases. It breaks assumptions in the existing "-cpu ?" handling code in
main().Quoted 17 lines
Quoted 4 lines
If we decide to change that assumption, let's do it in a generic way and not as a arch-specific hack. The options I see are:
welcome
Quoted 10 lines
1) Continue with the current policy where "-cpu ?" does not depend on -machine arguments, and show all CPU models on "-cpu ?".
2) Deciding that, yes, it is OK to make "-cpu ?" depend on -machine arguments, and move thelist_cpus()call after machine initialization inside genericmain()code for all arches.
2.1) We could delay thelist_cpus()call insidemain()on all cases. 2.2) We could delay thelist_cpus()call insidemain()only if
an explicit -machine option is present.Quoted 6 lines
Quoted 3 lines
I prefer (1) and my second choice would be (2.2), but the main point is that none of the options above require making s390 special and introducing
cpu_desc_avail().My take here is 2.1 because omitting option -machine is a decision to some defaults for machine type and accelerator type already.
Quoted 6 lines
The problem with 2.1 is that some machine init functions require that additional command-line parameters are set and will abort (e.g. mips machines). So we can't do that unconditionally for all architectures.
The proposal above is like 2.1, but conditional: it will delay "-cpu ?" handling only on architectures that don't define
cpu_list().
perfect.
Michael
Quoted 1 line
PATCH v6 2/17 Add accelerator id and model name to CPUState
In reply to Michael MuellerThe patch defines ids per accelerator and adds the accel_id and the model_name to the CPUState. The accel_id is initialized by common code, the model name needs to be initialized by target specific code.
--- include/qom/cpu.h | 5 +++++ qapi-schema.json | 9 +++++++++ qom/cpu.c | 14 ++++++++++++++ 3 files changed, 28 insertions(+)
include/qom/cpu.h +5 -0
@@ -236,6 +236,8 @@ struct kvm_run;* @mem_io_pc: Host Program Counter at which the memory was accessed. * @mem_io_vaddr: Target virtual address at which the memory was accessed. * @kvm_fd: vCPU file descriptor for KVM. +* @accel_id: accelerator id of this CPU. +* @model_name: model name of this CPU * * State of one CPU core or thread. */
@@ -313,6 +315,9 @@ struct CPUState {(absolute value) offset as small as possible. This reduces code size, especially for hosts without large memory offsets. */ volatile sig_atomic_t tcg_exit_req; + +AccelId accel_id; +char *model_name; };QTAILQ_HEAD (CPUTailQ, CPUState);
qapi-schema.json +9 -0
@@ -2515,6 +2515,15 @@ ## { 'command': 'query-machines', 'returns': ['MachineInfo'] } +# @AccelId +# +# Defines accelerator ids +# +# Since: 2.4 +## +{ 'enum': 'AccelId', + 'data': ['qtest', 'tcg', 'kvm', 'xen'] } + ## # @CpuDefinitionInfo: #
qom/cpu.c +14 -0
@@ -67,6 +67,20 @@ CPUState *cpu_generic_init(const char *typename, const char *cpu_model) goto out; } +if (tcg_enabled ()) { + cpu->accel_id =ACCEL_ID_TCG ; + }else if (kvm_enabled ()) { + cpu->accel_id =ACCEL_ID_KVM ; + } +#ifdef CONFIG_XEN + else if (xen_enabled()) { + cpu->accel_id =ACCEL_ID_XEN ; + } +#endif + else { + cpu->accel_id =ACCEL_ID_QTEST ; + } +object_property_set_bool (OBJECT (cpu), true,"realized" , &err); out:
Signature · 1 line
1.8.3.1
Re: [Qemu-devel] [PATCH v6 02/17] Add accelerator id and model name to CPUState
Quoted 27 lines · Michael Mueller
The patch defines ids per accelerator and adds the
accel_idand themodel_nameto the CPUState. Theaccel_idis initialized by common code, the model name needs to be initialized by target specific code.Signed-off-by Michael Mueller <[email protected]>--- include/qom/cpu.h | 5 +++++ qapi-schema.json | 9 +++++++++ qom/cpu.c | 14 ++++++++++++++ 3 files changed, 28 insertions(+)include/qom/cpu.h +2
-0@@ -236,6 +236,8 @@ struct kvm_run;* @mem_io_pc: Host Program Counter at which the memory was accessed. * @mem_io_vaddr: Target virtual address at which the memory was accessed. * @kvm_fd: vCPU file descriptor for KVM. +* @accel_id: accelerator id of this CPU. +* @model_name: model name of this CPU * * State of one CPU core or thread. */
include/qom/cpu.h struct CPUState { · line 319
Quoted 5 lines
include/qom/cpu.h +2
-0@@ -313,6 +315,9 @@ struct CPUState {(absolute value) offset as small as possible. This reduces code size, especially for hosts without large memory offsets. */ volatile sig_atomic_t tcg_exit_req; + +AccelId accel_id;
This can be a AccelState pointer, set on initialization, because we have another user case for having a AccelState pointer: query-cpu-definition implementations may create temporary CPU objects with a different accel object to be able to probe for accel-specific data.
(The pointer may become a link QOM property later.)
Quoted 11 lines
include/qom/cpu.h +1
-0+char *model_name; };QTAILQ_HEAD (CPUTailQ, CPUState);qapi-schema.json +0
-0@@ -2515,6 +2515,15 @@ ## { 'command': 'query-machines', 'returns': ['MachineInfo'] }
qapi-schema.json line 2526
Quoted 10 lines
qapi-schema.json +9
-0+# @AccelId +# +# Defines accelerator ids +# +# Since: 2.4 +## +{ 'enum': 'AccelId', + 'data': ['qtest', 'tcg', 'kvm', 'xen'] } +
Not sure if it is better to have an enum or simply a string here.
Quoted 14 lines
qapi-schema.json +0
-0## # @CpuDefinitionInfo: #qom/cpu.c +3
-0@@ -67,6 +67,20 @@ CPUState *cpu_generic_init(const char *typename, const char *cpu_model) goto out; } +if (tcg_enabled ()) { + cpu->accel_id =ACCEL_ID_TCG ; + }else if (kvm_enabled ()) {
qom/cpu.c CPUState *cpu_generic_init(const char *typename, const char *cpu_model) · line 82
Quoted 10 lines
qom/cpu.c +10
-0+ cpu->accel_id =ACCEL_ID_KVM ; + } +#ifdef CONFIG_XEN + else if (xen_enabled()) { + cpu->accel_id =ACCEL_ID_XEN ; + } +#endif + else { + cpu->accel_id =ACCEL_ID_QTEST ; + }
You can simply use ACCEL_GET_CLASS(current_machine->accelerator)->name here. If we really want an enum, we can add an AccelId field to AccelClass, and initialize it properly on the accel class_init functions.
CONFIG_USER may require some special code when returning the accelerator ID as "tcg" because IIRC it doesn't use the QOM accel classes (yet).
Quoted 7 lines
qom/cpu.c +1
-0+object_property_set_bool (OBJECT (cpu), true,"realized" , &err); out:Signature · 1 line
1.8.3.1
Signature · 1 line
Eduardo
Re: [Qemu-devel] [PATCH v6 02/17] Add accelerator id and model name to CPUState
Quoted 16 lines · Eduardo Habkost
Quoted 15 lines · Michael Mueller
The patch defines ids per accelerator and adds the
accel_idand themodel_nameto the CPUState. Theaccel_idis initialized by common code, the model name needs to be initialized by target specific code.Signed-off-by Michael Mueller <[email protected]>--- include/qom/cpu.h | 5 +++++ qapi-schema.json | 9 +++++++++ qom/cpu.c | 14 ++++++++++++++ 3 files changed, 28 insertions(+)
Quoted 5 lines
qapi-schema.json line 2522
Quoted 5 lines
qapi-schema.json +5
-0+# @AccelId +# +# Defines accelerator ids +# +# Since: 2.4
Might be nice to document the possible values, but not a show-stopper if you don't.
Quoted 6 lines
qapi-schema.json line 2526
Quoted 4 lines
qapi-schema.json +4
-0+## +{ 'enum': 'AccelId', + 'data': ['qtest', 'tcg', 'kvm', 'xen'] } +Not sure if it is better to have an enum or simply a string here.
enum is almost always better when there is a finite set of possible strings - it's better documented, and when introspection is in place, will make it easier to determine when the set has grown.
Signature · 2 lines
Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org
Re: [Qemu-devel] [PATCH v6 02/17] Add accelerator id and model name to CPUState
Quoted 10 lines · Eric Blake
Quoted 5 lines · Eduardo Habkost
qapi-schema.json line 2526
Quoted 3 lines
qapi-schema.json +3
-0+{ 'enum': 'AccelId', + 'data': ['qtest', 'tcg', 'kvm', 'xen'] } +Not sure if it is better to have an enum or simply a string here.
enum is almost always better when there is a finite set of possible strings - it's better documented, and when introspection is in place, will make it easier to determine when the set has grown.
True, and there are other cases where we could use an enum internally in QEMU (e.g. arrays for accelerator-specific data inside CPU classes).
Signature · 1 line
Eduardo
Re: [Qemu-devel] [PATCH v6 02/17] Add accelerator id and model name to CPUState
Quoted 8 lines · On Tue, 5 May 2015 11:46:04 -0300 Eduardo Habkost <[email protected]> wrote:
Quoted 7 lines · Eric Blake
Quoted 5 lines · Eduardo Habkost
qapi-schema.json line 2526
Quoted 3 lines
qapi-schema.json +3
-0+{ 'enum': 'AccelId', + 'data': ['qtest', 'tcg', 'kvm', 'xen'] } +Not sure if it is better to have an enum or simply a string here.
Quoted 6 lines
Quoted 3 lines
enum is almost always better when there is a finite set of possible strings - it's better documented, and when introspection is in place, will make it easier to determine when the set has grown.
True, and there are other cases where we could use an enum internally in QEMU (e.g. arrays for accelerator-specific data inside CPU classes).
Actually the accelerator name currently represented as string (ac->name = "KVM";) can be initialized from the respective lookup value (AccelId_lookup[]) instead.
Quoted 1 line
Re: [Qemu-devel] [PATCH v6 02/17] Add accelerator id and model name to CPUState
In reply to Eduardo HabkostQuoted 87 lines · On Tue, 5 May 2015 10:26:02 -0300 Eduardo Habkost <[email protected]> wrote:
Quoted 27 lines · Michael Mueller
The patch defines ids per accelerator and adds the
accel_idand themodel_nameto the CPUState. Theaccel_idis initialized by common code, the model name needs to be initialized by target specific code.Signed-off-by Michael Mueller <[email protected]>--- include/qom/cpu.h | 5 +++++ qapi-schema.json | 9 +++++++++ qom/cpu.c | 14 ++++++++++++++ 3 files changed, 28 insertions(+)include/qom/cpu.h +2
-0@@ -236,6 +236,8 @@ struct kvm_run;* @mem_io_pc: Host Program Counter at which the memory was accessed. * @mem_io_vaddr: Target virtual address at which the memory was accessed. * @kvm_fd: vCPU file descriptor for KVM. +* @accel_id: accelerator id of this CPU. +* @model_name: model name of this CPU * * State of one CPU core or thread. */ include/qom/cpu.h struct CPUState { · line 319
Quoted 5 lines
include/qom/cpu.h +2
-0@@ -313,6 +315,9 @@ struct CPUState {(absolute value) offset as small as possible. This reduces code size, especially for hosts without large memory offsets. */ volatile sig_atomic_t tcg_exit_req; + +AccelId accel_id;This can be a AccelState pointer, set on initialization, because we have another user case for having a AccelState pointer: query-cpu-definition implementations may create temporary CPU objects with a different accel object to be able to probe for accel-specific data.
(The pointer may become a link QOM property later.)
Quoted 11 lines
include/qom/cpu.h +1
-0+char *model_name; };QTAILQ_HEAD (CPUTailQ, CPUState);qapi-schema.json +0
-0@@ -2515,6 +2515,15 @@ ## { 'command': 'query-machines', 'returns': ['MachineInfo'] }qapi-schema.json line 2526
Quoted 10 lines
qapi-schema.json +9
-0+# @AccelId +# +# Defines accelerator ids +# +# Since: 2.4 +## +{ 'enum': 'AccelId', + 'data': ['qtest', 'tcg', 'kvm', 'xen'] } +Not sure if it is better to have an enum or simply a string here.
Quoted 21 lines
qapi-schema.json +0
-0## # @CpuDefinitionInfo: #qom/cpu.c +10
-0@@ -67,6 +67,20 @@ CPUState *cpu_generic_init(const char *typename, const char *cpu_model) goto out; } +if (tcg_enabled ()) { + cpu->accel_id =ACCEL_ID_TCG ; + }else if (kvm_enabled ()) { + cpu->accel_id =ACCEL_ID_KVM ; + } +#ifdef CONFIG_XEN + else if (xen_enabled()) { + cpu->accel_id =ACCEL_ID_XEN ; + } +#endif
Quoted 8 lines
qom/cpu.c CPUState *cpu_generic_init(const char *typename, const char *cpu_model) · line 82
Quoted 3 lines
qom/cpu.c +3
-0+else { + cpu->accel_id =ACCEL_ID_QTEST ; + }You can simply use ACCEL_GET_CLASS(current_machine->accelerator)->name here. If we really want an enum, we can add an AccelId field to AccelClass, and initialize it properly on the accel
class_initfunctions.
The AccelClass (ac = ACCEL_GET_CLASS(current_machine->accelerator) would be ok though. That will allow to access the ac->accel_id (not yet there) at places where required.
I'm just not sure how to access current_machine here.
Quoted 12 lines
CONFIG_USERmay require some special code when returning the accelerator ID as "tcg" because IIRC it doesn't use the QOM accel classes (yet).Quoted 7 lines
qom/cpu.c +1
-0+object_property_set_bool (OBJECT (cpu), true,"realized" , &err); out:Signature · 1 line
1.8.3.1
Re: [Qemu-devel] [PATCH v6 02/17] Add accelerator id and model name to CPUState
Quoted 99 lines · Michael Mueller
Quoted 87 lines · On Tue, 5 May 2015 10:26:02 -0300 Eduardo Habkost <[email protected]> wrote:
Quoted 27 lines · Michael Mueller
The patch defines ids per accelerator and adds the
accel_idand themodel_nameto the CPUState. Theaccel_idis initialized by common code, the model name needs to be initialized by target specific code.Signed-off-by Michael Mueller <[email protected]>--- include/qom/cpu.h | 5 +++++ qapi-schema.json | 9 +++++++++ qom/cpu.c | 14 ++++++++++++++ 3 files changed, 28 insertions(+)include/qom/cpu.h +2
-0@@ -236,6 +236,8 @@ struct kvm_run;* @mem_io_pc: Host Program Counter at which the memory was accessed. * @mem_io_vaddr: Target virtual address at which the memory was accessed. * @kvm_fd: vCPU file descriptor for KVM. +* @accel_id: accelerator id of this CPU. +* @model_name: model name of this CPU * * State of one CPU core or thread. */ include/qom/cpu.h struct CPUState { · line 319
Quoted 5 lines
include/qom/cpu.h +2
-0@@ -313,6 +315,9 @@ struct CPUState {(absolute value) offset as small as possible. This reduces code size, especially for hosts without large memory offsets. */ volatile sig_atomic_t tcg_exit_req; + +AccelId accel_id;This can be a AccelState pointer, set on initialization, because we have another user case for having a AccelState pointer: query-cpu-definition implementations may create temporary CPU objects with a different accel object to be able to probe for accel-specific data.
(The pointer may become a link QOM property later.)
Quoted 11 lines
include/qom/cpu.h +1
-0+char *model_name; };QTAILQ_HEAD (CPUTailQ, CPUState);qapi-schema.json +0
-0@@ -2515,6 +2515,15 @@ ## { 'command': 'query-machines', 'returns': ['MachineInfo'] }qapi-schema.json line 2526
Quoted 10 lines
qapi-schema.json +9
-0+# @AccelId +# +# Defines accelerator ids +# +# Since: 2.4 +## +{ 'enum': 'AccelId', + 'data': ['qtest', 'tcg', 'kvm', 'xen'] } +Not sure if it is better to have an enum or simply a string here.
Quoted 21 lines
qapi-schema.json +0
-0## # @CpuDefinitionInfo: #qom/cpu.c +10
-0@@ -67,6 +67,20 @@ CPUState *cpu_generic_init(const char *typename, const char *cpu_model) goto out; } +if (tcg_enabled ()) { + cpu->accel_id =ACCEL_ID_TCG ; + }else if (kvm_enabled ()) { + cpu->accel_id =ACCEL_ID_KVM ; + } +#ifdef CONFIG_XEN + else if (xen_enabled()) { + cpu->accel_id =ACCEL_ID_XEN ; + } +#endif Quoted 8 lines
qom/cpu.c CPUState *cpu_generic_init(const char *typename, const char *cpu_model) · line 82
Quoted 3 lines
qom/cpu.c +3
-0+else { + cpu->accel_id =ACCEL_ID_QTEST ; + }You can simply use ACCEL_GET_CLASS(current_machine->accelerator)->name here. If we really want an enum, we can add an AccelId field to AccelClass, and initialize it properly on the accel
class_initfunctions.
Quoted 4 lines
The AccelClass (ac =
ACCEL_GET_CLASS(current_machine->accelerator)would be ok though. That will allow to access theac->accel_id(not yet there) at places where required.I'm just not sure how to access
current_machinehere.
It is a global variable declared in hw/boards.h. But it makes sense only if !CONFIG_USER.
But I am starting to wonder if we shouldn't simply expose accel info as a /mmachine property, instead of per-CPU information. It may become per-CPU in the future, but right now we really don't support having multiple accelerators so why are we trying to pretend we do?
Quoted 14 lines
Quoted 13 lines
CONFIG_USERmay require some special code when returning the accelerator ID as "tcg" because IIRC it doesn't use the QOM accel classes (yet).Quoted 7 lines
qom/cpu.c +1
-0+object_property_set_bool (OBJECT (cpu), true,"realized" , &err); out:Signature · 1 line
1.8.3.1
Signature · 1 line
Eduardo
Re: [Qemu-devel] [PATCH v6 02/17] Add accelerator id and model name to CPUState
Quoted 105 lines · On Wed, 6 May 2015 08:41:50 -0300 Eduardo Habkost <[email protected]> wrote:
Quoted 99 lines · Michael Mueller
Quoted 87 lines · On Tue, 5 May 2015 10:26:02 -0300 Eduardo Habkost <[email protected]> wrote:
Quoted 27 lines · Michael Mueller
The patch defines ids per accelerator and adds the
accel_idand themodel_nameto the CPUState. Theaccel_idis initialized by common code, the model name needs to be initialized by target specific code.Signed-off-by Michael Mueller <[email protected]>--- include/qom/cpu.h | 5 +++++ qapi-schema.json | 9 +++++++++ qom/cpu.c | 14 ++++++++++++++ 3 files changed, 28 insertions(+)include/qom/cpu.h +2
-0@@ -236,6 +236,8 @@ struct kvm_run;* @mem_io_pc: Host Program Counter at which the memory was accessed. * @mem_io_vaddr: Target virtual address at which the memory was accessed. * @kvm_fd: vCPU file descriptor for KVM. +* @accel_id: accelerator id of this CPU. +* @model_name: model name of this CPU * * State of one CPU core or thread. */ include/qom/cpu.h struct CPUState { · line 319
Quoted 5 lines
include/qom/cpu.h +2
-0@@ -313,6 +315,9 @@ struct CPUState {(absolute value) offset as small as possible. This reduces code size, especially for hosts without large memory offsets. */ volatile sig_atomic_t tcg_exit_req; + +AccelId accel_id;This can be a AccelState pointer, set on initialization, because we have another user case for having a AccelState pointer: query-cpu-definition implementations may create temporary CPU objects with a different accel object to be able to probe for accel-specific data.
(The pointer may become a link QOM property later.)
Quoted 11 lines
include/qom/cpu.h +1
-0+char *model_name; };QTAILQ_HEAD (CPUTailQ, CPUState);qapi-schema.json +0
-0@@ -2515,6 +2515,15 @@ ## { 'command': 'query-machines', 'returns': ['MachineInfo'] }qapi-schema.json line 2526
Quoted 10 lines
qapi-schema.json +9
-0+# @AccelId +# +# Defines accelerator ids +# +# Since: 2.4 +## +{ 'enum': 'AccelId', + 'data': ['qtest', 'tcg', 'kvm', 'xen'] } +Not sure if it is better to have an enum or simply a string here.
Quoted 21 lines
qapi-schema.json +0
-0## # @CpuDefinitionInfo: #qom/cpu.c +10
-0@@ -67,6 +67,20 @@ CPUState *cpu_generic_init(const char *typename, const char *cpu_model) goto out; } +if (tcg_enabled ()) { + cpu->accel_id =ACCEL_ID_TCG ; + }else if (kvm_enabled ()) { + cpu->accel_id =ACCEL_ID_KVM ; + } +#ifdef CONFIG_XEN + else if (xen_enabled()) { + cpu->accel_id =ACCEL_ID_XEN ; + } +#endif Quoted 8 lines
qom/cpu.c CPUState *cpu_generic_init(const char *typename, const char *cpu_model) · line 82
Quoted 3 lines
qom/cpu.c +3
-0+else { + cpu->accel_id =ACCEL_ID_QTEST ; + }You can simply use ACCEL_GET_CLASS(current_machine->accelerator)->name here. If we really want an enum, we can add an AccelId field to AccelClass, and initialize it properly on the accel
class_initfunctions.Quoted 4 lines
The AccelClass (ac =
ACCEL_GET_CLASS(current_machine->accelerator)would be ok though. That will allow to access theac->accel_id(not yet there) at places where required.I'm just not sure how to access
current_machinehere.
Quoted 8 lines
It is a global variable declared in
hw/boards.h. But it makes sense only if !CONFIG_USER.But I am starting to wonder if we shouldn't simply expose accel info as a /mmachine property, instead of per-CPU information. It may become per-CPU in the future, but right now we really don't support having multiple accelerators so why are we trying to pretend we do?
That brings me back into the direction I was before with the proposed query-cpu-model QMP call... but that's OK. In the end that holds true also for the cpu model name as well...
Quoted 15 lines
Quoted 14 lines
Quoted 13 lines
CONFIG_USERmay require some special code when returning the accelerator ID as "tcg" because IIRC it doesn't use the QOM accel classes (yet).Quoted 7 lines
qom/cpu.c +1
-0+object_property_set_bool (OBJECT (cpu), true,"realized" , &err); out:Signature · 1 line
1.8.3.1
Re: [Qemu-devel] [PATCH v6 02/17] Add accelerator id and model name to CPUState
Quoted 2 lines · Michael Mueller
On Wed, 6 May 2015 08:41:50 -0300
Eduardo Habkost <[email protected]> wrote:
[...]
Quoted 41 lines
Quoted 32 lines
Quoted 27 lines
Quoted 18 lines
Quoted 18 lines
qom/cpu.c +10
-0@@ -67,6 +67,20 @@ CPUState *cpu_generic_init(const char *typename, const char *cpu_model) goto out; } +if (tcg_enabled ()) { + cpu->accel_id =ACCEL_ID_TCG ; + }else if (kvm_enabled ()) { + cpu->accel_id =ACCEL_ID_KVM ; + } +#ifdef CONFIG_XEN + else if (xen_enabled()) { + cpu->accel_id =ACCEL_ID_XEN ; + } +#endif Quoted 8 lines
qom/cpu.c CPUState *cpu_generic_init(const char *typename, const char *cpu_model) · line 82
Quoted 3 lines
qom/cpu.c +3
-0+else { + cpu->accel_id =ACCEL_ID_QTEST ; + }You can simply use ACCEL_GET_CLASS(current_machine->accelerator)->name here. If we really want an enum, we can add an AccelId field to AccelClass, and initialize it properly on the accel
class_initfunctions.Quoted 4 lines
The AccelClass (ac =
ACCEL_GET_CLASS(current_machine->accelerator)would be ok though. That will allow to access theac->accel_id(not yet there) at places where required.I'm just not sure how to access
current_machinehere.Quoted 8 lines
It is a global variable declared in
hw/boards.h. But it makes sense only if !CONFIG_USER.But I am starting to wonder if we shouldn't simply expose accel info as a /mmachine property, instead of per-CPU information. It may become per-CPU in the future, but right now we really don't support having multiple accelerators so why are we trying to pretend we do?
Quoted 3 lines
That brings me back into the direction I was before with the proposed query-cpu-model QMP call... but that's OK. In the end that holds true also for the cpu model name as well...
That's probably true with the current command-line options and current machine implementations, but CPU model information is already inside the CPU objects. Accel information, on the other hand, is still in global variables such as kvm_allowed and current_machine.
I still believe per-CPU accel links are the right way to go in the future, but it's not how the accelerator code works today.
That means I am OK with both approaches: exposing CPU::accel info, or MachineState::accel info. The difference is that /machine/accel is simpler to implement today.
Signature · 1 line
Eduardo
PATCH v6 3/17 Extend QMP command query-cpus to return accelerator id and model name
In reply to Michael MuellerThe QMP command query-cpus now additionally displays a model name and the backing accelerator. Both are omitted if the model name is not initialized.
request:
{ "execute" : "query-cpus" }answer:
{ { "current": true,
"CPU": 0,
"model": "2827-ga2",
"halted": false,
"accel": "kvm",
"thread_id": 31917
}, ... }--- cpus.c | 4 ++++ qapi-schema.json | 7 ++++++- 2 files changed, 10 insertions(+), 1 deletion(-)
cpus.c +4 -0
@@ -1436,6 +1436,10 @@ CpuInfoList *qmp_query_cpus(Error **errp) info->value->current = (cpu == first_cpu); info->value->halted = cpu->halted; info->value->thread_id = cpu->thread_id; + info->value->model =g_strdup (cpu->model_name); + info->value->accel = cpu->accel_id; + info->value->has_model = info->value->has_accel = + info->value->model !=NULL ;#if defined(TARGET_I386 ) info->value->has_pc = true; info->value->pc = env->eip + env->segs[R_CS ].base;
qapi-schema.json +6 -1
@@ -616,6 +616,10 @@ # # @thread_id: ID of the underlying host thread # +# @accel: #optional accelerator id (since 2.4) +# +# @model: #optional cpu model name (since 2.4) +# # Since: 0.14.0 # # Notes: @halted is a transient state that changes frequently. By the time the
@@ -623,7 +627,8 @@ ## { 'type': 'CpuInfo', 'data': {'CPU': 'int', 'current': 'bool', 'halted': 'bool', '*pc': 'int', - '*nip': 'int', '*npc': 'int', '*PC': 'int', 'thread_id': 'int'} } + '*nip': 'int', '*npc': 'int', '*PC': 'int', 'thread_id': 'int', + '*accel': 'AccelId', '*model': 'str'} } ## # @query-cpus:
Signature · 1 line
1.8.3.1
Re: [Qemu-devel] [PATCH v6 03/17] Extend QMP command query-cpus to return accelerator id and model name
Quoted 16 lines · Michael Mueller
The QMP command query-cpus now additionally displays a model name and the backing accelerator. Both are omitted if the model name is not initialized.
request:
{ "execute" : "query-cpus" }answer:
{ { "current": true, "CPU": 0, "model": "2827-ga2", "halted": false, "accel": "kvm", "thread_id": 31917 }, ... }
Quoted 2 lines
Signed-off-by Michael Mueller <[email protected]>
With the new qom-path field I submitted yesterday, this can be provided as QOM properties through qom-get.
Signature · 1 line
Eduardo
Re: [Qemu-devel] [PATCH v6 03/17] Extend QMP command query-cpus to return accelerator id and model name
Quoted 17 lines · On Tue, 5 May 2015 10:11:15 -0300 Eduardo Habkost <[email protected]> wrote:
Quoted 16 lines · Michael Mueller
The QMP command query-cpus now additionally displays a model name and the backing accelerator. Both are omitted if the model name is not initialized.
request:
{ "execute" : "query-cpus" }answer:
{ { "current": true, "CPU": 0, "model": "2827-ga2", "halted": false, "accel": "kvm", "thread_id": 31917 }, ... }
Quoted 5 lines
Quoted 2 lines
Signed-off-by Michael Mueller <[email protected]>With the new qom-path field I submitted yesterday, this can be provided as QOM properties through qom-get.
Is that really a good idea to make the object representation part of the ABI. I guess there is a related discussion already somewhere. I mean not just adding the qom-path field, I saw that suggested patch, I mean the approach to expose the objects themselves...
I will try your patch of course as well...
Michael
Quoted 1 line
Re: [Qemu-devel] [PATCH v6 03/17] Extend QMP command query-cpus to return accelerator id and model name
Quoted 20 lines · Michael Mueller
Quoted 17 lines · On Tue, 5 May 2015 10:11:15 -0300 Eduardo Habkost <[email protected]> wrote:
Quoted 16 lines · Michael Mueller
The QMP command query-cpus now additionally displays a model name and the backing accelerator. Both are omitted if the model name is not initialized.
request:
{ "execute" : "query-cpus" }answer:
{ { "current": true, "CPU": 0, "model": "2827-ga2", "halted": false, "accel": "kvm", "thread_id": 31917 }, ... }
Quoted 7 lines
Quoted 5 lines
Quoted 2 lines
Signed-off-by Michael Mueller <[email protected]>With the new qom-path field I submitted yesterday, this can be provided as QOM properties through qom-get.
Is that really a good idea to make the object representation part of the ABI.
I believe that's the whole point of QOM properties.
Quoted 5 lines
I guess there is a related discussion already somewhere. I mean not just adding the qom-path field, I saw that suggested patch, I mean the approach to expose the objects themselves...
I will try your patch of course as well...
Yes, there are two approaches we are considering to allow clients to find the CPU QOM objects (qom-path in query-cpus, and links/aliases in /machine/cpus). But whatever approach we use, if clients can find the CPU objects in the QOM tree, you won't need the new fields in query-cpus and the info can be provided using qom-get.
Signature · 1 line
Eduardo
PATCH v6 4/17 Extend HMP command info cpus to display accelerator id and model name
In reply to Michael MuellerThe HMP command info cpus now displays the CPU model name and the backing accelerator if part of the CPUState.
(qemu) info cpus
* CPU #0: (halted) model=2827-ga2 accel=kvm thread_id=1679
--- hmp.c | 7 +++++++ 1 file changed, 7 insertions(+)
hmp.c +7 -0
@@ -290,6 +290,13 @@ void hmp_info_cpus(Monitor *mon, const QDict *qdict)monitor_printf (mon," (halted)" ); } +if (cpu->value->has_model) { +monitor_printf (mon," model=%s" , cpu->value->model); + } +if (cpu->value->has_accel) { +monitor_printf (mon," accel=%s" , AccelId_lookup[cpu->value->accel]); + } +monitor_printf (mon," thread_id=%" PRId64"\n" , cpu->value->thread_id); }
Signature · 1 line
1.8.3.1
Re: [Qemu-devel] [PATCH v6 04/17] Extend HMP command info cpus to display accelerator id and model name
Quoted 8 lines · Michael Mueller
The HMP command info cpus now displays the CPU model name and the backing accelerator if part of the CPUState.
(qemu) info cpus
* CPU #0: (halted) model=2827-ga2 accel=kvm thread_id=1679Signed-off-by Michael Mueller <[email protected]>
Do we really need this? I mean: I expect the amount of CPU data we provide to QMP clients to grow a lot in the near future, but that doesn't mean HMP users need all that data to be printed by "info cpus".
Quoted 25 lines
--- hmp.c | 7 +++++++ 1 file changed, 7 insertions(+)hmp.c +7
-0@@ -290,6 +290,13 @@ void hmp_info_cpus(Monitor *mon, const QDict *qdict)monitor_printf (mon," (halted)" ); } +if (cpu->value->has_model) { +monitor_printf (mon," model=%s" , cpu->value->model); + } +if (cpu->value->has_accel) { +monitor_printf (mon," accel=%s" , AccelId_lookup[cpu->value->accel]); + } +monitor_printf (mon," thread_id=%" PRId64"\n" , cpu->value->thread_id); }Signature · 1 line
1.8.3.1
Signature · 1 line
Eduardo
Re: [Qemu-devel] [PATCH v6 04/17] Extend HMP command info cpus to display accelerator id and model name
Quoted 7 lines · On Tue, 5 May 2015 10:14:32 -0300 Eduardo Habkost <[email protected]> wrote:
Quoted 6 lines · Michael Mueller
The HMP command info cpus now displays the CPU model name and the backing accelerator if part of the CPUState.
(qemu) info cpus
* CPU #0: (halted) model=2827-ga2 accel=kvm thread_id=1679
Quoted 6 lines
Quoted 2 lines
Signed-off-by Michael Mueller <[email protected]>Do we really need this? I mean: I expect the amount of CPU data we provide to QMP clients to grow a lot in the near future, but that doesn't mean HMP users need all that data to be printed by "info cpus".
Where do you see the limit of what is worth to be shown an what not. I personally use "info cpus" less then sporadic but already got a comment internally on that information being worthwhile to be shown.
Quoted 28 lines
Quoted 27 lines
--- hmp.c | 7 +++++++ 1 file changed, 7 insertions(+)hmp.c +7
-0@@ -290,6 +290,13 @@ void hmp_info_cpus(Monitor *mon, const QDict *qdict)monitor_printf (mon," (halted)" ); } +if (cpu->value->has_model) { +monitor_printf (mon," model=%s" , cpu->value->model); + } +if (cpu->value->has_accel) { +monitor_printf (mon," accel=%s" , AccelId_lookup[cpu->value->accel]); + } +monitor_printf (mon," thread_id=%" PRId64"\n" , cpu->value->thread_id); }Signature · 1 line
1.8.3.1
Re: [Qemu-devel] [PATCH v6 04/17] Extend HMP command info cpus to display accelerator id and model name
Quoted 13 lines · Michael Mueller
Quoted 10 lines · On Tue, 5 May 2015 10:14:32 -0300 Eduardo Habkost <[email protected]> wrote:
Quoted 8 lines · Michael Mueller
The HMP command info cpus now displays the CPU model name and the backing accelerator if part of the CPUState.
(qemu) info cpus
* CPU #0: (halted) model=2827-ga2 accel=kvm thread_id=1679Signed-off-by Michael Mueller <[email protected]>
Quoted 7 lines
Quoted 3 lines
Do we really need this? I mean: I expect the amount of CPU data we provide to QMP clients to grow a lot in the near future, but that doesn't mean HMP users need all that data to be printed by "info cpus".
Where do you see the limit of what is worth to be shown an what not. I personally use "info cpus" less then sporadic but already got a comment internally on that information being worthwhile to be shown.
I really don't know, but I think we shouldn't add stuff to HMP unless we have a good reason. For each new piece of data in HMP I would like to at least see the description of a real use case that justifies adding it to HMP and not just implementing a simple script on top of QMP.
For accel info we already have "info kvm" that is not ideal but is enough for current use cases, isn't it? CPU model name information seems to be more useful, but if it is just for debugging, people can just run QMP query-cpus command.
Luiz, what do you think?
Quoted 30 lines
Quoted 29 lines
Quoted 28 lines
--- hmp.c | 7 +++++++ 1 file changed, 7 insertions(+)hmp.c +7
-0@@ -290,6 +290,13 @@ void hmp_info_cpus(Monitor *mon, const QDict *qdict)monitor_printf (mon," (halted)" ); } +if (cpu->value->has_model) { +monitor_printf (mon," model=%s" , cpu->value->model); + } +if (cpu->value->has_accel) { +monitor_printf (mon," accel=%s" , AccelId_lookup[cpu->value->accel]); + } +monitor_printf (mon," thread_id=%" PRId64"\n" , cpu->value->thread_id); }Signature · 1 line
1.8.3.1
Signature · 1 line
Eduardo
Re: [Qemu-devel] [PATCH v6 04/17] Extend HMP command info cpus to display accelerator id and model name
Quoted 27 lines · On Wed, 6 May 2015 07:38:53 -0300 Eduardo Habkost <[email protected]> wrote:
Quoted 13 lines · Michael Mueller
Quoted 10 lines · On Tue, 5 May 2015 10:14:32 -0300 Eduardo Habkost <[email protected]> wrote:
Quoted 8 lines · Michael Mueller
The HMP command info cpus now displays the CPU model name and the backing accelerator if part of the CPUState.
(qemu) info cpus
* CPU #0: (halted) model=2827-ga2 accel=kvm thread_id=1679Signed-off-by Michael Mueller <[email protected]>Quoted 7 lines
Quoted 3 lines
Do we really need this? I mean: I expect the amount of CPU data we provide to QMP clients to grow a lot in the near future, but that doesn't mean HMP users need all that data to be printed by "info cpus".
Where do you see the limit of what is worth to be shown an what not. I personally use "info cpus" less then sporadic but already got a comment internally on that information being worthwhile to be shown.
I really don't know, but I think we shouldn't add stuff to HMP unless we have a good reason. For each new piece of data in HMP I would like to at least see the description of a real use case that justifies adding it to HMP and not just implementing a simple script on top of QMP.
Quoted 6 lines
For accel info we already have "info kvm" that is not ideal but is enough for current use cases, isn't it? CPU model name information seems to be more useful, but if it is just for debugging, people can just run QMP query-cpus command.
Luiz, what do you think?
I don't see a problem with that. HMP is a debugging interface anyways. Actually, I think it's a good test-case for QMP having a high-level in-tree client (vs. qmp-shell, which is too low-level).
If the problem is that a command is dumping too much information to the point of hurting usability, we can split the command or add a '-a' option or something like that.
Quoted 32 lines
Quoted 31 lines
Quoted 30 lines
Quoted 29 lines
--- hmp.c | 7 +++++++ 1 file changed, 7 insertions(+)hmp.c +7
-0@@ -290,6 +290,13 @@ void hmp_info_cpus(Monitor *mon, const QDict *qdict)monitor_printf (mon," (halted)" ); } +if (cpu->value->has_model) { +monitor_printf (mon," model=%s" , cpu->value->model); + } +if (cpu->value->has_accel) { +monitor_printf (mon," accel=%s" , AccelId_lookup[cpu->value->accel]); + } +monitor_printf (mon," thread_id=%" PRId64"\n" , cpu->value->thread_id); }Signature · 1 line
1.8.3.1
Re: [Qemu-devel] [PATCH v6 04/17] Extend HMP command info cpus to display accelerator id and model name
Quoted 37 lines · Luiz Capitulino
Quoted 27 lines · On Wed, 6 May 2015 07:38:53 -0300 Eduardo Habkost <[email protected]> wrote:
Quoted 13 lines · Michael Mueller
Quoted 10 lines · On Tue, 5 May 2015 10:14:32 -0300 Eduardo Habkost <[email protected]> wrote:
Quoted 8 lines · Michael Mueller
The HMP command info cpus now displays the CPU model name and the backing accelerator if part of the CPUState.
(qemu) info cpus
* CPU #0: (halted) model=2827-ga2 accel=kvm thread_id=1679Signed-off-by Michael Mueller <[email protected]>Quoted 7 lines
Quoted 3 lines
Do we really need this? I mean: I expect the amount of CPU data we provide to QMP clients to grow a lot in the near future, but that doesn't mean HMP users need all that data to be printed by "info cpus".
Where do you see the limit of what is worth to be shown an what not. I personally use "info cpus" less then sporadic but already got a comment internally on that information being worthwhile to be shown.
I really don't know, but I think we shouldn't add stuff to HMP unless we have a good reason. For each new piece of data in HMP I would like to at least see the description of a real use case that justifies adding it to HMP and not just implementing a simple script on top of QMP.
Quoted 6 lines
For accel info we already have "info kvm" that is not ideal but is enough for current use cases, isn't it? CPU model name information seems to be more useful, but if it is just for debugging, people can just run QMP query-cpus command.
Luiz, what do you think?
Quoted 7 lines
I don't see a problem with that. HMP is a debugging interface anyways. Actually, I think it's a good test-case for QMP having a high-level in-tree client (vs. qmp-shell, which is too low-level).
If the problem is that a command is dumping too much information to the point of hurting usability, we can split the command or add a '-a' option or something like that.
Thanks! If HMP is seen as a debugging interface, my main objections aren't valid.
That said, I would prefer to keep the command output cleaner and add only the "model" field, as people can use "info kvm" for the accel info by now.
Signature · 1 line
Eduardo
Re: [Qemu-devel] [PATCH v6 04/17] Extend HMP command info cpus to display accelerator id and model name
Quoted 46 lines · On Wed, 6 May 2015 10:33:55 -0300 Eduardo Habkost <[email protected]> wrote:
Quoted 37 lines · Luiz Capitulino
Quoted 27 lines · On Wed, 6 May 2015 07:38:53 -0300 Eduardo Habkost <[email protected]> wrote:
Quoted 13 lines · Michael Mueller
Quoted 10 lines · On Tue, 5 May 2015 10:14:32 -0300 Eduardo Habkost <[email protected]> wrote:
Quoted 8 lines · Michael Mueller
The HMP command info cpus now displays the CPU model name and the backing accelerator if part of the CPUState.
(qemu) info cpus
* CPU #0: (halted) model=2827-ga2 accel=kvm thread_id=1679Signed-off-by Michael Mueller <[email protected]>Quoted 7 lines
Quoted 3 lines
Do we really need this? I mean: I expect the amount of CPU data we provide to QMP clients to grow a lot in the near future, but that doesn't mean HMP users need all that data to be printed by "info cpus".
Where do you see the limit of what is worth to be shown an what not. I personally use "info cpus" less then sporadic but already got a comment internally on that information being worthwhile to be shown.
I really don't know, but I think we shouldn't add stuff to HMP unless we have a good reason. For each new piece of data in HMP I would like to at least see the description of a real use case that justifies adding it to HMP and not just implementing a simple script on top of QMP.
Quoted 6 lines
For accel info we already have "info kvm" that is not ideal but is enough for current use cases, isn't it? CPU model name information seems to be more useful, but if it is just for debugging, people can just run QMP query-cpus command.
Luiz, what do you think?
Quoted 7 lines
I don't see a problem with that. HMP is a debugging interface anyways. Actually, I think it's a good test-case for QMP having a high-level in-tree client (vs. qmp-shell, which is too low-level).
If the problem is that a command is dumping too much information to the point of hurting usability, we can split the command or add a '-a' option or something like that.
Quoted 6 lines
Thanks! If HMP is seen as a debugging interface, my main objections aren't valid.
That said, I would prefer to keep the command output cleaner and add only the "model" field, as people can use "info kvm" for the accel info by now.
Ok, I buy that and will kick the accel name out again.
Michael
Quoted 1 line
PATCH v6 5/17 Add optional parameters to QMP command query-cpu-definitions
In reply to Michael MuellerThe patch adds optional parameters to the QMP command query-cpu-definitions. Thus the signature of routine arch_query_cpu_definitions needs to be changed for the stub function and all target implementations:
target-arm
target-i386
target-ppc
target-s390
--- include/sysemu/arch_init.h | 7 +++++-- qapi-schema.json | 28 +++++++++++++++++++++++++--- qmp-commands.hx | 2 +- qmp.c | 11 ++++++++--- stubs/arch-query-cpu-def.c | 6 +++++- target-arm/helper.c | 6 +++++- target-i386/cpu.c | 6 +++++- target-ppc/translate_init.c | 6 +++++- target-s390x/cpu.c | 6 +++++- 9 files changed, 64 insertions(+), 14 deletions(-)
include/sysemu/arch_init.h +5 -2
@@ -36,6 +36,9 @@ void audio_init(void);int kvm_available (void );int xen_available (void ); -CpuDefinitionInfoList *arch_query_cpu_definitions (Error **errp); - +CpuDefinitionInfoList *arch_query_cpu_definitions (bool has_machine, +const char *machine, +bool has_accel, +AccelId accel, +Error **errp);#endif
qapi-schema.json +25 -3
@@ -2536,21 +2536,43 @@ # # @name: the name of the CPU definition # +# @default: #optional true if cpu model is the default, +# omitted if false (since 2.4) +# +# @runnable: #optional true if cpu model is runnable, +# omitted if false (since 2.4) +# +# @live-migration-safe: #optional true if cpu model represents a +# cpu model that is safely migratable +# omitted if false (since 2.4) +# +# @order: #optional order criterion +# # Since: 1.2.0 ## { 'type': 'CpuDefinitionInfo', - 'data': { 'name': 'str' } } + 'data': { 'name': 'str', '*is-default': 'bool', '*runnable': 'bool', + '*live-migration-safe': 'bool', '*order': 'int' } } ## # @query-cpu-definitions: # -# Return a list of supported virtual CPU definitions +# Return a list of supported virtual CPU definitions. In context with the +# optional parameters @machine and @accel the returned list contains +# also information if the respective cpu definition is runnable or the +# default to be used. +# +# @machine: #optional machine type (since 2.4) +# +# @accel: #optional accelerator id (since 2.4) # # Returns: a list of CpuDefInfo # # Since: 1.2.0 ## -{ 'command': 'query-cpu-definitions', 'returns': ['CpuDefinitionInfo'] } +{ 'command': 'query-cpu-definitions', + 'data': { '*machine': 'str', '*accel': 'AccelId' }, + 'returns': ['CpuDefinitionInfo'] } # @AddfdInfo: #
qmp-commands.hx +1 -1
@@ -3412,7 +3412,7 @@ EQMP { .name = "query-cpu-definitions", - .args_type = "", + .args_type = "machine:s?,accel:s?", .mhandler.cmd_new = qmp_marshal_input_query_cpu_definitions, },
qmp.c +8 -3
@@ -567,9 +567,14 @@ DevicePropertyInfoList *qmp_device_list_properties(const char *typename,return prop_list; } -CpuDefinitionInfoList *qmp_query_cpu_definitions (Error **errp) -{ -return arch_query_cpu_definitions (errp); +CpuDefinitionInfoList *qmp_query_cpu_definitions (bool has_machine, +const char *machine, +bool has_accel, +AccelId accel, +Error **errp) +{ +return arch_query_cpu_definitions (has_machine, machine, + has_accel, accel, errp); } void qmp_add_client(const char *protocol, const char *fdname,
stubs/arch-query-cpu-def.c +5 -1
@@ -2,7 +2,11 @@#include "sysemu/arch_init.h" #include "qapi/qmp/qerror.h" -CpuDefinitionInfoList *arch_query_cpu_definitions (Error **errp) +CpuDefinitionInfoList *arch_query_cpu_definitions (bool has_machine, +const char *machine, +bool has_accel, +AccelId accel, +Error **errp) {error_set (errp,QERR_UNSUPPORTED );return NULL ;
target-arm/helper.c +5 -1
@@ -3535,7 +3535,11 @@ static void arm_cpu_add_definition(gpointer data, gpointer user_data) *cpu_list = entry; } -CpuDefinitionInfoList *arch_query_cpu_definitions (Error **errp) +CpuDefinitionInfoList *arch_query_cpu_definitions (bool has_machine, +const char *machine, +bool has_accel, +AccelId accel, +Error **errp) {CpuDefinitionInfoList *cpu_list =NULL ;GSList *list;
target-i386/cpu.c +5 -1
@@ -2023,7 +2023,11 @@ void x86_cpu_list(FILE *f, fprintf_function cpu_fprintf) } } -CpuDefinitionInfoList *arch_query_cpu_definitions (Error **errp) +CpuDefinitionInfoList *arch_query_cpu_definitions (bool has_machine, +const char *machine, +bool has_accel, +AccelId accel, +Error **errp) {CpuDefinitionInfoList *cpu_list =NULL ;X86CPUDefinition *def;
target-ppc/translate_init.c +5 -1
@@ -9472,7 +9472,11 @@ static void ppc_cpu_defs_entry(gpointer data, gpointer user_data) *first = entry; } -CpuDefinitionInfoList *arch_query_cpu_definitions (Error **errp) +CpuDefinitionInfoList *arch_query_cpu_definitions (bool has_machine, +const char *machine, +bool has_accel, +AccelId accel, +Error **errp) {CpuDefinitionInfoList *cpu_list =NULL ;GSList *list;
target-s390x/cpu.c +5 -1
@@ -45,7 +45,11 @@ void s390_cpu_list(FILE *f, fprintf_function cpu_fprintf) }#ifndef CONFIG_USER_ONLY -CpuDefinitionInfoList *arch_query_cpu_definitions (Error **errp) +CpuDefinitionInfoList *arch_query_cpu_definitions (bool has_machine, +const char *machine, +bool has_accel, +AccelId accel, +Error **errp) {CpuDefinitionInfoList *entry;CpuDefinitionInfo *info;
Signature · 1 line
1.8.3.1
Re: [Qemu-devel] [PATCH v6 05/17] Add optional parameters to QMP command query-cpu-definitions
On Mon, Apr 27, 2015 at 04:53:19PM +0200, Michael Mueller wrote:
[...]
qapi-schema.json line 2540
Quoted 10 lines
qapi-schema.json +2
-0@@ -2536,21 +2536,43 @@ # # @name: the name of the CPU definition # +# @default: #optional true if cpu model is the default, +# omitted if false (since 2.4)
Maybe we should clarify that it is the default in the machine provided as argument to query-cpu-definitions?
qapi-schema.json line 2543
Quoted 3 lines
qapi-schema.json +3
-0+# +# @runnable: #optional true if cpu model is runnable, +# omitted if false (since 2.4)
Maybe we should clarify that it means the CPU model is runnable using the machine+accel combination provided as arguments to query-cpu-definitions?
(See also my question about the meaning of runnable when machine is omitted, in my reply to patch 15/17).
Quoted 36 lines
qapi-schema.json +20
-3+# +# @live-migration-safe: #optional true if cpu model represents a +# cpu model that is safely migratable +# omitted if false (since 2.4) +# +# @order: #optional order criterion +# # Since: 1.2.0 ## { 'type': 'CpuDefinitionInfo', - 'data': { 'name': 'str' } } + 'data': { 'name': 'str', '*is-default': 'bool', '*runnable': 'bool', + '*live-migration-safe': 'bool', '*order': 'int' } } ## # @query-cpu-definitions: # -# Return a list of supported virtual CPU definitions +# Return a list of supported virtual CPU definitions. In context with the +# optional parameters @machine and @accel the returned list contains +# also information if the respective cpu definition is runnable or the +# default to be used. +# +# @machine: #optional machine type (since 2.4) +# +# @accel: #optional accelerator id (since 2.4) # # Returns: a list of CpuDefInfo # # Since: 1.2.0 ## -{ 'command': 'query-cpu-definitions', 'returns': ['CpuDefinitionInfo'] } +{ 'command': 'query-cpu-definitions', + 'data': { '*machine': 'str', '*accel': 'AccelId' }, + 'returns': ['CpuDefinitionInfo'] }
Signature · 1 line
Eduardo
Re: [Qemu-devel] [PATCH v6 05/17] Add optional parameters to QMP command query-cpu-definitions
Quoted 16 lines · On Wed, 6 May 2015 09:42:26 -0300 Eduardo Habkost <[email protected]> wrote:
On Mon, Apr 27, 2015 at 04:53:19PM +0200, Michael Mueller wrote:
[...]qapi-schema.json line 2540
Quoted 10 lines
qapi-schema.json +2
-0@@ -2536,21 +2536,43 @@ # # @name: the name of the CPU definition # +# @default: #optional true if cpu model is the default, +# omitted if false (since 2.4)Maybe we should clarify that it is the default in the machine provided as argument to query-cpu-definitions?
Quoted 7 lines
qapi-schema.json line 2543
Quoted 3 lines
qapi-schema.json +3
-0+# +# @runnable: #optional true if cpu model is runnable, +# omitted if false (since 2.4)Maybe we should clarify that it means the CPU model is runnable using the machine+accel combination provided as arguments to query-cpu-definitions?
I will extend the comments accordingly.
Quoted 41 lines
(See also my question about the meaning of runnable when machine is omitted, in my reply to patch 15/17).
Quoted 36 lines
qapi-schema.json +20
-3+# +# @live-migration-safe: #optional true if cpu model represents a +# cpu model that is safely migratable +# omitted if false (since 2.4) +# +# @order: #optional order criterion +# # Since: 1.2.0 ## { 'type': 'CpuDefinitionInfo', - 'data': { 'name': 'str' } } + 'data': { 'name': 'str', '*is-default': 'bool', '*runnable': 'bool', + '*live-migration-safe': 'bool', '*order': 'int' } } ## # @query-cpu-definitions: # -# Return a list of supported virtual CPU definitions +# Return a list of supported virtual CPU definitions. In context with the +# optional parameters @machine and @accel the returned list contains +# also information if the respective cpu definition is runnable or the +# default to be used. +# +# @machine: #optional machine type (since 2.4) +# +# @accel: #optional accelerator id (since 2.4) # # Returns: a list of CpuDefInfo # # Since: 1.2.0 ## -{ 'command': 'query-cpu-definitions', 'returns': ['CpuDefinitionInfo'] } +{ 'command': 'query-cpu-definitions', + 'data': { '*machine': 'str', '*accel': 'AccelId' }, + 'returns': ['CpuDefinitionInfo'] }
PATCH v6 6/17 target-s390x: Introduce S390 CPU facilities
In reply to Michael MuellerThe patch introduces S390 CPU facility bit numbers and names as well as the architectural facility size limit in bytes.
--- target-s390x/cpu-facilities.h | 86 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 86 insertions(+) create mode 100644 target-s390x/cpu-facilities.h
target-s390x/cpu-facilities.h new file +86 -0
@@ -0,0 +1,86 @@ +/* +* CPU facilities for s390 +* +* Copyright 2015 IBM Corp. +* +* Author(s): Michael Mueller <[email protected]> +* +* This work is licensed under the terms of the GNU GPL, version 2 or (at +* your option) any later version. See the COPYING file in the top-level +* directory. +*/ + +#ifndef TARGET_S390X_CPU_FACILITIES_H +#define TARGET_S390X_CPU_FACILITIES_H + +/* architectural size of facilities is 2KB */ +#define FAC_LIST_ARCH_S390_SIZE_UINT8 (1<<11) + +/* CPU facility bits */ +typedef enum { +FAC_N3 =0 , +FAC_ZARCH =1 , +FAC_ZARCH_ACTIVE =2 , +FAC_DAT_ENH =3 , +FAC_ASN_LX_REUSE =6 , +FAC_STFLE =7 , +FAC_ENHANCED_DAT_1 =8 , +FAC_SENSE_RUNNING_STATUS =9 , +FAC_CONDITIONAL_SSKE =10 , +FAC_CONFIGURATION_TOPOLOGY =11 , +FAC_IPTE_RANGE =13 , +FAC_NONQ_KEY_SETTING =14 , +FAC_EXTENDED_TRANSLATION_2 =16 , +FAC_MESSAGE_SECURITY_ASSIST =17 , +FAC_LONG_DISPLACEMENT =18 , +FAC_LONG_DISPLACEMENT_FAST =19 , +FAC_HFP_MADDSUB =20 , +FAC_EXTENDED_IMMEDIATE =21 , +FAC_EXTENDED_TRANSLATION_3 =22 , +FAC_HFP_UNNORMALIZED_EXT =23 , +FAC_ETF2_ENH =24 , +FAC_STORE_CLOCK_FAST =25 , +FAC_PARSING_ENH =26 , +FAC_MOVE_WITH_OPTIONAL_SPEC =27 , +FAC_TOD_CLOCK_STEERING =28 , +FAC_ETF3_ENH =30 , +FAC_EXTRACT_CPU_TIME =31 , +FAC_COMPARE_AND_SWAP_AND_STORE =32 , +FAC_COMPARE_AND_SWAP_AND_STORE_2 =33 , +FAC_GENERAL_INSTRUCTIONS_EXT =34 , +FAC_EXECUTE_EXT =35 , +FAC_ENHANCED_MONITOR =36 , +FAC_FLOATING_POINT_EXT =37 , +FAC_LOAD_PROGRAM_PARAMETERS =40 , +FAC_FLOATING_POINT_SUPPPORT_ENH =41 , +FAC_DFP =42 , +FAC_DFP_FAST =43 , +FAC_PFPO =44 , +FAC_MULTI_45 =45 , +FAC_CMPSC_ENH =47 , +FAC_DFP_ZONED_CONVERSION =48 , +FAC_MULTI_49 =49 , +FAC_CONSTRAINT_TRANSACTIONAL_EXE =50 , +FAC_LOCAL_TLB_CLEARING =51 , +FAC_INTERLOCKED_ACCESS_2 =52 , +FAC_LOAD_STORE_ON_COND_2 =53 , +FAC_MESSAGE_SECURITY_ASSIST_5 =57 , +FAC_RESET_REFERENCE_BITS_MULTIPLE =66 , +FAC_CPU_MEASUREMENT_COUNTER =67 , +FAC_CPU_MEASUREMENT_SAMPLING =68 , +FAC_ZPCI =69 , +FAC_ADAPTER_EVENT_NOTIFICATION =71 , +FAC_ADAPTER_INT_SUPPRESSION =72 , +FAC_TRANSACTIONAL_EXE =73 , +/* z/VM-specific, see: SC24-6179-05 page 953) */ +FAC_STHYI =74 , +FAC_ACCESS_EXCEPTION_FS_INDICATION =75 , +FAC_MESSAGE_SECURITY_ASSIST_3 =76 , +FAC_MESSAGE_SECURITY_ASSIST_4 =77 , +FAC_ENHANCED_DAT_2 =78 , +FAC_DFP_PACKED_CONVERSION =80 , +FAC_VECTOR =129 , +FAC_STORE_CPU_COUNTER_MULTI =142 , +}S390Facility ; + +#endif
Signature · 1 line
1.8.3.1
PATCH v6 7/17 target-s390x: Generate facility defines per S390 CPU model
In reply to Michael MuellerThis patch introduces the helper "gen-facilities" which allows to generate facility list definitions and masks at compile time. Its flexibility is better and the error-proneness is lower when compared to static programming time added statements.
The helper includes "target-s390x/cpu-facilities.h" to be able to use named facility bits instead of numbers. Its output will be feed back into the cpu model related header file "target-s390x/cpu-models.h" by including gen-facilities.h to implement model related data structures.
The following defines/symbols are expected to be provided by the cpu-facilities header file:
FAC_LIST_ARCH_S390_SIZE_UINT8FAC_N3FAC_ZARCHFAC_ZARCH_ACTIVE
...
The defines provided by gen-facilities follow the following schema:
FAC_LIST_CPU_S390_SIZE_UINT1 %PRIu32 FAC_LIST_CPU_S390_SIZE_UINT8 %PRIu32 FAC_LIST_CPU_S390_SIZE_UINT64 %PRIu32 FAC_LIST_CPU_S390_MASK_QEMU 0x%016PRIx64,0x%016PRIx64,... FAC_LIST_CPU_S390_<TYPE>_GA<n> 0x%016PRIx64,0x%016PRIx64,...
--- Makefile.target | 2 +- rules.mak | 1 + target-s390x/Makefile.objs | 20 ++ target-s390x/gen-facilities.c | 424 ++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 446 insertions(+), 1 deletion(-) create mode 100644 target-s390x/gen-facilities.c
Makefile.target +1 -1
@@ -190,7 +190,7 @@ hmp-commands.h: $(SRC_PATH)/hmp-commands.hx qmp-commands-old.h: $(SRC_PATH)/qmp-commands.hx $(call quiet-command,sh $(SRC_PATH)/scripts/hxtool -h < $< > $@," GEN $(TARGET_DIR)$@") -clean: +clean: clean-target rm -f *.a *~ $(PROGS) rm -f $(shell find . -name '*.[od]') rm -f hmp-commands.h qmp-commands-old.h gdbstub-xml.c
rules.mak +1 -0
@@ -12,6 +12,7 @@ MAKEFLAGS += -rR %.cpp: %.m: %.mak: +clean-target: # Flags for C++ compilation QEMU_CXXFLAGS = -D__STDC_LIMIT_MACROS $(filter-out -Wstrict-prototypes -Wmissing-prototypes -Wnested-externs -Wold-style-declaration -Wold-style-definition -Wredundant-decls, $(QEMU_CFLAGS))
target-s390x/Makefile.objs +20 -0
@@ -3,3 +3,23 @@ obj-y += int_helper.o fpu_helper.o cc_helper.o mem_helper.o misc_helper.o obj-y += gdbstub.o obj-$(CONFIG_SOFTMMU) += machine.o ioinst.o arch_dump.o mmu_helper.o obj-$(CONFIG_KVM) += kvm.o + +# build and run facility generator +# +fac = gen-facilities +fac-src = $(SRC_PATH)/target-$(TARGET_BASE_ARCH) +fac-dst = $(BUILD_DIR)/$(TARGET_DIR) + +ifneq ($(MAKECMDGOALS),clean) +GENERATED_HEADERS += $(fac-dst)$(fac).h +endif + +$(fac-dst)$(fac).h: $(fac-dst)$(fac) + $(call quiet-command,$< >$@," GEN $(TARGET_DIR)$(fac).h") + +$(fac-dst)$(fac): $(fac-src)/$(fac).c $(fac-src)/cpu-facilities.h + $(call quiet-command,$(CC) $(QEMU_INCLUDES) $(QEMU_CFLAGS) $(CFLAGS) -o $@ $<," CC $(TARGET_DIR)$(fac)") + +clean-target: + rm -f $(fac).h + rm -f $(fac)
target-s390x/gen-facilities.c new file +424 -0
424 lines not on this page · raw message
Signature · 1 line
1.8.3.1
PATCH v6 8/17 target-s390x: Introduce S390 CPU models
In reply to Michael MuellerThis patch implements the static part of the S390 CPU class definitions. It defines S390 CPU models by means of virtual CPU ids (enum) which contain information on the CPU generation, the machine class, the GA number and the machine type. The CPU id is used to instantiate a CPU class per CPU model.
Furthermore it extends S390CPUClass by model related properties.
--- target-s390x/Makefile.objs | 1 + target-s390x/cpu-models.c | 78 ++++++++++++++++++++++++++++++++++++++++++++++ target-s390x/cpu-models.h | 72 ++++++++++++++++++++++++++++++++++++++++++ target-s390x/cpu-qom.h | 49 +++++++++++++++++++++++++++++ target-s390x/cpu.c | 2 ++ 5 files changed, 202 insertions(+) create mode 100644 target-s390x/cpu-models.c create mode 100644 target-s390x/cpu-models.h
target-s390x/Makefile.objs +1 -0
@@ -1,6 +1,7 @@ obj-y += translate.o helper.o cpu.o interrupt.o obj-y += int_helper.o fpu_helper.o cc_helper.o mem_helper.o misc_helper.o obj-y += gdbstub.o +obj-y += cpu-models.o obj-$(CONFIG_SOFTMMU) += machine.o ioinst.o arch_dump.o mmu_helper.o obj-$(CONFIG_KVM) += kvm.o
target-s390x/cpu-models.c new file +78 -0
78 lines not on this page · raw message
target-s390x/cpu-models.h new file +72 -0
72 lines not on this page · raw message
target-s390x/cpu-qom.h +49 -0
69 lines not on this page · raw message
target-s390x/cpu.c +2 -0
@@ -331,6 +331,8 @@ static void s390_cpu_class_init(ObjectClass *oc, void *data)#endif cc->gdb_num_core_regs =S390_NUM_CORE_REGS ; cc->gdb_core_xml_file ="s390x-core64.xml" ; + scc->is_active[ACCEL_CURRENT ] =is_cpu_class_none (scc); + scc->is_active[ACCEL_TEMP ] =is_cpu_class_none (scc); }static const TypeInfo s390_cpu_type_info = {
Signature · 1 line
1.8.3.1
PATCH v6 9/17 target-s390x: Define S390 CPU model specific facility lists
In reply to Michael MuellerThis patch defines S390 CPU facilities and their presence at the different CPU model levels. Beside defining a base which facilities have to be requested per CPU model, these sets are associated to the defined CPU classes and used to calculate the list of supported CPU models in context of the current hosting machine model.
The also defined qemu side facility mask allows to implement and enable facilities in QEMU land.
--- target-s390x/cpu-models.c | 11 +++++++++++ target-s390x/cpu-models.h | 8 ++++++++ target-s390x/cpu.c | 1 + 3 files changed, 20 insertions(+)
target-s390x/cpu-models.c +11 -0
@@ -12,6 +12,7 @@#include "qemu-common.h" #include "cpu-models.h" +#include "gen-facilities.h" #define S390_PROC_DEF (_name, _cpu_id, _desc) \ static void \
@@ -20,6 +21,10 @@ { \DeviceClass *dc =DEVICE_CLASS (oc); \S390CPUClass *cc =S390_CPU_CLASS (oc); \ +uint64_t nbits =FAC_LIST_CPU_S390_SIZE_UINT1 ; \ +uint64_t fac_list[FAC_LIST_CPU_S390_SIZE_UINT64 ] = { \ +glue (FAC_LIST_ , _cpu_id) \ + }; \ \ cc->is_migration_safe = true; \ cc->mach.ga =cpu_ga (_cpu_id); \
@@ -30,6 +35,7 @@ cc->proc.id =S390_DEF_ID ; \ cc->proc.type =cpu_type (_cpu_id); \ cc->proc.ibc =S390_DEF_IBC ; \ +bitmap_copy (cc->proc.fac_list, fac_list, nbits); \ dc->desc = _desc; \ } \ static const TypeInfo \
@@ -46,6 +52,11 @@ } \type_init (glue(_cpu_id ,_cpu_register_types )) +/* facilities implemented by qemu */ +uint64_t qemu_s390_fac_list_mask[FAC_LIST_CPU_S390_SIZE_UINT64] = { +FAC_LIST_CPU_S390_MASK_QEMU +}; +/* define S390 CPU model classes */ S390_PROC_DEF("2064-ga1", CPU_S390_2064_GA1, "IBM zSeries 900 GA1")S390_PROC_DEF ("2064-ga2" ,CPU_S390_2064_GA2 ,"IBM zSeries 900 GA2" )
target-s390x/cpu-models.h +8 -0
@@ -13,6 +13,14 @@#ifndef TARGET_S390X_CPU_MODELS_H #define TARGET_S390X_CPU_MODELS_H +#include "cpu-facilities.h" +#include "gen-facilities.h" + +#define FAC_LIST_ARCH_S390_SIZE_UINT1 \ + (FAC_LIST_ARCH_S390_SIZE_UINT8 * BITS_PER_BYTE) +#define FAC_LIST_ARCH_S390_SIZE_UINT64 \ + (FAC_LIST_ARCH_S390_SIZE_UINT8 / sizeof(uint64_t)) +#define S390_EC 0x1#define S390_BC 0x2
target-s390x/cpu.c +1 -0
@@ -29,6 +29,7 @@#include "qemu/error-report.h" #include "hw/hw.h" #include "trace.h" +#include "cpu-models.h" #ifndef CONFIG_USER_ONLY #include "sysemu/arch_init.h" #endif
Signature · 1 line
1.8.3.1
PATCH v6 10/17 target-s390x: Add S390 CPU model alias definition routines
In reply to Michael MuellerThis patch implements the infrastructure to dynamically add CPU model aliases.
--- target-s390x/cpu-models.c | 82 +++++++++++++++++++++++++++++++++++++++++++++++ target-s390x/cpu-models.h | 13 ++++++++ target-s390x/cpu.c | 1 + 3 files changed, 96 insertions(+)
target-s390x/cpu-models.c +82 -0
@@ -57,6 +57,8 @@ uint64_t qemu_s390_fac_list_mask[FAC_LIST_CPU_S390_SIZE_UINT64] = {FAC_LIST_CPU_S390_MASK_QEMU }; +GSList *s390_cpu_aliases; +/* define S390 CPU model classes */ S390_PROC_DEF("2064-ga1", CPU_S390_2064_GA1, "IBM zSeries 900 GA1")S390_PROC_DEF ("2064-ga2" ,CPU_S390_2064_GA2 ,"IBM zSeries 900 GA2" )
@@ -87,3 +89,83 @@ S390_PROC_DEF("2827-ga1", CPU_S390_2827_GA1, "IBM zEnterprise EC12 GA1") S390_PROC_DEF("2827-ga2", CPU_S390_2827_GA2, "IBM zEnterprise EC12 GA2") S390_PROC_DEF("2828-ga1", CPU_S390_2828_GA1, "IBM zEnterprise BC12 GA1") S390_PROC_DEF("2964-ga1", CPU_S390_2964_GA1, "IBM z13 GA1") + +static gint s390_cpu_compare_name (gconstpointer a,gconstpointer b) +{ +char *aname =strdup_cpu_name ((S390CPUClass *) a); +gint rc; + + rc =strcasecmp (aname, (char *) b); +free (aname); + +return rc; +} + +/** +* s390_cpu_class_by_name: +* @name: a cpu model or alias name +* +* The function searches for the requested cpu model name or an alias +* cpu model name and returns the associated object class. +* +* Returns: reference to object class on success or %NULL elsewise. +* +* Since: 2.4 +*/ +ObjectClass *s390_cpu_class_by_name (const char *name) +{ +GSList *list, *item; +ObjectClass *ret =NULL ; +S390CPUAlias *alias; + +for (item = s390_cpu_aliases; item !=NULL ; item = item->next) { + alias = (S390CPUAlias *) item->data; +if (strcmp (alias->name, name) ==0 ) { +return s390_cpu_class_by_name (alias->model); + } + } + list =object_class_get_list (TYPE_S390_CPU , false); + item =g_slist_find_custom (list, name, s390_cpu_compare_name); +if (item) { + ret =OBJECT_CLASS (item->data); + } +g_slist_free (list); +return ret; +} + +/** +* set_s390_cpu_alias: +* @name: the cpu alias name +* @model: the cpu model name +* +* The function registers the alias @name for an existing cpu @model. +* +* Returns: %0 in case of success +* -%EINVAL if name or model is %NULL or both are idential +* or model is not a valid cpu model +* -%ENOMEM if internal memory allocation fails +* +* Since: 2.4 +*/ +int set_s390_cpu_alias (const char *name,const char *model) +{ +S390CPUAlias *alias; + +if (!name || !model) { +return -EINVAL ; + } +if (!strcmp (name, model)) { +return -EINVAL ; + } +if (!s390_cpu_class_by_name (model)) { +return -EINVAL ; + } + alias =g_try_malloc0 (sizeof (S390CPUAlias)); +if (!alias) { +return -ENOMEM ; + } + alias->name =g_strdup (name); + alias->model =g_strdup (model); + s390_cpu_aliases =g_slist_append (s390_cpu_aliases, alias); +return 0 ; +}
target-s390x/cpu-models.h +13 -0
@@ -36,6 +36,19 @@#define cpu_generation (x) (((x) >> 24) & 0xff)/* +* S390 cpu aliases will be added dynamically +*/ +typedef struct S390CPUAlias { +char *name; +char *model; +}S390CPUAlias ; + +extern GSList *s390_cpu_aliases; + +ObjectClass *s390_cpu_class_by_name (const char *name); +int set_s390_cpu_alias (const char *name,const char *model); + +/* * bits 0-7 : CMOS generation * bits 8-9 : reserved * bits 10-11 : machine class 0=unknown 1=EC 2=BC
target-s390x/cpu.c +1 -0
@@ -314,6 +314,7 @@ static void s390_cpu_class_init(ObjectClass *oc, void *data)#endif scc->cpu_reset = s390_cpu_reset; scc->initial_cpu_reset = s390_cpu_initial_reset; + cc->class_by_name = s390_cpu_class_by_name; cc->reset = s390_cpu_full_reset; cc->has_work = s390_cpu_has_work; cc->do_interrupt = s390_cpu_do_interrupt;
Signature · 1 line
1.8.3.1
PATCH v6 11/17 target-s390x: Add KVM VM attribute interface for S390 CPU models
In reply to Michael MuellerThe patch implements routines to set and retrieve processor configuration data and to retrieve machine configuration data. The machine related data is used together with the CPU model facility lists to determine the list of supported CPU models of this host. The above mentioned routines have QEMU trace point instrumentation.
--- target-s390x/cpu-models.h | 36 ++++++++++++++++++++- target-s390x/kvm.c | 79 +++++++++++++++++++++++++++++++++++++++++++++++ trace-events | 3 ++ 3 files changed, 117 insertions(+), 1 deletion(-)
target-s390x/cpu-models.h +35 -1
@@ -43,11 +43,45 @@ typedef struct S390CPUAlias {char *model; } S390CPUAlias; -extern GSList *s390_cpu_aliases; +typedef struct S390ProcessorProps { +uint64_t cpuid; +uint16_t ibc; +uint8_t pad[6 ]; +uint64_t fac_list[FAC_LIST_ARCH_S390_SIZE_UINT64 ]; +}S390ProcessorProps ; + +typedef struct S390MachineProps { +uint64_t cpuid; +uint32_t ibc; +uint8_t pad[4 ]; +uint64_t fac_mask[FAC_LIST_ARCH_S390_SIZE_UINT64 ]; +uint64_t fac_list[FAC_LIST_ARCH_S390_SIZE_UINT64 ]; +}S390MachineProps ;ObjectClass *s390_cpu_class_by_name (const char *name);int set_s390_cpu_alias (const char *name,const char *model); +#ifdef CONFIG_KVM +int kvm_s390_get_processor_props (S390ProcessorProps *prop); +int kvm_s390_set_processor_props (S390ProcessorProps *prop); +bool kvm_s390_cpu_classes_initialized (void ); +#else +static inline int kvm_s390_get_processor_props (S390ProcessorProps *prop) +{ +return -ENOSYS ; +} +static inline int kvm_s390_set_processor_props (S390ProcessorProps *prop) +{ +return -ENOSYS ; +} +static inline bool kvm_s390_cpu_classes_initialized (void ) +{ +return false; +} +#endif + +extern GSList *s390_cpu_aliases; +/* * bits 0-7 : CMOS generation * bits 8-9 : reserved
target-s390x/kvm.c +79 -0
106 lines not on this page · raw message
trace-events +3 -0
@@ -1582,6 +1582,9 @@ kvm_enable_cmma(int rc) "CMMA: enabling with result code %d" kvm_clear_cmma(int rc) "CMMA: clearing with result code %d" kvm_failed_cpu_state_set(int cpu_index, uint8_t state, const char *msg) "Warning: Unable to set cpu %d state %" PRIu8 " to KVM: %s" kvm_sigp_finished(uint8_t order, int cpu_index, int dst_index, int cc) "SIGP: Finished order %u on cpu %d -> cpu %d with cc=%d" +kvm_get_machine_props(int rc, uint64_t cpuid, uint16_t ibc) "CPU-MODEL: fetching machine properties rc=%d cpuid=0x%"PRIx64" ibc=0x%"PRIx16 +kvm_get_processor_props(int rc, uint64_t cpuid, uint32_t ibc_range) "CPU-MODEL: fetching processor properties rc=%d cpuid=0x%"PRIx64" ibc_range=0x%"PRIx32 +kvm_set_processor_props(int rc) "CPU-MODEL: requesting processor properties rc=%d" # hw/dma/i8257.c i8257_unregistered_dma(int nchan, int dma_pos, int dma_len) "unregistered DMA channel used nchan=%d dma_pos=%d dma_len=%d"
Signature · 1 line
1.8.3.1
PATCH v6 12/17 target-s390x: Add S390 CPU class initialization routines
In reply to Michael MuellerThis patch provides routines to dynamically update the previously defined S390 CPU classes in the current host context. The main function performing this process is s390_setup_cpu_classes(). It takes the current host context and a facility list mask as parameter to setup the classes accordingly. It basically performs the following sub-tasks:
- Update of CPU classes with accelerator specific host and QEMU properties
- Mark adequate CPU class as default CPU class to be used for CPU model 'host'
- Invalidate CPU classes not supported by this hosting machine
- Define machine type aliases to latest GA number of a processor model
- Define aliases for common CPU model names
- Set CPU model alias 'host' to default CPU class
Forthermore the patch provides the following routines:
- cpu_desc_avail(), s390 specific stub indicating that list_cpus() can run
- s390_setup_cpu_aliases(), adds cu model aliases
- s390_cpu_classes_initialized(), test if CPU classes have been initialized
- s390_fac_list_mask_by_machine(), returns facility list mask by machine
- s390_current_fac_list_mask(), returns facility list mask of current machine
--- target-s390x/cpu-models.c | 501 ++++++++++++++++++++++++++++++++++++++++++++++ target-s390x/cpu-models.h | 29 +++ target-s390x/cpu.c | 17 +- target-s390x/kvm.c | 5 +- 4 files changed, 550 insertions(+), 2 deletions(-)
target-s390x/cpu-models.c +501 -0
@@ -13,6 +13,11 @@#include "qemu-common.h" #include "cpu-models.h" #include "gen-facilities.h" +#include "qemu/error-report.h" +#ifndef CONFIG_USER_ONLY +#include "exec/cpu-common.h" +#include "hw/boards.h" +#endif #define S390_PROC_DEF (_name, _cpu_id, _desc) \ static void \
@@ -90,6 +95,39 @@ S390_PROC_DEF("2827-ga2", CPU_S390_2827_GA2, "IBM zEnterprise EC12 GA2") S390_PROC_DEF("2828-ga1", CPU_S390_2828_GA1, "IBM zEnterprise BC12 GA1")S390_PROC_DEF ("2964-ga1" ,CPU_S390_2964_GA1 ,"IBM z13 GA1" ) +/* some types for calls to g_list_foreach() with parameters */ +typedef struct ParmBoolShortShort { +bool valid; +unsigned short type; +union { +unsigned short class; +unsigned short gen; +unsigned short ga; + }; +}ParmBoolShortShort ; + +typedef struct ParmAddrAddrModeMask { +S390MachineProps *prop; +S390CPUClass *host_cc; +S390AccelMode mode; +uint64_t *mask; +}ParmAddrAddrModeMask ; + +/* compare order of two cpu classes for ascending sort */ +gint s390_cpu_class_asc_order_compare (gconstpointer a,gconstpointer b) +{ +S390CPUClass *cc_a =S390_CPU_CLASS ((ObjectClass *) a); +S390CPUClass *cc_b =S390_CPU_CLASS ((ObjectClass *) b); + +if (cc_a->mach.order < cc_b->mach.order) { +return -1 ; + } +if (cc_a->mach.order > cc_b->mach.order) { +return 1 ; + } +return 0 ; +} +static gint s390_cpu_compare_name (gconstpointer a,gconstpointer b) {char *aname =strdup_cpu_name ((S390CPUClass *) a);
@@ -169,3 +207,466 @@ int set_s390_cpu_alias(const char *name, const char *model) s390_cpu_aliases =g_slist_append (s390_cpu_aliases, alias);return 0 ; } + +/* return machine class for specific machine type */ +static void s390_machine_class_test_cpu_class (gpointer data,gpointer user_data) +{ +S390CPUClass *cc =S390_CPU_CLASS ((ObjectClass *) data); +ParmBoolShortShort *parm = user_data; + +if (parm->valid ||is_cpu_class_none (cc) || parm->type != cc->proc.type) { +return ; + } + + parm->class = cc->mach.class; + parm->valid = true; +} + +/* return machine class by machine type */ +static unsigned short machine_class (unsigned short type,void *user_data) +{ +GSList *list =object_class_get_list (TYPE_S390_CPU , false); +ParmBoolShortShort parm_class, *parm = user_data; + +if (parm->type != type) { + parm->class =0 ; + } +if (!parm->class) { + parm_class.type = type; + parm_class.class =0 ; + parm_class.valid = false; +g_slist_foreach (list, (GFunc ) s390_machine_class_test_cpu_class, + &parm_class); +g_slist_free (list); +if (parm_class.valid) { + parm->class = parm_class.class; + } + } + parm->type = type; + +return parm->class; +} + +/* return CMOS generation for specific machine type */ +static void s390_machine_class_test_cpu_gen (gpointer data,gpointer user_data) +{ +S390CPUClass *cc =S390_CPU_CLASS ((ObjectClass *) data); +ParmBoolShortShort *parm = user_data; + +if (parm->valid) { +return ; + } + +if (parm->type == cc->proc.type) { + parm->gen = cc->proc.gen; + parm->valid = true; + } +} + +/* return CMOS generation by machine type */ +static uint16_t machine_gen (unsigned short type) +{ +GSList *list =object_class_get_list (TYPE_S390_CPU , false); +ParmBoolShortShort parm; + + parm.type = type; + parm.gen =0 ; + parm.valid = false; +g_slist_foreach (list, (GFunc ) s390_machine_class_test_cpu_gen, &parm); +g_slist_free (list); + +return parm.gen; +} + +/* mark cpu class, used in host cpu model case */ +static void s390_mark_host_cpu_class (gpointer data,gpointer user_data) +{ +S390CPUClass *cc =S390_CPU_CLASS ((ObjectClass *) data); +ParmAddrAddrModeMask *parm = user_data; +ParmBoolShortShort parm_tc; + +if (!cc->is_active[parm->mode]) { +return ; + } + + parm_tc.type =0 ; + parm_tc.class =0 ; +if (cc->mach.class !=machine_class (cpuid_type (parm->prop->cpuid), + &parm_tc)) { +/* sort out machines that differ from host machine class */ +return ; + } +if (!parm->host_cc) { +/* use first matching machine type */ + cc->is_host[parm->mode] = true; + parm->host_cc = cc; +return ; + } +if (cc->proc.gen >machine_gen (cpuid_type (parm->prop->cpuid))) { +/* sort out CMOS generations later than hosts generation */ + cc->is_active[parm->mode] = false; +return ; + } +if (cc->mach.order > parm->host_cc->mach.order) { +/* select later machine as host */ + parm->host_cc->is_host[parm->mode] = false; + cc->is_host[parm->mode] = true; + parm->host_cc = cc; + } +} + +/* update a specific cpu model class with host retrieved configuration */ +static void s390_update_cpu_class (gpointer data,gpointer user_data) +{ +ObjectClass *oc = data; +ParmAddrAddrModeMask *parm = user_data; +S390CPUClass *cc =S390_CPU_CLASS (oc); +uint64_t nbits =FAC_LIST_CPU_S390_SIZE_UINT1 ; +static uint64_t fac_list[FAC_LIST_CPU_S390_SIZE_UINT64 ]; + + cc->is_host[parm->mode] = false; + +if (is_cpu_class_none (cc)) { +return ; + } + +/* Set processor identifier */ + cc->proc.id =cpuid_id (parm->prop->cpuid); + +/* +* Define model specific IBC value in current host context. +* IBC was introduced with CMOS version 10 i.e. type 2097. +* For older CPUs it is assumed to be 0x000. The BC system +* has always the same IBC version as the previous EC system. +* If the host supports IBC but not the requested type, it +* will be set to the oldest supported value. +*/ +if (has_ibc (parm->prop->ibc)) { +if (cc->proc.gen >=S390_CMOS_G10 ) { + cc->proc.ibc = ((cc->proc.gen -S390_CMOS_G10 ) <<4 ); + cc->proc.ibc += cc->mach.ga; +if (cc->mach.class ==S390_BC ) { + cc->proc.ibc++; + } +if (cc->proc.ibc <oldest_ibc (parm->prop->ibc)) { + cc->proc.ibc =oldest_ibc (parm->prop->ibc); + } +if (cc->proc.ibc >newest_ibc (parm->prop->ibc)) { + cc->proc.ibc =newest_ibc (parm->prop->ibc); + } + }else { + cc->proc.ibc =oldest_ibc (parm->prop->ibc); + } + } + +/* +* Processor generation and GA level specific facility properties: +* +* - cc->fac_list (RFL): +* resulting facility list to be requested for guest cpus +* - cc->proc.fac_list (PFL): +* facility list defined per processor generation and GA level +* +* Machine specific facility properties reported by the host: +* +* - parm->prop->fac_list (MFL): +* host specifc facility list, might be reduced by some facilities +* in case the host is backed by z/VM and not a LPAR +* - parm->prop->fac_list_mask (MFM): +* host specific facility list mask containing facilities +* +* QEMU defined properties: +* +* - qemu_s390_fac_list_mask (QFM): +* locally defined facilities, they are added to the set of +* facilities requested for a guest vcpu. They are visible in +* the guest and require qemu side instruction handling +* +* The calculation for the vcpu specific facility list (RFL) from the +* above defined lists/masks works as follows: +* +* RFL = PFL & (QFM | MFM) +* +* Set resulting/desired facilities of given cpu class +*/ +if (parm->mask) { +bitmap_or (cc->fac_list[parm->mode], parm->mask, + parm->prop->fac_mask, nbits); +bitmap_and (cc->fac_list[parm->mode], cc->fac_list[parm->mode], + cc->proc.fac_list, nbits); + }else { +bitmap_and (cc->fac_list[parm->mode], parm->prop->fac_mask, + cc->proc.fac_list, nbits); + } + +/* +* Finally, mark the cpu class active if all resulting/desired +* facilities are offered by the host. +* (RFL & MFL) != RFL +*/ +bitmap_and (fac_list, cc->fac_list[parm->mode], parm->prop->fac_list, nbits); +if (bitmap_equal (fac_list, cc->fac_list[parm->mode], nbits)) { + cc->is_active[parm->mode] = true; + } +} + +/* cpu models newer than the hosting machine are not supported */ +static void s390_disable_not_supported_cpu_class (gpointer data, +gpointer user_data) +{ +S390CPUClass *cc =S390_CPU_CLASS ((ObjectClass *) data); +ParmAddrAddrModeMask *parm = user_data; + +if (!cc->is_active[parm->mode]) { +return ; + } +if (parm->host_cc) { +if (cc->proc.gen < parm->host_cc->proc.gen) { +return ; + } +if (cc->proc.gen == parm->host_cc->proc.gen) { +if (cc->mach.class == parm->host_cc->mach.class && + cc->mach.ga <= parm->host_cc->mach.ga) { +return ; + } +if (cc->mach.class ==S390_EC && + cc->mach.ga > parm->host_cc->mach.ga) { +return ; + } +if (cc->mach.class ==S390_BC && + cc->mach.ga < parm->host_cc->mach.ga) { +return ; + } + } + } + cc->is_active[parm->mode] = false; +} + +static void set_s390_cpu_alias_by_type_ga (unsigned short type, +unsigned short ga) +{ +set_s390_cpu_alias (g_strdup_printf ("%04x" , type), +g_strdup_printf ("%04x-ga%u" , type, ga)); +} + +/* set cpu model type alias to newest ga release */ +static void s390_set_ga_alias (gpointer data,gpointer user_data) +{ +S390CPUClass *cc =S390_CPU_CLASS ((ObjectClass *) data); +ParmBoolShortShort *parm = user_data; + +if (!cc->is_active[ACCEL_CURRENT ]) { +return ; + } +if (!parm->type) { + parm->type = cc->proc.type; + } +if (cc->proc.type == parm->type) { + parm->ga = cc->mach.ga; +return ; + } +set_s390_cpu_alias_by_type_ga (parm->type, parm->ga); + parm->type = cc->proc.type; + parm->ga = cc->mach.ga; +} + +/* set cpu model alias host to cpu class marked is host cpu class */ +static void s390_set_host_alias (gpointer data,gpointer user_data) +{ +S390CPUClass *cc =S390_CPU_CLASS ((ObjectClass *) data); + +if (cc->is_active[ACCEL_CURRENT ] && cc->is_host[ACCEL_CURRENT ]) { +set_s390_cpu_alias ("host" ,g_strdup_printf ("%04x-ga%u" , + cc->proc.type, + cc->mach.ga)); + } +} + +/** +* s390_setup_cpu_classes: +* @mode: the accelerator mode +* @prop: the machine property structure's address +* +* This function validates the defined cpu classes against the given +* machine properties @prop. Only cpu classes that are runnable on the +* current host will be set active. In addition the corresponding +* cpuid, ibc value and the active set of facilities will be +* initialized. Depending on @mode, the function porforms operations +* on the current or the temporary accelerator properies. +* +* Since: 2.4 +*/ +void s390_setup_cpu_classes (S390AccelMode mode,S390MachineProps *prop, +uint64_t *fac_list_mask) +{ +GSList *list; +ParmAddrAddrModeMask parm = { + .mode = mode, + .prop = prop, + .mask = fac_list_mask, + .host_cc =NULL , + }; + + list =object_class_get_list (TYPE_S390_CPU , false); + list =g_slist_sort (list, s390_cpu_class_asc_order_compare); + +g_slist_foreach (list, (GFunc ) s390_update_cpu_class, (gpointer) &parm); +g_slist_foreach (list, (GFunc ) s390_mark_host_cpu_class, (gpointer) &parm); +g_slist_foreach (list, (GFunc ) s390_disable_not_supported_cpu_class, &parm); + +g_slist_free (list); +} + +/** +* s390_setup_cpu_aliases: +* +* This function addes cpu model aliases that will allow to specify common +* model names in cunjunction with the -cpu command line parameter. +* There will be aliases for cpu types, pointing to the respective newest +* ga of a cpu type, aliases like z-something which are widely known and +* a the alias host pointing to the cpu type representing the current hosting +* mahine. +* +* Since: 2.4 +*/ +void s390_setup_cpu_aliases (void ) +{ +GSList *list; +ParmBoolShortShort parm = { .type =0 , { .ga =0 } }; + + list =object_class_get_list (TYPE_S390_CPU , false); + list =g_slist_sort (list, s390_cpu_class_asc_order_compare); + +g_slist_foreach (list, (GFunc ) s390_set_ga_alias, &parm); +set_s390_cpu_alias_by_type_ga (parm.type, parm.ga); + +set_s390_cpu_alias ("z900" ,"2064" ); +set_s390_cpu_alias ("z800" ,"2066" ); +set_s390_cpu_alias ("z990" ,"2084" ); +set_s390_cpu_alias ("z890" ,"2086" ); +set_s390_cpu_alias ("z9-109" ,"2094-ga1" ); +set_s390_cpu_alias ("z9" ,"2094" ); +set_s390_cpu_alias ("z9-ec" ,"2094" ); +set_s390_cpu_alias ("z9-bc" ,"2096" ); +set_s390_cpu_alias ("z10" ,"2097" ); +set_s390_cpu_alias ("z10-ec" ,"2097" ); +set_s390_cpu_alias ("z10-bc" ,"2098" ); +set_s390_cpu_alias ("z196" ,"2817" ); +set_s390_cpu_alias ("z114" ,"2818" ); +set_s390_cpu_alias ("zEC12" ,"2827" ); +set_s390_cpu_alias ("zBC12" ,"2828" ); +set_s390_cpu_alias ("z13" ,"2964" ); + +g_slist_foreach (list, (GFunc ) s390_set_host_alias, &parm); + +g_slist_free (list); +} + +/* list all supported cpu models and alias names */ +void s390_cpu_list_entry (gpointer data,gpointer user_data) +{ +ObjectClass *alias_oc, *oc = data; +CPUListState *s = user_data; +DeviceClass *dc =DEVICE_CLASS (oc); +S390CPUClass *cc =S390_CPU_CLASS (oc); +S390CPUAlias *alias; +GSList *item; +char *name; + +if (!kvm_enabled ()) { +return ; + } +if (!cc->is_active[ACCEL_CURRENT ]) { +return ; + } + name =strdup_cpu_name (cc); + (*s->cpu_fprintf)(s->file,"s390 %-10s %s\n" , + name, dc->desc ? dc->desc :"" ); + +for (item = s390_cpu_aliases; item !=NULL ; item = item->next) { + alias = (S390CPUAlias *) item->data; + alias_oc =s390_cpu_class_by_name (alias->model); +if (alias_oc != oc) { +continue ; + } + (*s->cpu_fprintf)(s->file,"s390 %-10s (alias for %s)\n" , + alias->name, name); + } + +g_free (name); +} + +/** +* s390_cpu_classes_initialized: +* +* This function indicates if the all cpu classes and their properties +* have been initialized. +* +* Returns: a boolean value. +* +* Since: 2.4 +*/ +bool s390_cpu_classes_initialized (void ) +{ +if (kvm_enabled ()) { +return kvm_s390_cpu_classes_initialized (); + } +return false; +} + +bool cpu_desc_avail (void ) +{ +return s390_cpu_classes_initialized (); +} + +/** +* s390_fac_list_mask_by_machine: +* @name: machine name +* +* This function returns the address of a facility list mask to +* be used in cunjunction with the specified machine type name +* or alias. +* +* Returns: The address of the facility list mask or %NULL in case +* @name is not a valid machine type name or alias +* +* Since: 2.4 +*/ +#ifndef CONFIG_USER_ONLY +uint64_t *s390_fac_list_mask_by_machine (const char *name) +{ +uint64_t *mask =NULL ; +GSList *machine, *mlist =object_class_get_list (TYPE_MACHINE , false); +MachineClass *mc; + +for (machine = mlist; machine; machine = machine->next) { + mc = machine->data; +if (!strcmp (mc->name, name) || + (mc->alias && !strcmp (mc->alias, name))) { +/* add cases as required */ + mask = qemu_s390_fac_list_mask; +break ; + } + } +return mask; +} +#endif + +/** +* s390_current_fac_list_mask: +* +* This function returns the address of a facility list mask of the +* currently active machine. +* +* Returns: The address of the facility list mask. +* +* Since: 2.4 +*/ +#ifndef CONFIG_USER_ONLY +uint64_t *s390_current_fac_list_mask (void ) +{ +MachineClass *mc =MACHINE_GET_CLASS (MACHINE (qdev_get_machine ())); + +return s390_fac_list_mask_by_machine (mc->name); +} +#endif
target-s390x/cpu-models.h +29 -0
@@ -29,12 +29,32 @@#define S390_DEF_ID 0xdecade#define S390_DEF_TYPE 0x2064 +/* first s390 CMOS generation supporting IBC */ +#define S390_CMOS_G10 0xa +#define cpu_type (x) (((x) >> 0) & 0xffff)#define cpu_order (x) (((x) >> 16) & 0xffff)#define cpu_ga (x) (((x) >> 16) & 0xf)#define cpu_class (x) (((x) >> 20) & 0x3)#define cpu_generation (x) (((x) >> 24) & 0xff) +#define cpuid_type (x) (((x) >> 16) & 0xffff) +#define cpuid_id (x) (((x) >> 32) & 0xffffff) +#define cpuid_ver (x) (((x) >> 56) & 0xff) + +#define type_cpuid (x) ((uint64_t)((x) & 0xffff) << 16) +#define id_cpuid (x) ((uint64_t)((x) & 0xffffff) << 32) +#define ver_cpuid (x) ((uint64_t)((x) & 0xff) << 56) + +#define oldest_ibc (x) (((uint32_t)(x) >> 16) & 0xfff) +#define newest_ibc (x) ((uint32_t)(x) & 0xfff) +#define has_ibc (x) (oldest_ibc(x) != 0) + +#define S390_DEF_CPUID \ + (ver_cpuid(S390_DEF_VERSION) | \ + id_cpuid(S390_DEF_ID) | \ + type_cpuid(S390_DEF_TYPE)) +/* * S390 cpu aliases will be added dynamically */
@@ -60,6 +80,14 @@ typedef struct S390MachineProps {ObjectClass *s390_cpu_class_by_name (const char *name);int set_s390_cpu_alias (const char *name,const char *model); +void s390_setup_cpu_classes (S390AccelMode mode,S390MachineProps *prop, +uint64_t *fac_list_mask); +void s390_setup_cpu_aliases (void ); +gint s390_cpu_class_asc_order_compare (gconstpointer a,gconstpointer b); +void s390_cpu_list_entry (gpointer data,gpointer user_data); +bool s390_cpu_classes_initialized (void ); +uint64_t *s390_fac_list_mask_by_machine (const char *name); +uint64_t *s390_current_fac_list_mask (void );#ifdef CONFIG_KVM int kvm_s390_get_processor_props (S390ProcessorProps *prop);
@@ -81,6 +109,7 @@ static inline bool kvm_s390_cpu_classes_initialized(void)#endif extern GSList *s390_cpu_aliases; +extern uint64_t qemu_s390_fac_list_mask[];/* * bits 0-7 : CMOS generation
target-s390x/cpu.c +16 -1
@@ -41,7 +41,22 @@void s390_cpu_list (FILE *f,fprintf_function cpu_fprintf) {#ifdef CONFIG_KVM - (*cpu_fprintf)(f,"s390 %16s\n" ,"host" ); +CPUListState s = { + .file = f, + .cpu_fprintf = cpu_fprintf, + }; +GSList *list; + +if (kvm_enabled () &&s390_cpu_classes_initialized ()) { + list =object_class_get_list (TYPE_S390_CPU , false); + list =g_slist_sort (list, s390_cpu_class_asc_order_compare); +g_slist_foreach (list, s390_cpu_list_entry, &s); +g_slist_free (list); + }else { +#endif + (*cpu_fprintf)(f,"s390 host\n" ); +#ifdef CONFIG_KVM + }#endif }
target-s390x/kvm.c +4 -1
@@ -293,7 +293,10 @@ static void kvm_setup_cpu_classes(KVMState *s)S390MachineProps mach;if (!kvm_s390_get_machine_props (s, &mach)) { - cpu_classes_initialized = false; +s390_setup_cpu_classes (ACCEL_CURRENT , &mach, +s390_current_fac_list_mask ()); +s390_setup_cpu_aliases (); + cpu_classes_initialized = true; } }
Signature · 1 line
1.8.3.1
Re: [Qemu-devel] [PATCH v6 12/17] target-s390x: Add S390 CPU class initialization routines
Quoted 24 lines · Michael Mueller
This patch provides routines to dynamically update the previously defined S390 CPU classes in the current host context. The main function performing this process is
s390_setup_cpu_classes(). It takes the current host context and a facility list mask as parameter to setup the classes accordingly. It basically performs the following sub-tasks:- Update of CPU classes with accelerator specific host and QEMU properties
- Mark adequate CPU class as default CPU class to be used for CPU model 'host'
- Invalidate CPU classes not supported by this hosting machine
- Define machine type aliases to latest GA number of a processor model
- Define aliases for common CPU model names
- Set CPU model alias 'host' to default CPU classForthermore the patch provides the following routines:
-
cpu_desc_avail(), s390 specific stub indicating thatlist_cpus()can run
-s390_setup_cpu_aliases(), adds cu model aliases
-s390_cpu_classes_initialized(), test if CPU classes have been initialized
-s390_fac_list_mask_by_machine(), returns facility list mask by machine
-s390_current_fac_list_mask(), returns facility list mask of current machineSigned-off-by Michael Mueller <[email protected]>---
[...]
Quoted 7 lines
target-s390x/cpu-models.c +7
-0+/** +* s390_setup_cpu_classes: +* @mode: the accelerator mode +* @prop: the machine property structure's address +* +* This function validates the defined cpu classes against the given +* machine properties @prop. Only cpu classes that are runnable on the
target-s390x/cpu-models.c int set_s390_cpu_alias(const char *name, const char *model) · line 501
Quoted 10 lines
target-s390x/cpu-models.c +10
-0+* current host will be set active. In addition the corresponding +* cpuid, ibc value and the active set of facilities will be +* initialized. Depending on @mode, the function porforms operations +* on the current or the temporary accelerator properies. +* +* Since: 2.4 +*/ +void s390_setup_cpu_classes (S390AccelMode mode,S390MachineProps *prop, +uint64_t *fac_list_mask) +{
Can't you replace the S390AccelMode arguments everywhere with simply an AccelState pointer? That's the kind of thing that should have been easier to implement using the accel QOM stuff.
If you still need to save accel-specific data somewhere (like the is_active, is_host and fac_list arrays), maybe it can be indexed using the AccelId enum you have introduced, instead of S390AccelMode?
Quoted 18 lines
target-s390x/cpu-models.c +18
-0+GSList *list; +ParmAddrAddrModeMask parm = { + .mode = mode, + .prop = prop, + .mask = fac_list_mask, + .host_cc =NULL , + }; + + list =object_class_get_list (TYPE_S390_CPU , false); + list =g_slist_sort (list, s390_cpu_class_asc_order_compare); + +g_slist_foreach (list, (GFunc ) s390_update_cpu_class, (gpointer) &parm); +g_slist_foreach (list, (GFunc ) s390_mark_host_cpu_class, (gpointer) &parm); +g_slist_foreach (list, (GFunc ) s390_disable_not_supported_cpu_class, &parm); + +g_slist_free (list); +} +
[...]
Signature · 1 line
Eduardo
Re: [Qemu-devel] [PATCH v6 12/17] target-s390x: Add S390 CPU class initialization routines
Quoted 39 lines · On Tue, 5 May 2015 11:34:06 -0300 Eduardo Habkost <[email protected]> wrote:
Quoted 24 lines · Michael Mueller
This patch provides routines to dynamically update the previously defined S390 CPU classes in the current host context. The main function performing this process is
s390_setup_cpu_classes(). It takes the current host context and a facility list mask as parameter to setup the classes accordingly. It basically performs the following sub-tasks:- Update of CPU classes with accelerator specific host and QEMU properties
- Mark adequate CPU class as default CPU class to be used for CPU model 'host'
- Invalidate CPU classes not supported by this hosting machine
- Define machine type aliases to latest GA number of a processor model
- Define aliases for common CPU model names
- Set CPU model alias 'host' to default CPU classForthermore the patch provides the following routines:
-
cpu_desc_avail(), s390 specific stub indicating thatlist_cpus()can run
-s390_setup_cpu_aliases(), adds cu model aliases
-s390_cpu_classes_initialized(), test if CPU classes have been initialized
-s390_fac_list_mask_by_machine(), returns facility list mask by machine
-s390_current_fac_list_mask(), returns facility list mask of current machineSigned-off-by Michael Mueller <[email protected]>---
[...]
Quoted 13 lines
+/**
+ *s390_setup_cpu_classes:
+ * @mode: the accelerator mode
+ * @prop: the machine property structure's address
+ *
+ * This function validates the defined cpu classes against the given
+ * machine properties @prop. Only cpu classes that are runnable on the
+ * current host will be set active. In addition the corresponding
+ * cpuid, ibc value and the active set of facilities will be
+ * initialized. Depending on @mode, the function porforms operations
+ * on the current or the temporary accelerator properies.
+ *
+ * Since: 2.4
Quoted 8 lines
target-s390x/cpu-models.c int set_s390_cpu_alias(const char *name, const char *model) · line 501
Quoted 4 lines
+ */
target-s390x/cpu-models.c +3
-0+void s390_setup_cpu_classes (S390AccelMode mode,S390MachineProps *prop, +uint64_t *fac_list_mask) +{Can't you replace the S390AccelMode arguments everywhere with simply an AccelState pointer? That's the kind of thing that should have been easier to implement using the accel QOM stuff.
Would just make sense in conjunction with an AccelId indexed array in the CPU class but see my concerns below.
Quoted 4 lines
If you still need to save accel-specific data somewhere (like the
is_active,is_hostandfac_listarrays), maybe it can be indexed using the AccelId enum you have introduced, instead of S390AccelMode?
I had an AccelId indexed array in a previous version of the patch but dismissed it in favor to this AccelMode index approach for the following reasons:
a) There is just one accelerator active and and a second set of values is
used for the query-cpu-definitions case. Using the AcceldId index would instantly double the required memory being used for no reason. The size
of the second dimension in uint64_t fac_list[ACCEL_MODE_MAX][FAC_LIST_CPU_S390_SIZE_UINT64]; is architecturally allowed to grow up to 2KB.
b) The information stored has more dimensions than just the accelerator, it also contains the selected machine (s390-virtio) which is represented by means of qemu_s390_fac_list_mask[] which currently is identical for all machines but that will change as the implementation progresses.
So AccelMode (current, tmp) might also not fully express the semantics.
Michael
Quoted 21 lines
Quoted 19 lines
target-s390x/cpu-models.c +18
-0+GSList *list; +ParmAddrAddrModeMask parm = { + .mode = mode, + .prop = prop, + .mask = fac_list_mask, + .host_cc =NULL , + }; + + list =object_class_get_list (TYPE_S390_CPU , false); + list =g_slist_sort (list, s390_cpu_class_asc_order_compare); + +g_slist_foreach (list, (GFunc ) s390_update_cpu_class, (gpointer) &parm); +g_slist_foreach (list, (GFunc ) s390_mark_host_cpu_class, (gpointer) &parm); +g_slist_foreach (list, (GFunc ) s390_disable_not_supported_cpu_class, &parm); + +g_slist_free (list); +} +[...]
Re: [Qemu-devel] [PATCH v6 12/17] target-s390x: Add S390 CPU class initialization routines
Quoted 69 lines · Michael Mueller
Quoted 39 lines · On Tue, 5 May 2015 11:34:06 -0300 Eduardo Habkost <[email protected]> wrote:
Quoted 24 lines · Michael Mueller
This patch provides routines to dynamically update the previously defined S390 CPU classes in the current host context. The main function performing this process is
s390_setup_cpu_classes(). It takes the current host context and a facility list mask as parameter to setup the classes accordingly. It basically performs the following sub-tasks:- Update of CPU classes with accelerator specific host and QEMU properties
- Mark adequate CPU class as default CPU class to be used for CPU model 'host'
- Invalidate CPU classes not supported by this hosting machine
- Define machine type aliases to latest GA number of a processor model
- Define aliases for common CPU model names
- Set CPU model alias 'host' to default CPU classForthermore the patch provides the following routines:
-
cpu_desc_avail(), s390 specific stub indicating thatlist_cpus()can run
-s390_setup_cpu_aliases(), adds cu model aliases
-s390_cpu_classes_initialized(), test if CPU classes have been initialized
-s390_fac_list_mask_by_machine(), returns facility list mask by machine
-s390_current_fac_list_mask(), returns facility list mask of current machineSigned-off-by Michael Mueller <[email protected]>---
[...]
Quoted 13 lines
+/**
+ *s390_setup_cpu_classes:
+ * @mode: the accelerator mode
+ * @prop: the machine property structure's address
+ *
+ * This function validates the defined cpu classes against the given
+ * machine properties @prop. Only cpu classes that are runnable on the
+ * current host will be set active. In addition the corresponding
+ * cpuid, ibc value and the active set of facilities will be
+ * initialized. Depending on @mode, the function porforms operations
+ * on the current or the temporary accelerator properies.
+ *
+ * Since: 2.4Quoted 8 lines
target-s390x/cpu-models.c int set_s390_cpu_alias(const char *name, const char *model) · line 501
Quoted 4 lines
+ */
target-s390x/cpu-models.c +3
-0+void s390_setup_cpu_classes (S390AccelMode mode,S390MachineProps *prop, +uint64_t *fac_list_mask) +{Can't you replace the S390AccelMode arguments everywhere with simply an AccelState pointer? That's the kind of thing that should have been easier to implement using the accel QOM stuff.
Would just make sense in conjunction with an AccelId indexed array in the CPU class but see my concerns below.
Quoted 4 lines
If you still need to save accel-specific data somewhere (like the
is_active,is_hostandfac_listarrays), maybe it can be indexed using the AccelId enum you have introduced, instead of S390AccelMode?I had an AccelId indexed array in a previous version of the patch but dismissed it in favor to this AccelMode index approach for the following reasons:
a) There is just one accelerator active and and a second set of values is
used for the query-cpu-definitions case. Using the AcceldId index would instantly double the required memory being used for no reason. The size
of the second dimension inuint64_tfac_list[ACCEL_MODE_MAX][FAC_LIST_CPU_S390_SIZE_UINT64]; is architecturally allowed to grow up to 2KB.
Quoted 6 lines
b) The information stored has more dimensions than just the accelerator, it also contains the selected machine (s390-virtio) which is represented by means of qemu_s390_fac_list_mask[] which currently is identical for all machines but that will change as the implementation progresses.
So AccelMode (current, tmp) might also not fully express the semantics.
Right. So the data depends on (cpu_model, accel, machine), but we need to cache the results for very few (just 2) accel+machine combinations at any given moment. AccelMode makes more sense to me, now.
Signature · 1 line
Eduardo
PATCH v6 13/17 target-s390x: Prepare accelerator during S390 CPU object realization
In reply to Michael MuellerThis patch implements routine s390_cpu_model_init(). It is called by the realize function during instantiation of an CPU object. Its task is to initialize the current accelerator with the properties of the selected processor model.
--- target-s390x/cpu-models.c | 30 ++++++++++++++++++++++++++++++ target-s390x/cpu-models.h | 4 ++++ target-s390x/cpu.c | 1 + 3 files changed, 35 insertions(+)
target-s390x/cpu-models.c +30 -0
@@ -670,3 +670,33 @@ uint64_t *s390_current_fac_list_mask(void) return s390_fac_list_mask_by_machine(mc->name); }#endif + +/** +* s390_cpu_model_init: +* @cc: S390 CPU class +* +* This function intitializes the current accelerator with processor +* related properties. +* +* Since: 2.4 +*/ +void s390_cpu_model_init (S390CPUClass *cc) +{ +S390ProcessorProps proc = { + .cpuid =cpuid (cc->proc), + .ibc = cc->proc.ibc, + }; + +/* none cpu model case */ +if (!proc.cpuid) { +return ; + } + +bitmap_zero (proc.fac_list,FAC_LIST_ARCH_S390_SIZE_UINT1 ); +bitmap_copy (proc.fac_list, cc->fac_list[ACCEL_CURRENT ], +FAC_LIST_CPU_S390_SIZE_UINT1 ); + +if (kvm_enabled ()) { +kvm_s390_set_processor_props (&proc); + } +}
target-s390x/cpu-models.h +4 -0
@@ -45,6 +45,9 @@#define type_cpuid (x) ((uint64_t)((x) & 0xffff) << 16)#define id_cpuid (x) ((uint64_t)((x) & 0xffffff) << 32)#define ver_cpuid (x) ((uint64_t)((x) & 0xff) << 56) +#define cpuid (x) (ver_cpuid(x.ver) | \ + id_cpuid(x.id) | \ + type_cpuid(x.type))#define oldest_ibc (x) (((uint32_t)(x) >> 16) & 0xfff)#define newest_ibc (x) ((uint32_t)(x) & 0xfff)
@@ -88,6 +91,7 @@ void s390_cpu_list_entry(gpointer data, gpointer user_data);bool s390_cpu_classes_initialized (void );uint64_t *s390_fac_list_mask_by_machine (const char *name);uint64_t *s390_current_fac_list_mask (void ); +void s390_cpu_model_init (S390CPUClass *cc);#ifdef CONFIG_KVM int kvm_s390_get_processor_props (S390ProcessorProps *prop);
target-s390x/cpu.c +1 -0
@@ -184,6 +184,7 @@ static void s390_cpu_realizefn(DeviceState *dev, Error **errp)CPUState *cs =CPU (dev);S390CPUClass *scc =S390_CPU_GET_CLASS (dev); +s390_cpu_model_init (scc);s390_cpu_gdb_init (cs);qemu_init_vcpu (cs);#if !defined(CONFIG_USER_ONLY )
Signature · 1 line
1.8.3.1
PATCH v6 14/17 target-s390x: Initialize S390 CPU model name in CPUState
In reply to Michael MuellerThe cpu model name now gets initialized during CPU instance initialization.
--- target-s390x/cpu.c | 1 + 1 file changed, 1 insertion(+)
target-s390x/cpu.c +1 -0
@@ -207,6 +207,7 @@ static void s390_cpu_initfn(Object *obj)struct tm tm;#endif + cs->model_name =strdup_cpu_name (S390_CPU_GET_CLASS (cs)); cs->env_ptr = env;cpu_exec_init (env);#if !defined(CONFIG_USER_ONLY )
Signature · 1 line
1.8.3.1
PATCH v6 15/17 target-s390x: Extend arch specific QMP command query-cpu-definitions
In reply to Michael MuellerThis patch implements the QMP command 'query-cpu-definitions' in the S390 context. The command returns a list of cpu definitions in the current host context. A runnable and migratable cpu model has the related attributes set to true. The order attribute is used to bring the listed cpu definitions in a release order.
request:
{"execute": "query-cpu-definitions",
"arguments": { "accel": "kvm",
"machine": "s390-ccw-virtio" }}
answer:
{"return": [ { "order": 3345, "name": "2964-ga1",
"live-migration-safe": true },
{ "name": "zBC12", "runnable": true },
{ "name": "2828", "runnable": true },
...
{ "name": "host", "runnable": true },
...
{ "order": 3090, "name": "2827-ga2", "runnable": true,
"live-migration-safe": true, "is-default": true },
...
{ "name": "none", "runnable": true } ]}
The request arguments are optional and if omitted lead to different answers. Eventually only the CPU model none gets returned as runnable and as default
...
{ "name": "none", "runnable": true, "is-default": true }The returned values for attributes like runnable depend on the machine type QEMU is running on. The function kvm_s390_get_machine_props() is used to determine that. If QEMU was started for accelerator KVM, a KVMstate is established and machine properties are retrieved by cpu_model_get(). In case no KVMstate was established, e.g. during QEMU startup in daemonized mode with the default accelerator TCG, a fallback routine named get_machine_props_fallback() is used to retrieve the KVM machine properties. It first creates a temporary VM, performs the required ioctls and finally destroys the VM again.
--- target-s390x/cpu-models.c | 15 ++++++ target-s390x/cpu-models.h | 7 +++ target-s390x/cpu.c | 126 +++++++++++++++++++++++++++++++++++++++++++--- target-s390x/kvm.c | 49 +++++++++++++++++- 4 files changed, 189 insertions(+), 8 deletions(-)
target-s390x/cpu-models.c +15 -0
@@ -208,6 +208,21 @@ int set_s390_cpu_alias(const char *name, const char *model)return 0 ; } +/* compare order of two cpu classes for descending sort */ +gint s390_cpu_class_desc_order_compare (gconstpointer a,gconstpointer b) +{ +S390CPUClass *cc_a =S390_CPU_CLASS ((ObjectClass *) a); +S390CPUClass *cc_b =S390_CPU_CLASS ((ObjectClass *) b); + +if (cc_a->mach.order < cc_b->mach.order) { +return 1 ; + } +if (cc_a->mach.order > cc_b->mach.order) { +return -1 ; + } +return 0 ; +} +/* return machine class for specific machine type */ static void s390_machine_class_test_cpu_class (gpointer data,gpointer user_data) {
target-s390x/cpu-models.h +7 -0
@@ -87,6 +87,7 @@ void s390_setup_cpu_classes(S390AccelMode mode, S390MachineProps *prop, uint64_t *fac_list_mask);void s390_setup_cpu_aliases (void );gint s390_cpu_class_asc_order_compare (gconstpointer a,gconstpointer b); +gint s390_cpu_class_desc_order_compare (gconstpointer a,gconstpointer b);void s390_cpu_list_entry (gpointer data,gpointer user_data);bool s390_cpu_classes_initialized (void );uint64_t *s390_fac_list_mask_by_machine (const char *name);
@@ -94,10 +95,16 @@ uint64_t *s390_current_fac_list_mask(void);void s390_cpu_model_init (S390CPUClass *cc);#ifdef CONFIG_KVM +int kvm_s390_get_machine_props (KVMState *s,S390MachineProps *prop);int kvm_s390_get_processor_props (S390ProcessorProps *prop);int kvm_s390_set_processor_props (S390ProcessorProps *prop);bool kvm_s390_cpu_classes_initialized (void );#else +static inline int kvm_s390_get_machine_props (KVMState *s, +S390MachineProps *prop) +{ +return -ENOSYS ; +}static inline int kvm_s390_get_processor_props (S390ProcessorProps *prop) {return -ENOSYS ;
target-s390x/cpu.c +119 -7
148 lines not on this page · raw message
target-s390x/kvm.c +48 -1
60 lines not on this page · raw message
Signature · 1 line
1.8.3.1
Re: [Qemu-devel] [PATCH v6 15/17] target-s390x: Extend arch specific QMP command query-cpu-definitions
On Mon, Apr 27, 2015 at 04:53:29PM +0200, Michael Mueller wrote:
[...]
target-s390x/kvm.c static int cpu_model_set(KVMState *s, uint64_t attr, void *addr) · line 279
Quoted 9 lines
target-s390x/kvm.c +0
-1@@ -276,12 +276,59 @@ static int cpu_model_set(KVMState *s, uint64_t attr, void *addr)return rc; } -static int kvm_s390_get_machine_props (KVMState *s,S390MachineProps *prop)
This seems to duplicate lots of the existing KVM code. (See additional comment below about possible ways to avoid it).
Quoted 44 lines
target-s390x/kvm.c +44
-0+static int get_machine_props_fallback (S390MachineProps *prop) +{ +struct kvm_device_attr dev_attr; +int rc, kvmfd =-1 , vmfd =-1 ; + + rc =qemu_open ("/dev/kvm" ,O_RDWR ); +if (rc <0 ) { + goto out_err; + } + kvmfd = rc; + + rc =ioctl (kvmfd,KVM_CREATE_VM ,0 ); +if (rc <0 ) { + goto out_err; + } + vmfd = rc; + + rc =ioctl (vmfd,KVM_CHECK_EXTENSION ,KVM_CAP_VM_ATTRIBUTES ); +if (rc <0 ) { + rc = -ENOSYS ; + goto out_err; + } + + dev_attr.group =KVM_S390_VM_CPU_MODEL ; + dev_attr.attr =KVM_S390_VM_CPU_MACHINE ; + rc =ioctl (vmfd,KVM_HAS_DEVICE_ATTR , &dev_attr); +if (rc <0 ) { + rc = -EFAULT ; + goto out_err; + } + + dev_attr.addr = (uint64_t ) prop; + rc =ioctl (vmfd,KVM_GET_DEVICE_ATTR , &dev_attr); + +out_err: +if (vmfd >=0 ) { +close (vmfd); + } +if (kvmfd >=0 ) { +close (kvmfd); + } + +return rc; +}
target-s390x/kvm.c static int cpu_model_set(KVMState *s, uint64_t attr, void *addr) · line 332
Quoted 10 lines
target-s390x/kvm.c +4
-0+ +int kvm_s390_get_machine_props (KVMState *s,S390MachineProps *prop) {int rc = -EFAULT ;if (s) { rc =cpu_model_get (s,KVM_S390_VM_CPU_MACHINE , prop); + }else { + rc =get_machine_props_fallback (prop); }
The comments below are just suggestions, not something which should block the patch, in my opinion:
First, if s is always NULL inside arch_query_cpu_definitions(), and is always non-NULL inside kvm_setup_cpu_classes(), why don't you just call keep the original kvm_s390_get_machine_props() function, and call and get_machine_props_fallback() inside arch_query_cpu_definitions()?
The only thing common to both cases is the tracing point, but if we are running two completely different code paths I assume it would be a good thing to have a different tracing point for get_machine_props_fallback().
Second, you shouldn't even need to duplicate code in get_machine_props_fallback() if you are able to create an accel object and do just basic initialization so that cpu_model_get() works. Allowing accel objects to be created on the fly was one of the main purposes of the accel QOM work.
For example, if we do something like this:
https://github.com/ehabkost/qemu-hacks/commit/36a250e34c5fd0d43a25271f5bc9b04681fdd56a [1]
https://github.com/ehabkost/qemu-hacks/commits/work/accel-open-func
Then the code could look like this:
accel.c:
/* configure_accelerator() would be changed to reuse this function: */ AccelState *accel_create(const char *accel_name)
{
AccelClass *acc = accel_find(accel_name);
/*TODO: error handling, checking acc->available() */
return ACCEL(object_new(object_class_get_name(OBJECT_CLASS(acc))));
}/* Do basic accel initialization without affecting global QEMU state */ /* accel_init_machine() would be changed to reuse this function: */ void accel_open(AccelState *s, Error **errp)
{
object_property_set_bool(OBJECT(s), true, "open", errp);
}target-s390/kvm.c:
/* Using a different function name would be interesting, as it would be
* the main arch_query_cpu_definitions() code path, not a fallback. */
int get_machine_props_fallback(S390MachineProps *prop)
{
int r;
AccelState *ac = accel_create("kvm");
/*TODO: error handling */
accel_open(ac, &err);
r = cpu_model_get(ac, prop);
object_unref(OBJECT(ac));
return r;
}[1] I only moved the /dev/kvm opening to the open method, but maybe the whole code up to KVM_CREATE_VM and capabitlity checking could be moved.
(But I don't know how to handle kvm_type, as it is currently provided by MachineClass. Maybe kvm_type() belongs to CPUClass instead of MachineClass?)
Quoted 5 lines
target-s390x/kvm.c +0
-0trace_kvm_get_machine_props (rc, prop->cpuid, prop->ibc);Signature · 1 line
1.8.3.1
Signature · 1 line
Eduardo
Re: [Qemu-devel] [PATCH v6 15/17] target-s390x: Extend arch specific QMP command query-cpu-definitions
Quoted 10 lines · On Tue, 5 May 2015 15:40:34 -0300 Eduardo Habkost <[email protected]> wrote:
On Mon, Apr 27, 2015 at 04:53:29PM +0200, Michael Mueller wrote:
[...]Quoted 8 lines
target-s390x/kvm.c +0
-0@@ -276,12 +276,59 @@ static int cpu_model_set(KVMState *s, uint64_t attr, void *addr)return rc; }
Quoted 4 lines
target-s390x/kvm.c static int cpu_model_set(KVMState *s, uint64_t attr, void *addr) · line 279
Quoted 1 line
target-s390x/kvm.c +0
-1-static int kvm_s390_get_machine_props (KVMState *s,S390MachineProps *prop)This seems to duplicate lots of the existing KVM code. (See additional comment below about possible ways to avoid it).
some :-)
Quoted 59 lines
Quoted 45 lines
target-s390x/kvm.c +44
-0+static int get_machine_props_fallback (S390MachineProps *prop) +{ +struct kvm_device_attr dev_attr; +int rc, kvmfd =-1 , vmfd =-1 ; + + rc =qemu_open ("/dev/kvm" ,O_RDWR ); +if (rc <0 ) { + goto out_err; + } + kvmfd = rc; + + rc =ioctl (kvmfd,KVM_CREATE_VM ,0 ); +if (rc <0 ) { + goto out_err; + } + vmfd = rc; + + rc =ioctl (vmfd,KVM_CHECK_EXTENSION ,KVM_CAP_VM_ATTRIBUTES ); +if (rc <0 ) { + rc = -ENOSYS ; + goto out_err; + } + + dev_attr.group =KVM_S390_VM_CPU_MODEL ; + dev_attr.attr =KVM_S390_VM_CPU_MACHINE ; + rc =ioctl (vmfd,KVM_HAS_DEVICE_ATTR , &dev_attr); +if (rc <0 ) { + rc = -EFAULT ; + goto out_err; + } + + dev_attr.addr = (uint64_t ) prop; + rc =ioctl (vmfd,KVM_GET_DEVICE_ATTR , &dev_attr); + +out_err: +if (vmfd >=0 ) { +close (vmfd); + } +if (kvmfd >=0 ) { +close (kvmfd); + } + +return rc; +}target-s390x/kvm.c static int cpu_model_set(KVMState *s, uint64_t attr, void *addr) · line 332
Quoted 10 lines
target-s390x/kvm.c +4
-0+ +int kvm_s390_get_machine_props (KVMState *s,S390MachineProps *prop) {int rc = -EFAULT ;if (s) { rc =cpu_model_get (s,KVM_S390_VM_CPU_MACHINE , prop); + }else { + rc =get_machine_props_fallback (prop); }The comments below are just suggestions, not something which should block the patch, in my opinion:
Quoted 4 lines
First, if s is always NULL inside
arch_query_cpu_definitions(), and is always non-NULL insidekvm_setup_cpu_classes(), why don't you just call keep the originalkvm_s390_get_machine_props()function, and call andget_machine_props_fallback()insidearch_query_cpu_definitions()?
My reason for pulling both paths through the same internal interface call is to have just single call for the same purpose.
Quoted 13 lines
The only thing common to both cases is the tracing point, but if we are running two completely different code paths I assume it would be a good thing to have a different tracing point for
get_machine_props_fallback().Second, you shouldn't even need to duplicate code in
get_machine_props_fallback()if you are able to create an accel object and do just basic initialization so thatcpu_model_get()works. Allowing accel objects to be created on the fly was one of the main purposes of the accel QOM work.
Quoted 3 lines
For example, if we do something like this:
https://github.com/ehabkost/qemu-hacks/commit/36a250e34c5fd0d43a25271f5bc9b04681fdd56a [1]
https://github.com/ehabkost/qemu-hacks/commits/work/accel-open-func
I had a look at your qemu-hacks before writing the _fallback() routine but did not wanted to base on some not yet published code. Once your part goes upstream my intend is to provide a cleanup patch... And I was missing the KVM_CREATE_VM actually.
Quoted 37 lines
Then the code could look like this:
accel.c:/*
configure_accelerator()would be changed to reuse this function: */ AccelState *accel_create(const char*accel_name){ AccelClass *acc = accel_find(accel_name); /*TODO: error handling, checking acc->available() */ return ACCEL(object_new(object_class_get_name(OBJECT_CLASS(acc)))); }/* Do basic accel initialization without affecting global QEMU state */ /*
accel_init_machine()would be changed to reuse this function: */ voidaccel_open(AccelState *s, Error **errp){ object_property_set_bool(OBJECT(s), true, "open", errp); }
target-s390/kvm.c:/* Using a different function name would be interesting, as it would be
* the mainarch_query_cpu_definitions()code path, not a fallback. */
intget_machine_props_fallback(S390MachineProps *prop){ int r; AccelState *ac = accel_create("kvm"); /*TODO: error handling */ accel_open(ac, &err); r = cpu_model_get(ac, prop); object_unref(OBJECT(ac)); return r; }
Quoted 3 lines
[1] I only moved the
/dev/kvmopening to the open method, but maybe the whole code up toKVM_CREATE_VMand capabitlity checking could be moved.
Yes as mentioned above.
Quoted 10 lines
(But I don't know how to handle
kvm_type, as it is currently provided by MachineClass. Maybekvm_type()belongs to CPUClass instead of MachineClass?)Quoted 5 lines
target-s390x/kvm.c +0
-0trace_kvm_get_machine_props (rc, prop->cpuid, prop->ibc);Signature · 1 line
1.8.3.1
Re: [Qemu-devel] [PATCH v6 15/17] target-s390x: Extend arch specific QMP command query-cpu-definitions
Quoted 2 lines · Michael Mueller
On Tue, 5 May 2015 15:40:34 -0300
Eduardo Habkost <[email protected]> wrote:
[...]
Quoted 6 lines
Quoted 6 lines
Second, you shouldn't even need to duplicate code in
get_machine_props_fallback()if you are able to create an accel object and do just basic initialization so thatcpu_model_get()works. Allowing accel objects to be created on the fly was one of the main purposes of the accel QOM work.
Quoted 8 lines
Quoted 3 lines
For example, if we do something like this:
https://github.com/ehabkost/qemu-hacks/commit/36a250e34c5fd0d43a25271f5bc9b04681fdd56a [1]
https://github.com/ehabkost/qemu-hacks/commits/work/accel-open-funcI had a look at your qemu-hacks before writing the
_fallback()routine but did not wanted to base on some not yet published code. Once your part goes upstream my intend is to provide a cleanup patch... And I was missing theKVM_CREATE_VMactually.
No problem to me if you prefer to keep it this way and change it to use AccelState as a follow-up, after appropriate methods are provided by TYPE_KVM_ACCEL. Your patch was helpful to show that just extracting the open("/dev/kvm") part isn't enough and more work is needed.
Signature · 1 line
Eduardo
Re: [Qemu-devel] [PATCH v6 15/17] target-s390x: Extend arch specific QMP command query-cpu-definitions
Quoted 19 lines · On Wed, 6 May 2015 13:00:32 -0300 Eduardo Habkost <[email protected]> wrote:
Quoted 2 lines · Michael Mueller
On Tue, 5 May 2015 15:40:34 -0300
Eduardo Habkost <[email protected]> wrote:[...]
Quoted 6 lines
Quoted 6 lines
Second, you shouldn't even need to duplicate code in
get_machine_props_fallback()if you are able to create an accel object and do just basic initialization so thatcpu_model_get()works. Allowing accel objects to be created on the fly was one of the main purposes of the accel QOM work.Quoted 8 lines
Quoted 3 lines
For example, if we do something like this:
https://github.com/ehabkost/qemu-hacks/commit/36a250e34c5fd0d43a25271f5bc9b04681fdd56a [1]
https://github.com/ehabkost/qemu-hacks/commits/work/accel-open-funcI had a look at your qemu-hacks before writing the
_fallback()routine but did not wanted to base on some not yet published code. Once your part goes upstream my intend is to provide a cleanup patch... And I was missing theKVM_CREATE_VMactually.
Quoted 4 lines
No problem to me if you prefer to keep it this way and change it to use AccelState as a follow-up, after appropriate methods are provided by
TYPE_KVM_ACCEL. Your patch was helpful to show that just extracting theopen("/dev/kvm")part isn't enough and more work is needed.
promised :-)
Quoted 1 line
Re: [Qemu-devel] [PATCH v6 15/17] target-s390x: Extend arch specific QMP command query-cpu-definitions
In reply to Michael MuellerOn Mon, Apr 27, 2015 at 04:53:29PM +0200, Michael Mueller wrote:
[...]
Quoted 22 lines
#ifndef
CONFIG_USER_ONLYtarget-s390x/cpu.c +21
-0+static CpuDefinitionInfoList *qmp_query_cpu_definition_host (void ) +{ +CpuDefinitionInfoList *host =NULL ; +CpuDefinitionInfo *info; + + info =g_try_new0 (CpuDefinitionInfo,1 ); +if (!info) { + goto out; + } + info->name =g_strdup ("host" ); + + host =g_try_new0 (CpuDefinitionInfoList,1 ); +if (!host) { +g_free (info->name); +g_free (info); + goto out; + } + host->value = info; +out: +return host; +}
[...]
Quoted 11 lines
CpuDefinitionInfoList *arch_query_cpu_definitions(bool
has_machine,
const char *machine, boolhas_accel, AccelId accel, Error **errp)
{target-s390x/cpu.c +3
-2-CpuDefinitionInfoList *entry; -CpuDefinitionInfo *info; +S390MachineProps mach; +GSList *classes; +uint64_t *mask =NULL ;
target-s390x/cpu.c void s390_cpu_list(FILE *f, fprintf_function cpu_fprintf) · line 171
Quoted 10 lines
target-s390x/cpu.c +10
-0+CpuDefinitionInfoList *list =NULL ; + +if (has_machine) { + mask =s390_fac_list_mask_by_machine (machine); +if (!mask) { +error_set (errp,QERR_INVALID_PARAMETER_VALUE ,"machine" , +"a valid machine type" ); +return NULL ; + } + }
I would like to understand better the meaning of "runnable" when machine is omitted. Is it really possible to tell if a CPU model is runnable if no machine/mask info is provided as input?
If machine is omitted and the command returns runnable=true, does that mean the CPU model is runnable using any machine? Does it mean it is runnable using some of the available machines? If so, which ones? Does it mean something else?
target-s390x/cpu.c void s390_cpu_list(FILE *f, fprintf_function cpu_fprintf) · line 180
Quoted 11 lines
target-s390x/cpu.c +8
-2- info =g_malloc0 (sizeof (*info)); - info->name =g_strdup ("host" ); +memset (&mach,0 ,sizeof (mach)); +if (has_accel) { +switch (accel) { +case ACCEL_ID_KVM : +kvm_s390_get_machine_props (NULL , &mach); +break ; +default : +return qmp_query_cpu_definition_host ();
This will return only a single element. I don't think that's correct. If machine or accel is omitted, I believe we should just omit the "runnable" field, but always return the full list of CPU models.
Quoted 17 lines
target-s390x/cpu.c +9
-3+ } + } - entry =g_malloc0 (sizeof (*entry)); - entry->value = info; +s390_setup_cpu_classes (ACCEL_TEMP , &mach, mask); + + classes =object_class_get_list (TYPE_S390_CPU , false); + classes =g_slist_sort (classes, s390_cpu_class_asc_order_compare); +g_slist_foreach (classes, qmp_query_cpu_definition_entry, &list); +g_slist_free (classes); - return entry; +return list; }#endif
[...]
Signature · 1 line
Eduardo
Re: [Qemu-devel] [PATCH v6 15/17] target-s390x: Extend arch specific QMP command query-cpu-definitions
Quoted 47 lines · On Wed, 6 May 2015 09:37:41 -0300 Eduardo Habkost <[email protected]> wrote:
On Mon, Apr 27, 2015 at 04:53:29PM +0200, Michael Mueller wrote:
[...]Quoted 22 lines
#ifndef
CONFIG_USER_ONLYtarget-s390x/cpu.c +21
-0+static CpuDefinitionInfoList *qmp_query_cpu_definition_host (void ) +{ +CpuDefinitionInfoList *host =NULL ; +CpuDefinitionInfo *info; + + info =g_try_new0 (CpuDefinitionInfo,1 ); +if (!info) { + goto out; + } + info->name =g_strdup ("host" ); + + host =g_try_new0 (CpuDefinitionInfoList,1 ); +if (!host) { +g_free (info->name); +g_free (info); + goto out; + } + host->value = info; +out: +return host; +}[...]
Quoted 11 lines
CpuDefinitionInfoList *arch_query_cpu_definitions(bool
has_machine,
const char *machine, boolhas_accel, AccelId accel, Error **errp)
{target-s390x/cpu.c +3
-2-CpuDefinitionInfoList *entry; -CpuDefinitionInfo *info; +S390MachineProps mach; +GSList *classes; +uint64_t *mask =NULL ;target-s390x/cpu.c void s390_cpu_list(FILE *f, fprintf_function cpu_fprintf) · line 171
Quoted 10 lines
target-s390x/cpu.c +10
-0+CpuDefinitionInfoList *list =NULL ; + +if (has_machine) { + mask =s390_fac_list_mask_by_machine (machine); +if (!mask) { +error_set (errp,QERR_INVALID_PARAMETER_VALUE ,"machine" , +"a valid machine type" ); +return NULL ; + } + }
Quoted 3 lines
I would like to understand better the meaning of "runnable" when machine is omitted. Is it really possible to tell if a CPU model is runnable if no machine/mask info is provided as input?
Yes it is. The list of runnable CPU models is derived from the set of S390 CPU facilities available. One subset of facilities depends on the accelerator and the second on the capabilities of QEMU which is represented by the mask. In the case the no machine is specified only those of the accelerator are taken into account for the calculation.
It is even possible to omit both, the accelerator and the machine, in that case only the model none is runnable and becomes the default:
{"return":[{"order":3345,"name":"2964-ga1","live-migration-safe":true},{"name":"zBC12"}, {"name":"2828"},{"order":3105,"name":"2828-ga1","live-migration-safe":true},{"name":"host"}, {"name":"zEC12"},{"name":"2827"},{"order":3090,"name":"2827-ga2","live-migration-safe":true}, {"order":3089,"name":"2827-ga1","live-migration-safe":true},{"name":"z114"},{"name":"2818"}, {"order":2849,"name":"2818-ga1","live-migration-safe":true},{"name":"z196"},{"name":"2817"}, {"order":2834,"name":"2817-ga2","live-migration-safe":true},{"order":2833,"name":"2817-ga1", "live-migration-safe":true},{"name":"z10-bc"},{"name":"2098"},{"order":2594,"name":"2098-ga2", "live-migration-safe":true},{"order":2593,"name":"2098-ga1","live-migration-safe":true}, {"name":"z10-ec"},{"name":"z10"},{"name":"2097"},{"order":2579,"name":"2097-ga3", "live-migration-safe":true},{"order":2578,"name":"2097-ga2","live-migration-safe":true}, {"order":2577,"name":"2097-ga1","live-migration-safe":true},{"name":"z9-bc"},{"name":"2096"}, {"order":2338,"name":"2096-ga2","live-migration-safe":true},{"order":2337,"name":"2096-ga1", "live-migration-safe":true},{"name":"z9-ec"},{"name":"z9"},{"name":"2094"},{"order":2323, "name":"2094-ga3","live-migration-safe":true},{"order":2322,"name":"2094-ga2", "live-migration-safe":true},{"name":"z9-109"},{"order":2321,"name":"2094-ga1", "live-migration-safe":true},{"name":"z890"},{"name":"2086"},{"order":2083,"name":"2086-ga3", "live-migration-safe":true},{"order":2082,"name":"2086-ga2","live-migration-safe":true}, {"order":2081,"name":"2086-ga1","live-migration-safe":true},{"name":"z990"},{"name":"2084"}, {"order":2069,"name":"2084-ga5","live-migration-safe":true},{"order":2068,"name":"2084-ga4", "live-migration-safe":true},{"order":2067,"name":"2084-ga3","live-migration-safe":true}, {"order":2066,"name":"2084-ga2","live-migration-safe":true},{"order":2065,"name":"2084-ga1", "live-migration-safe":true},{"name":"z800"},{"name":"2066"},{"order":1825,"name":"2066-ga1", "live-migration-safe":true},{"name":"z900"},{"name":"2064"},{"order":1811,"name":"2064-ga3", "live-migration-safe":true},{"order":1810,"name":"2064-ga2","live-migration-safe":true}, {"order":1809,"name":"2064-ga1","live-migration-safe":true},{"name":"none","runnable":true, "is-default":true}],"id":"libvirt-15"}
Quoted 5 lines
If machine is omitted and the command returns runnable=true, does that mean the CPU model is runnable using any machine? Does it mean it is runnable using some of the available machines? If so, which ones? Does it mean something else?
As it is a lower limit all machines shall be able to run it. Although a somewhat clever management interface should iterate through all accel/machine combinations.
Quoted 13 lines
target-s390x/cpu.c void s390_cpu_list(FILE *f, fprintf_function cpu_fprintf) · line 180
Quoted 12 lines
target-s390x/cpu.c +8
-2- info =g_malloc0 (sizeof (*info)); - info->name =g_strdup ("host" ); +memset (&mach,0 ,sizeof (mach)); +if (has_accel) { +switch (accel) { +case ACCEL_ID_KVM : +kvm_s390_get_machine_props (NULL , &mach); +break ; +default : +return qmp_query_cpu_definition_host ();
Quoted 3 lines
This will return only a single element. I don't think that's correct. If machine or accel is omitted, I believe we should just omit the "runnable" field, but always return the full list of CPU models.
That is the !KVM case where I keep the behavior currently unchanged to the existing implementation. But right for the TCG case there has to be a comparable get_machine_props() call returning whatever TCG is implementing. But that is not part of this patch series.
Quoted 20 lines
Quoted 18 lines
target-s390x/cpu.c +9
-3+ } + } - entry =g_malloc0 (sizeof (*entry)); - entry->value = info; +s390_setup_cpu_classes (ACCEL_TEMP , &mach, mask); + + classes =object_class_get_list (TYPE_S390_CPU , false); + classes =g_slist_sort (classes, s390_cpu_class_asc_order_compare); +g_slist_foreach (classes, qmp_query_cpu_definition_entry, &list); +g_slist_free (classes); - return entry; +return list; }#endif [...]
Re: [Qemu-devel] [PATCH v6 15/17] target-s390x: Extend arch specific QMP command query-cpu-definitions
Quoted 2 lines · Michael Mueller
On Wed, 6 May 2015 09:37:41 -0300
Eduardo Habkost <[email protected]> wrote:
[...]
Quoted 13 lines
Quoted 13 lines
Quoted 12 lines
target-s390x/cpu.c +8
-2- info =g_malloc0 (sizeof (*info)); - info->name =g_strdup ("host" ); +memset (&mach,0 ,sizeof (mach)); +if (has_accel) { +switch (accel) { +case ACCEL_ID_KVM : +kvm_s390_get_machine_props (NULL , &mach); +break ; +default : +return qmp_query_cpu_definition_host ();
Quoted 8 lines
Quoted 3 lines
This will return only a single element. I don't think that's correct. If machine or accel is omitted, I believe we should just omit the "runnable" field, but always return the full list of CPU models.
That is the !KVM case where I keep the behavior currently unchanged to the existing implementation. But right for the TCG case there has to be a comparable
get_machine_props()call returning whatever TCG is implementing. But that is not part of this patch series.
I believe the right thing to do is to return the full list of CPU models, but report them as not runnable if accel is TCG, and simply omit the runnable field if no accel argument is provided.
This way, existing management code that already runs query-cpu-models (e.g. libvirt, that does that with "-machine none") will keep working.
Signature · 1 line
Eduardo
PATCH v6 16/17 target-s390x: Introduce S390 CPU facility test routine
In reply to Michael MuellerThe patch introduces routine s390_facility_test() which allows to verify if a specific facility bit is set.
--- target-s390x/cpu-models.c | 29 +++++++++++++++++++++++++++++ target-s390x/cpu-models.h | 1 + 2 files changed, 30 insertions(+)
target-s390x/cpu-models.c +29 -0
@@ -715,3 +715,32 @@ void s390_cpu_model_init(S390CPUClass *cc)kvm_s390_set_processor_props (&proc); } } + +static inline int test_facility (uint64_t *fac_list,uint16_t nr) +{ +uint16_t word = nr /BITS_PER_LONG ; +uint16_t be_bit = (BITS_PER_LONG -1 ) - (nr %BITS_PER_LONG ); + +return (nr <FAC_LIST_CPU_S390_SIZE_UINT1 ) ? + (fac_list[word] >> be_bit) &__UINT64_C (1 ) :0 ; +} + +/** +* s390_test_facility: +* @nr: facility bit number to test +* @cc: cpu class to test +* +* The functions tests if the cpu facility identified by bit @nr is available +* to the cpu class @cc. +* +* Returns: a boolean value. +* +* Since: 2.4 +*/ +bool s390_test_facility (S390CPUClass *cc,uint16_t nr) +{ +if (!cc) { +return false; + } +return test_facility (cc->fac_list[ACCEL_CURRENT ], nr) ? true : false; +}
target-s390x/cpu-models.h +1 -0
@@ -93,6 +93,7 @@ bool s390_cpu_classes_initialized(void);uint64_t *s390_fac_list_mask_by_machine (const char *name);uint64_t *s390_current_fac_list_mask (void );void s390_cpu_model_init (S390CPUClass *cc); +bool s390_test_facility (S390CPUClass *cc,uint16_t nr);#ifdef CONFIG_KVM int kvm_s390_get_machine_props (KVMState *s,S390MachineProps *prop);
Signature · 1 line
1.8.3.1
PATCH v6 17/17 target-s390x: Enable S390 CPU model usage
In reply to Michael MuellerThis patch enables QEMU to instantiate S390 CPUs with CPU model types.
--- hw/s390x/s390-virtio.c | 12 +++++++++++- target-s390x/helper.c | 9 ++------- 2 files changed, 13 insertions(+), 8 deletions(-)
hw/s390x/s390-virtio.c +11 -1
@@ -32,6 +32,7 @@#include "hw/virtio/virtio.h" #include "hw/sysbus.h" #include "sysemu/kvm.h" +#include "sysemu/cpus.h" #include "exec/address-spaces.h" #include "hw/s390x/s390-virtio-bus.h"
@@ -157,7 +158,12 @@ void s390_init_cpus(const char *cpu_model, uint8_t *storage_keys)int i;if (cpu_model ==NULL ) { - cpu_model ="host" ; + cpu_model ="none" ; + } + +if (is_help_option (cpu_model)) { +list_cpus (stdout, &fprintf, cpu_model); +exit (0 ); } ipi_states =g_malloc (sizeof (S390CPU *) * smp_cpus);
@@ -167,6 +173,10 @@ void s390_init_cpus(const char *cpu_model, uint8_t *storage_keys)CPUState *cs; cpu =cpu_s390x_init (cpu_model); +if (cpu ==NULL ) { +fprintf (stderr,"Unable to find CPU definition\n" ); +exit (1 ); + } cs =CPU (cpu); ipi_states[i] = cpu;
target-s390x/helper.c +2 -7
@@ -22,6 +22,7 @@#include "exec/gdbstub.h" #include "qemu/timer.h" #include "exec/cpu_ldst.h" +#include "cpu-models.h" #ifndef CONFIG_USER_ONLY #include "sysemu/sysemu.h" #endif
@@ -66,13 +67,7 @@ void s390x_cpu_timer(void *opaque)S390CPU *cpu_s390x_init (const char *cpu_model) { -S390CPU *cpu; - - cpu =S390_CPU (object_new (TYPE_S390_CPU )); - -object_property_set_bool (OBJECT (cpu), true,"realized" ,NULL ); - -return cpu; +return S390_CPU (cpu_generic_init (TYPE_S390_CPU , cpu_model)); }#if defined(CONFIG_USER_ONLY )
Signature · 1 line
1.8.3.1