QOMify accelerator code
cover QOMify accelerator code
Git tree:
https://github.com/ehabkost/qemu-hacks/tree/accel-qom.v1
This is an attempt to convert the accel initialization and registration code to be QOM-based. I see two use cases for this:
* KVM-specific CPU compat bits;
* Probing for accelerator-specific CPU model "runnable" information.
= KVM-specific compat bits =
Currently, the PC compat code that deals with KVM-specific CPUID compat bits can't use compat_props to control compatibility, because it needs to affect the X86CPU CPUID initialization behavior only when KVM is enabled. The solution I propose is to have a "x86-kvm-accel" class which would be responsible for the KVM-specific CPU initialization behavior. Any compatibility properties for that behavior could then be tuned using "x86-kvm-accel" compat properties.
To be able to implement x86-specific accelerator methods, a TYPE_X86_ACCEL interface was introduced.
Patches 19-24 implements this (except for the actual compat properties).
= Accel-specific runnable information =
There are plans to eventually make the "query-cpu-definitions" QMP command return "runnable" information, which is accelerator-specific (e.g. some CPU models may be runnable when using KVM, but not when using TCG). The existing accelerator code maintains lots of global state, and the QOM-based approach will allow us to eventually make query-cpu-definitions instantiate short-lived accelerator objects (without affecting any machine and/or global state) to query for accelerator-specific information.
Eduardo Habkost (25):
vl.c: Small coding style fix
accel: Move accel code to accel.c
accel: Create struct AccelType
accel: Simplify configure_accelerator() using AccelType *acc variable
accel: Move accel name lookup to separate function
accel: Use QOM classes for accel types
accel: Make AccelClass.available() optional
accel: Move KVM accel registration to kvm-all.c
accel: Move Xen registration code to xen-common.c
accel: Move qtest accel registration to qtest.c
accel: Remove tcg_available() function
accel: Move accel init/allowed code to separate function
accel: Rename 'init' method to 'init_machine'
accel: Pass MachineState object to accel init functions
accel: Create accel object when initializing machine
accel: Save AccelState on MachineState when initializing
kvm: Make KVMState be the TYPE_KVM_ACCEL instance struct
accel: Get target name as argument when initializing accelerator
accel: Use target-specific accel class if available
accel: TYPE_X86_ACCEL interface
kvm: x86 KVM accelerator subclass
target-i386: Add AccelState parameter to cpu_x86_create()
target-i386: Move accelerator-specific code outside
X86CPU.instance_init
target-i386: Accept "host" as value for CPU vendor
target-i386: Move KVM CPUID hacking to accelerator cpu_post_init hook
arch_init.c | 11 +-- hw/core/Makefile.objs | 1 + hw/core/accel.c | 171 +++++++++++++++++++++++++++++++++++++++++++++ hw/i386/pc.c | 3 +- include/hw/accel.h | 60 ++++++++++++++++ include/hw/boards.h | 1 + include/hw/i386/accel.h | 42 +++++++++++ include/hw/xen/xen.h | 1 - include/qemu/typedefs.h | 5 ++ include/sysemu/arch_init.h | 1 - include/sysemu/kvm.h | 5 +- include/sysemu/qtest.h | 1 - kvm-all.c | 40 +++++++++-- kvm-stub.c | 5 -- qtest.c | 27 ++++++- target-i386/Makefile.objs | 1 + target-i386/accel.c | 38 ++++++++++ target-i386/cpu.c | 101 +++++++++++--------------- target-i386/cpu.h | 2 +- target-i386/kvm.c | 70 +++++++++++++++++++ vl.c | 83 +--------------------- xen-common-stub.c | 6 -- xen-common.c | 25 ++++++- 23 files changed, 528 insertions(+), 172 deletions(-) create mode 100644 hw/core/accel.c create mode 100644 include/hw/accel.h create mode 100644 include/hw/i386/accel.h create mode 100644 target-i386/accel.c
Signature · 1 line
1.9.3
RFC 1/25 vl.c: Small coding style fix
Just to make checkpatch.pl happy when moving the code.
--- vl.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
vl.c +1 -1
@@ -2692,7 +2692,7 @@ static int configure_accelerator(MachineClass *mc)if (*p ==':' ) { p++; } - p =get_opt_name (buf,sizeof (buf), p,':' ); + p =get_opt_name (buf,sizeof (buf), p,':' );for (i =0 ; i <ARRAY_SIZE (accel_list); i++) {if (strcmp (accel_list[i].opt_name, buf) ==0 ) {if (!accel_list[i].available ()) {
Signature · 1 line
1.9.3
RFC 2/25 accel: Move accel code to accel.c
In reply to Eduardo Habkost--- hw/core/Makefile.objs | 1 + hw/core/accel.c | 113 ++++++++++++++++++++++++++++++++++++++++++++++++++ include/hw/accel.h | 32 ++++++++++++++ vl.c | 81 +----------------------------------- 4 files changed, 147 insertions(+), 80 deletions(-) create mode 100644 hw/core/accel.c create mode 100644 include/hw/accel.h
hw/core/Makefile.objs +1 -0
@@ -13,3 +13,4 @@ common-obj-$(CONFIG_SOFTMMU) += machine.o common-obj-$(CONFIG_SOFTMMU) += null-machine.o common-obj-$(CONFIG_SOFTMMU) += loader.o common-obj-$(CONFIG_SOFTMMU) += qdev-properties-system.o +common-obj-$(CONFIG_SOFTMMU) += accel.o
hw/core/accel.c new file +113 -0
113 lines not on this page · raw message
include/hw/accel.h new file +32 -0
@@ -0,0 +1,32 @@ +/* QEMU accelerator interfaces +* +* Copyright (c) 2014 Red Hat Inc +* +* Permission is hereby granted, free of charge, to any person obtaining a copy +* of this software and associated documentation files (the "Software"), to deal +* in the Software without restriction, including without limitation the rights +* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +* copies of the Software, and to permit persons to whom the Software is +* furnished to do so, subject to the following conditions: +* +* The above copyright notice and this permission notice shall be included in +* all copies or substantial portions of the Software. +* +* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +* THE SOFTWARE. +*/ +#ifndef HW_ACCEL_H +#define HW_ACCEL_H + +#include "qemu/typedefs.h" + +extern int tcg_tb_size; + +int configure_accelerator (MachineClass *mc); + +#endif
vl.c +1 -80
102 lines not on this page · raw message
Signature · 1 line
1.9.3
RFC 3/25 accel: Create struct AccelType
In reply to Eduardo Habkost--- hw/core/accel.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
hw/core/accel.c +4 -2
@@ -40,13 +40,15 @@ static int tcg_init(MachineClass *mc)return 0 ; } -static struct { +typedef struct AccelType {const char *opt_name;const char *name;int (*available)(void );int (*init)(MachineClass *mc);bool *allowed; -} accel_list[] = { +}AccelType ; + +static AccelType accel_list[] = { {"tcg" ,"tcg" , tcg_available, tcg_init, &tcg_allowed }, {"xen" ,"Xen" , xen_available, xen_init, &xen_allowed }, {"kvm" ,"KVM" , kvm_available, kvm_init, &kvm_allowed },
Signature · 1 line
1.9.3
RFC 4/25 accel: Simplify configure_accelerator() using AccelType *acc variable
In reply to Eduardo Habkost--- hw/core/accel.c | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-)
hw/core/accel.c +10 -8
@@ -62,6 +62,7 @@ int configure_accelerator(MachineClass *mc)int i, ret;bool accel_initialised = false;bool init_failed = false; +AccelType *acc =NULL ; p =qemu_opt_get (qemu_get_machine_opts (),"accel" );if (p ==NULL ) {
@@ -75,20 +76,21 @@ int configure_accelerator(MachineClass *mc) } p =get_opt_name (buf,sizeof (buf), p,':' );for (i =0 ; i <ARRAY_SIZE (accel_list); i++) { -if (strcmp (accel_list[i].opt_name, buf) ==0 ) { -if (!accel_list[i].available ()) { + acc = &accel_list[i]; +if (strcmp (acc->opt_name, buf) ==0 ) { +if (!acc->available ()) {printf ("%s not supported for this target\n" , - accel_list[i].name); + acc->name);break ; } - *(accel_list[i].allowed) = true; - ret = accel_list[i].init (mc); + *(acc->allowed) = true; + ret = acc->init (mc);if (ret <0 ) { init_failed = true;fprintf (stderr,"failed to initialize %s: %s\n" , - accel_list[i].name, + acc->name,strerror (-ret)); - *(accel_list[i].allowed) = false; + *(acc->allowed) = false; }else { accel_initialised = true; }
@@ -108,7 +110,7 @@ int configure_accelerator(MachineClass *mc) }if (init_failed) { -fprintf (stderr,"Back to %s accelerator.\n" , accel_list[i].name); +fprintf (stderr,"Back to %s accelerator.\n" , acc->name); }return !accel_initialised;
Signature · 1 line
1.9.3
RFC 5/25 accel: Move accel name lookup to separate function
In reply to Eduardo Habkost--- hw/core/accel.c | 57 +++++++++++++++++++++++++++++++++------------------------ 1 file changed, 33 insertions(+), 24 deletions(-)
hw/core/accel.c +33 -24
@@ -55,11 +55,24 @@ static AccelType accel_list[] = { { "qtest", "QTest", qtest_available, qtest_init_accel, &qtest_allowed }, }; +/* Lookup AccelType from opt_name. Returns NULL if not found */ +static AccelType *accel_find (const char *opt_name) +{ +int i; +for (i =0 ; i <ARRAY_SIZE (accel_list); i++) { +AccelType *acc = &accel_list[i]; +if (acc->opt_name &&strcmp (acc->opt_name, opt_name) ==0 ) { +return acc; + } + } +return NULL ; +} +int configure_accelerator (MachineClass *mc) {const char *p;char buf[10 ]; -int i, ret; +int ret;bool accel_initialised = false;bool init_failed = false;AccelType *acc =NULL ;
@@ -75,30 +88,26 @@ int configure_accelerator(MachineClass *mc) p++; } p =get_opt_name (buf,sizeof (buf), p,':' ); -for (i =0 ; i <ARRAY_SIZE (accel_list); i++) { - acc = &accel_list[i]; -if (strcmp (acc->opt_name, buf) ==0 ) { -if (!acc->available ()) { -printf ("%s not supported for this target\n" , - acc->name); -break ; - } - *(acc->allowed) = true; - ret = acc->init (mc); -if (ret <0 ) { - init_failed = true; -fprintf (stderr,"failed to initialize %s: %s\n" , - acc->name, -strerror (-ret)); - *(acc->allowed) = false; - }else { - accel_initialised = true; - } -break ; - } - } -if (i ==ARRAY_SIZE (accel_list)) { + acc =accel_find (buf); +if (!acc) {fprintf (stderr,"\"%s\" accelerator does not exist.\n" , buf); +continue ; + } +if (!acc->available ()) { +printf ("%s not supported for this target\n" , + acc->name); +continue ; + } + *(acc->allowed) = true; + ret = acc->init (mc); +if (ret <0 ) { + init_failed = true; +fprintf (stderr,"failed to initialize %s: %s\n" , + acc->name, +strerror (-ret)); + *(acc->allowed) = false; + }else { + accel_initialised = true; } }
Signature · 1 line
1.9.3
RFC 6/25 accel: Use QOM classes for accel types
In reply to Eduardo Habkost--- hw/core/accel.c | 117 ++++++++++++++++++++++++++++++++++++++++++----------- include/hw/accel.h | 27 +++++++++++++ 2 files changed, 120 insertions(+), 24 deletions(-)
hw/core/accel.c +93 -24
@@ -30,6 +30,7 @@#include "sysemu/kvm.h" #include "sysemu/qtest.h" #include "hw/xen/xen.h" +#include "qom/object.h" int tcg_tb_size;static bool tcg_allowed = true;
@@ -40,32 +41,20 @@ static int tcg_init(MachineClass *mc)return 0 ; } -typedef struct AccelType { -const char *opt_name; -const char *name; -int (*available)(void ); -int (*init)(MachineClass *mc); -bool *allowed; -}AccelType ; - -static AccelType accel_list[] = { - {"tcg" ,"tcg" , tcg_available, tcg_init, &tcg_allowed }, - {"xen" ,"Xen" , xen_available, xen_init, &xen_allowed }, - {"kvm" ,"KVM" , kvm_available, kvm_init, &kvm_allowed }, - {"qtest" ,"QTest" , qtest_available, qtest_init_accel, &qtest_allowed }, +static const TypeInfo accel_type = { + .name =TYPE_ACCEL , + .parent =TYPE_OBJECT , + .class_size =sizeof (AccelClass), + .instance_size =sizeof (AccelState), }; -/* Lookup AccelType from opt_name. Returns NULL if not found */ -static AccelType *accel_find (const char *opt_name) +/* Lookup AccelClass from opt_name. Returns NULL if not found */ +static AccelClass *accel_find (const char *opt_name) { -int i; -for (i =0 ; i <ARRAY_SIZE (accel_list); i++) { -AccelType *acc = &accel_list[i]; -if (acc->opt_name &&strcmp (acc->opt_name, opt_name) ==0 ) { -return acc; - } - } -return NULL ; +char *class_name =g_strdup_printf ("%s-accel" , opt_name); +AccelClass *ac =ACCEL_CLASS (object_class_by_name (class_name)); +g_free (class_name); +return ac; }int configure_accelerator (MachineClass *mc)
@@ -75,7 +64,7 @@ int configure_accelerator(MachineClass *mc)int ret;bool accel_initialised = false;bool init_failed = false; -AccelType *acc =NULL ; +AccelClass *acc =NULL ; p =qemu_opt_get (qemu_get_machine_opts (),"accel" );if (p ==NULL ) {
@@ -124,3 +113,83 @@ int configure_accelerator(MachineClass *mc)return !accel_initialised; } + + +static void tcg_accel_class_init (ObjectClass *oc,void *data) +{ +AccelClass *ac =ACCEL_CLASS (oc); + ac->name ="tcg" ; + ac->available = tcg_available; + ac->init = tcg_init; + ac->allowed = &tcg_allowed; +} + +#define TYPE_TCG_ACCEL "tcg-accel" + +static const TypeInfo tcg_accel_type = { + .name =TYPE_TCG_ACCEL , + .parent =TYPE_ACCEL , + .class_init = tcg_accel_class_init, +}; + +static void xen_accel_class_init (ObjectClass *oc,void *data) +{ +AccelClass *ac =ACCEL_CLASS (oc); + ac->name ="Xen" ; + ac->available = xen_available; + ac->init = xen_init; + ac->allowed = &xen_allowed; +} + +#define TYPE_XEN_ACCEL "xen-accel" + +static const TypeInfo xen_accel_type = { + .name =TYPE_XEN_ACCEL , + .parent =TYPE_ACCEL , + .class_init = xen_accel_class_init, +}; + +static void kvm_accel_class_init (ObjectClass *oc,void *data) +{ +AccelClass *ac =ACCEL_CLASS (oc); + ac->name ="KVM" ; + ac->available = kvm_available; + ac->init = kvm_init; + ac->allowed = &kvm_allowed; +} + +#define TYPE_KVM_ACCEL "kvm-accel" + +static const TypeInfo kvm_accel_type = { + .name =TYPE_KVM_ACCEL , + .parent =TYPE_ACCEL , + .class_init = kvm_accel_class_init, +}; + +static void qtest_accel_class_init (ObjectClass *oc,void *data) +{ +AccelClass *ac =ACCEL_CLASS (oc); + ac->name ="QTest" ; + ac->available = qtest_available; + ac->init = qtest_init_accel; + ac->allowed = &qtest_allowed; +} + +#define TYPE_QTEST_ACCEL "qtest-accel" + +static const TypeInfo qtest_accel_type = { + .name =TYPE_QTEST_ACCEL , + .parent =TYPE_ACCEL , + .class_init = qtest_accel_class_init, +}; + +static void register_accel_types (void ) +{ +type_register_static (&accel_type); +type_register_static (&tcg_accel_type); +type_register_static (&xen_accel_type); +type_register_static (&kvm_accel_type); +type_register_static (&qtest_accel_type); +} + +type_init (register_accel_types);
include/hw/accel.h +27 -0
@@ -24,6 +24,33 @@#define HW_ACCEL_H #include "qemu/typedefs.h" +#include "qom/object.h" + +typedef struct AccelState { +/*< private >*/ +Object parent_obj; +}AccelState ; + +typedef struct AccelClass { +/*< private >*/ +ObjectClass parent_class; +/*< public >*/ + +const char *opt_name; +const char *name; +int (*available)(void ); +int (*init)(MachineClass *mc); +bool *allowed; +}AccelClass ; + +#define TYPE_ACCEL "accel" + +#define ACCEL_CLASS (klass) \ + OBJECT_CLASS_CHECK(AccelClass, (klass), TYPE_ACCEL) +#define ACCEL (obj) \ + OBJECT_CHECK(AccelState, (obj), TYPE_ACCEL) +#define ACCEL_GET_CLASS (obj) \ + OBJECT_GET_CLASS(AccelClass, (obj), TYPE_ACCEL)extern int tcg_tb_size;
Signature · 1 line
1.9.3
RFC 7/25 accel: Make AccelClass.available() optional
In reply to Eduardo HabkostWhen we move accel classes outside accel.c, the available() function won't be necessary anymore, because the classes will be registered only if the accelerator code is really enable at build time.
--- hw/core/accel.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
hw/core/accel.c +1 -1
@@ -82,7 +82,7 @@ int configure_accelerator(MachineClass *mc)fprintf (stderr,"\"%s\" accelerator does not exist.\n" , buf);continue ; } -if (!acc->available ()) { +if (acc->available && !acc->available ()) {printf ("%s not supported for this target\n" , acc->name);continue ;
Signature · 1 line
1.9.3
RFC 8/25 accel: Move KVM accel registration to kvm-all.c
In reply to Eduardo HabkostNote that this has an user-visible side-effect: instead of reporting "KVM is not supported for this target", QEMU binaries not supporting KVM will report "kvm accelerator does not exist".
As kvm_availble() always return 1 when CONFIG_KVM is enabled, we don't need to set AccelClass.available anymore. kvm_enabled() is not being completely removed yet only because qmp_query_kvm() still uses it.
This also allows us to make kvm_init() static.
--- hw/core/accel.c | 18 ------------------ include/sysemu/kvm.h | 2 -- kvm-all.c | 28 +++++++++++++++++++++++++++- kvm-stub.c | 5 ----- 4 files changed, 27 insertions(+), 26 deletions(-)
hw/core/accel.c +0 -18
@@ -149,23 +149,6 @@ static const TypeInfo xen_accel_type = { .class_init = xen_accel_class_init, }; -static void kvm_accel_class_init (ObjectClass *oc,void *data) -{ -AccelClass *ac =ACCEL_CLASS (oc); - ac->name ="KVM" ; - ac->available = kvm_available; - ac->init = kvm_init; - ac->allowed = &kvm_allowed; -} - -#define TYPE_KVM_ACCEL "kvm-accel" - -static const TypeInfo kvm_accel_type = { - .name =TYPE_KVM_ACCEL , - .parent =TYPE_ACCEL , - .class_init = kvm_accel_class_init, -}; -static void qtest_accel_class_init (ObjectClass *oc,void *data) {AccelClass *ac =ACCEL_CLASS (oc);
@@ -188,7 +171,6 @@ static void register_accel_types(void)type_register_static (&accel_type);type_register_static (&tcg_accel_type);type_register_static (&xen_accel_type); -type_register_static (&kvm_accel_type);type_register_static (&qtest_accel_type); }
include/sysemu/kvm.h +0 -2
@@ -163,8 +163,6 @@ extern KVMState *kvm_state;/* external API */ -int kvm_init (MachineClass *mc); -int kvm_has_sync_mmu (void );int kvm_has_vcpu_events (void );int kvm_has_robust_singlestep (void );
kvm-all.c +27 -1
@@ -26,6 +26,7 @@#include "qemu/config-file.h" #include "sysemu/sysemu.h" #include "hw/hw.h" +#include "hw/accel.h" #include "hw/pci/msi.h" #include "hw/s390x/adapter.h" #include "exec/gdbstub.h"
@@ -110,6 +111,8 @@ struct KVMState#endif }; +#define TYPE_KVM_ACCEL "kvm-accel" +KVMState *kvm_state;bool kvm_kernel_irqchip;bool kvm_async_interrupts_allowed;
@@ -1368,7 +1371,7 @@ static int kvm_max_vcpus(KVMState *s)return (ret) ? ret :kvm_recommended_vcpus (s); } -int kvm_init (MachineClass *mc) +static int kvm_init (MachineClass *mc) {static const char upgrade_note[] ="Please upgrade to at least kernel 2.6.29 or recent kvm-kmod\n"
@@ -2198,3 +2201,26 @@ int kvm_get_one_reg(CPUState *cs, uint64_t id, void *target) }return r; } + +static void kvm_accel_class_init (ObjectClass *oc,void *data) +{ +AccelClass *ac =ACCEL_CLASS (oc); + ac->name ="KVM" ; + ac->init = kvm_init; + ac->allowed = &kvm_allowed; +} + +#define TYPE_KVM_ACCEL "kvm-accel" + +static const TypeInfo kvm_accel_type = { + .name =TYPE_KVM_ACCEL , + .parent =TYPE_ACCEL , + .class_init = kvm_accel_class_init, +}; + +static void kvm_type_init (void ) +{ +type_register_static (&kvm_accel_type); +} + +type_init (kvm_type_init);
kvm-stub.c +0 -5
@@ -35,11 +35,6 @@ int kvm_init_vcpu(CPUState *cpu)return -ENOSYS ; } -int kvm_init (MachineClass *mc) -{ -return -ENOSYS ; -} -void kvm_flush_coalesced_mmio_buffer (void ) { }
Signature · 1 line
1.9.3
RFC 9/25 accel: Move Xen registration code to xen-common.c
In reply to Eduardo HabkostNote that this has an user-visible side-effect: instead of reporting "Xen is not supported for this target", QEMU binaries not supporting Xen will report "xen accelerator does not exist".
As xen_available() always return 1 when CONFIG_XEN is enabled, we don't need to set AccelClass.available anymore. xen_enabled() is not being is not being removed yet, only because vl.c is still using it.
This also allows us to make xen_init() static.
--- hw/core/accel.c | 18 ------------------ include/hw/xen/xen.h | 1 - xen-common-stub.c | 6 ------ xen-common.c | 25 ++++++++++++++++++++++++- 4 files changed, 24 insertions(+), 26 deletions(-)
hw/core/accel.c +0 -18
@@ -132,23 +132,6 @@ static const TypeInfo tcg_accel_type = { .class_init = tcg_accel_class_init, }; -static void xen_accel_class_init (ObjectClass *oc,void *data) -{ -AccelClass *ac =ACCEL_CLASS (oc); - ac->name ="Xen" ; - ac->available = xen_available; - ac->init = xen_init; - ac->allowed = &xen_allowed; -} - -#define TYPE_XEN_ACCEL "xen-accel" - -static const TypeInfo xen_accel_type = { - .name =TYPE_XEN_ACCEL , - .parent =TYPE_ACCEL , - .class_init = xen_accel_class_init, -}; -static void qtest_accel_class_init (ObjectClass *oc,void *data) {AccelClass *ac =ACCEL_CLASS (oc);
@@ -170,7 +153,6 @@ static void register_accel_types(void) {type_register_static (&accel_type);type_register_static (&tcg_accel_type); -type_register_static (&xen_accel_type);type_register_static (&qtest_accel_type); }
include/hw/xen/xen.h +0 -1
@@ -36,7 +36,6 @@ void xen_cmos_set_s3_resume(void *opaque, int irq, int level);qemu_irq *xen_interrupt_controller_init (void ); -int xen_init (MachineClass *mc);void xenstore_store_pv_console_info (int i,struct CharDriverState *chr);#if defined(NEED_CPU_H ) && !defined(CONFIG_USER_ONLY )
xen-common-stub.c +0 -6
@@ -11,9 +11,3 @@void xenstore_store_pv_console_info (int i,CharDriverState *chr) { } - -int xen_init (MachineClass *mc) -{ -return -ENOSYS ; -} -
xen-common.c +24 -1
@@ -9,6 +9,7 @@*/ #include "hw/xen/xen_backend.h" +#include "hw/accel.h" #include "qmp-commands.h" #include "sysemu/char.h"
@@ -109,7 +110,7 @@ static void xen_change_state_handler(void *opaque, int running, } } -int xen_init (MachineClass *mc) +static int xen_init (MachineClass *mc) { xen_xc =xen_xc_interface_open (0 ,0 ,0 );if (xen_xc ==XC_HANDLER_INITIAL_VALUE ) {
@@ -121,3 +122,25 @@ int xen_init(MachineClass *mc)return 0 ; } +static void xen_accel_class_init (ObjectClass *oc,void *data) +{ +AccelClass *ac =ACCEL_CLASS (oc); + ac->name ="Xen" ; + ac->init = xen_init; + ac->allowed = &xen_allowed; +} + +#define TYPE_XEN_ACCEL "xen-accel" + +static const TypeInfo xen_accel_type = { + .name =TYPE_XEN_ACCEL , + .parent =TYPE_ACCEL , + .class_init = xen_accel_class_init, +}; + +static void xen_type_init (void ) +{ +type_register_static (&xen_accel_type); +} + +type_init (xen_type_init);
Signature · 1 line
1.9.3
RFC 10/25 accel: Move qtest accel registration to qtest.c
In reply to Eduardo HabkostAs qtest_availble() returns 1 only when CONFIG_POSIX is set, keep setting AccelClass.available to keep current behavior (this is different from what we did for KVM and Xen).
This also allows us to make qtest_init_accel() static.
--- hw/core/accel.c | 18 ------------------ include/sysemu/qtest.h | 1 - qtest.c | 27 ++++++++++++++++++++++++++- 3 files changed, 26 insertions(+), 20 deletions(-)
hw/core/accel.c +0 -18
@@ -132,28 +132,10 @@ static const TypeInfo tcg_accel_type = { .class_init = tcg_accel_class_init, }; -static void qtest_accel_class_init (ObjectClass *oc,void *data) -{ -AccelClass *ac =ACCEL_CLASS (oc); - ac->name ="QTest" ; - ac->available = qtest_available; - ac->init = qtest_init_accel; - ac->allowed = &qtest_allowed; -} - -#define TYPE_QTEST_ACCEL "qtest-accel" - -static const TypeInfo qtest_accel_type = { - .name =TYPE_QTEST_ACCEL , - .parent =TYPE_ACCEL , - .class_init = qtest_accel_class_init, -}; -static void register_accel_types (void ) {type_register_static (&accel_type);type_register_static (&tcg_accel_type); -type_register_static (&qtest_accel_type); }type_init (register_accel_types);
include/sysemu/qtest.h +0 -1
@@ -26,7 +26,6 @@ static inline bool qtest_enabled(void)bool qtest_driver (void ); -int qtest_init_accel (MachineClass *mc);void qtest_init (const char *qtest_chrdev,const char *qtest_log,Error **errp);static inline int qtest_available (void )
qtest.c +26 -1
@@ -17,6 +17,7 @@#include "exec/ioport.h" #include "exec/memory.h" #include "hw/irq.h" +#include "hw/accel.h" #include "sysemu/sysemu.h" #include "sysemu/cpus.h"
@@ -509,7 +510,7 @@ static void qtest_event(void *opaque, int event) } } -int qtest_init_accel (MachineClass *mc) +static int qtest_init_accel (MachineClass *mc) {configure_icount ("0" );
@@ -548,3 +549,27 @@ bool qtest_driver(void) {return qtest_chr; } + +static void qtest_accel_class_init (ObjectClass *oc,void *data) +{ +AccelClass *ac =ACCEL_CLASS (oc); + ac->name ="QTest" ; + ac->available = qtest_available; + ac->init = qtest_init_accel; + ac->allowed = &qtest_allowed; +} + +#define TYPE_QTEST_ACCEL "qtest-accel" + +static const TypeInfo qtest_accel_type = { + .name =TYPE_QTEST_ACCEL , + .parent =TYPE_ACCEL , + .class_init = qtest_accel_class_init, +}; + +static void qtest_type_init (void ) +{ +type_register_static (&qtest_accel_type); +} + +type_init (qtest_type_init);
Signature · 1 line
1.9.3
RFC 11/25 accel: Remove tcg_available() function
In reply to Eduardo HabkostAs the function always return 1, it is not needed anymore.
--- arch_init.c | 5 ----- hw/core/accel.c | 1 - include/sysemu/arch_init.h | 1 - 3 files changed, 7 deletions(-)
arch_init.c +0 -5
@@ -1335,11 +1335,6 @@ void cpudef_init(void)#endif } -int tcg_available (void ) -{ -return 1 ; -} -int kvm_available (void ) {#ifdef CONFIG_KVM
hw/core/accel.c +0 -1
@@ -119,7 +119,6 @@ static void tcg_accel_class_init(ObjectClass *oc, void *data) {AccelClass *ac =ACCEL_CLASS (oc); ac->name ="tcg" ; - ac->available = tcg_available; ac->init = tcg_init; ac->allowed = &tcg_allowed; }
include/sysemu/arch_init.h +0 -1
@@ -32,7 +32,6 @@ void do_smbios_option(QemuOpts *opts);void ram_mig_init (void );void cpudef_init (void );void audio_init (void ); -int tcg_available (void );int kvm_available (void );int xen_available (void );
Signature · 1 line
1.9.3
RFC 12/25 accel: Move accel init/allowed code to separate function
In reply to Eduardo Habkost--- hw/core/accel.c | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-)
hw/core/accel.c +12 -3
@@ -57,6 +57,17 @@ static AccelClass *accel_find(const char *opt_name)return ac; } +static int accel_init (AccelClass *acc,MachineClass *mc) +{ +int ret; + *(acc->allowed) = true; + ret = acc->init (mc); +if (ret <0 ) { + *(acc->allowed) = false; + } +return ret; +} +int configure_accelerator (MachineClass *mc) {const char *p;
@@ -87,14 +98,12 @@ int configure_accelerator(MachineClass *mc) acc->name);continue ; } - *(acc->allowed) = true; - ret = acc->init (mc); + ret =accel_init (acc, mc);if (ret <0 ) { init_failed = true;fprintf (stderr,"failed to initialize %s: %s\n" , acc->name,strerror (-ret)); - *(acc->allowed) = false; }else { accel_initialised = true; }
Signature · 1 line
1.9.3
RFC 13/25 accel: Rename 'init' method to 'init_machine'
In reply to Eduardo HabkostThis makes more explicit the fact that the method is for machine initialization, not just for accelerator object initialization.
--- hw/core/accel.c | 8 ++++---- include/hw/accel.h | 2 +- kvm-all.c | 2 +- qtest.c | 2 +- xen-common.c | 2 +- 5 files changed, 8 insertions(+), 8 deletions(-)
hw/core/accel.c +4 -4
@@ -57,11 +57,11 @@ static AccelClass *accel_find(const char *opt_name)return ac; } -static int accel_init (AccelClass *acc,MachineClass *mc) +static int accel_init_machine (AccelClass *acc,MachineClass *mc) {int ret; *(acc->allowed) = true; - ret = acc->init (mc); + ret = acc->init_machine (mc);if (ret <0 ) { *(acc->allowed) = false; }
@@ -98,7 +98,7 @@ int configure_accelerator(MachineClass *mc) acc->name);continue ; } - ret =accel_init (acc, mc); + ret =accel_init_machine (acc, mc);if (ret <0 ) { init_failed = true; fprintf(stderr, "failed to initialize %s: %s\n",
@@ -128,7 +128,7 @@ static void tcg_accel_class_init(ObjectClass *oc, void *data) {AccelClass *ac =ACCEL_CLASS (oc); ac->name ="tcg" ; - ac->init = tcg_init; + ac->init_machine = tcg_init; ac->allowed = &tcg_allowed; }
include/hw/accel.h +1 -1
@@ -39,7 +39,7 @@ typedef struct AccelClass {const char *opt_name;const char *name;int (*available)(void ); -int (*init)(MachineClass *mc); +int (*init_machine)(MachineClass *mc);bool *allowed; } AccelClass;
kvm-all.c +1 -1
@@ -2206,7 +2206,7 @@ static void kvm_accel_class_init(ObjectClass *oc, void *data) {AccelClass *ac =ACCEL_CLASS (oc); ac->name ="KVM" ; - ac->init = kvm_init; + ac->init_machine = kvm_init; ac->allowed = &kvm_allowed; }
qtest.c +1 -1
@@ -555,7 +555,7 @@ static void qtest_accel_class_init(ObjectClass *oc, void *data)AccelClass *ac =ACCEL_CLASS (oc); ac->name ="QTest" ; ac->available = qtest_available; - ac->init = qtest_init_accel; + ac->init_machine = qtest_init_accel; ac->allowed = &qtest_allowed; }
xen-common.c +1 -1
@@ -126,7 +126,7 @@ static void xen_accel_class_init(ObjectClass *oc, void *data) {AccelClass *ac =ACCEL_CLASS (oc); ac->name ="Xen" ; - ac->init = xen_init; + ac->init_machine = xen_init; ac->allowed = &xen_allowed; }
Signature · 1 line
1.9.3
RFC 14/25 accel: Pass MachineState object to accel init functions
In reply to Eduardo HabkostMost of the machine options and machine state information is in the MachineState object, not on the MachineClass. This will allow init functions to use the MachineState object directly instead of the qemu_get_machine_opts() or current_machine globals, and get the AccelState object using MachineState.accelerator.
--- hw/core/accel.c | 11 ++++++----- include/hw/accel.h | 4 ++-- include/qemu/typedefs.h | 1 + kvm-all.c | 3 ++- qtest.c | 2 +- vl.c | 2 +- xen-common.c | 2 +- 7 files changed, 14 insertions(+), 11 deletions(-)
hw/core/accel.c +6 -5
@@ -24,6 +24,7 @@*/ #include "hw/accel.h" +#include "hw/boards.h" #include "qemu-common.h" #include "sysemu/arch_init.h" #include "sysemu/sysemu.h"
@@ -35,7 +36,7 @@int tcg_tb_size;static bool tcg_allowed = true; -static int tcg_init (MachineClass *mc) +static int tcg_init (MachineState *ms) {tcg_exec_init (tcg_tb_size *1024 *1024 );return 0 ;
@@ -57,18 +58,18 @@ static AccelClass *accel_find(const char *opt_name)return ac; } -static int accel_init_machine (AccelClass *acc,MachineClass *mc) +static int accel_init_machine (AccelClass *acc,MachineState *ms) {int ret; *(acc->allowed) = true; - ret = acc->init_machine (mc); + ret = acc->init_machine (ms);if (ret <0 ) { *(acc->allowed) = false; }return ret; } -int configure_accelerator (MachineClass *mc) +int configure_accelerator (MachineState *ms) {const char *p;char buf[10 ];
@@ -98,7 +99,7 @@ int configure_accelerator(MachineClass *mc) acc->name);continue ; } - ret =accel_init_machine (acc, mc); + ret =accel_init_machine (acc, ms);if (ret <0 ) { init_failed = true; fprintf(stderr, "failed to initialize %s: %s\n",
include/hw/accel.h +2 -2
@@ -39,7 +39,7 @@ typedef struct AccelClass {const char *opt_name;const char *name;int (*available)(void ); -int (*init_machine)(MachineClass *mc); +int (*init_machine)(MachineState *ms);bool *allowed; } AccelClass;
@@ -54,6 +54,6 @@ typedef struct AccelClass {extern int tcg_tb_size; -int configure_accelerator (MachineClass *mc); +int configure_accelerator (MachineState *ms);#endif
include/qemu/typedefs.h +1 -0
@@ -32,6 +32,7 @@ typedef struct MemoryMappingList MemoryMappingList;typedef struct QEMUMachine QEMUMachine ;typedef struct MachineClass MachineClass ; +typedef struct MachineState MachineState ;typedef struct NICInfo NICInfo ;typedef struct HCIInfo HCIInfo ;typedef struct AudioState AudioState ;
kvm-all.c +2 -1
@@ -1371,8 +1371,9 @@ static int kvm_max_vcpus(KVMState *s)return (ret) ? ret :kvm_recommended_vcpus (s); } -static int kvm_init (MachineClass *mc) +static int kvm_init (MachineState *ms) { +MachineClass *mc =MACHINE_GET_CLASS (ms);static const char upgrade_note[] ="Please upgrade to at least kernel 2.6.29 or recent kvm-kmod\n" "(see http://sourceforge.net/projects/kvm).\n" ;
qtest.c +1 -1
@@ -510,7 +510,7 @@ static void qtest_event(void *opaque, int event) } } -static int qtest_init_accel (MachineClass *mc) +static int qtest_init_accel (MachineState *ms) {configure_icount ("0" );
vl.c +1 -1
@@ -4142,7 +4142,7 @@ int main(int argc, char **argv, char **envp)exit (1 ); } -configure_accelerator (machine_class); +configure_accelerator (current_machine);if (qtest_chrdev) {Error *local_err =NULL ;
xen-common.c +1 -1
@@ -110,7 +110,7 @@ static void xen_change_state_handler(void *opaque, int running, } } -static int xen_init (MachineClass *mc) +static int xen_init (MachineState *ms) { xen_xc =xen_xc_interface_open (0 ,0 ,0 );if (xen_xc ==XC_HANDLER_INITIAL_VALUE ) {
Signature · 1 line
1.9.3
RFC 15/25 accel: Create accel object when initializing machine
In reply to Eduardo Habkost--- hw/core/accel.c | 4 ++++ 1 file changed, 4 insertions(+)
hw/core/accel.c +4 -0
@@ -60,11 +60,15 @@ static AccelClass *accel_find(const char *opt_name)static int accel_init_machine (AccelClass *acc,MachineState *ms) { +ObjectClass *oc =OBJECT_CLASS (acc); +const char *cname =object_class_get_name (oc); +AccelState *accel =ACCEL (object_new (cname));int ret; *(acc->allowed) = true; ret = acc->init_machine (ms);if (ret <0 ) { *(acc->allowed) = false; +object_unref (OBJECT (accel)); }return ret; }
Signature · 1 line
1.9.3
RFC 16/25 accel: Save AccelState on MachineState when initializing
In reply to Eduardo Habkost--- hw/core/accel.c | 3 +++ include/hw/boards.h | 1 + include/qemu/typedefs.h | 2 ++ 3 files changed, 6 insertions(+)
hw/core/accel.c +3 -0
@@ -32,6 +32,7 @@#include "sysemu/qtest.h" #include "hw/xen/xen.h" #include "qom/object.h" +#include "hw/boards.h" int tcg_tb_size;static bool tcg_allowed = true;
@@ -64,9 +65,11 @@ static int accel_init_machine(AccelClass *acc, MachineState *ms)const char *cname =object_class_get_name (oc);AccelState *accel =ACCEL (object_new (cname));int ret; + ms->accelerator = accel; *(acc->allowed) = true; ret = acc->init_machine (ms);if (ret <0 ) { + ms->accelerator =NULL ; *(acc->allowed) = false;object_unref (OBJECT (accel)); }
include/hw/boards.h +1 -0
@@ -132,6 +132,7 @@ struct MachineState {char *kernel_cmdline;char *initrd_filename;const char *cpu_model; + AccelState *accelerator; };#endif
include/qemu/typedefs.h +2 -0
@@ -30,6 +30,8 @@ typedef struct MemoryListener MemoryListener;typedef struct MemoryMappingList MemoryMappingList ; +typedef struct AccelState AccelState ; +typedef struct QEMUMachine QEMUMachine ;typedef struct MachineClass MachineClass ;typedef struct MachineState MachineState ;
Signature · 1 line
1.9.3
RFC 17/25 kvm: Make KVMState be the TYPE_KVM_ACCEL instance struct
In reply to Eduardo HabkostNow that we create an accel object before calling machine_init, we can simply use the object to save all KVMState data.
--- kvm-all.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-)
kvm-all.c +9 -4
@@ -75,8 +75,10 @@ typedef struct KVMSlottypedef struct kvm_dirty_log KVMDirtyLog ; -struct KVMState +typedef struct KVMState { + AccelState parent_obj; + KVMSlot *slots; int nr_slots; int fd;
@@ -109,10 +111,13 @@ struct KVMState QTAILQ_HEAD(msi_hashtab, KVMMSIRoute) msi_hashtab[KVM_MSI_HASHTAB_SIZE];bool direct_msi;#endif -}; +} KVMState;#define TYPE_KVM_ACCEL "kvm-accel" +#define KVM_STATE (obj) \ + OBJECT_CHECK(KVMState, (obj), TYPE_KVM_ACCEL) +KVMState *kvm_state;bool kvm_kernel_irqchip;bool kvm_async_interrupts_allowed;
@@ -1392,7 +1397,7 @@ static int kvm_init(MachineState *ms)int i, type =0 ;const char *kvm_type; - s =g_malloc0 (sizeof (KVMState)); + s =KVM_STATE (ms->accelerator);/* * On systems where the kernel can support different base page
@@ -1581,7 +1586,6 @@ err:close (s->fd); }g_free (s->slots); -g_free (s);return ret; }
@@ -2217,6 +2221,7 @@ static const TypeInfo kvm_accel_type = { .name = TYPE_KVM_ACCEL, .parent = TYPE_ACCEL, .class_init = kvm_accel_class_init, + .instance_size = sizeof(KVMState), };static void kvm_type_init (void )
Signature · 1 line
1.9.3
RFC 18/25 accel: Get target name as argument when initializing accelerator
In reply to Eduardo HabkostWe will look for target-specific accel subclasses, if available.
--- arch_init.c | 6 ++++++ hw/core/accel.c | 2 +- include/hw/accel.h | 1 + 3 files changed, 8 insertions(+), 1 deletion(-)
arch_init.c +6 -0
@@ -52,6 +52,7 @@#include "exec/ram_addr.h" #include "hw/acpi/acpi.h" #include "qemu/host-utils.h" +#include "hw/accel.h" #ifdef DEBUG_ARCH_INIT #define DPRINTF (fmt, ...) \
@@ -155,6 +156,11 @@ int qemu_read_default_config_files(bool userconfig)return 0 ; } +int configure_accelerator (MachineState *ms) +{ +return init_accelerator (ms,TARGET_NAME ); +} +static inline bool is_zero_range (uint8_t *p,uint64_t size) {return buffer_find_nonzero_offset (p, size) == size;
hw/core/accel.c +1 -1
@@ -76,7 +76,7 @@ static int accel_init_machine(AccelClass *acc, MachineState *ms)return ret; } -int configure_accelerator (MachineState *ms) +int init_accelerator (MachineState *ms,const char *target_name) {const char *p;char buf[10 ];
include/hw/accel.h +1 -0
@@ -55,5 +55,6 @@ typedef struct AccelClass {extern int tcg_tb_size;int configure_accelerator (MachineState *ms); +int init_accelerator (MachineState *ms,const char *target_name);#endif
Signature · 1 line
1.9.3
RFC 19/25 accel: Use target-specific accel class if available
In reply to Eduardo HabkostTarget-specific accelerator subclasses are optional. If a given accelerator type needs to make it mandatory, the base class can be made abstract.
--- hw/core/accel.c | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-)
hw/core/accel.c +17 -3
@@ -51,11 +51,25 @@ static const TypeInfo accel_type = { };/* Lookup AccelClass from opt_name. Returns NULL if not found */ -static AccelClass *accel_find (const char *opt_name) +static AccelClass *accel_find (const char *opt_name,const char *target_name) {char *class_name =g_strdup_printf ("%s-accel" , opt_name); -AccelClass *ac =ACCEL_CLASS (object_class_by_name (class_name)); +char *target_class_name =g_strdup_printf ("%s-%s-accel" , + target_name, opt_name); +ObjectClass *oc; +AccelClass *ac; + oc =object_class_by_name (target_class_name); +if (!oc) { + oc =object_class_by_name (class_name); + } +/* Must be a TYPE_ACCEL subclass, and not abstract */ + oc =object_class_dynamic_cast (oc,TYPE_ACCEL ); +if (oc &&object_class_is_abstract (oc)) { + oc =NULL ; + } + ac =ACCEL_CLASS (oc);g_free (class_name); +g_free (target_class_name);return ac; }
@@ -96,7 +110,7 @@ int init_accelerator(MachineState *ms, const char *target_name) p++; } p =get_opt_name (buf,sizeof (buf), p,':' ); - acc =accel_find (buf); + acc =accel_find (buf, target_name);if (!acc) {fprintf (stderr,"\"%s\" accelerator does not exist.\n" , buf);continue ;
Signature · 1 line
1.9.3
RFC 20/25 accel: TYPE_X86_ACCEL interface
In reply to Eduardo Habkost--- include/hw/i386/accel.h | 35 +++++++++++++++++++++++++++++++++++ target-i386/Makefile.objs | 1 + target-i386/accel.c | 38 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 74 insertions(+) create mode 100644 include/hw/i386/accel.h create mode 100644 target-i386/accel.c
include/hw/i386/accel.h new file +35 -0
@@ -0,0 +1,35 @@ +/* TYPE_X86_ACCEL interface +*/ +#ifndef HW_I386_ACCEL_H +#define HW_I386_ACCEL_H + +#include "hw/accel.h" + +#define TYPE_X86_ACCEL "x86-accel" + +#define X86_ACCEL_CLASS (klass) \ + OBJECT_CLASS_CHECK(X86AccelClass, (klass), TYPE_X86_ACCEL) +#define X86_ACCEL_GET_CLASS (obj) \ + OBJECT_GET_CLASS(X86AccelClass, (obj), TYPE_X86_ACCEL) +#define X86_ACCEL (obj) \ + INTERFACE_CHECK(X86Accel, (obj), TYPE_X86_ACCEL) + + +typedef struct X86Accel { +/* <private> */ +Object Parent; +}X86Accel ; + +/** +* HotplugDeviceClass: +* +* Interface that may be implemented by target-specific accelerator +* classes. +*/ +typedef struct X86AccelClass { +/* <private> */ +InterfaceClass parent; +}X86AccelClass ; + + +#endif
target-i386/Makefile.objs +1 -0
@@ -2,6 +2,7 @@ obj-y += translate.o helper.o cpu.o obj-y += excp_helper.o fpu_helper.o cc_helper.o int_helper.o svm_helper.o obj-y += smm_helper.o misc_helper.o mem_helper.o seg_helper.o obj-y += gdbstub.o +obj-y += accel.o obj-$(CONFIG_SOFTMMU) += machine.o arch_memory_mapping.o arch_dump.o obj-$(CONFIG_KVM) += kvm.o obj-$(call lnot,$(CONFIG_KVM)) += kvm-stub.o
target-i386/accel.c new file +38 -0
@@ -0,0 +1,38 @@ +/* TYPE_X86_ACCEL interface +* +* Copyright (c) 2014 Red Hat Inc. +* +* Permission is hereby granted, free of charge, to any person obtaining a copy +* of this software and associated documentation files (the "Software"), to deal +* in the Software without restriction, including without limitation the rights +* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +* copies of the Software, and to permit persons to whom the Software is +* furnished to do so, subject to the following conditions: +* +* The above copyright notice and this permission notice shall be included in +* all copies or substantial portions of the Software. +* +* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +* THE SOFTWARE. +*/ + +#include "qemu/module.h" +#include "hw/i386/accel.h" + +static const TypeInfo x86_accel_type = { + .name =TYPE_X86_ACCEL , + .parent =TYPE_INTERFACE , + .class_size =sizeof (X86AccelClass), +}; + +static void x86_accel_type_init (void ) +{ +type_register_static (&x86_accel_type); +} + +type_init (x86_accel_type_init);
Signature · 1 line
1.9.3
RFC 21/25 kvm: x86 KVM accelerator subclass
In reply to Eduardo HabkostImplements TYPE_X86_ACCEL.
--- include/sysemu/kvm.h | 3 +++ kvm-all.c | 2 -- target-i386/kvm.c | 19 +++++++++++++++++++ 3 files changed, 22 insertions(+), 2 deletions(-)
include/sysemu/kvm.h +3 -0
@@ -414,4 +414,7 @@ int kvm_set_one_reg(CPUState *cs, uint64_t id, void *source);* Returns: 0 on success, or a negative errno on failure. */ int kvm_get_one_reg (CPUState *cs,uint64_t id,void *target); + +#define TYPE_KVM_ACCEL "kvm-accel" +#endif
kvm-all.c +0 -2
@@ -113,8 +113,6 @@ typedef struct KVMState#endif } KVMState; -#define TYPE_KVM_ACCEL "kvm-accel" -#define KVM_STATE (obj) \ OBJECT_CHECK(KVMState, (obj), TYPE_KVM_ACCEL)
target-i386/kvm.c +19 -0
@@ -28,6 +28,7 @@#include "exec/gdbstub.h" #include "qemu/host-utils.h" #include "qemu/config-file.h" +#include "hw/i386/accel.h" #include "hw/i386/pc.h" #include "hw/i386/apic.h" #include "hw/i386/apic_internal.h"
@@ -2591,3 +2592,21 @@ int kvm_device_msix_deassign(KVMState *s, uint32_t dev_id)return kvm_deassign_irq_internal (s, dev_id,KVM_DEV_IRQ_GUEST_MSIX |KVM_DEV_IRQ_HOST_MSIX ); } + +#define TYPE_X86_KVM_ACCEL TARGET_NAME "-kvm-accel" + +static const TypeInfo x86_kvm_accel_type = { + .name =TYPE_X86_KVM_ACCEL , + .parent =TYPE_KVM_ACCEL , + .interfaces = (InterfaceInfo []) { + {TYPE_X86_ACCEL }, + { } + }, +}; + +static void x86_kvm_type_init (void ) +{ +type_register_static (&x86_kvm_accel_type); +} + +type_init (x86_kvm_type_init);
Signature · 1 line
1.9.3
RFC 22/25 target-i386: Add AccelState parameter to cpu_x86_create()
In reply to Eduardo Habkost--- hw/i386/pc.c | 3 ++- target-i386/cpu.c | 4 ++-- target-i386/cpu.h | 2 +- 3 files changed, 5 insertions(+), 4 deletions(-)
hw/i386/pc.c +2 -1
@@ -960,7 +960,8 @@ static X86CPU *pc_new_cpu(const char *cpu_model, int64_t apic_id,X86CPU *cpu;Error *local_err =NULL ; - cpu =cpu_x86_create (cpu_model, icc_bridge, &local_err); + cpu =cpu_x86_create (cpu_model, icc_bridge, current_machine->accelerator, + &local_err);if (local_err !=NULL ) {error_propagate (errp, local_err);return NULL ;
target-i386/cpu.c +2 -2
@@ -2015,7 +2015,7 @@ static void x86_cpu_load_def(X86CPU *cpu, X86CPUDefinition *def, Error **errp) }X86CPU *cpu_x86_create (const char *cpu_model,DeviceState *icc_bridge, -Error **errp) +AccelState *accel,Error **errp) {X86CPU *cpu =NULL ;X86CPUClass *xcc;
@@ -2077,7 +2077,7 @@ X86CPU *cpu_x86_init(const char *cpu_model)Error *error =NULL ;X86CPU *cpu; - cpu =cpu_x86_create (cpu_model,NULL , &error); + cpu =cpu_x86_create (cpu_model,NULL ,NULL , &error);if (error) { goto out; }
target-i386/cpu.h +1 -1
@@ -964,7 +964,7 @@ typedef struct CPUX86State {X86CPU *cpu_x86_init (const char *cpu_model);X86CPU *cpu_x86_create (const char *cpu_model,DeviceState *icc_bridge, -Error **errp); +AccelState *accel,Error **errp);int cpu_x86_exec (CPUX86State *s);void x86_cpu_list (FILE *f,fprintf_function cpu_fprintf);void x86_cpudef_setup (void );
Signature · 1 line
1.9.3
RFC 23/25 target-i386: Move accelerator-specific code outside X86CPU.instance_init
In reply to Eduardo HabkostThe code will be changed to use the accelerator object, so it has to be outside instance_init (which can't get any extra parameters).
--- target-i386/cpu.c | 61 +++++++++++++++++++++++++++++++------------------------ 1 file changed, 34 insertions(+), 27 deletions(-)
target-i386/cpu.c +34 -27
@@ -1968,8 +1968,6 @@ static int x86_cpu_filter_features(X86CPU *cpu)static void x86_cpu_load_def (X86CPU *cpu,X86CPUDefinition *def,Error **errp) {CPUX86State *env = &cpu->env; -const char *vendor; -char host_vendor[CPUID_VENDOR_SZ +1 ];FeatureWord w;object_property_set_int (OBJECT (cpu), def->level,"level" , errp);
@@ -1977,6 +1975,7 @@ static void x86_cpu_load_def(X86CPU *cpu, X86CPUDefinition *def, Error **errp)object_property_set_int (OBJECT (cpu), def->model,"model" , errp);object_property_set_int (OBJECT (cpu), def->stepping,"stepping" , errp);object_property_set_int (OBJECT (cpu), def->xlevel,"xlevel" , errp); +object_property_set_str (OBJECT (cpu), def->vendor,"vendor" , errp); env->cpuid_xlevel2 = def->xlevel2; cpu->cache_info_passthrough = def->cache_info_passthrough;object_property_set_str (OBJECT (cpu), def->model_id,"model-id" , errp);
@@ -1985,32 +1984,46 @@ static void x86_cpu_load_def(X86CPU *cpu, X86CPUDefinition *def, Error **errp) }/* Special cases not set in the X86CPUDefinition structs: */ + env->features[FEAT_1_ECX ] |=CPUID_EXT_HYPERVISOR ; +} + +/* Accelerator-specific initialization code, to be called immediately after +* creation of the X86CPU object, and before x86_cpu_parse_featurestr(). +*/ +static void x86_cpu_accel_init (X86CPU *cpu,Error **errp) +{ +CPUX86State *env = &cpu->env; +static int inited; +if (kvm_enabled ()) { +char host_vendor[CPUID_VENDOR_SZ +1 ]; +uint32_t ebx =0 , ecx =0 , edx =0 ;FeatureWord w;for (w =0 ; w <FEATURE_WORDS ; w++) { env->features[w] |= kvm_default_features[w]; env->features[w] &= ~kvm_default_unset_features[w]; } - } - env->features[FEAT_1_ECX ] |=CPUID_EXT_HYPERVISOR ; - -/* sysenter isn't supported in compatibility mode on AMD, -* syscall isn't supported in compatibility mode on Intel. -* Normally we advertise the actual CPU vendor, but you can -* override this using the 'vendor' property if you want to use -* KVM's sysenter/syscall emulation in compatibility mode and -* when doing cross vendor migration -*/ - vendor = def->vendor; -if (kvm_enabled ()) { -uint32_t ebx =0 , ecx =0 , edx =0 ; +/* sysenter isn't supported in compatibility mode on AMD, +* syscall isn't supported in compatibility mode on Intel. +* Normally we advertise the actual CPU vendor, but you can +* override this using the 'vendor' property if you want to use +* KVM's sysenter/syscall emulation in compatibility mode and +* when doing cross vendor migration +*/ host_cpuid (0 ,0 ,NULL , &ebx, &ecx, &edx);x86_cpu_vendor_words2str (host_vendor, ebx, edx, ecx); - vendor = host_vendor; +object_property_set_str (OBJECT (cpu), host_vendor,"vendor" , errp); } -object_property_set_str (OBJECT (cpu), vendor,"vendor" , errp); +/* init various static tables used in TCG mode */ +if (tcg_enabled () && !inited) { + inited =1 ; +optimize_flags_init (); +#ifndef CONFIG_USER_ONLY +cpu_set_debug_excp_handler (breakpoint_handler); +#endif + } }
@@ -2045,6 +2058,10 @@ X86CPU *cpu_x86_create(const char *cpu_model, DeviceState *icc_bridge, } cpu =X86_CPU (object_new (object_class_get_name (oc))); +x86_cpu_accel_init (cpu, &error); +if (error) { + goto out; + }#ifndef CONFIG_USER_ONLY if (icc_bridge ==NULL ) {
@@ -2777,7 +2794,6 @@ static void x86_cpu_initfn(Object *obj)X86CPU *cpu =X86_CPU (obj);X86CPUClass *xcc =X86_CPU_GET_CLASS (obj);CPUX86State *env = &cpu->env; -static int inited; cs->env_ptr = env;cpu_exec_init (env);
@@ -2820,15 +2836,6 @@ static void x86_cpu_initfn(Object *obj) env->cpuid_apic_id =x86_cpu_apic_id_from_index (cs->cpu_index);x86_cpu_load_def (cpu, xcc->cpu_def, &error_abort); - -/* init various static tables used in TCG mode */ -if (tcg_enabled () && !inited) { - inited =1 ; -optimize_flags_init (); -#ifndef CONFIG_USER_ONLY -cpu_set_debug_excp_handler (breakpoint_handler); -#endif - } }static int64_t x86_cpu_get_arch_id (CPUState *cs)
Signature · 1 line
1.9.3
RFC 24/25 target-i386: Accept "host" as value for CPU vendor
In reply to Eduardo HabkostWhen using vendor=host, the host CPU vendor will be used.
--- target-i386/cpu.c | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-)
target-i386/cpu.c +9 -5
@@ -1528,8 +1528,16 @@ static void x86_cpuid_set_vendor(Object *obj, const char *value, {X86CPU *cpu =X86_CPU (obj);CPUX86State *env = &cpu->env; +char host_vendor[CPUID_VENDOR_SZ +1 ];int i; +if (!strcmp (value,"host" )) { +uint32_t ebx =0 , ecx =0 , edx =0 ; +host_cpuid (0 ,0 ,NULL , &ebx, &ecx, &edx); +x86_cpu_vendor_words2str (host_vendor, ebx, edx, ecx); + value = host_vendor; + } +if (strlen (value) !=CPUID_VENDOR_SZ ) {error_set (errp,QERR_PROPERTY_VALUE_BAD ,"" ,"vendor" , value);
@@ -1996,8 +2004,6 @@ static void x86_cpu_accel_init(X86CPU *cpu, Error **errp)static int inited;if (kvm_enabled ()) { -char host_vendor[CPUID_VENDOR_SZ +1 ]; -uint32_t ebx =0 , ecx =0 , edx =0 ;FeatureWord w;for (w =0 ; w <FEATURE_WORDS ; w++) { env->features[w] |= kvm_default_features[w];
@@ -2011,9 +2017,7 @@ static void x86_cpu_accel_init(X86CPU *cpu, Error **errp)* KVM's sysenter/syscall emulation in compatibility mode and * when doing cross vendor migration */ -host_cpuid (0 ,0 ,NULL , &ebx, &ecx, &edx); -x86_cpu_vendor_words2str (host_vendor, ebx, edx, ecx); -object_property_set_str (OBJECT (cpu), host_vendor,"vendor" , errp); +object_property_set_str (OBJECT (cpu),"host" ,"vendor" , errp); }/* init various static tables used in TCG mode */
Signature · 1 line
1.9.3
RFC 25/25 target-i386: Move KVM CPUID hacking to accelerator cpu_post_init hook
In reply to Eduardo Habkost--- include/hw/i386/accel.h | 7 +++++++ include/qemu/typedefs.h | 2 ++ target-i386/cpu.c | 54 ++++++++++--------------------------------------- target-i386/kvm.c | 51 ++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 71 insertions(+), 43 deletions(-)
include/hw/i386/accel.h +7 -0
@@ -4,6 +4,7 @@#define HW_I386_ACCEL_H #include "hw/accel.h" +#include "qemu/typedefs.h" #define TYPE_X86_ACCEL "x86-accel"
@@ -25,10 +26,16 @@ typedef struct X86Accel {* * Interface that may be implemented by target-specific accelerator * classes. +* +* @cpu_post_init: Hook called after creation of X86CPU objects. Can be used, +* to change CPUID data to match accelerator-specific +* requirements. */ typedef struct X86AccelClass {/* <private> */ InterfaceClass parent; +/* <public> */ +void (*cpu_post_init)(AccelState *accel,X86CPU *cpu,Error **errp); }X86AccelClass ;
include/qemu/typedefs.h +2 -0
@@ -79,4 +79,6 @@ typedef struct PcGuestInfo PcGuestInfo;typedef struct Range Range ;typedef struct AdapterInfo AdapterInfo ; +typedef struct X86CPU X86CPU ; +#endif /* QEMU_TYPEDEFS_H */
target-i386/cpu.c +11 -43
81 lines not on this page · raw message
target-i386/kvm.c +51 -0
62 lines not on this page · raw message
Signature · 1 line
1.9.3