* [RFC PATCH v2 01/48] system/runstate: Document qemu_add_vm_change_state_handler()
2025-06-20 17:12 [RFC PATCH v2 00/48] accel: Preparatory cleanups for split-accel Philippe Mathieu-Daudé
@ 2025-06-20 17:12 ` Philippe Mathieu-Daudé
2025-06-22 1:11 ` Richard Henderson
2025-06-20 17:12 ` [RFC PATCH v2 02/48] system/cpus: Defer memory layout changes until vCPUs are realized Philippe Mathieu-Daudé
` (39 subsequent siblings)
40 siblings, 1 reply; 77+ messages in thread
From: Philippe Mathieu-Daudé @ 2025-06-20 17:12 UTC (permalink / raw)
To: qemu-devel
Cc: Alex Bennée, Alexander Graf, Richard Henderson,
Pierrick Bouvier, Peter Maydell, Thomas Huth, Cameron Esfahani,
Julian Armistead, Paolo Bonzini, Edgar E. Iglesias,
Philippe Mathieu-Daudé
Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
---
include/system/runstate.h | 10 ++++++++++
1 file changed, 10 insertions(+)
diff --git a/include/system/runstate.h b/include/system/runstate.h
index fdd5c4a5172..b6e8d6beab7 100644
--- a/include/system/runstate.h
+++ b/include/system/runstate.h
@@ -14,6 +14,16 @@ void runstate_replay_enable(void);
typedef void VMChangeStateHandler(void *opaque, bool running, RunState state);
typedef int VMChangeStateHandlerWithRet(void *opaque, bool running, RunState state);
+/**
+ * qemu_add_vm_change_state_handler:
+ * @cb: the callback to invoke
+ * @opaque: user data passed to the callback
+ *
+ * Register a callback function that is invoked when the vm starts or stops
+ * running.
+ *
+ * Returns: an entry to be freed using qemu_del_vm_change_state_handler()
+ */
VMChangeStateEntry *qemu_add_vm_change_state_handler(VMChangeStateHandler *cb,
void *opaque);
VMChangeStateEntry *qemu_add_vm_change_state_handler_prio(
--
2.49.0
^ permalink raw reply related [flat|nested] 77+ messages in thread
* Re: [RFC PATCH v2 01/48] system/runstate: Document qemu_add_vm_change_state_handler()
2025-06-20 17:12 ` [RFC PATCH v2 01/48] system/runstate: Document qemu_add_vm_change_state_handler() Philippe Mathieu-Daudé
@ 2025-06-22 1:11 ` Richard Henderson
0 siblings, 0 replies; 77+ messages in thread
From: Richard Henderson @ 2025-06-22 1:11 UTC (permalink / raw)
To: Philippe Mathieu-Daudé, qemu-devel
Cc: Alex Bennée, Alexander Graf, Pierrick Bouvier, Peter Maydell,
Thomas Huth, Cameron Esfahani, Julian Armistead, Paolo Bonzini,
Edgar E. Iglesias
On 6/20/25 10:12, Philippe Mathieu-Daudé wrote:
> Signed-off-by: Philippe Mathieu-Daudé<philmd@linaro.org>
> ---
> include/system/runstate.h | 10 ++++++++++
> 1 file changed, 10 insertions(+)
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
r~
^ permalink raw reply [flat|nested] 77+ messages in thread
* [RFC PATCH v2 02/48] system/cpus: Defer memory layout changes until vCPUs are realized
2025-06-20 17:12 [RFC PATCH v2 00/48] accel: Preparatory cleanups for split-accel Philippe Mathieu-Daudé
2025-06-20 17:12 ` [RFC PATCH v2 01/48] system/runstate: Document qemu_add_vm_change_state_handler() Philippe Mathieu-Daudé
@ 2025-06-20 17:12 ` Philippe Mathieu-Daudé
2025-06-20 17:12 ` [RFC PATCH v2 03/48] system/cpus: Assert interrupt handling is done with BQL locked Philippe Mathieu-Daudé
` (38 subsequent siblings)
40 siblings, 0 replies; 77+ messages in thread
From: Philippe Mathieu-Daudé @ 2025-06-20 17:12 UTC (permalink / raw)
To: qemu-devel
Cc: Alex Bennée, Alexander Graf, Richard Henderson,
Pierrick Bouvier, Peter Maydell, Thomas Huth, Cameron Esfahani,
Julian Armistead, Paolo Bonzini, Edgar E. Iglesias,
Philippe Mathieu-Daudé
vCPUs are not really usable until fully realized. Do not attempt
to commit memory changes in the middle of vCPU realization. Defer
until realization is completed and vCPU fully operational.
Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
---
system/physmem.c | 8 ++++++++
1 file changed, 8 insertions(+)
diff --git a/system/physmem.c b/system/physmem.c
index a8a9ca309ea..7004de3992c 100644
--- a/system/physmem.c
+++ b/system/physmem.c
@@ -2773,6 +2773,14 @@ static void tcg_commit(MemoryListener *listener)
cpuas = container_of(listener, CPUAddressSpace, tcg_as_listener);
cpu = cpuas->cpu;
+ if (!qdev_is_realized(DEVICE(cpu))) {
+ /*
+ * The listener is also called during realize, before
+ * all of the tcg machinery for run-on is initialized.
+ */
+ return;
+ }
+
/*
* Defer changes to as->memory_dispatch until the cpu is quiescent.
* Otherwise we race between (1) other cpu threads and (2) ongoing
--
2.49.0
^ permalink raw reply related [flat|nested] 77+ messages in thread
* [RFC PATCH v2 03/48] system/cpus: Assert interrupt handling is done with BQL locked
2025-06-20 17:12 [RFC PATCH v2 00/48] accel: Preparatory cleanups for split-accel Philippe Mathieu-Daudé
2025-06-20 17:12 ` [RFC PATCH v2 01/48] system/runstate: Document qemu_add_vm_change_state_handler() Philippe Mathieu-Daudé
2025-06-20 17:12 ` [RFC PATCH v2 02/48] system/cpus: Defer memory layout changes until vCPUs are realized Philippe Mathieu-Daudé
@ 2025-06-20 17:12 ` Philippe Mathieu-Daudé
2025-06-22 1:12 ` Richard Henderson
2025-06-20 17:12 ` [RFC PATCH v2 04/48] accel/kvm: Remove kvm_init_cpu_signals() stub Philippe Mathieu-Daudé
` (37 subsequent siblings)
40 siblings, 1 reply; 77+ messages in thread
From: Philippe Mathieu-Daudé @ 2025-06-20 17:12 UTC (permalink / raw)
To: qemu-devel
Cc: Alex Bennée, Alexander Graf, Richard Henderson,
Pierrick Bouvier, Peter Maydell, Thomas Huth, Cameron Esfahani,
Julian Armistead, Paolo Bonzini, Edgar E. Iglesias,
Philippe Mathieu-Daudé
Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
---
accel/tcg/tcg-accel-ops.c | 2 --
system/cpus.c | 2 ++
2 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/accel/tcg/tcg-accel-ops.c b/accel/tcg/tcg-accel-ops.c
index da2e22a7dff..37b4b21f882 100644
--- a/accel/tcg/tcg-accel-ops.c
+++ b/accel/tcg/tcg-accel-ops.c
@@ -93,8 +93,6 @@ static void tcg_cpu_reset_hold(CPUState *cpu)
/* mask must never be zero, except for A20 change call */
void tcg_handle_interrupt(CPUState *cpu, int mask)
{
- g_assert(bql_locked());
-
cpu->interrupt_request |= mask;
/*
diff --git a/system/cpus.c b/system/cpus.c
index d16b0dff989..a43e0e4e796 100644
--- a/system/cpus.c
+++ b/system/cpus.c
@@ -265,6 +265,8 @@ static void generic_handle_interrupt(CPUState *cpu, int mask)
void cpu_interrupt(CPUState *cpu, int mask)
{
+ g_assert(bql_locked());
+
if (cpus_accel->handle_interrupt) {
cpus_accel->handle_interrupt(cpu, mask);
} else {
--
2.49.0
^ permalink raw reply related [flat|nested] 77+ messages in thread
* Re: [RFC PATCH v2 03/48] system/cpus: Assert interrupt handling is done with BQL locked
2025-06-20 17:12 ` [RFC PATCH v2 03/48] system/cpus: Assert interrupt handling is done with BQL locked Philippe Mathieu-Daudé
@ 2025-06-22 1:12 ` Richard Henderson
0 siblings, 0 replies; 77+ messages in thread
From: Richard Henderson @ 2025-06-22 1:12 UTC (permalink / raw)
To: Philippe Mathieu-Daudé, qemu-devel
On 6/20/25 10:12, Philippe Mathieu-Daudé wrote:
> Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
> ---
> accel/tcg/tcg-accel-ops.c | 2 --
> system/cpus.c | 2 ++
> 2 files changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/accel/tcg/tcg-accel-ops.c b/accel/tcg/tcg-accel-ops.c
> index da2e22a7dff..37b4b21f882 100644
> --- a/accel/tcg/tcg-accel-ops.c
> +++ b/accel/tcg/tcg-accel-ops.c
> @@ -93,8 +93,6 @@ static void tcg_cpu_reset_hold(CPUState *cpu)
> /* mask must never be zero, except for A20 change call */
> void tcg_handle_interrupt(CPUState *cpu, int mask)
> {
> - g_assert(bql_locked());
> -
> cpu->interrupt_request |= mask;
>
> /*
> diff --git a/system/cpus.c b/system/cpus.c
> index d16b0dff989..a43e0e4e796 100644
> --- a/system/cpus.c
> +++ b/system/cpus.c
> @@ -265,6 +265,8 @@ static void generic_handle_interrupt(CPUState *cpu, int mask)
>
> void cpu_interrupt(CPUState *cpu, int mask)
> {
> + g_assert(bql_locked());
> +
> if (cpus_accel->handle_interrupt) {
> cpus_accel->handle_interrupt(cpu, mask);
> } else {
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
r~
^ permalink raw reply [flat|nested] 77+ messages in thread
* [RFC PATCH v2 04/48] accel/kvm: Remove kvm_init_cpu_signals() stub
2025-06-20 17:12 [RFC PATCH v2 00/48] accel: Preparatory cleanups for split-accel Philippe Mathieu-Daudé
` (2 preceding siblings ...)
2025-06-20 17:12 ` [RFC PATCH v2 03/48] system/cpus: Assert interrupt handling is done with BQL locked Philippe Mathieu-Daudé
@ 2025-06-20 17:12 ` Philippe Mathieu-Daudé
2025-06-22 1:13 ` Richard Henderson
2025-06-20 17:12 ` [RFC PATCH v2 05/48] accel/kvm: Reduce kvm_create_vcpu() declaration scope Philippe Mathieu-Daudé
` (36 subsequent siblings)
40 siblings, 1 reply; 77+ messages in thread
From: Philippe Mathieu-Daudé @ 2025-06-20 17:12 UTC (permalink / raw)
To: qemu-devel
Cc: Alex Bennée, Alexander Graf, Richard Henderson,
Pierrick Bouvier, Peter Maydell, Thomas Huth, Cameron Esfahani,
Julian Armistead, Paolo Bonzini, Edgar E. Iglesias,
Philippe Mathieu-Daudé
Since commit 57038a92bb0 ("cpus: extract out kvm-specific code
to accel/kvm") the kvm_init_cpu_signals() stub is not necessary.
Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
---
accel/stubs/kvm-stub.c | 5 -----
1 file changed, 5 deletions(-)
diff --git a/accel/stubs/kvm-stub.c b/accel/stubs/kvm-stub.c
index ecfd7636f5f..b9b4427c919 100644
--- a/accel/stubs/kvm-stub.c
+++ b/accel/stubs/kvm-stub.c
@@ -105,11 +105,6 @@ unsigned int kvm_get_free_memslots(void)
return 0;
}
-void kvm_init_cpu_signals(CPUState *cpu)
-{
- abort();
-}
-
bool kvm_arm_supports_user_irq(void)
{
return false;
--
2.49.0
^ permalink raw reply related [flat|nested] 77+ messages in thread
* Re: [RFC PATCH v2 04/48] accel/kvm: Remove kvm_init_cpu_signals() stub
2025-06-20 17:12 ` [RFC PATCH v2 04/48] accel/kvm: Remove kvm_init_cpu_signals() stub Philippe Mathieu-Daudé
@ 2025-06-22 1:13 ` Richard Henderson
0 siblings, 0 replies; 77+ messages in thread
From: Richard Henderson @ 2025-06-22 1:13 UTC (permalink / raw)
To: Philippe Mathieu-Daudé, qemu-devel
On 6/20/25 10:12, Philippe Mathieu-Daudé wrote:
> Since commit 57038a92bb0 ("cpus: extract out kvm-specific code
> to accel/kvm") the kvm_init_cpu_signals() stub is not necessary.
>
> Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
> ---
> accel/stubs/kvm-stub.c | 5 -----
> 1 file changed, 5 deletions(-)
>
> diff --git a/accel/stubs/kvm-stub.c b/accel/stubs/kvm-stub.c
> index ecfd7636f5f..b9b4427c919 100644
> --- a/accel/stubs/kvm-stub.c
> +++ b/accel/stubs/kvm-stub.c
> @@ -105,11 +105,6 @@ unsigned int kvm_get_free_memslots(void)
> return 0;
> }
>
> -void kvm_init_cpu_signals(CPUState *cpu)
> -{
> - abort();
> -}
> -
> bool kvm_arm_supports_user_irq(void)
> {
> return false;
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
r~
^ permalink raw reply [flat|nested] 77+ messages in thread
* [RFC PATCH v2 05/48] accel/kvm: Reduce kvm_create_vcpu() declaration scope
2025-06-20 17:12 [RFC PATCH v2 00/48] accel: Preparatory cleanups for split-accel Philippe Mathieu-Daudé
` (3 preceding siblings ...)
2025-06-20 17:12 ` [RFC PATCH v2 04/48] accel/kvm: Remove kvm_init_cpu_signals() stub Philippe Mathieu-Daudé
@ 2025-06-20 17:12 ` Philippe Mathieu-Daudé
2025-06-22 1:14 ` Richard Henderson
2025-06-20 17:12 ` [RFC PATCH v2 06/48] accel: Propagate AccelState to AccelClass::init_machine() Philippe Mathieu-Daudé
` (35 subsequent siblings)
40 siblings, 1 reply; 77+ messages in thread
From: Philippe Mathieu-Daudé @ 2025-06-20 17:12 UTC (permalink / raw)
To: qemu-devel
Cc: Alex Bennée, Alexander Graf, Richard Henderson,
Pierrick Bouvier, Peter Maydell, Thomas Huth, Cameron Esfahani,
Julian Armistead, Paolo Bonzini, Edgar E. Iglesias,
Philippe Mathieu-Daudé
kvm_create_vcpu() is only used within the same file unit.
Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
---
include/system/kvm.h | 8 --------
accel/kvm/kvm-all.c | 8 +++++++-
2 files changed, 7 insertions(+), 9 deletions(-)
diff --git a/include/system/kvm.h b/include/system/kvm.h
index 7cc60d26f24..e943df2c09d 100644
--- a/include/system/kvm.h
+++ b/include/system/kvm.h
@@ -316,14 +316,6 @@ int kvm_create_device(KVMState *s, uint64_t type, bool test);
*/
bool kvm_device_supported(int vmfd, uint64_t type);
-/**
- * kvm_create_vcpu - Gets a parked KVM vCPU or creates a KVM vCPU
- * @cpu: QOM CPUState object for which KVM vCPU has to be fetched/created.
- *
- * @returns: 0 when success, errno (<0) when failed.
- */
-int kvm_create_vcpu(CPUState *cpu);
-
/**
* kvm_park_vcpu - Park QEMU KVM vCPU context
* @cpu: QOM CPUState object for which QEMU KVM vCPU context has to be parked.
diff --git a/accel/kvm/kvm-all.c b/accel/kvm/kvm-all.c
index a31778341c2..aeb75e1602c 100644
--- a/accel/kvm/kvm-all.c
+++ b/accel/kvm/kvm-all.c
@@ -453,7 +453,13 @@ static void kvm_reset_parked_vcpus(KVMState *s)
}
}
-int kvm_create_vcpu(CPUState *cpu)
+/**
+ * kvm_create_vcpu - Gets a parked KVM vCPU or creates a KVM vCPU
+ * @cpu: QOM CPUState object for which KVM vCPU has to be fetched/created.
+ *
+ * @returns: 0 when success, errno (<0) when failed.
+ */
+static int kvm_create_vcpu(CPUState *cpu)
{
unsigned long vcpu_id = kvm_arch_vcpu_id(cpu);
KVMState *s = kvm_state;
--
2.49.0
^ permalink raw reply related [flat|nested] 77+ messages in thread
* [RFC PATCH v2 06/48] accel: Propagate AccelState to AccelClass::init_machine()
2025-06-20 17:12 [RFC PATCH v2 00/48] accel: Preparatory cleanups for split-accel Philippe Mathieu-Daudé
` (4 preceding siblings ...)
2025-06-20 17:12 ` [RFC PATCH v2 05/48] accel/kvm: Reduce kvm_create_vcpu() declaration scope Philippe Mathieu-Daudé
@ 2025-06-20 17:12 ` Philippe Mathieu-Daudé
2025-06-20 17:13 ` [RFC PATCH v2 07/48] accel/kvm: Prefer local AccelState over global MachineState::accel Philippe Mathieu-Daudé
` (34 subsequent siblings)
40 siblings, 0 replies; 77+ messages in thread
From: Philippe Mathieu-Daudé @ 2025-06-20 17:12 UTC (permalink / raw)
To: qemu-devel
Cc: Alex Bennée, Alexander Graf, Richard Henderson,
Pierrick Bouvier, Peter Maydell, Thomas Huth, Cameron Esfahani,
Julian Armistead, Paolo Bonzini, Edgar E. Iglesias,
Philippe Mathieu-Daudé
In order to avoid init_machine() to call current_accel(),
pass AccelState along.
Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
Reviewed-by: Alex Bennée <alex.bennee@linaro.org>
---
include/qemu/accel.h | 2 +-
accel/accel-system.c | 2 +-
accel/hvf/hvf-accel-ops.c | 2 +-
accel/kvm/kvm-all.c | 2 +-
accel/qtest/qtest.c | 2 +-
accel/tcg/tcg-all.c | 2 +-
bsd-user/main.c | 2 +-
linux-user/main.c | 2 +-
target/i386/nvmm/nvmm-all.c | 2 +-
target/i386/whpx/whpx-all.c | 2 +-
10 files changed, 10 insertions(+), 10 deletions(-)
diff --git a/include/qemu/accel.h b/include/qemu/accel.h
index 9dea3145429..39b52adc9cb 100644
--- a/include/qemu/accel.h
+++ b/include/qemu/accel.h
@@ -40,7 +40,7 @@ typedef struct AccelClass {
/* Cached by accel_init_ops_interfaces() when created */
AccelOpsClass *ops;
- int (*init_machine)(MachineState *ms);
+ int (*init_machine)(MachineState *ms, AccelState *as);
bool (*cpu_common_realize)(CPUState *cpu, Error **errp);
void (*cpu_common_unrealize)(CPUState *cpu);
diff --git a/accel/accel-system.c b/accel/accel-system.c
index 64bc991b1ce..68d2f28388b 100644
--- a/accel/accel-system.c
+++ b/accel/accel-system.c
@@ -37,7 +37,7 @@ int accel_init_machine(AccelState *accel, MachineState *ms)
int ret;
ms->accelerator = accel;
*(acc->allowed) = true;
- ret = acc->init_machine(ms);
+ ret = acc->init_machine(ms, accel);
if (ret < 0) {
ms->accelerator = NULL;
*(acc->allowed) = false;
diff --git a/accel/hvf/hvf-accel-ops.c b/accel/hvf/hvf-accel-ops.c
index b9511103a75..ec82b79b515 100644
--- a/accel/hvf/hvf-accel-ops.c
+++ b/accel/hvf/hvf-accel-ops.c
@@ -321,7 +321,7 @@ static void dummy_signal(int sig)
bool hvf_allowed;
-static int hvf_accel_init(MachineState *ms)
+static int hvf_accel_init(MachineState *ms, AccelState *as)
{
int x;
hv_return_t ret;
diff --git a/accel/kvm/kvm-all.c b/accel/kvm/kvm-all.c
index aeb75e1602c..f19b20c9fdb 100644
--- a/accel/kvm/kvm-all.c
+++ b/accel/kvm/kvm-all.c
@@ -2573,7 +2573,7 @@ static int kvm_setup_dirty_ring(KVMState *s)
return 0;
}
-static int kvm_init(MachineState *ms)
+static int kvm_init(MachineState *ms, AccelState *as)
{
MachineClass *mc = MACHINE_GET_CLASS(ms);
static const char upgrade_note[] =
diff --git a/accel/qtest/qtest.c b/accel/qtest/qtest.c
index 92bed9264ce..c5a53ecb6dd 100644
--- a/accel/qtest/qtest.c
+++ b/accel/qtest/qtest.c
@@ -37,7 +37,7 @@ static void qtest_set_virtual_clock(int64_t count)
qatomic_set_i64(&qtest_clock_counter, count);
}
-static int qtest_init_accel(MachineState *ms)
+static int qtest_init_accel(MachineState *ms, AccelState *as)
{
return 0;
}
diff --git a/accel/tcg/tcg-all.c b/accel/tcg/tcg-all.c
index 6e5dc333d59..6c5979861cf 100644
--- a/accel/tcg/tcg-all.c
+++ b/accel/tcg/tcg-all.c
@@ -80,7 +80,7 @@ static void tcg_accel_instance_init(Object *obj)
bool one_insn_per_tb;
-static int tcg_init_machine(MachineState *ms)
+static int tcg_init_machine(MachineState *ms, AccelState *as)
{
TCGState *s = TCG_STATE(current_accel());
unsigned max_threads = 1;
diff --git a/bsd-user/main.c b/bsd-user/main.c
index 7c0a059c3ba..ad2032a8b01 100644
--- a/bsd-user/main.c
+++ b/bsd-user/main.c
@@ -474,7 +474,7 @@ int main(int argc, char **argv)
opt_one_insn_per_tb, &error_abort);
object_property_set_int(OBJECT(accel), "tb-size",
opt_tb_size, &error_abort);
- ac->init_machine(NULL);
+ ac->init_machine(NULL, accel);
}
/*
diff --git a/linux-user/main.c b/linux-user/main.c
index 5ac5b55dc65..2441e6edc71 100644
--- a/linux-user/main.c
+++ b/linux-user/main.c
@@ -820,7 +820,7 @@ int main(int argc, char **argv, char **envp)
opt_one_insn_per_tb, &error_abort);
object_property_set_int(OBJECT(accel), "tb-size",
opt_tb_size, &error_abort);
- ac->init_machine(NULL);
+ ac->init_machine(NULL, accel);
}
/*
diff --git a/target/i386/nvmm/nvmm-all.c b/target/i386/nvmm/nvmm-all.c
index f1c6120ccf1..887534d4ca6 100644
--- a/target/i386/nvmm/nvmm-all.c
+++ b/target/i386/nvmm/nvmm-all.c
@@ -1153,7 +1153,7 @@ static struct RAMBlockNotifier nvmm_ram_notifier = {
/* -------------------------------------------------------------------------- */
static int
-nvmm_accel_init(MachineState *ms)
+nvmm_accel_init(MachineState *ms, AccelState *as)
{
int ret, err;
diff --git a/target/i386/whpx/whpx-all.c b/target/i386/whpx/whpx-all.c
index cf6d3e4cdd4..238c3b95c6f 100644
--- a/target/i386/whpx/whpx-all.c
+++ b/target/i386/whpx/whpx-all.c
@@ -2505,7 +2505,7 @@ static void whpx_set_kernel_irqchip(Object *obj, Visitor *v,
* Partition support
*/
-static int whpx_accel_init(MachineState *ms)
+static int whpx_accel_init(MachineState *ms, AccelState *as)
{
struct whpx_state *whpx;
int ret;
--
2.49.0
^ permalink raw reply related [flat|nested] 77+ messages in thread
* [RFC PATCH v2 07/48] accel/kvm: Prefer local AccelState over global MachineState::accel
2025-06-20 17:12 [RFC PATCH v2 00/48] accel: Preparatory cleanups for split-accel Philippe Mathieu-Daudé
` (5 preceding siblings ...)
2025-06-20 17:12 ` [RFC PATCH v2 06/48] accel: Propagate AccelState to AccelClass::init_machine() Philippe Mathieu-Daudé
@ 2025-06-20 17:13 ` Philippe Mathieu-Daudé
2025-06-20 17:13 ` [RFC PATCH v2 08/48] accel/hvf: Re-use QOM allocated state Philippe Mathieu-Daudé
` (33 subsequent siblings)
40 siblings, 0 replies; 77+ messages in thread
From: Philippe Mathieu-Daudé @ 2025-06-20 17:13 UTC (permalink / raw)
To: qemu-devel
Cc: Alex Bennée, Alexander Graf, Richard Henderson,
Pierrick Bouvier, Peter Maydell, Thomas Huth, Cameron Esfahani,
Julian Armistead, Paolo Bonzini, Edgar E. Iglesias,
Philippe Mathieu-Daudé
Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
---
accel/kvm/kvm-all.c | 4 +---
1 file changed, 1 insertion(+), 3 deletions(-)
diff --git a/accel/kvm/kvm-all.c b/accel/kvm/kvm-all.c
index f19b20c9fdb..8f6c0bf3888 100644
--- a/accel/kvm/kvm-all.c
+++ b/accel/kvm/kvm-all.c
@@ -2588,15 +2588,13 @@ static int kvm_init(MachineState *ms, AccelState *as)
{ /* end of list */ }
}, *nc = num_cpus;
int soft_vcpus_limit, hard_vcpus_limit;
- KVMState *s;
+ KVMState *s = KVM_STATE(as);
const KVMCapabilityInfo *missing_cap;
int ret;
int type;
qemu_mutex_init(&kml_slots_lock);
- s = KVM_STATE(ms->accelerator);
-
/*
* On systems where the kernel can support different base page
* sizes, host page size may be different from TARGET_PAGE_SIZE,
--
2.49.0
^ permalink raw reply related [flat|nested] 77+ messages in thread
* [RFC PATCH v2 08/48] accel/hvf: Re-use QOM allocated state
2025-06-20 17:12 [RFC PATCH v2 00/48] accel: Preparatory cleanups for split-accel Philippe Mathieu-Daudé
` (6 preceding siblings ...)
2025-06-20 17:13 ` [RFC PATCH v2 07/48] accel/kvm: Prefer local AccelState over global MachineState::accel Philippe Mathieu-Daudé
@ 2025-06-20 17:13 ` Philippe Mathieu-Daudé
2025-06-20 17:13 ` [RFC PATCH v2 09/48] accel/tcg: Prefer local AccelState over global current_accel() Philippe Mathieu-Daudé
` (32 subsequent siblings)
40 siblings, 0 replies; 77+ messages in thread
From: Philippe Mathieu-Daudé @ 2025-06-20 17:13 UTC (permalink / raw)
To: qemu-devel
Cc: Alex Bennée, Alexander Graf, Richard Henderson,
Pierrick Bouvier, Peter Maydell, Thomas Huth, Cameron Esfahani,
Julian Armistead, Paolo Bonzini, Edgar E. Iglesias,
Philippe Mathieu-Daudé
Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
---
accel/hvf/hvf-accel-ops.c | 4 +---
1 file changed, 1 insertion(+), 3 deletions(-)
diff --git a/accel/hvf/hvf-accel-ops.c b/accel/hvf/hvf-accel-ops.c
index ec82b79b515..6a612599856 100644
--- a/accel/hvf/hvf-accel-ops.c
+++ b/accel/hvf/hvf-accel-ops.c
@@ -325,7 +325,7 @@ static int hvf_accel_init(MachineState *ms, AccelState *as)
{
int x;
hv_return_t ret;
- HVFState *s;
+ HVFState *s = HVF_STATE(as);
int pa_range = 36;
MachineClass *mc = MACHINE_GET_CLASS(ms);
@@ -339,8 +339,6 @@ static int hvf_accel_init(MachineState *ms, AccelState *as)
ret = hvf_arch_vm_create(ms, (uint32_t)pa_range);
assert_hvf_ok(ret);
- s = g_new0(HVFState, 1);
-
s->num_slots = ARRAY_SIZE(s->slots);
for (x = 0; x < s->num_slots; ++x) {
s->slots[x].size = 0;
--
2.49.0
^ permalink raw reply related [flat|nested] 77+ messages in thread
* [RFC PATCH v2 09/48] accel/tcg: Prefer local AccelState over global current_accel()
2025-06-20 17:12 [RFC PATCH v2 00/48] accel: Preparatory cleanups for split-accel Philippe Mathieu-Daudé
` (7 preceding siblings ...)
2025-06-20 17:13 ` [RFC PATCH v2 08/48] accel/hvf: Re-use QOM allocated state Philippe Mathieu-Daudé
@ 2025-06-20 17:13 ` Philippe Mathieu-Daudé
2025-06-20 17:13 ` [RFC PATCH v2 10/48] accel: Pass AccelState argument to gdbstub_supported_sstep_flags() Philippe Mathieu-Daudé
` (31 subsequent siblings)
40 siblings, 0 replies; 77+ messages in thread
From: Philippe Mathieu-Daudé @ 2025-06-20 17:13 UTC (permalink / raw)
To: qemu-devel
Cc: Alex Bennée, Alexander Graf, Richard Henderson,
Pierrick Bouvier, Peter Maydell, Thomas Huth, Cameron Esfahani,
Julian Armistead, Paolo Bonzini, Edgar E. Iglesias,
Philippe Mathieu-Daudé
Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
---
accel/tcg/tcg-all.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/accel/tcg/tcg-all.c b/accel/tcg/tcg-all.c
index 6c5979861cf..4b1238ed345 100644
--- a/accel/tcg/tcg-all.c
+++ b/accel/tcg/tcg-all.c
@@ -82,7 +82,7 @@ bool one_insn_per_tb;
static int tcg_init_machine(MachineState *ms, AccelState *as)
{
- TCGState *s = TCG_STATE(current_accel());
+ TCGState *s = TCG_STATE(as);
unsigned max_threads = 1;
#ifndef CONFIG_USER_ONLY
--
2.49.0
^ permalink raw reply related [flat|nested] 77+ messages in thread
* [RFC PATCH v2 10/48] accel: Pass AccelState argument to gdbstub_supported_sstep_flags()
2025-06-20 17:12 [RFC PATCH v2 00/48] accel: Preparatory cleanups for split-accel Philippe Mathieu-Daudé
` (8 preceding siblings ...)
2025-06-20 17:13 ` [RFC PATCH v2 09/48] accel/tcg: Prefer local AccelState over global current_accel() Philippe Mathieu-Daudé
@ 2025-06-20 17:13 ` Philippe Mathieu-Daudé
2025-06-22 1:16 ` Richard Henderson
2025-06-20 17:13 ` [RFC PATCH v2 11/48] accel: Move supports_guest_debug() declaration to AccelClass Philippe Mathieu-Daudé
` (30 subsequent siblings)
40 siblings, 1 reply; 77+ messages in thread
From: Philippe Mathieu-Daudé @ 2025-06-20 17:13 UTC (permalink / raw)
To: qemu-devel
Cc: Alex Bennée, Alexander Graf, Richard Henderson,
Pierrick Bouvier, Peter Maydell, Thomas Huth, Cameron Esfahani,
Julian Armistead, Paolo Bonzini, Edgar E. Iglesias,
Philippe Mathieu-Daudé
In order to have AccelClass methods instrospect their state,
we need to pass AccelState by argument.
Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
---
include/qemu/accel.h | 2 +-
accel/accel-common.c | 2 +-
accel/hvf/hvf-accel-ops.c | 2 +-
accel/kvm/kvm-all.c | 2 +-
accel/tcg/tcg-all.c | 2 +-
5 files changed, 5 insertions(+), 5 deletions(-)
diff --git a/include/qemu/accel.h b/include/qemu/accel.h
index 39b52adc9cb..2831e61de08 100644
--- a/include/qemu/accel.h
+++ b/include/qemu/accel.h
@@ -50,7 +50,7 @@ typedef struct AccelClass {
hwaddr start_addr, hwaddr size);
/* gdbstub related hooks */
- int (*gdbstub_supported_sstep_flags)(void);
+ int (*gdbstub_supported_sstep_flags)(AccelState *as);
bool *allowed;
/*
diff --git a/accel/accel-common.c b/accel/accel-common.c
index 55d21b63a48..1d04610f55e 100644
--- a/accel/accel-common.c
+++ b/accel/accel-common.c
@@ -128,7 +128,7 @@ int accel_supported_gdbstub_sstep_flags(void)
AccelState *accel = current_accel();
AccelClass *acc = ACCEL_GET_CLASS(accel);
if (acc->gdbstub_supported_sstep_flags) {
- return acc->gdbstub_supported_sstep_flags();
+ return acc->gdbstub_supported_sstep_flags(accel);
}
return 0;
}
diff --git a/accel/hvf/hvf-accel-ops.c b/accel/hvf/hvf-accel-ops.c
index 6a612599856..3797cab2bf6 100644
--- a/accel/hvf/hvf-accel-ops.c
+++ b/accel/hvf/hvf-accel-ops.c
@@ -353,7 +353,7 @@ static int hvf_accel_init(MachineState *ms, AccelState *as)
return hvf_arch_init();
}
-static inline int hvf_gdbstub_sstep_flags(void)
+static inline int hvf_gdbstub_sstep_flags(AccelState *as)
{
return SSTEP_ENABLE | SSTEP_NOIRQ;
}
diff --git a/accel/kvm/kvm-all.c b/accel/kvm/kvm-all.c
index 8f6c0bf3888..2a44d9eaabb 100644
--- a/accel/kvm/kvm-all.c
+++ b/accel/kvm/kvm-all.c
@@ -3974,7 +3974,7 @@ static void kvm_accel_instance_init(Object *obj)
* Returns: SSTEP_* flags that KVM supports for guest debug. The
* support is probed during kvm_init()
*/
-static int kvm_gdbstub_sstep_flags(void)
+static int kvm_gdbstub_sstep_flags(AccelState *as)
{
return kvm_sstep_flags;
}
diff --git a/accel/tcg/tcg-all.c b/accel/tcg/tcg-all.c
index 4b1238ed345..4eb49c6407d 100644
--- a/accel/tcg/tcg-all.c
+++ b/accel/tcg/tcg-all.c
@@ -219,7 +219,7 @@ static void tcg_set_one_insn_per_tb(Object *obj, bool value, Error **errp)
qatomic_set(&one_insn_per_tb, value);
}
-static int tcg_gdbstub_supported_sstep_flags(void)
+static int tcg_gdbstub_supported_sstep_flags(AccelState *as)
{
/*
* In replay mode all events will come from the log and can't be
--
2.49.0
^ permalink raw reply related [flat|nested] 77+ messages in thread
* Re: [RFC PATCH v2 10/48] accel: Pass AccelState argument to gdbstub_supported_sstep_flags()
2025-06-20 17:13 ` [RFC PATCH v2 10/48] accel: Pass AccelState argument to gdbstub_supported_sstep_flags() Philippe Mathieu-Daudé
@ 2025-06-22 1:16 ` Richard Henderson
0 siblings, 0 replies; 77+ messages in thread
From: Richard Henderson @ 2025-06-22 1:16 UTC (permalink / raw)
To: Philippe Mathieu-Daudé, qemu-devel
Cc: Alex Bennée, Alexander Graf, Pierrick Bouvier, Peter Maydell,
Thomas Huth, Cameron Esfahani, Julian Armistead, Paolo Bonzini,
Edgar E. Iglesias
On 6/20/25 10:13, Philippe Mathieu-Daudé wrote:
> In order to have AccelClass methods instrospect their state,
> we need to pass AccelState by argument.
>
> Signed-off-by: Philippe Mathieu-Daudé<philmd@linaro.org>
> ---
> include/qemu/accel.h | 2 +-
> accel/accel-common.c | 2 +-
> accel/hvf/hvf-accel-ops.c | 2 +-
> accel/kvm/kvm-all.c | 2 +-
> accel/tcg/tcg-all.c | 2 +-
> 5 files changed, 5 insertions(+), 5 deletions(-)
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
r~
^ permalink raw reply [flat|nested] 77+ messages in thread
* [RFC PATCH v2 11/48] accel: Move supports_guest_debug() declaration to AccelClass
2025-06-20 17:12 [RFC PATCH v2 00/48] accel: Preparatory cleanups for split-accel Philippe Mathieu-Daudé
` (9 preceding siblings ...)
2025-06-20 17:13 ` [RFC PATCH v2 10/48] accel: Pass AccelState argument to gdbstub_supported_sstep_flags() Philippe Mathieu-Daudé
@ 2025-06-20 17:13 ` Philippe Mathieu-Daudé
2025-06-22 1:20 ` Richard Henderson
2025-06-20 17:13 ` [RFC PATCH v2 12/48] accel: Move cpus_are_resettable() " Philippe Mathieu-Daudé
` (29 subsequent siblings)
40 siblings, 1 reply; 77+ messages in thread
From: Philippe Mathieu-Daudé @ 2025-06-20 17:13 UTC (permalink / raw)
To: qemu-devel
Cc: Alex Bennée, Alexander Graf, Richard Henderson,
Pierrick Bouvier, Peter Maydell, Thomas Huth, Cameron Esfahani,
Julian Armistead, Paolo Bonzini, Edgar E. Iglesias,
Philippe Mathieu-Daudé
AccelOpsClass is for methods dealing with vCPUs.
When only dealing with AccelState, AccelClass is sufficient.
In order to have AccelClass methods instrospect their state,
we need to pass AccelState by argument.
Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
---
include/qemu/accel.h | 1 +
include/system/accel-ops.h | 1 -
include/system/hvf.h | 2 +-
accel/hvf/hvf-accel-ops.c | 2 +-
accel/tcg/tcg-accel-ops.c | 6 ------
accel/tcg/tcg-all.c | 6 ++++++
gdbstub/system.c | 7 ++++---
target/arm/hvf/hvf.c | 2 +-
target/i386/hvf/hvf.c | 2 +-
9 files changed, 15 insertions(+), 14 deletions(-)
diff --git a/include/qemu/accel.h b/include/qemu/accel.h
index 2831e61de08..b807cca6678 100644
--- a/include/qemu/accel.h
+++ b/include/qemu/accel.h
@@ -50,6 +50,7 @@ typedef struct AccelClass {
hwaddr start_addr, hwaddr size);
/* gdbstub related hooks */
+ bool (*supports_guest_debug)(AccelState *as);
int (*gdbstub_supported_sstep_flags)(AccelState *as);
bool *allowed;
diff --git a/include/system/accel-ops.h b/include/system/accel-ops.h
index a863fe59388..51faf47ac69 100644
--- a/include/system/accel-ops.h
+++ b/include/system/accel-ops.h
@@ -65,7 +65,6 @@ struct AccelOpsClass {
int64_t (*get_elapsed_ticks)(void);
/* gdbstub hooks */
- bool (*supports_guest_debug)(void);
int (*update_guest_debug)(CPUState *cpu);
int (*insert_breakpoint)(CPUState *cpu, int type, vaddr addr, vaddr len);
int (*remove_breakpoint)(CPUState *cpu, int type, vaddr addr, vaddr len);
diff --git a/include/system/hvf.h b/include/system/hvf.h
index 8c4409a13f1..7b9384d816c 100644
--- a/include/system/hvf.h
+++ b/include/system/hvf.h
@@ -71,7 +71,7 @@ void hvf_arch_update_guest_debug(CPUState *cpu);
/*
* Return whether the guest supports debugging.
*/
-bool hvf_arch_supports_guest_debug(void);
+bool hvf_arch_supports_guest_debug(AccelState *as);
bool hvf_arch_cpu_realize(CPUState *cpu, Error **errp);
diff --git a/accel/hvf/hvf-accel-ops.c b/accel/hvf/hvf-accel-ops.c
index 3797cab2bf6..45dd4baa321 100644
--- a/accel/hvf/hvf-accel-ops.c
+++ b/accel/hvf/hvf-accel-ops.c
@@ -364,6 +364,7 @@ static void hvf_accel_class_init(ObjectClass *oc, const void *data)
ac->name = "HVF";
ac->init_machine = hvf_accel_init;
ac->allowed = &hvf_allowed;
+ ac->supports_guest_debug = hvf_arch_supports_guest_debug;
ac->gdbstub_supported_sstep_flags = hvf_gdbstub_sstep_flags;
}
@@ -600,7 +601,6 @@ static void hvf_accel_ops_class_init(ObjectClass *oc, const void *data)
ops->remove_breakpoint = hvf_remove_breakpoint;
ops->remove_all_breakpoints = hvf_remove_all_breakpoints;
ops->update_guest_debug = hvf_update_guest_debug;
- ops->supports_guest_debug = hvf_arch_supports_guest_debug;
};
static const TypeInfo hvf_accel_ops_type = {
.name = ACCEL_OPS_NAME("hvf"),
diff --git a/accel/tcg/tcg-accel-ops.c b/accel/tcg/tcg-accel-ops.c
index 37b4b21f882..07b1ec4ea50 100644
--- a/accel/tcg/tcg-accel-ops.c
+++ b/accel/tcg/tcg-accel-ops.c
@@ -106,11 +106,6 @@ void tcg_handle_interrupt(CPUState *cpu, int mask)
}
}
-static bool tcg_supports_guest_debug(void)
-{
- return true;
-}
-
/* Translate GDB watchpoint type to a flags value for cpu_watchpoint_* */
static inline int xlat_gdb_type(CPUState *cpu, int gdbtype)
{
@@ -218,7 +213,6 @@ static void tcg_accel_ops_init(AccelClass *ac)
}
ops->cpu_reset_hold = tcg_cpu_reset_hold;
- ops->supports_guest_debug = tcg_supports_guest_debug;
ops->insert_breakpoint = tcg_insert_breakpoint;
ops->remove_breakpoint = tcg_remove_breakpoint;
ops->remove_all_breakpoints = tcg_remove_all_breakpoints;
diff --git a/accel/tcg/tcg-all.c b/accel/tcg/tcg-all.c
index 4eb49c6407d..164bba41ed9 100644
--- a/accel/tcg/tcg-all.c
+++ b/accel/tcg/tcg-all.c
@@ -219,6 +219,11 @@ static void tcg_set_one_insn_per_tb(Object *obj, bool value, Error **errp)
qatomic_set(&one_insn_per_tb, value);
}
+static bool tcg_supports_guest_debug(AccelState *as)
+{
+ return true;
+}
+
static int tcg_gdbstub_supported_sstep_flags(AccelState *as)
{
/*
@@ -242,6 +247,7 @@ static void tcg_accel_class_init(ObjectClass *oc, const void *data)
ac->cpu_common_realize = tcg_exec_realizefn;
ac->cpu_common_unrealize = tcg_exec_unrealizefn;
ac->allowed = &tcg_allowed;
+ ac->supports_guest_debug = tcg_supports_guest_debug;
ac->gdbstub_supported_sstep_flags = tcg_gdbstub_supported_sstep_flags;
object_class_property_add_str(oc, "thread",
diff --git a/gdbstub/system.c b/gdbstub/system.c
index 8a32d8e1a1d..bced226fd94 100644
--- a/gdbstub/system.c
+++ b/gdbstub/system.c
@@ -634,9 +634,10 @@ int gdb_signal_to_target(int sig)
bool gdb_supports_guest_debug(void)
{
- const AccelOpsClass *ops = cpus_get_accel();
- if (ops->supports_guest_debug) {
- return ops->supports_guest_debug();
+ AccelState *accel = current_accel();
+ AccelClass *acc = ACCEL_GET_CLASS(accel);
+ if (acc->supports_guest_debug) {
+ return acc->supports_guest_debug(accel);
}
return false;
}
diff --git a/target/arm/hvf/hvf.c b/target/arm/hvf/hvf.c
index 87cd323c14d..48ce83eb8fc 100644
--- a/target/arm/hvf/hvf.c
+++ b/target/arm/hvf/hvf.c
@@ -2409,7 +2409,7 @@ void hvf_arch_update_guest_debug(CPUState *cpu)
hvf_arch_set_traps(cpu);
}
-bool hvf_arch_supports_guest_debug(void)
+bool hvf_arch_supports_guest_debug(AccelState *as)
{
return true;
}
diff --git a/target/i386/hvf/hvf.c b/target/i386/hvf/hvf.c
index 28484496710..bcf30662bec 100644
--- a/target/i386/hvf/hvf.c
+++ b/target/i386/hvf/hvf.c
@@ -1024,7 +1024,7 @@ void hvf_arch_update_guest_debug(CPUState *cpu)
{
}
-bool hvf_arch_supports_guest_debug(void)
+bool hvf_arch_supports_guest_debug(AccelState *as)
{
return false;
}
--
2.49.0
^ permalink raw reply related [flat|nested] 77+ messages in thread
* Re: [RFC PATCH v2 11/48] accel: Move supports_guest_debug() declaration to AccelClass
2025-06-20 17:13 ` [RFC PATCH v2 11/48] accel: Move supports_guest_debug() declaration to AccelClass Philippe Mathieu-Daudé
@ 2025-06-22 1:20 ` Richard Henderson
0 siblings, 0 replies; 77+ messages in thread
From: Richard Henderson @ 2025-06-22 1:20 UTC (permalink / raw)
To: Philippe Mathieu-Daudé, qemu-devel
On 6/20/25 10:13, Philippe Mathieu-Daudé wrote:
> AccelOpsClass is for methods dealing with vCPUs.
> When only dealing with AccelState, AccelClass is sufficient.
>
> In order to have AccelClass methods instrospect their state,
> we need to pass AccelState by argument.
>
> Signed-off-by: Philippe Mathieu-Daudé<philmd@linaro.org>
> ---
> include/qemu/accel.h | 1 +
> include/system/accel-ops.h | 1 -
> include/system/hvf.h | 2 +-
> accel/hvf/hvf-accel-ops.c | 2 +-
> accel/tcg/tcg-accel-ops.c | 6 ------
> accel/tcg/tcg-all.c | 6 ++++++
> gdbstub/system.c | 7 ++++---
> target/arm/hvf/hvf.c | 2 +-
> target/i386/hvf/hvf.c | 2 +-
> 9 files changed, 15 insertions(+), 14 deletions(-)
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
r~
^ permalink raw reply [flat|nested] 77+ messages in thread
* [RFC PATCH v2 12/48] accel: Move cpus_are_resettable() declaration to AccelClass
2025-06-20 17:12 [RFC PATCH v2 00/48] accel: Preparatory cleanups for split-accel Philippe Mathieu-Daudé
` (10 preceding siblings ...)
2025-06-20 17:13 ` [RFC PATCH v2 11/48] accel: Move supports_guest_debug() declaration to AccelClass Philippe Mathieu-Daudé
@ 2025-06-20 17:13 ` Philippe Mathieu-Daudé
2025-06-22 1:22 ` Richard Henderson
2025-06-20 17:13 ` [RFC PATCH v2 13/48] accel: Move cpu_common_[un]realize() declarations to AccelOpsClass Philippe Mathieu-Daudé
` (28 subsequent siblings)
40 siblings, 1 reply; 77+ messages in thread
From: Philippe Mathieu-Daudé @ 2025-06-20 17:13 UTC (permalink / raw)
To: qemu-devel
Cc: Alex Bennée, Alexander Graf, Richard Henderson,
Pierrick Bouvier, Peter Maydell, Thomas Huth, Cameron Esfahani,
Julian Armistead, Paolo Bonzini, Edgar E. Iglesias,
Philippe Mathieu-Daudé
AccelOpsClass is for methods dealing with vCPUs.
When only dealing with AccelState, AccelClass is sufficient.
Move cpus_are_resettable() declaration to accel/accel-system.c.
In order to have AccelClass methods instrospect their state,
we need to pass AccelState by argument.
Adapt KVM handler.
Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
---
include/qemu/accel.h | 1 +
include/system/accel-ops.h | 1 -
accel/accel-system.c | 10 ++++++++++
accel/kvm/kvm-accel-ops.c | 6 ------
accel/kvm/kvm-all.c | 6 ++++++
system/cpus.c | 8 --------
6 files changed, 17 insertions(+), 15 deletions(-)
diff --git a/include/qemu/accel.h b/include/qemu/accel.h
index b807cca6678..04d252d3d65 100644
--- a/include/qemu/accel.h
+++ b/include/qemu/accel.h
@@ -48,6 +48,7 @@ typedef struct AccelClass {
void (*setup_post)(MachineState *ms, AccelState *accel);
bool (*has_memory)(MachineState *ms, AddressSpace *as,
hwaddr start_addr, hwaddr size);
+ bool (*cpus_are_resettable)(AccelState *as);
/* gdbstub related hooks */
bool (*supports_guest_debug)(AccelState *as);
diff --git a/include/system/accel-ops.h b/include/system/accel-ops.h
index 51faf47ac69..d854b84a66a 100644
--- a/include/system/accel-ops.h
+++ b/include/system/accel-ops.h
@@ -34,7 +34,6 @@ struct AccelOpsClass {
/* initialization function called when accel is chosen */
void (*ops_init)(AccelClass *ac);
- bool (*cpus_are_resettable)(void);
bool (*cpu_target_realize)(CPUState *cpu, Error **errp);
void (*cpu_reset_hold)(CPUState *cpu);
diff --git a/accel/accel-system.c b/accel/accel-system.c
index 68d2f28388b..1db146139c4 100644
--- a/accel/accel-system.c
+++ b/accel/accel-system.c
@@ -62,6 +62,16 @@ void accel_setup_post(MachineState *ms)
}
}
+bool cpus_are_resettable(void)
+{
+ AccelState *accel = current_accel();
+ AccelClass *acc = ACCEL_GET_CLASS(accel);
+ if (acc->cpus_are_resettable) {
+ return acc->cpus_are_resettable(accel);
+ }
+ return true;
+}
+
/* initialize the arch-independent accel operation interfaces */
void accel_init_ops_interfaces(AccelClass *ac)
{
diff --git a/accel/kvm/kvm-accel-ops.c b/accel/kvm/kvm-accel-ops.c
index e5c15449aa6..be960bde5c4 100644
--- a/accel/kvm/kvm-accel-ops.c
+++ b/accel/kvm/kvm-accel-ops.c
@@ -78,11 +78,6 @@ static bool kvm_vcpu_thread_is_idle(CPUState *cpu)
return !kvm_halt_in_kernel();
}
-static bool kvm_cpus_are_resettable(void)
-{
- return !kvm_enabled() || !kvm_state->guest_state_protected;
-}
-
#ifdef TARGET_KVM_HAVE_GUEST_DEBUG
static int kvm_update_guest_debug_ops(CPUState *cpu)
{
@@ -96,7 +91,6 @@ static void kvm_accel_ops_class_init(ObjectClass *oc, const void *data)
ops->create_vcpu_thread = kvm_start_vcpu_thread;
ops->cpu_thread_is_idle = kvm_vcpu_thread_is_idle;
- ops->cpus_are_resettable = kvm_cpus_are_resettable;
ops->synchronize_post_reset = kvm_cpu_synchronize_post_reset;
ops->synchronize_post_init = kvm_cpu_synchronize_post_init;
ops->synchronize_state = kvm_cpu_synchronize_state;
diff --git a/accel/kvm/kvm-all.c b/accel/kvm/kvm-all.c
index 2a44d9eaabb..37faf615cbc 100644
--- a/accel/kvm/kvm-all.c
+++ b/accel/kvm/kvm-all.c
@@ -3968,6 +3968,11 @@ static void kvm_accel_instance_init(Object *obj)
s->msr_energy.enable = false;
}
+static bool kvm_cpus_are_resettable(AccelState *as)
+{
+ return !kvm_enabled() || !kvm_state->guest_state_protected;
+}
+
/**
* kvm_gdbstub_sstep_flags():
*
@@ -3986,6 +3991,7 @@ static void kvm_accel_class_init(ObjectClass *oc, const void *data)
ac->init_machine = kvm_init;
ac->has_memory = kvm_accel_has_memory;
ac->allowed = &kvm_allowed;
+ ac->cpus_are_resettable = kvm_cpus_are_resettable;
ac->gdbstub_supported_sstep_flags = kvm_gdbstub_sstep_flags;
object_class_property_add(oc, "kernel-irqchip", "on|off|split",
diff --git a/system/cpus.c b/system/cpus.c
index a43e0e4e796..4fb764ac880 100644
--- a/system/cpus.c
+++ b/system/cpus.c
@@ -195,14 +195,6 @@ void cpu_synchronize_pre_loadvm(CPUState *cpu)
}
}
-bool cpus_are_resettable(void)
-{
- if (cpus_accel->cpus_are_resettable) {
- return cpus_accel->cpus_are_resettable();
- }
- return true;
-}
-
void cpu_exec_reset_hold(CPUState *cpu)
{
if (cpus_accel->cpu_reset_hold) {
--
2.49.0
^ permalink raw reply related [flat|nested] 77+ messages in thread
* Re: [RFC PATCH v2 12/48] accel: Move cpus_are_resettable() declaration to AccelClass
2025-06-20 17:13 ` [RFC PATCH v2 12/48] accel: Move cpus_are_resettable() " Philippe Mathieu-Daudé
@ 2025-06-22 1:22 ` Richard Henderson
0 siblings, 0 replies; 77+ messages in thread
From: Richard Henderson @ 2025-06-22 1:22 UTC (permalink / raw)
To: Philippe Mathieu-Daudé, qemu-devel
Cc: Alex Bennée, Alexander Graf, Pierrick Bouvier, Peter Maydell,
Thomas Huth, Cameron Esfahani, Julian Armistead, Paolo Bonzini,
Edgar E. Iglesias
On 6/20/25 10:13, Philippe Mathieu-Daudé wrote:
> AccelOpsClass is for methods dealing with vCPUs.
> When only dealing with AccelState, AccelClass is sufficient.
>
> Move cpus_are_resettable() declaration to accel/accel-system.c.
>
> In order to have AccelClass methods instrospect their state,
> we need to pass AccelState by argument.
>
> Adapt KVM handler.
>
> Signed-off-by: Philippe Mathieu-Daudé<philmd@linaro.org>
> ---
> include/qemu/accel.h | 1 +
> include/system/accel-ops.h | 1 -
> accel/accel-system.c | 10 ++++++++++
> accel/kvm/kvm-accel-ops.c | 6 ------
> accel/kvm/kvm-all.c | 6 ++++++
> system/cpus.c | 8 --------
> 6 files changed, 17 insertions(+), 15 deletions(-)
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
r~
^ permalink raw reply [flat|nested] 77+ messages in thread
* [RFC PATCH v2 13/48] accel: Move cpu_common_[un]realize() declarations to AccelOpsClass
2025-06-20 17:12 [RFC PATCH v2 00/48] accel: Preparatory cleanups for split-accel Philippe Mathieu-Daudé
` (11 preceding siblings ...)
2025-06-20 17:13 ` [RFC PATCH v2 12/48] accel: Move cpus_are_resettable() " Philippe Mathieu-Daudé
@ 2025-06-20 17:13 ` Philippe Mathieu-Daudé
2025-06-22 1:24 ` Richard Henderson
2025-06-20 17:13 ` [RFC PATCH v2 14/48] hw/core/machine: Display CPU model name in 'info cpus' command Philippe Mathieu-Daudé
` (27 subsequent siblings)
40 siblings, 1 reply; 77+ messages in thread
From: Philippe Mathieu-Daudé @ 2025-06-20 17:13 UTC (permalink / raw)
To: qemu-devel
Cc: Alex Bennée, Alexander Graf, Richard Henderson,
Pierrick Bouvier, Peter Maydell, Thomas Huth, Cameron Esfahani,
Julian Armistead, Paolo Bonzini, Edgar E. Iglesias,
Philippe Mathieu-Daudé
AccelClass is for methods dealing with AccelState.
When dealing with vCPUs, we want AccelOpsClass.
Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
---
include/qemu/accel.h | 2 --
include/system/accel-ops.h | 2 ++
accel/accel-common.c | 10 ++++++----
accel/tcg/tcg-accel-ops.c | 3 +++
accel/tcg/tcg-all.c | 2 --
5 files changed, 11 insertions(+), 8 deletions(-)
diff --git a/include/qemu/accel.h b/include/qemu/accel.h
index 04d252d3d65..aee0a2e3309 100644
--- a/include/qemu/accel.h
+++ b/include/qemu/accel.h
@@ -41,8 +41,6 @@ typedef struct AccelClass {
AccelOpsClass *ops;
int (*init_machine)(MachineState *ms, AccelState *as);
- bool (*cpu_common_realize)(CPUState *cpu, Error **errp);
- void (*cpu_common_unrealize)(CPUState *cpu);
/* system related hooks */
void (*setup_post)(MachineState *ms, AccelState *accel);
diff --git a/include/system/accel-ops.h b/include/system/accel-ops.h
index d854b84a66a..fb199dc78f0 100644
--- a/include/system/accel-ops.h
+++ b/include/system/accel-ops.h
@@ -34,6 +34,8 @@ struct AccelOpsClass {
/* initialization function called when accel is chosen */
void (*ops_init)(AccelClass *ac);
+ bool (*cpu_common_realize)(CPUState *cpu, Error **errp);
+ void (*cpu_common_unrealize)(CPUState *cpu);
bool (*cpu_target_realize)(CPUState *cpu, Error **errp);
void (*cpu_reset_hold)(CPUState *cpu);
diff --git a/accel/accel-common.c b/accel/accel-common.c
index 1d04610f55e..d1a5f3ca3df 100644
--- a/accel/accel-common.c
+++ b/accel/accel-common.c
@@ -102,10 +102,12 @@ bool accel_cpu_common_realize(CPUState *cpu, Error **errp)
}
/* generic realization */
- if (acc->cpu_common_realize && !acc->cpu_common_realize(cpu, errp)) {
+ if (acc->ops->cpu_common_realize
+ && !acc->ops->cpu_common_realize(cpu, errp)) {
return false;
}
- if (acc->ops->cpu_target_realize && !acc->ops->cpu_target_realize(cpu, errp)) {
+ if (acc->ops->cpu_target_realize
+ && !acc->ops->cpu_target_realize(cpu, errp)) {
return false;
}
@@ -118,8 +120,8 @@ void accel_cpu_common_unrealize(CPUState *cpu)
AccelClass *acc = ACCEL_GET_CLASS(accel);
/* generic unrealization */
- if (acc->cpu_common_unrealize) {
- acc->cpu_common_unrealize(cpu);
+ if (acc->ops->cpu_common_unrealize) {
+ acc->ops->cpu_common_unrealize(cpu);
}
}
diff --git a/accel/tcg/tcg-accel-ops.c b/accel/tcg/tcg-accel-ops.c
index 07b1ec4ea50..95ff451c148 100644
--- a/accel/tcg/tcg-accel-ops.c
+++ b/accel/tcg/tcg-accel-ops.c
@@ -46,6 +46,7 @@
#include "tcg-accel-ops-mttcg.h"
#include "tcg-accel-ops-rr.h"
#include "tcg-accel-ops-icount.h"
+#include "internal-common.h"
/* common functionality among all TCG variants */
@@ -212,6 +213,8 @@ static void tcg_accel_ops_init(AccelClass *ac)
}
}
+ ops->cpu_common_realize = tcg_exec_realizefn;
+ ops->cpu_common_unrealize = tcg_exec_unrealizefn;
ops->cpu_reset_hold = tcg_cpu_reset_hold;
ops->insert_breakpoint = tcg_insert_breakpoint;
ops->remove_breakpoint = tcg_remove_breakpoint;
diff --git a/accel/tcg/tcg-all.c b/accel/tcg/tcg-all.c
index 164bba41ed9..28206ca5e76 100644
--- a/accel/tcg/tcg-all.c
+++ b/accel/tcg/tcg-all.c
@@ -244,8 +244,6 @@ static void tcg_accel_class_init(ObjectClass *oc, const void *data)
AccelClass *ac = ACCEL_CLASS(oc);
ac->name = "tcg";
ac->init_machine = tcg_init_machine;
- ac->cpu_common_realize = tcg_exec_realizefn;
- ac->cpu_common_unrealize = tcg_exec_unrealizefn;
ac->allowed = &tcg_allowed;
ac->supports_guest_debug = tcg_supports_guest_debug;
ac->gdbstub_supported_sstep_flags = tcg_gdbstub_supported_sstep_flags;
--
2.49.0
^ permalink raw reply related [flat|nested] 77+ messages in thread
* [RFC PATCH v2 14/48] hw/core/machine: Display CPU model name in 'info cpus' command
2025-06-20 17:12 [RFC PATCH v2 00/48] accel: Preparatory cleanups for split-accel Philippe Mathieu-Daudé
` (12 preceding siblings ...)
2025-06-20 17:13 ` [RFC PATCH v2 13/48] accel: Move cpu_common_[un]realize() declarations to AccelOpsClass Philippe Mathieu-Daudé
@ 2025-06-20 17:13 ` Philippe Mathieu-Daudé
2025-06-20 17:13 ` [RFC PATCH v2 15/48] accel/system: Add 'info accel' on human monitor Philippe Mathieu-Daudé
` (26 subsequent siblings)
40 siblings, 0 replies; 77+ messages in thread
From: Philippe Mathieu-Daudé @ 2025-06-20 17:13 UTC (permalink / raw)
To: qemu-devel
Cc: Alex Bennée, Alexander Graf, Richard Henderson,
Pierrick Bouvier, Peter Maydell, Thomas Huth, Cameron Esfahani,
Julian Armistead, Paolo Bonzini, Edgar E. Iglesias,
Philippe Mathieu-Daudé
Display the CPU model in 'info cpus'. Example before:
$ qemu-system-aarch64 -M xlnx-versal-virt -S -monitor stdio
QEMU 10.0.0 monitor - type 'help' for more information
(qemu) info cpus
* CPU #0: thread_id=42924
CPU #1: thread_id=42924
CPU #2: thread_id=42924
CPU #3: thread_id=42924
(qemu) q
and after:
$ qemu-system-aarch64 -M xlnx-versal-virt -S -monitor stdio
QEMU 10.0.50 monitor - type 'help' for more information
(qemu) info cpus
* CPU #0: thread_id=42916 (cortex-a72)
CPU #1: thread_id=42916 (cortex-a72)
CPU #2: thread_id=42916 (cortex-r5f)
CPU #3: thread_id=42916 (cortex-r5f)
(qemu)
Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
---
qapi/machine.json | 3 +++
hw/core/machine-hmp-cmds.c | 3 ++-
hw/core/machine-qmp-cmds.c | 1 +
3 files changed, 6 insertions(+), 1 deletion(-)
diff --git a/qapi/machine.json b/qapi/machine.json
index 0650b8de71a..d5bbb5e367e 100644
--- a/qapi/machine.json
+++ b/qapi/machine.json
@@ -80,6 +80,8 @@
#
# @thread-id: ID of the underlying host thread
#
+# @model: CPU model name (since 10.1)
+#
# @props: properties associated with a virtual CPU, e.g. the socket id
#
# @target: the QEMU system emulation target, which determines which
@@ -91,6 +93,7 @@
'base' : { 'cpu-index' : 'int',
'qom-path' : 'str',
'thread-id' : 'int',
+ 'model' : 'str',
'*props' : 'CpuInstanceProperties',
'target' : 'SysEmuTarget' },
'discriminator' : 'target',
diff --git a/hw/core/machine-hmp-cmds.c b/hw/core/machine-hmp-cmds.c
index c6325cdcaaa..65eeb5e9cc2 100644
--- a/hw/core/machine-hmp-cmds.c
+++ b/hw/core/machine-hmp-cmds.c
@@ -40,7 +40,8 @@ void hmp_info_cpus(Monitor *mon, const QDict *qdict)
monitor_printf(mon, "%c CPU #%" PRId64 ":", active,
cpu->value->cpu_index);
- monitor_printf(mon, " thread_id=%" PRId64 "\n", cpu->value->thread_id);
+ monitor_printf(mon, " thread_id=%" PRId64 " (%s)\n",
+ cpu->value->thread_id, cpu->value->model);
}
qapi_free_CpuInfoFastList(cpu_list);
diff --git a/hw/core/machine-qmp-cmds.c b/hw/core/machine-qmp-cmds.c
index d82043e1c68..ab4fd1ec08a 100644
--- a/hw/core/machine-qmp-cmds.c
+++ b/hw/core/machine-qmp-cmds.c
@@ -47,6 +47,7 @@ CpuInfoFastList *qmp_query_cpus_fast(Error **errp)
value->cpu_index = cpu->cpu_index;
value->qom_path = object_get_canonical_path(OBJECT(cpu));
value->thread_id = cpu->thread_id;
+ value->model = cpu_model_from_type(object_get_typename(OBJECT(cpu)));
if (mc->cpu_index_to_instance_props) {
CpuInstanceProperties *props;
--
2.49.0
^ permalink raw reply related [flat|nested] 77+ messages in thread
* [RFC PATCH v2 15/48] accel/system: Add 'info accel' on human monitor
2025-06-20 17:12 [RFC PATCH v2 00/48] accel: Preparatory cleanups for split-accel Philippe Mathieu-Daudé
` (13 preceding siblings ...)
2025-06-20 17:13 ` [RFC PATCH v2 14/48] hw/core/machine: Display CPU model name in 'info cpus' command Philippe Mathieu-Daudé
@ 2025-06-20 17:13 ` Philippe Mathieu-Daudé
2025-06-22 1:26 ` Richard Henderson
2025-06-20 17:13 ` [RFC PATCH v2 16/48] accel/tcg: Factor tcg_dump_flush_info() out Philippe Mathieu-Daudé
` (25 subsequent siblings)
40 siblings, 1 reply; 77+ messages in thread
From: Philippe Mathieu-Daudé @ 2025-06-20 17:13 UTC (permalink / raw)
To: qemu-devel
Cc: Alex Bennée, Alexander Graf, Richard Henderson,
Pierrick Bouvier, Peter Maydell, Thomas Huth, Cameron Esfahani,
Julian Armistead, Paolo Bonzini, Edgar E. Iglesias,
Philippe Mathieu-Daudé
'info accel' dispatches to the AccelOpsClass::get_stats()
and get_vcpu_stats() handlers.
Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
---
include/qemu/accel.h | 1 +
include/system/accel-ops.h | 2 ++
accel/accel-system.c | 28 ++++++++++++++++++++++++++++
hmp-commands-info.hx | 12 ++++++++++++
4 files changed, 43 insertions(+)
diff --git a/include/qemu/accel.h b/include/qemu/accel.h
index aee0a2e3309..4ed5f264a88 100644
--- a/include/qemu/accel.h
+++ b/include/qemu/accel.h
@@ -41,6 +41,7 @@ typedef struct AccelClass {
AccelOpsClass *ops;
int (*init_machine)(MachineState *ms, AccelState *as);
+ void (*get_stats)(AccelState *as, GString *buf);
/* system related hooks */
void (*setup_post)(MachineState *ms, AccelState *accel);
diff --git a/include/system/accel-ops.h b/include/system/accel-ops.h
index fb199dc78f0..5c5171ea5b5 100644
--- a/include/system/accel-ops.h
+++ b/include/system/accel-ops.h
@@ -51,6 +51,8 @@ struct AccelOpsClass {
void (*handle_interrupt)(CPUState *cpu, int mask);
+ void (*get_vcpu_stats)(CPUState *cpu, GString *buf);
+
/**
* @get_virtual_clock: fetch virtual clock
* @set_virtual_clock: set virtual clock
diff --git a/accel/accel-system.c b/accel/accel-system.c
index 1db146139c4..b37889b84f0 100644
--- a/accel/accel-system.c
+++ b/accel/accel-system.c
@@ -25,6 +25,8 @@
#include "qemu/osdep.h"
#include "qemu/accel.h"
+#include "qapi/type-helpers.h"
+#include "monitor/monitor.h"
#include "hw/boards.h"
#include "system/accel-ops.h"
#include "system/cpus.h"
@@ -72,6 +74,26 @@ bool cpus_are_resettable(void)
return true;
}
+static HumanReadableText *hmp_info_accel(Error **errp)
+{
+ AccelState *accel = current_accel();
+ AccelClass *acc = ACCEL_GET_CLASS(accel);
+ g_autoptr(GString) buf = g_string_new("");
+
+ if (acc->get_stats) {
+ acc->get_stats(accel, buf);
+ }
+ if (acc->ops->get_vcpu_stats) {
+ CPUState *cpu;
+
+ CPU_FOREACH(cpu) {
+ acc->ops->get_vcpu_stats(cpu, buf);
+ }
+ }
+
+ return human_readable_text_from_str(buf);
+}
+
/* initialize the arch-independent accel operation interfaces */
void accel_init_ops_interfaces(AccelClass *ac)
{
@@ -102,11 +124,17 @@ void accel_init_ops_interfaces(AccelClass *ac)
cpus_register_accel(ops);
}
+static void accel_ops_class_init(ObjectClass *oc, const void *data)
+{
+ monitor_register_hmp_info_hrt("accel", hmp_info_accel);
+}
+
static const TypeInfo accel_ops_type_info = {
.name = TYPE_ACCEL_OPS,
.parent = TYPE_OBJECT,
.abstract = true,
.class_size = sizeof(AccelOpsClass),
+ .class_init = accel_ops_class_init,
};
static void accel_system_register_types(void)
diff --git a/hmp-commands-info.hx b/hmp-commands-info.hx
index 639a450ee51..0496be6abfb 100644
--- a/hmp-commands-info.hx
+++ b/hmp-commands-info.hx
@@ -281,6 +281,18 @@ ERST
.cmd = hmp_info_sync_profile,
},
+ {
+ .name = "accel",
+ .args_type = "",
+ .params = "",
+ .help = "show accelerator info",
+ },
+
+SRST
+ ``info accel``
+ Show accelerator info.
+ERST
+
SRST
``info sync-profile [-m|-n]`` [*max*]
Show synchronization profiling info, up to *max* entries (default: 10),
--
2.49.0
^ permalink raw reply related [flat|nested] 77+ messages in thread
* [RFC PATCH v2 16/48] accel/tcg: Factor tcg_dump_flush_info() out
2025-06-20 17:12 [RFC PATCH v2 00/48] accel: Preparatory cleanups for split-accel Philippe Mathieu-Daudé
` (14 preceding siblings ...)
2025-06-20 17:13 ` [RFC PATCH v2 15/48] accel/system: Add 'info accel' on human monitor Philippe Mathieu-Daudé
@ 2025-06-20 17:13 ` Philippe Mathieu-Daudé
2025-06-22 1:28 ` Richard Henderson
2025-06-20 17:13 ` [RFC PATCH v2 17/48] accel/tcg: Implement get_[vcpu]_stats() Philippe Mathieu-Daudé
` (24 subsequent siblings)
40 siblings, 1 reply; 77+ messages in thread
From: Philippe Mathieu-Daudé @ 2025-06-20 17:13 UTC (permalink / raw)
To: qemu-devel
Cc: Alex Bennée, Alexander Graf, Richard Henderson,
Pierrick Bouvier, Peter Maydell, Thomas Huth, Cameron Esfahani,
Julian Armistead, Paolo Bonzini, Edgar E. Iglesias,
Philippe Mathieu-Daudé
Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
---
accel/tcg/internal-common.h | 2 ++
accel/tcg/monitor.c | 27 +++++++++++++++++----------
2 files changed, 19 insertions(+), 10 deletions(-)
diff --git a/accel/tcg/internal-common.h b/accel/tcg/internal-common.h
index 1dbc45dd955..fb265d0cefa 100644
--- a/accel/tcg/internal-common.h
+++ b/accel/tcg/internal-common.h
@@ -139,4 +139,6 @@ G_NORETURN void cpu_io_recompile(CPUState *cpu, uintptr_t retaddr);
void tb_phys_invalidate(TranslationBlock *tb, tb_page_addr_t page_addr);
void tb_set_jmp_target(TranslationBlock *tb, int n, uintptr_t addr);
+void tcg_dump_flush_info(GString *buf);
+
#endif
diff --git a/accel/tcg/monitor.c b/accel/tcg/monitor.c
index 1c182b6bfb5..5f74881f2a3 100644
--- a/accel/tcg/monitor.c
+++ b/accel/tcg/monitor.c
@@ -146,11 +146,26 @@ static void tcg_dump_info(GString *buf)
g_string_append_printf(buf, "[TCG profiler not compiled]\n");
}
+void tcg_dump_flush_info(GString *buf)
+{
+ size_t flush_full, flush_part, flush_elide;
+
+ g_string_append_printf(buf, "TB flush count %u\n",
+ qatomic_read(&tb_ctx.tb_flush_count));
+ g_string_append_printf(buf, "TB invalidate count %u\n",
+ qatomic_read(&tb_ctx.tb_phys_invalidate_count));
+
+ tlb_flush_counts(&flush_full, &flush_part, &flush_elide);
+ g_string_append_printf(buf, "TLB full flushes %zu\n", flush_full);
+ g_string_append_printf(buf, "TLB partial flushes %zu\n", flush_part);
+ g_string_append_printf(buf, "TLB elided flushes %zu\n", flush_elide);
+}
+
static void dump_exec_info(GString *buf)
{
struct tb_tree_stats tst = {};
struct qht_stats hst;
- size_t nb_tbs, flush_full, flush_part, flush_elide;
+ size_t nb_tbs;
tcg_tb_foreach(tb_tree_stats_iter, &tst);
nb_tbs = tst.nb_tbs;
@@ -187,15 +202,7 @@ static void dump_exec_info(GString *buf)
qht_statistics_destroy(&hst);
g_string_append_printf(buf, "\nStatistics:\n");
- g_string_append_printf(buf, "TB flush count %u\n",
- qatomic_read(&tb_ctx.tb_flush_count));
- g_string_append_printf(buf, "TB invalidate count %u\n",
- qatomic_read(&tb_ctx.tb_phys_invalidate_count));
-
- tlb_flush_counts(&flush_full, &flush_part, &flush_elide);
- g_string_append_printf(buf, "TLB full flushes %zu\n", flush_full);
- g_string_append_printf(buf, "TLB partial flushes %zu\n", flush_part);
- g_string_append_printf(buf, "TLB elided flushes %zu\n", flush_elide);
+ tcg_dump_flush_info(buf);
tcg_dump_info(buf);
}
--
2.49.0
^ permalink raw reply related [flat|nested] 77+ messages in thread
* [RFC PATCH v2 17/48] accel/tcg: Implement get_[vcpu]_stats()
2025-06-20 17:12 [RFC PATCH v2 00/48] accel: Preparatory cleanups for split-accel Philippe Mathieu-Daudé
` (15 preceding siblings ...)
2025-06-20 17:13 ` [RFC PATCH v2 16/48] accel/tcg: Factor tcg_dump_flush_info() out Philippe Mathieu-Daudé
@ 2025-06-20 17:13 ` Philippe Mathieu-Daudé
2025-06-22 1:28 ` Richard Henderson
2025-06-20 17:13 ` [RFC PATCH v2 18/48] accel/hvf: Implement get_vcpu_stats() Philippe Mathieu-Daudé
` (23 subsequent siblings)
40 siblings, 1 reply; 77+ messages in thread
From: Philippe Mathieu-Daudé @ 2025-06-20 17:13 UTC (permalink / raw)
To: qemu-devel
Cc: Alex Bennée, Alexander Graf, Richard Henderson,
Pierrick Bouvier, Peter Maydell, Thomas Huth, Cameron Esfahani,
Julian Armistead, Paolo Bonzini, Edgar E. Iglesias,
Philippe Mathieu-Daudé
Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
---
accel/tcg/tcg-all.c | 6 ++++++
1 file changed, 6 insertions(+)
diff --git a/accel/tcg/tcg-all.c b/accel/tcg/tcg-all.c
index 28206ca5e76..f5920b5796e 100644
--- a/accel/tcg/tcg-all.c
+++ b/accel/tcg/tcg-all.c
@@ -239,11 +239,17 @@ static int tcg_gdbstub_supported_sstep_flags(AccelState *as)
}
}
+static void tcg_get_stats(AccelState *as, GString *buf)
+{
+ tcg_dump_flush_info(buf);
+}
+
static void tcg_accel_class_init(ObjectClass *oc, const void *data)
{
AccelClass *ac = ACCEL_CLASS(oc);
ac->name = "tcg";
ac->init_machine = tcg_init_machine;
+ ac->get_stats = tcg_get_stats;
ac->allowed = &tcg_allowed;
ac->supports_guest_debug = tcg_supports_guest_debug;
ac->gdbstub_supported_sstep_flags = tcg_gdbstub_supported_sstep_flags;
--
2.49.0
^ permalink raw reply related [flat|nested] 77+ messages in thread
* Re: [RFC PATCH v2 17/48] accel/tcg: Implement get_[vcpu]_stats()
2025-06-20 17:13 ` [RFC PATCH v2 17/48] accel/tcg: Implement get_[vcpu]_stats() Philippe Mathieu-Daudé
@ 2025-06-22 1:28 ` Richard Henderson
0 siblings, 0 replies; 77+ messages in thread
From: Richard Henderson @ 2025-06-22 1:28 UTC (permalink / raw)
To: Philippe Mathieu-Daudé, qemu-devel
On 6/20/25 10:13, Philippe Mathieu-Daudé wrote:
> Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
> ---
> accel/tcg/tcg-all.c | 6 ++++++
> 1 file changed, 6 insertions(+)
>
> diff --git a/accel/tcg/tcg-all.c b/accel/tcg/tcg-all.c
> index 28206ca5e76..f5920b5796e 100644
> --- a/accel/tcg/tcg-all.c
> +++ b/accel/tcg/tcg-all.c
> @@ -239,11 +239,17 @@ static int tcg_gdbstub_supported_sstep_flags(AccelState *as)
> }
> }
>
> +static void tcg_get_stats(AccelState *as, GString *buf)
> +{
> + tcg_dump_flush_info(buf);
> +}
> +
> static void tcg_accel_class_init(ObjectClass *oc, const void *data)
> {
> AccelClass *ac = ACCEL_CLASS(oc);
> ac->name = "tcg";
> ac->init_machine = tcg_init_machine;
> + ac->get_stats = tcg_get_stats;
> ac->allowed = &tcg_allowed;
> ac->supports_guest_debug = tcg_supports_guest_debug;
> ac->gdbstub_supported_sstep_flags = tcg_gdbstub_supported_sstep_flags;
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
r~
^ permalink raw reply [flat|nested] 77+ messages in thread
* [RFC PATCH v2 18/48] accel/hvf: Implement get_vcpu_stats()
2025-06-20 17:12 [RFC PATCH v2 00/48] accel: Preparatory cleanups for split-accel Philippe Mathieu-Daudé
` (16 preceding siblings ...)
2025-06-20 17:13 ` [RFC PATCH v2 17/48] accel/tcg: Implement get_[vcpu]_stats() Philippe Mathieu-Daudé
@ 2025-06-20 17:13 ` Philippe Mathieu-Daudé
2025-06-22 1:30 ` Richard Henderson
2025-06-20 17:13 ` [RFC PATCH v2 19/48] cpus: Document CPUState::vcpu_dirty field Philippe Mathieu-Daudé
` (22 subsequent siblings)
40 siblings, 1 reply; 77+ messages in thread
From: Philippe Mathieu-Daudé @ 2025-06-20 17:13 UTC (permalink / raw)
To: qemu-devel
Cc: Alex Bennée, Alexander Graf, Richard Henderson,
Pierrick Bouvier, Peter Maydell, Thomas Huth, Cameron Esfahani,
Julian Armistead, Paolo Bonzini, Edgar E. Iglesias,
Philippe Mathieu-Daudé
Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
---
accel/hvf/hvf-accel-ops.c | 19 +++++++++++++++++++
1 file changed, 19 insertions(+)
diff --git a/accel/hvf/hvf-accel-ops.c b/accel/hvf/hvf-accel-ops.c
index 45dd4baa321..bfdfef7c397 100644
--- a/accel/hvf/hvf-accel-ops.c
+++ b/accel/hvf/hvf-accel-ops.c
@@ -358,6 +358,12 @@ static inline int hvf_gdbstub_sstep_flags(AccelState *as)
return SSTEP_ENABLE | SSTEP_NOIRQ;
}
+static void do_hvf_get_vcpu_exec_time(CPUState *cpu, run_on_cpu_data arg)
+{
+ int r = hv_vcpu_get_exec_time(cpu->accel->fd, arg.host_ptr);
+ assert_hvf_ok(r);
+}
+
static void hvf_accel_class_init(ObjectClass *oc, const void *data)
{
AccelClass *ac = ACCEL_CLASS(oc);
@@ -583,6 +589,16 @@ static void hvf_remove_all_breakpoints(CPUState *cpu)
}
}
+static void hvf_get_vcpu_stats(CPUState *cpu, GString *buf)
+{
+ uint64_t time_us; /* units of mach_absolute_time() */
+
+ run_on_cpu(cpu, do_hvf_get_vcpu_exec_time, RUN_ON_CPU_HOST_PTR(&time_us));
+
+ g_string_append_printf(buf, "HVF cumulative execution time: %llu.%.3llus\n",
+ time_us / 1000000, (time_us % 1000000) / 1000);
+}
+
static void hvf_accel_ops_class_init(ObjectClass *oc, const void *data)
{
AccelOpsClass *ops = ACCEL_OPS_CLASS(oc);
@@ -601,7 +617,10 @@ static void hvf_accel_ops_class_init(ObjectClass *oc, const void *data)
ops->remove_breakpoint = hvf_remove_breakpoint;
ops->remove_all_breakpoints = hvf_remove_all_breakpoints;
ops->update_guest_debug = hvf_update_guest_debug;
+
+ ops->get_vcpu_stats = hvf_get_vcpu_stats;
};
+
static const TypeInfo hvf_accel_ops_type = {
.name = ACCEL_OPS_NAME("hvf"),
--
2.49.0
^ permalink raw reply related [flat|nested] 77+ messages in thread
* [RFC PATCH v2 19/48] cpus: Document CPUState::vcpu_dirty field
2025-06-20 17:12 [RFC PATCH v2 00/48] accel: Preparatory cleanups for split-accel Philippe Mathieu-Daudé
` (17 preceding siblings ...)
2025-06-20 17:13 ` [RFC PATCH v2 18/48] accel/hvf: Implement get_vcpu_stats() Philippe Mathieu-Daudé
@ 2025-06-20 17:13 ` Philippe Mathieu-Daudé
2025-06-22 1:30 ` Richard Henderson
2025-06-20 17:13 ` [RFC PATCH v2 20/48] cpus: Rename 'vcpu_dirty' field as negated 'hwaccel_synchronized' Philippe Mathieu-Daudé
` (21 subsequent siblings)
40 siblings, 1 reply; 77+ messages in thread
From: Philippe Mathieu-Daudé @ 2025-06-20 17:13 UTC (permalink / raw)
To: qemu-devel
Cc: Alex Bennée, Alexander Graf, Richard Henderson,
Pierrick Bouvier, Peter Maydell, Thomas Huth, Cameron Esfahani,
Julian Armistead, Paolo Bonzini, Edgar E. Iglesias,
Philippe Mathieu-Daudé
Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
---
include/hw/core/cpu.h | 1 +
1 file changed, 1 insertion(+)
diff --git a/include/hw/core/cpu.h b/include/hw/core/cpu.h
index 33296a1c080..69ea425c458 100644
--- a/include/hw/core/cpu.h
+++ b/include/hw/core/cpu.h
@@ -441,6 +441,7 @@ struct qemu_work_item;
* @opaque: User data.
* @mem_io_pc: Host Program Counter at which the memory was accessed.
* @accel: Pointer to accelerator specific state.
+ * @vcpu_dirty: Hardware accelerator is not synchronized with QEMU state
* @kvm_fd: vCPU file descriptor for KVM.
* @work_mutex: Lock to prevent multiple access to @work_list.
* @work_list: List of pending asynchronous work.
--
2.49.0
^ permalink raw reply related [flat|nested] 77+ messages in thread
* Re: [RFC PATCH v2 19/48] cpus: Document CPUState::vcpu_dirty field
2025-06-20 17:13 ` [RFC PATCH v2 19/48] cpus: Document CPUState::vcpu_dirty field Philippe Mathieu-Daudé
@ 2025-06-22 1:30 ` Richard Henderson
0 siblings, 0 replies; 77+ messages in thread
From: Richard Henderson @ 2025-06-22 1:30 UTC (permalink / raw)
To: Philippe Mathieu-Daudé, qemu-devel
On 6/20/25 10:13, Philippe Mathieu-Daudé wrote:
> Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
> ---
> include/hw/core/cpu.h | 1 +
> 1 file changed, 1 insertion(+)
>
> diff --git a/include/hw/core/cpu.h b/include/hw/core/cpu.h
> index 33296a1c080..69ea425c458 100644
> --- a/include/hw/core/cpu.h
> +++ b/include/hw/core/cpu.h
> @@ -441,6 +441,7 @@ struct qemu_work_item;
> * @opaque: User data.
> * @mem_io_pc: Host Program Counter at which the memory was accessed.
> * @accel: Pointer to accelerator specific state.
> + * @vcpu_dirty: Hardware accelerator is not synchronized with QEMU state
> * @kvm_fd: vCPU file descriptor for KVM.
> * @work_mutex: Lock to prevent multiple access to @work_list.
> * @work_list: List of pending asynchronous work.
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
r~
^ permalink raw reply [flat|nested] 77+ messages in thread
* [RFC PATCH v2 20/48] cpus: Rename 'vcpu_dirty' field as negated 'hwaccel_synchronized'
2025-06-20 17:12 [RFC PATCH v2 00/48] accel: Preparatory cleanups for split-accel Philippe Mathieu-Daudé
` (18 preceding siblings ...)
2025-06-20 17:13 ` [RFC PATCH v2 19/48] cpus: Document CPUState::vcpu_dirty field Philippe Mathieu-Daudé
@ 2025-06-20 17:13 ` Philippe Mathieu-Daudé
2025-06-22 1:35 ` Richard Henderson
2025-06-20 17:13 ` [RFC PATCH v2 21/48] accel/hvf: Replace @dirty field by generic @hwaccel_synchronized Philippe Mathieu-Daudé
` (20 subsequent siblings)
40 siblings, 1 reply; 77+ messages in thread
From: Philippe Mathieu-Daudé @ 2025-06-20 17:13 UTC (permalink / raw)
To: qemu-devel
Cc: Alex Bennée, Alexander Graf, Richard Henderson,
Pierrick Bouvier, Peter Maydell, Thomas Huth, Cameron Esfahani,
Julian Armistead, Paolo Bonzini, Edgar E. Iglesias,
Philippe Mathieu-Daudé
Try to better describe which side is dirty (QEMU process or
hardware accelerator) by renaming as @hwaccel_synchronized.
Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
---
include/hw/core/cpu.h | 4 ++--
accel/kvm/kvm-all.c | 20 ++++++++++----------
target/mips/kvm.c | 4 ++--
3 files changed, 14 insertions(+), 14 deletions(-)
diff --git a/include/hw/core/cpu.h b/include/hw/core/cpu.h
index 69ea425c458..d5f82609943 100644
--- a/include/hw/core/cpu.h
+++ b/include/hw/core/cpu.h
@@ -441,7 +441,7 @@ struct qemu_work_item;
* @opaque: User data.
* @mem_io_pc: Host Program Counter at which the memory was accessed.
* @accel: Pointer to accelerator specific state.
- * @vcpu_dirty: Hardware accelerator is not synchronized with QEMU state
+ * @hwaccel_synchronized: Hardware accelerator is synchronized with QEMU state
* @kvm_fd: vCPU file descriptor for KVM.
* @work_mutex: Lock to prevent multiple access to @work_list.
* @work_list: List of pending asynchronous work.
@@ -538,7 +538,6 @@ struct CPUState {
uint32_t kvm_fetch_index;
uint64_t dirty_pages;
int kvm_vcpu_stats_fd;
- bool vcpu_dirty;
/* Use by accel-block: CPU is executing an ioctl() */
QemuLockCnt in_ioctl_lock;
@@ -555,6 +554,7 @@ struct CPUState {
int32_t exception_index;
AccelCPUState *accel;
+ bool hwaccel_synchronized;
/* Used to keep track of an outstanding cpu throttle thread for migration
* autoconverge
diff --git a/accel/kvm/kvm-all.c b/accel/kvm/kvm-all.c
index 37faf615cbc..dca6d4b99ef 100644
--- a/accel/kvm/kvm-all.c
+++ b/accel/kvm/kvm-all.c
@@ -478,8 +478,8 @@ static int kvm_create_vcpu(CPUState *cpu)
cpu->kvm_fd = kvm_fd;
cpu->kvm_state = s;
- if (!s->guest_state_protected) {
- cpu->vcpu_dirty = true;
+ if (s->guest_state_protected) {
+ cpu->hwaccel_synchronized = true;
}
cpu->dirty_pages = 0;
cpu->throttle_us_per_full = 0;
@@ -2880,7 +2880,7 @@ void kvm_flush_coalesced_mmio_buffer(void)
static void do_kvm_cpu_synchronize_state(CPUState *cpu, run_on_cpu_data arg)
{
- if (!cpu->vcpu_dirty && !kvm_state->guest_state_protected) {
+ if (cpu->hwaccel_synchronized && !kvm_state->guest_state_protected) {
Error *err = NULL;
int ret = kvm_arch_get_registers(cpu, &err);
if (ret) {
@@ -2894,13 +2894,13 @@ static void do_kvm_cpu_synchronize_state(CPUState *cpu, run_on_cpu_data arg)
vm_stop(RUN_STATE_INTERNAL_ERROR);
}
- cpu->vcpu_dirty = true;
+ cpu->hwaccel_synchronized = false;
}
}
void kvm_cpu_synchronize_state(CPUState *cpu)
{
- if (!cpu->vcpu_dirty && !kvm_state->guest_state_protected) {
+ if (cpu->hwaccel_synchronized && !kvm_state->guest_state_protected) {
run_on_cpu(cpu, do_kvm_cpu_synchronize_state, RUN_ON_CPU_NULL);
}
}
@@ -2920,7 +2920,7 @@ static void do_kvm_cpu_synchronize_post_reset(CPUState *cpu, run_on_cpu_data arg
vm_stop(RUN_STATE_INTERNAL_ERROR);
}
- cpu->vcpu_dirty = false;
+ cpu->hwaccel_synchronized = true;
}
void kvm_cpu_synchronize_post_reset(CPUState *cpu)
@@ -2946,7 +2946,7 @@ static void do_kvm_cpu_synchronize_post_init(CPUState *cpu, run_on_cpu_data arg)
exit(1);
}
- cpu->vcpu_dirty = false;
+ cpu->hwaccel_synchronized = true;
}
void kvm_cpu_synchronize_post_init(CPUState *cpu)
@@ -2962,7 +2962,7 @@ void kvm_cpu_synchronize_post_init(CPUState *cpu)
static void do_kvm_cpu_synchronize_pre_loadvm(CPUState *cpu, run_on_cpu_data arg)
{
- cpu->vcpu_dirty = true;
+ cpu->hwaccel_synchronized = false;
}
void kvm_cpu_synchronize_pre_loadvm(CPUState *cpu)
@@ -3131,7 +3131,7 @@ int kvm_cpu_exec(CPUState *cpu)
do {
MemTxAttrs attrs;
- if (cpu->vcpu_dirty) {
+ if (!cpu->hwaccel_synchronized) {
Error *err = NULL;
ret = kvm_arch_put_registers(cpu, KVM_PUT_RUNTIME_STATE, &err);
if (ret) {
@@ -3145,7 +3145,7 @@ int kvm_cpu_exec(CPUState *cpu)
break;
}
- cpu->vcpu_dirty = false;
+ cpu->hwaccel_synchronized = true;
}
kvm_arch_pre_run(cpu, run);
diff --git a/target/mips/kvm.c b/target/mips/kvm.c
index ec53acb51a1..44fca0d649f 100644
--- a/target/mips/kvm.c
+++ b/target/mips/kvm.c
@@ -565,7 +565,7 @@ static void kvm_mips_update_state(void *opaque, bool running, RunState state)
* already saved and can be restored when it is synced back to KVM.
*/
if (!running) {
- if (!cs->vcpu_dirty) {
+ if (cs->hwaccel_synchronized) {
ret = kvm_mips_save_count(cs);
if (ret < 0) {
warn_report("Failed saving count");
@@ -581,7 +581,7 @@ static void kvm_mips_update_state(void *opaque, bool running, RunState state)
return;
}
- if (!cs->vcpu_dirty) {
+ if (cs->hwaccel_synchronized) {
ret = kvm_mips_restore_count(cs);
if (ret < 0) {
warn_report("Failed restoring count");
--
2.49.0
^ permalink raw reply related [flat|nested] 77+ messages in thread
* Re: [RFC PATCH v2 20/48] cpus: Rename 'vcpu_dirty' field as negated 'hwaccel_synchronized'
2025-06-20 17:13 ` [RFC PATCH v2 20/48] cpus: Rename 'vcpu_dirty' field as negated 'hwaccel_synchronized' Philippe Mathieu-Daudé
@ 2025-06-22 1:35 ` Richard Henderson
2025-06-23 14:13 ` Philippe Mathieu-Daudé
0 siblings, 1 reply; 77+ messages in thread
From: Richard Henderson @ 2025-06-22 1:35 UTC (permalink / raw)
To: Philippe Mathieu-Daudé, qemu-devel
Cc: Alex Bennée, Alexander Graf, Pierrick Bouvier, Peter Maydell,
Thomas Huth, Cameron Esfahani, Julian Armistead, Paolo Bonzini,
Edgar E. Iglesias
On 6/20/25 10:13, Philippe Mathieu-Daudé wrote:
> Try to better describe which side is dirty (QEMU process or
> hardware accelerator) by renaming as @hwaccel_synchronized.
>
> Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
> ---
> include/hw/core/cpu.h | 4 ++--
> accel/kvm/kvm-all.c | 20 ++++++++++----------
> target/mips/kvm.c | 4 ++--
> 3 files changed, 14 insertions(+), 14 deletions(-)
>
> diff --git a/include/hw/core/cpu.h b/include/hw/core/cpu.h
> index 69ea425c458..d5f82609943 100644
> --- a/include/hw/core/cpu.h
> +++ b/include/hw/core/cpu.h
> @@ -441,7 +441,7 @@ struct qemu_work_item;
> * @opaque: User data.
> * @mem_io_pc: Host Program Counter at which the memory was accessed.
> * @accel: Pointer to accelerator specific state.
> - * @vcpu_dirty: Hardware accelerator is not synchronized with QEMU state
> + * @hwaccel_synchronized: Hardware accelerator is synchronized with QEMU state
Is this change really helpful? It isn't to me...
If you want to change anything, this could be a tri-state enum:
- qemu state is current
- hwaccel state is current
- qemu+hwaccel are synced
r~
^ permalink raw reply [flat|nested] 77+ messages in thread
* Re: [RFC PATCH v2 20/48] cpus: Rename 'vcpu_dirty' field as negated 'hwaccel_synchronized'
2025-06-22 1:35 ` Richard Henderson
@ 2025-06-23 14:13 ` Philippe Mathieu-Daudé
0 siblings, 0 replies; 77+ messages in thread
From: Philippe Mathieu-Daudé @ 2025-06-23 14:13 UTC (permalink / raw)
To: Richard Henderson, qemu-devel
Cc: Alex Bennée, Alexander Graf, Pierrick Bouvier, Peter Maydell,
Thomas Huth, Cameron Esfahani, Julian Armistead, Paolo Bonzini,
Edgar E. Iglesias
On 22/6/25 03:35, Richard Henderson wrote:
> On 6/20/25 10:13, Philippe Mathieu-Daudé wrote:
>> Try to better describe which side is dirty (QEMU process or
>> hardware accelerator) by renaming as @hwaccel_synchronized.
>>
>> Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
>> ---
>> include/hw/core/cpu.h | 4 ++--
>> accel/kvm/kvm-all.c | 20 ++++++++++----------
>> target/mips/kvm.c | 4 ++--
>> 3 files changed, 14 insertions(+), 14 deletions(-)
>>
>> diff --git a/include/hw/core/cpu.h b/include/hw/core/cpu.h
>> index 69ea425c458..d5f82609943 100644
>> --- a/include/hw/core/cpu.h
>> +++ b/include/hw/core/cpu.h
>> @@ -441,7 +441,7 @@ struct qemu_work_item;
>> * @opaque: User data.
>> * @mem_io_pc: Host Program Counter at which the memory was accessed.
>> * @accel: Pointer to accelerator specific state.
>> - * @vcpu_dirty: Hardware accelerator is not synchronized with QEMU state
>> + * @hwaccel_synchronized: Hardware accelerator is synchronized with
>> QEMU state
>
> Is this change really helpful? It isn't to me...
>
> If you want to change anything, this could be a tri-state enum:
>
> - qemu state is current
> - hwaccel state is current
> - qemu+hwaccel are synced
Good idea. I'll drop these patches for now.
^ permalink raw reply [flat|nested] 77+ messages in thread
* [RFC PATCH v2 21/48] accel/hvf: Replace @dirty field by generic @hwaccel_synchronized
2025-06-20 17:12 [RFC PATCH v2 00/48] accel: Preparatory cleanups for split-accel Philippe Mathieu-Daudé
` (19 preceding siblings ...)
2025-06-20 17:13 ` [RFC PATCH v2 20/48] cpus: Rename 'vcpu_dirty' field as negated 'hwaccel_synchronized' Philippe Mathieu-Daudé
@ 2025-06-20 17:13 ` Philippe Mathieu-Daudé
2025-06-20 17:13 ` [RFC PATCH v2 22/48] accel/nvmm: " Philippe Mathieu-Daudé
` (19 subsequent siblings)
40 siblings, 0 replies; 77+ messages in thread
From: Philippe Mathieu-Daudé @ 2025-06-20 17:13 UTC (permalink / raw)
To: qemu-devel
Cc: Alex Bennée, Alexander Graf, Richard Henderson,
Pierrick Bouvier, Peter Maydell, Thomas Huth, Cameron Esfahani,
Julian Armistead, Paolo Bonzini, Edgar E. Iglesias,
Philippe Mathieu-Daudé
No need for accel-specific @dirty field when we have
a generic one in CPUState.
Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
---
include/system/hvf_int.h | 1 -
accel/hvf/hvf-accel-ops.c | 10 +++++-----
target/arm/hvf/hvf.c | 4 ++--
target/i386/hvf/hvf.c | 4 ++--
target/i386/hvf/x86hvf.c | 2 +-
5 files changed, 10 insertions(+), 11 deletions(-)
diff --git a/include/system/hvf_int.h b/include/system/hvf_int.h
index d774e58df91..8df0085b9d4 100644
--- a/include/system/hvf_int.h
+++ b/include/system/hvf_int.h
@@ -60,7 +60,6 @@ struct AccelCPUState {
bool vtimer_masked;
sigset_t unblock_ipi_mask;
bool guest_debug_enabled;
- bool dirty;
};
void assert_hvf_ok_impl(hv_return_t ret, const char *file, unsigned int line,
diff --git a/accel/hvf/hvf-accel-ops.c b/accel/hvf/hvf-accel-ops.c
index bfdfef7c397..78bf0ac6cba 100644
--- a/accel/hvf/hvf-accel-ops.c
+++ b/accel/hvf/hvf-accel-ops.c
@@ -207,15 +207,15 @@ static void hvf_set_phys_mem(MemoryRegionSection *section, bool add)
static void do_hvf_cpu_synchronize_state(CPUState *cpu, run_on_cpu_data arg)
{
- if (!cpu->accel->dirty) {
+ if (cpu->hwaccel_synchronized) {
hvf_get_registers(cpu);
- cpu->accel->dirty = true;
+ cpu->hwaccel_synchronized = false;
}
}
static void hvf_cpu_synchronize_state(CPUState *cpu)
{
- if (!cpu->accel->dirty) {
+ if (cpu->hwaccel_synchronized) {
run_on_cpu(cpu, do_hvf_cpu_synchronize_state, RUN_ON_CPU_NULL);
}
}
@@ -224,7 +224,7 @@ static void do_hvf_cpu_synchronize_set_dirty(CPUState *cpu,
run_on_cpu_data arg)
{
/* QEMU state is the reference, push it to HVF now and on next entry */
- cpu->accel->dirty = true;
+ cpu->hwaccel_synchronized = false;
}
static void hvf_cpu_synchronize_post_reset(CPUState *cpu)
@@ -420,8 +420,8 @@ static int hvf_init_vcpu(CPUState *cpu)
#else
r = hv_vcpu_create(&cpu->accel->fd, HV_VCPU_DEFAULT);
#endif
- cpu->accel->dirty = true;
assert_hvf_ok(r);
+ cpu->hwaccel_synchronized = false;
cpu->accel->guest_debug_enabled = false;
diff --git a/target/arm/hvf/hvf.c b/target/arm/hvf/hvf.c
index 48ce83eb8fc..3907ea8791e 100644
--- a/target/arm/hvf/hvf.c
+++ b/target/arm/hvf/hvf.c
@@ -814,9 +814,9 @@ int hvf_put_registers(CPUState *cpu)
static void flush_cpu_state(CPUState *cpu)
{
- if (cpu->accel->dirty) {
+ if (!cpu->hwaccel_synchronized) {
hvf_put_registers(cpu);
- cpu->accel->dirty = false;
+ cpu->hwaccel_synchronized = true;
}
}
diff --git a/target/i386/hvf/hvf.c b/target/i386/hvf/hvf.c
index bcf30662bec..d0000db0299 100644
--- a/target/i386/hvf/hvf.c
+++ b/target/i386/hvf/hvf.c
@@ -738,9 +738,9 @@ int hvf_vcpu_exec(CPUState *cpu)
}
do {
- if (cpu->accel->dirty) {
+ if (!cpu->hwaccel_synchronized) {
hvf_put_registers(cpu);
- cpu->accel->dirty = false;
+ cpu->hwaccel_synchronized = true;
}
if (hvf_inject_interrupts(cpu)) {
diff --git a/target/i386/hvf/x86hvf.c b/target/i386/hvf/x86hvf.c
index 2057314892a..1c3d03eafe2 100644
--- a/target/i386/hvf/x86hvf.c
+++ b/target/i386/hvf/x86hvf.c
@@ -427,7 +427,7 @@ int hvf_process_events(CPUState *cs)
X86CPU *cpu = X86_CPU(cs);
CPUX86State *env = &cpu->env;
- if (!cs->accel->dirty) {
+ if (cs->hwaccel_synchronized) {
/* light weight sync for CPU_INTERRUPT_HARD and IF_MASK */
env->eflags = rreg(cs->accel->fd, HV_X86_RFLAGS);
}
--
2.49.0
^ permalink raw reply related [flat|nested] 77+ messages in thread
* [RFC PATCH v2 22/48] accel/nvmm: Replace @dirty field by generic @hwaccel_synchronized
2025-06-20 17:12 [RFC PATCH v2 00/48] accel: Preparatory cleanups for split-accel Philippe Mathieu-Daudé
` (20 preceding siblings ...)
2025-06-20 17:13 ` [RFC PATCH v2 21/48] accel/hvf: Replace @dirty field by generic @hwaccel_synchronized Philippe Mathieu-Daudé
@ 2025-06-20 17:13 ` Philippe Mathieu-Daudé
2025-06-20 17:13 ` [RFC PATCH v2 23/48] accel/whpx: " Philippe Mathieu-Daudé
` (18 subsequent siblings)
40 siblings, 0 replies; 77+ messages in thread
From: Philippe Mathieu-Daudé @ 2025-06-20 17:13 UTC (permalink / raw)
To: qemu-devel
Cc: Alex Bennée, Alexander Graf, Richard Henderson,
Pierrick Bouvier, Peter Maydell, Thomas Huth, Cameron Esfahani,
Julian Armistead, Paolo Bonzini, Edgar E. Iglesias,
Philippe Mathieu-Daudé
No need for accel-specific @dirty field when we have
a generic one in CPUState.
Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
---
target/i386/nvmm/nvmm-all.c | 21 ++++++++++-----------
1 file changed, 10 insertions(+), 11 deletions(-)
diff --git a/target/i386/nvmm/nvmm-all.c b/target/i386/nvmm/nvmm-all.c
index 887534d4ca6..5c8e2857a8b 100644
--- a/target/i386/nvmm/nvmm-all.c
+++ b/target/i386/nvmm/nvmm-all.c
@@ -30,7 +30,6 @@ struct AccelCPUState {
struct nvmm_vcpu vcpu;
uint8_t tpr;
bool stop;
- bool dirty;
/* Window-exiting for INTs/NMIs. */
bool int_window_exit;
@@ -508,7 +507,7 @@ nvmm_io_callback(struct nvmm_io *io)
}
/* Needed, otherwise infinite loop. */
- current_cpu->accel->dirty = false;
+ current_cpu->hwaccel_synchronized = true;
}
static void
@@ -517,7 +516,7 @@ nvmm_mem_callback(struct nvmm_mem *mem)
cpu_physical_memory_rw(mem->gpa, mem->data, mem->size, mem->write);
/* Needed, otherwise infinite loop. */
- current_cpu->accel->dirty = false;
+ current_cpu->hwaccel_synchronized = true;
}
static struct nvmm_assist_callbacks nvmm_callbacks = {
@@ -727,9 +726,9 @@ nvmm_vcpu_loop(CPUState *cpu)
* Inner VCPU loop.
*/
do {
- if (cpu->accel->dirty) {
+ if (!cpu->hwaccel_synchronized) {
nvmm_set_registers(cpu);
- cpu->accel->dirty = false;
+ cpu->hwaccel_synchronized = true;
}
if (qcpu->stop) {
@@ -827,32 +826,32 @@ static void
do_nvmm_cpu_synchronize_state(CPUState *cpu, run_on_cpu_data arg)
{
nvmm_get_registers(cpu);
- cpu->accel->dirty = true;
+ cpu->hwaccel_synchronized = false;
}
static void
do_nvmm_cpu_synchronize_post_reset(CPUState *cpu, run_on_cpu_data arg)
{
nvmm_set_registers(cpu);
- cpu->accel->dirty = false;
+ cpu->hwaccel_synchronized = true;
}
static void
do_nvmm_cpu_synchronize_post_init(CPUState *cpu, run_on_cpu_data arg)
{
nvmm_set_registers(cpu);
- cpu->accel->dirty = false;
+ cpu->hwaccel_synchronized = true;
}
static void
do_nvmm_cpu_synchronize_pre_loadvm(CPUState *cpu, run_on_cpu_data arg)
{
- cpu->accel->dirty = true;
+ cpu->hwaccel_synchronized = false;
}
void nvmm_cpu_synchronize_state(CPUState *cpu)
{
- if (!cpu->accel->dirty) {
+ if (cpu->hwaccel_synchronized) {
run_on_cpu(cpu, do_nvmm_cpu_synchronize_state, RUN_ON_CPU_NULL);
}
}
@@ -982,7 +981,7 @@ nvmm_init_vcpu(CPUState *cpu)
}
}
- qcpu->dirty = true;
+ qcpu->hwaccel_synchronized = false;
cpu->accel = qcpu;
return 0;
--
2.49.0
^ permalink raw reply related [flat|nested] 77+ messages in thread
* [RFC PATCH v2 23/48] accel/whpx: Replace @dirty field by generic @hwaccel_synchronized
2025-06-20 17:12 [RFC PATCH v2 00/48] accel: Preparatory cleanups for split-accel Philippe Mathieu-Daudé
` (21 preceding siblings ...)
2025-06-20 17:13 ` [RFC PATCH v2 22/48] accel/nvmm: " Philippe Mathieu-Daudé
@ 2025-06-20 17:13 ` Philippe Mathieu-Daudé
2025-06-20 17:13 ` [RFC PATCH v2 24/48] accel/kvm: Remove kvm_cpu_synchronize_state() stub Philippe Mathieu-Daudé
` (17 subsequent siblings)
40 siblings, 0 replies; 77+ messages in thread
From: Philippe Mathieu-Daudé @ 2025-06-20 17:13 UTC (permalink / raw)
To: qemu-devel
Cc: Alex Bennée, Alexander Graf, Richard Henderson,
Pierrick Bouvier, Peter Maydell, Thomas Huth, Cameron Esfahani,
Julian Armistead, Paolo Bonzini, Edgar E. Iglesias,
Philippe Mathieu-Daudé
No need for accel-specific @dirty field when we have
a generic one in CPUState.
Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
---
target/i386/whpx/whpx-all.c | 23 +++++++++++------------
1 file changed, 11 insertions(+), 12 deletions(-)
diff --git a/target/i386/whpx/whpx-all.c b/target/i386/whpx/whpx-all.c
index 238c3b95c6f..77af84a87d4 100644
--- a/target/i386/whpx/whpx-all.c
+++ b/target/i386/whpx/whpx-all.c
@@ -237,7 +237,6 @@ struct AccelCPUState {
uint64_t tpr;
uint64_t apic_base;
bool interruption_pending;
- bool dirty;
/* Must be the last field as it may have a tail */
WHV_RUN_VP_EXIT_CONTEXT exit_ctx;
@@ -836,7 +835,7 @@ static HRESULT CALLBACK whpx_emu_setreg_callback(
* The emulator just successfully wrote the register state. We clear the
* dirty state so we avoid the double write on resume of the VP.
*/
- cpu->accel->dirty = false;
+ cpu->hwaccel_synchronized = true;
return hr;
}
@@ -1391,7 +1390,7 @@ static int whpx_last_vcpu_stopping(CPUState *cpu)
/* Returns the address of the next instruction that is about to be executed. */
static vaddr whpx_vcpu_get_pc(CPUState *cpu, bool exit_context_valid)
{
- if (cpu->accel->dirty) {
+ if (!cpu->hwaccel_synchronized) {
/* The CPU registers have been modified by other parts of QEMU. */
return cpu_env(cpu)->eip;
} else if (exit_context_valid) {
@@ -1704,9 +1703,9 @@ static int whpx_vcpu_run(CPUState *cpu)
}
do {
- if (cpu->accel->dirty) {
+ if (!cpu->hwaccel_synchronized) {
whpx_set_registers(cpu, WHPX_SET_RUNTIME_STATE);
- cpu->accel->dirty = false;
+ cpu->hwaccel_synchronized = true;
}
if (exclusive_step_mode == WHPX_STEP_NONE) {
@@ -2054,9 +2053,9 @@ static int whpx_vcpu_run(CPUState *cpu)
static void do_whpx_cpu_synchronize_state(CPUState *cpu, run_on_cpu_data arg)
{
- if (!cpu->accel->dirty) {
+ if (cpu->hwaccel_synchronized) {
whpx_get_registers(cpu);
- cpu->accel->dirty = true;
+ cpu->hwaccel_synchronized = false;
}
}
@@ -2064,20 +2063,20 @@ static void do_whpx_cpu_synchronize_post_reset(CPUState *cpu,
run_on_cpu_data arg)
{
whpx_set_registers(cpu, WHPX_SET_RESET_STATE);
- cpu->accel->dirty = false;
+ cpu->hwaccel_synchronized = true;
}
static void do_whpx_cpu_synchronize_post_init(CPUState *cpu,
run_on_cpu_data arg)
{
whpx_set_registers(cpu, WHPX_SET_FULL_STATE);
- cpu->accel->dirty = false;
+ cpu->hwaccel_synchronized = true;
}
static void do_whpx_cpu_synchronize_pre_loadvm(CPUState *cpu,
run_on_cpu_data arg)
{
- cpu->accel->dirty = true;
+ cpu->hwaccel_synchronized = false;
}
/*
@@ -2086,7 +2085,7 @@ static void do_whpx_cpu_synchronize_pre_loadvm(CPUState *cpu,
void whpx_cpu_synchronize_state(CPUState *cpu)
{
- if (!cpu->accel->dirty) {
+ if (cpu->hwaccel_synchronized) {
run_on_cpu(cpu, do_whpx_cpu_synchronize_state, RUN_ON_CPU_NULL);
}
}
@@ -2226,7 +2225,7 @@ int whpx_init_vcpu(CPUState *cpu)
}
vcpu->interruptable = true;
- vcpu->dirty = true;
+ vcpu->hwaccel_synchronized = false;
cpu->accel = vcpu;
max_vcpu_index = max(max_vcpu_index, cpu->cpu_index);
qemu_add_vm_change_state_handler(whpx_cpu_update_state, env);
--
2.49.0
^ permalink raw reply related [flat|nested] 77+ messages in thread
* [RFC PATCH v2 24/48] accel/kvm: Remove kvm_cpu_synchronize_state() stub
2025-06-20 17:12 [RFC PATCH v2 00/48] accel: Preparatory cleanups for split-accel Philippe Mathieu-Daudé
` (22 preceding siblings ...)
2025-06-20 17:13 ` [RFC PATCH v2 23/48] accel/whpx: " Philippe Mathieu-Daudé
@ 2025-06-20 17:13 ` Philippe Mathieu-Daudé
2025-06-22 1:35 ` Richard Henderson
2025-06-20 17:13 ` [RFC PATCH v2 25/48] accel/system: Document cpu_synchronize_state() Philippe Mathieu-Daudé
` (16 subsequent siblings)
40 siblings, 1 reply; 77+ messages in thread
From: Philippe Mathieu-Daudé @ 2025-06-20 17:13 UTC (permalink / raw)
To: qemu-devel
Cc: Alex Bennée, Alexander Graf, Richard Henderson,
Pierrick Bouvier, Peter Maydell, Thomas Huth, Cameron Esfahani,
Julian Armistead, Paolo Bonzini, Edgar E. Iglesias,
Philippe Mathieu-Daudé
Since commit 57038a92bb0 ("cpus: extract out kvm-specific code
to accel/kvm") the kvm_cpu_synchronize_state() stub is not
necessary.
Fixes: e0715f6abce ("kvm: remove kvm specific functions from global includes")
Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
---
accel/stubs/kvm-stub.c | 4 ----
1 file changed, 4 deletions(-)
diff --git a/accel/stubs/kvm-stub.c b/accel/stubs/kvm-stub.c
index b9b4427c919..68cd33ba973 100644
--- a/accel/stubs/kvm-stub.c
+++ b/accel/stubs/kvm-stub.c
@@ -29,10 +29,6 @@ void kvm_flush_coalesced_mmio_buffer(void)
{
}
-void kvm_cpu_synchronize_state(CPUState *cpu)
-{
-}
-
bool kvm_has_sync_mmu(void)
{
return false;
--
2.49.0
^ permalink raw reply related [flat|nested] 77+ messages in thread
* Re: [RFC PATCH v2 24/48] accel/kvm: Remove kvm_cpu_synchronize_state() stub
2025-06-20 17:13 ` [RFC PATCH v2 24/48] accel/kvm: Remove kvm_cpu_synchronize_state() stub Philippe Mathieu-Daudé
@ 2025-06-22 1:35 ` Richard Henderson
0 siblings, 0 replies; 77+ messages in thread
From: Richard Henderson @ 2025-06-22 1:35 UTC (permalink / raw)
To: Philippe Mathieu-Daudé, qemu-devel
On 6/20/25 10:13, Philippe Mathieu-Daudé wrote:
> Since commit 57038a92bb0 ("cpus: extract out kvm-specific code
> to accel/kvm") the kvm_cpu_synchronize_state() stub is not
> necessary.
>
> Fixes: e0715f6abce ("kvm: remove kvm specific functions from global includes")
> Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
> ---
> accel/stubs/kvm-stub.c | 4 ----
> 1 file changed, 4 deletions(-)
>
> diff --git a/accel/stubs/kvm-stub.c b/accel/stubs/kvm-stub.c
> index b9b4427c919..68cd33ba973 100644
> --- a/accel/stubs/kvm-stub.c
> +++ b/accel/stubs/kvm-stub.c
> @@ -29,10 +29,6 @@ void kvm_flush_coalesced_mmio_buffer(void)
> {
> }
>
> -void kvm_cpu_synchronize_state(CPUState *cpu)
> -{
> -}
> -
> bool kvm_has_sync_mmu(void)
> {
> return false;
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
r~
^ permalink raw reply [flat|nested] 77+ messages in thread
* [RFC PATCH v2 25/48] accel/system: Document cpu_synchronize_state()
2025-06-20 17:12 [RFC PATCH v2 00/48] accel: Preparatory cleanups for split-accel Philippe Mathieu-Daudé
` (23 preceding siblings ...)
2025-06-20 17:13 ` [RFC PATCH v2 24/48] accel/kvm: Remove kvm_cpu_synchronize_state() stub Philippe Mathieu-Daudé
@ 2025-06-20 17:13 ` Philippe Mathieu-Daudé
2025-06-22 1:46 ` Richard Henderson
2025-06-20 17:13 ` [RFC PATCH v2 26/48] accel/system: Document cpu_synchronize_state_post_init/reset() Philippe Mathieu-Daudé
` (15 subsequent siblings)
40 siblings, 1 reply; 77+ messages in thread
From: Philippe Mathieu-Daudé @ 2025-06-20 17:13 UTC (permalink / raw)
To: qemu-devel
Cc: Alex Bennée, Alexander Graf, Richard Henderson,
Pierrick Bouvier, Peter Maydell, Thomas Huth, Cameron Esfahani,
Julian Armistead, Paolo Bonzini, Edgar E. Iglesias,
Philippe Mathieu-Daudé
Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
---
include/system/accel-ops.h | 8 ++++++++
include/system/hw_accel.h | 13 +++++++++++--
2 files changed, 19 insertions(+), 2 deletions(-)
diff --git a/include/system/accel-ops.h b/include/system/accel-ops.h
index 5c5171ea5b5..f40098c1c92 100644
--- a/include/system/accel-ops.h
+++ b/include/system/accel-ops.h
@@ -45,6 +45,14 @@ struct AccelOpsClass {
void (*synchronize_post_reset)(CPUState *cpu);
void (*synchronize_post_init)(CPUState *cpu);
+ /**
+ * synchronize_state:
+ * synchronize_pre_loadvm:
+ * @cpu: The vCPU to synchronize.
+ *
+ * Request to synchronize QEMU vCPU registers from the hardware accelerator
+ * (the hardware accelerator is the reference).
+ */
void (*synchronize_state)(CPUState *cpu);
void (*synchronize_pre_loadvm)(CPUState *cpu);
void (*synchronize_pre_resume)(bool step_pending);
diff --git a/include/system/hw_accel.h b/include/system/hw_accel.h
index 380e9e640b6..574c9738408 100644
--- a/include/system/hw_accel.h
+++ b/include/system/hw_accel.h
@@ -17,9 +17,18 @@
#include "system/whpx.h"
#include "system/nvmm.h"
+/**
+ * cpu_synchronize_state:
+ * cpu_synchronize_pre_loadvm:
+ * @cpu: The vCPU to synchronize.
+ *
+ * Request to synchronize QEMU vCPU registers from the hardware accelerator
+ * (the hardware accelerator is the reference).
+ */
void cpu_synchronize_state(CPUState *cpu);
-void cpu_synchronize_post_reset(CPUState *cpu);
-void cpu_synchronize_post_init(CPUState *cpu);
void cpu_synchronize_pre_loadvm(CPUState *cpu);
+void cpu_synchronize_post_reset(CPUState *cpu);
+void cpu_synchronize_post_init(CPUState *cpu);
+
#endif /* QEMU_HW_ACCEL_H */
--
2.49.0
^ permalink raw reply related [flat|nested] 77+ messages in thread
* [RFC PATCH v2 26/48] accel/system: Document cpu_synchronize_state_post_init/reset()
2025-06-20 17:12 [RFC PATCH v2 00/48] accel: Preparatory cleanups for split-accel Philippe Mathieu-Daudé
` (24 preceding siblings ...)
2025-06-20 17:13 ` [RFC PATCH v2 25/48] accel/system: Document cpu_synchronize_state() Philippe Mathieu-Daudé
@ 2025-06-20 17:13 ` Philippe Mathieu-Daudé
2025-06-22 1:46 ` Richard Henderson
2025-06-20 17:13 ` [RFC PATCH v2 27/48] accel/dummy: Factor dummy_thread_precreate() out Philippe Mathieu-Daudé
` (14 subsequent siblings)
40 siblings, 1 reply; 77+ messages in thread
From: Philippe Mathieu-Daudé @ 2025-06-20 17:13 UTC (permalink / raw)
To: qemu-devel
Cc: Alex Bennée, Alexander Graf, Richard Henderson,
Pierrick Bouvier, Peter Maydell, Thomas Huth, Cameron Esfahani,
Julian Armistead, Paolo Bonzini, Edgar E. Iglesias,
Philippe Mathieu-Daudé
Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
---
include/system/accel-ops.h | 8 ++++++++
1 file changed, 8 insertions(+)
diff --git a/include/system/accel-ops.h b/include/system/accel-ops.h
index f40098c1c92..b1b9dce27d0 100644
--- a/include/system/accel-ops.h
+++ b/include/system/accel-ops.h
@@ -43,6 +43,14 @@ struct AccelOpsClass {
void (*kick_vcpu_thread)(CPUState *cpu);
bool (*cpu_thread_is_idle)(CPUState *cpu);
+ /**
+ * synchronize_post_reset:
+ * synchronize_post_init:
+ * @cpu: The vCPU to synchronize.
+ *
+ * Request to synchronize QEMU vCPU registers to the hardware accelerator
+ * (QEMU is the reference).
+ */
void (*synchronize_post_reset)(CPUState *cpu);
void (*synchronize_post_init)(CPUState *cpu);
/**
--
2.49.0
^ permalink raw reply related [flat|nested] 77+ messages in thread
* Re: [RFC PATCH v2 26/48] accel/system: Document cpu_synchronize_state_post_init/reset()
2025-06-20 17:13 ` [RFC PATCH v2 26/48] accel/system: Document cpu_synchronize_state_post_init/reset() Philippe Mathieu-Daudé
@ 2025-06-22 1:46 ` Richard Henderson
0 siblings, 0 replies; 77+ messages in thread
From: Richard Henderson @ 2025-06-22 1:46 UTC (permalink / raw)
To: Philippe Mathieu-Daudé, qemu-devel
On 6/20/25 10:13, Philippe Mathieu-Daudé wrote:
> Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
> ---
> include/system/accel-ops.h | 8 ++++++++
> 1 file changed, 8 insertions(+)
>
> diff --git a/include/system/accel-ops.h b/include/system/accel-ops.h
> index f40098c1c92..b1b9dce27d0 100644
> --- a/include/system/accel-ops.h
> +++ b/include/system/accel-ops.h
> @@ -43,6 +43,14 @@ struct AccelOpsClass {
> void (*kick_vcpu_thread)(CPUState *cpu);
> bool (*cpu_thread_is_idle)(CPUState *cpu);
>
> + /**
> + * synchronize_post_reset:
> + * synchronize_post_init:
> + * @cpu: The vCPU to synchronize.
> + *
> + * Request to synchronize QEMU vCPU registers to the hardware accelerator
> + * (QEMU is the reference).
> + */
> void (*synchronize_post_reset)(CPUState *cpu);
> void (*synchronize_post_init)(CPUState *cpu);
> /**
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
r~
^ permalink raw reply [flat|nested] 77+ messages in thread
* [RFC PATCH v2 27/48] accel/dummy: Factor dummy_thread_precreate() out
2025-06-20 17:12 [RFC PATCH v2 00/48] accel: Preparatory cleanups for split-accel Philippe Mathieu-Daudé
` (25 preceding siblings ...)
2025-06-20 17:13 ` [RFC PATCH v2 26/48] accel/system: Document cpu_synchronize_state_post_init/reset() Philippe Mathieu-Daudé
@ 2025-06-20 17:13 ` Philippe Mathieu-Daudé
2025-06-22 1:58 ` Richard Henderson
2025-06-20 17:13 ` [RFC PATCH v2 28/48] accel/dummy: Factor tcg_vcpu_thread_precreate() out Philippe Mathieu-Daudé
` (13 subsequent siblings)
40 siblings, 1 reply; 77+ messages in thread
From: Philippe Mathieu-Daudé @ 2025-06-20 17:13 UTC (permalink / raw)
To: qemu-devel
Cc: Alex Bennée, Alexander Graf, Richard Henderson,
Pierrick Bouvier, Peter Maydell, Thomas Huth, Cameron Esfahani,
Julian Armistead, Paolo Bonzini, Edgar E. Iglesias,
Philippe Mathieu-Daudé
Initialize the semaphore before creating the thread,
factor out as dummy_thread_precreate().
Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
---
include/system/cpus.h | 1 +
accel/dummy-cpus.c | 12 +++++++++---
2 files changed, 10 insertions(+), 3 deletions(-)
diff --git a/include/system/cpus.h b/include/system/cpus.h
index 3226c765d01..bfaa339dd73 100644
--- a/include/system/cpus.h
+++ b/include/system/cpus.h
@@ -8,6 +8,7 @@ void cpus_register_accel(const AccelOpsClass *i);
const AccelOpsClass *cpus_get_accel(void);
/* accel/dummy-cpus.c */
+void dummy_thread_precreate(CPUState *cpu);
/* Create a dummy vcpu for AccelOpsClass->create_vcpu_thread */
void dummy_start_vcpu_thread(CPUState *);
diff --git a/accel/dummy-cpus.c b/accel/dummy-cpus.c
index 867276144fa..7c34e6c0fc5 100644
--- a/accel/dummy-cpus.c
+++ b/accel/dummy-cpus.c
@@ -64,15 +64,21 @@ static void *dummy_cpu_thread_fn(void *arg)
return NULL;
}
+void dummy_thread_precreate(CPUState *cpu)
+{
+#ifdef _WIN32
+ qemu_sem_init(&cpu->sem, 0);
+#endif
+}
+
void dummy_start_vcpu_thread(CPUState *cpu)
{
char thread_name[VCPU_THREAD_NAME_SIZE];
+ dummy_thread_precreate(cpu);
+
snprintf(thread_name, VCPU_THREAD_NAME_SIZE, "CPU %d/DUMMY",
cpu->cpu_index);
qemu_thread_create(cpu->thread, thread_name, dummy_cpu_thread_fn, cpu,
QEMU_THREAD_JOINABLE);
-#ifdef _WIN32
- qemu_sem_init(&cpu->sem, 0);
-#endif
}
--
2.49.0
^ permalink raw reply related [flat|nested] 77+ messages in thread
* [RFC PATCH v2 28/48] accel/dummy: Factor tcg_vcpu_thread_precreate() out
2025-06-20 17:12 [RFC PATCH v2 00/48] accel: Preparatory cleanups for split-accel Philippe Mathieu-Daudé
` (26 preceding siblings ...)
2025-06-20 17:13 ` [RFC PATCH v2 27/48] accel/dummy: Factor dummy_thread_precreate() out Philippe Mathieu-Daudé
@ 2025-06-20 17:13 ` Philippe Mathieu-Daudé
2025-06-22 1:49 ` Richard Henderson
2025-06-20 17:13 ` [RFC PATCH v2 29/48] accel: Factor accel_create_vcpu_thread() out Philippe Mathieu-Daudé
` (12 subsequent siblings)
40 siblings, 1 reply; 77+ messages in thread
From: Philippe Mathieu-Daudé @ 2025-06-20 17:13 UTC (permalink / raw)
To: qemu-devel
Cc: Alex Bennée, Alexander Graf, Richard Henderson,
Pierrick Bouvier, Peter Maydell, Thomas Huth, Cameron Esfahani,
Julian Armistead, Paolo Bonzini, Edgar E. Iglesias,
Philippe Mathieu-Daudé
Factor tcg_vcpu_thread_precreate() out for re-use.
Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
---
accel/tcg/tcg-accel-ops.h | 1 +
accel/tcg/tcg-accel-ops-mttcg.c | 3 +--
accel/tcg/tcg-accel-ops-rr.c | 3 +--
accel/tcg/tcg-accel-ops.c | 7 +++++++
4 files changed, 10 insertions(+), 4 deletions(-)
diff --git a/accel/tcg/tcg-accel-ops.h b/accel/tcg/tcg-accel-ops.h
index 6feeb3f3e9b..129af89c3e7 100644
--- a/accel/tcg/tcg-accel-ops.h
+++ b/accel/tcg/tcg-accel-ops.h
@@ -14,6 +14,7 @@
#include "system/cpus.h"
+void tcg_vcpu_thread_precreate(CPUState *cpu);
void tcg_cpu_destroy(CPUState *cpu);
int tcg_cpu_exec(CPUState *cpu);
void tcg_handle_interrupt(CPUState *cpu, int mask);
diff --git a/accel/tcg/tcg-accel-ops-mttcg.c b/accel/tcg/tcg-accel-ops-mttcg.c
index dfcee30947e..462be7596b9 100644
--- a/accel/tcg/tcg-accel-ops-mttcg.c
+++ b/accel/tcg/tcg-accel-ops-mttcg.c
@@ -133,8 +133,7 @@ void mttcg_start_vcpu_thread(CPUState *cpu)
{
char thread_name[VCPU_THREAD_NAME_SIZE];
- g_assert(tcg_enabled());
- tcg_cpu_init_cflags(cpu, current_machine->smp.max_cpus > 1);
+ tcg_vcpu_thread_precreate(cpu);
/* create a thread per vCPU with TCG (MTTCG) */
snprintf(thread_name, VCPU_THREAD_NAME_SIZE, "CPU %d/TCG",
diff --git a/accel/tcg/tcg-accel-ops-rr.c b/accel/tcg/tcg-accel-ops-rr.c
index 6eec5c9eee9..fc33a13e4e8 100644
--- a/accel/tcg/tcg-accel-ops-rr.c
+++ b/accel/tcg/tcg-accel-ops-rr.c
@@ -311,8 +311,7 @@ void rr_start_vcpu_thread(CPUState *cpu)
static QemuCond *single_tcg_halt_cond;
static QemuThread *single_tcg_cpu_thread;
- g_assert(tcg_enabled());
- tcg_cpu_init_cflags(cpu, false);
+ tcg_vcpu_thread_precreate(cpu);
if (!single_tcg_cpu_thread) {
single_tcg_halt_cond = cpu->halt_cond;
diff --git a/accel/tcg/tcg-accel-ops.c b/accel/tcg/tcg-accel-ops.c
index 95ff451c148..861996649b7 100644
--- a/accel/tcg/tcg-accel-ops.c
+++ b/accel/tcg/tcg-accel-ops.c
@@ -41,6 +41,7 @@
#include "gdbstub/enums.h"
#include "hw/core/cpu.h"
+#include "hw/boards.h"
#include "tcg-accel-ops.h"
#include "tcg-accel-ops-mttcg.h"
@@ -69,6 +70,12 @@ void tcg_cpu_init_cflags(CPUState *cpu, bool parallel)
tcg_cflags_set(cpu, cflags);
}
+void tcg_vcpu_thread_precreate(CPUState *cpu)
+{
+ g_assert(tcg_enabled());
+ tcg_cpu_init_cflags(cpu, current_machine->smp.max_cpus > 1);
+}
+
void tcg_cpu_destroy(CPUState *cpu)
{
cpu_thread_signal_destroyed(cpu);
--
2.49.0
^ permalink raw reply related [flat|nested] 77+ messages in thread
* [RFC PATCH v2 29/48] accel: Factor accel_create_vcpu_thread() out
2025-06-20 17:12 [RFC PATCH v2 00/48] accel: Preparatory cleanups for split-accel Philippe Mathieu-Daudé
` (27 preceding siblings ...)
2025-06-20 17:13 ` [RFC PATCH v2 28/48] accel/dummy: Factor tcg_vcpu_thread_precreate() out Philippe Mathieu-Daudé
@ 2025-06-20 17:13 ` Philippe Mathieu-Daudé
2025-06-22 1:56 ` Richard Henderson
2025-06-20 17:13 ` [RFC PATCH v2 30/48] accel: Introduce AccelOpsClass::cpu_thread_routine handler Philippe Mathieu-Daudé
` (11 subsequent siblings)
40 siblings, 1 reply; 77+ messages in thread
From: Philippe Mathieu-Daudé @ 2025-06-20 17:13 UTC (permalink / raw)
To: qemu-devel
Cc: Alex Bennée, Alexander Graf, Richard Henderson,
Pierrick Bouvier, Peter Maydell, Thomas Huth, Cameron Esfahani,
Julian Armistead, Paolo Bonzini, Edgar E. Iglesias,
Philippe Mathieu-Daudé
Factor accel_create_vcpu_thread() out of system/cpus.c
to be able to access accel/ internal definitions.
Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
---
include/qemu/accel.h | 2 ++
accel/accel-common.c | 19 +++++++++++++++++++
system/cpus.c | 4 +---
3 files changed, 22 insertions(+), 3 deletions(-)
diff --git a/include/qemu/accel.h b/include/qemu/accel.h
index 4ed5f264a88..4e30a633bca 100644
--- a/include/qemu/accel.h
+++ b/include/qemu/accel.h
@@ -93,6 +93,8 @@ void accel_setup_post(MachineState *ms);
*/
void accel_cpu_instance_init(CPUState *cpu);
+void accel_create_vcpu_thread(AccelState *accel, CPUState *cpu);
+
/**
* accel_cpu_common_realize:
* @cpu: The CPU that needs to call accel-specific cpu realization.
diff --git a/accel/accel-common.c b/accel/accel-common.c
index d1a5f3ca3df..d719917063e 100644
--- a/accel/accel-common.c
+++ b/accel/accel-common.c
@@ -89,6 +89,25 @@ void accel_cpu_instance_init(CPUState *cpu)
}
}
+void accel_create_vcpu_thread(AccelState *accel, CPUState *cpu)
+{
+ AccelClass *ac;
+
+ if (!accel) {
+ accel = current_accel();
+ }
+ ac = ACCEL_GET_CLASS(accel);
+
+ /* accelerators all implement the AccelOpsClass */
+ g_assert(ac->ops);
+
+ if (ac->ops->create_vcpu_thread != NULL) {
+ ac->ops->create_vcpu_thread(cpu);
+ } else {
+ g_assert_not_reached();
+ }
+}
+
bool accel_cpu_common_realize(CPUState *cpu, Error **errp)
{
AccelState *accel = current_accel();
diff --git a/system/cpus.c b/system/cpus.c
index 4fb764ac880..1721b32fc3f 100644
--- a/system/cpus.c
+++ b/system/cpus.c
@@ -698,9 +698,7 @@ void qemu_init_vcpu(CPUState *cpu)
cpu_address_space_init(cpu, 0, "cpu-memory", cpu->memory);
}
- /* accelerators all implement the AccelOpsClass */
- g_assert(cpus_accel != NULL && cpus_accel->create_vcpu_thread != NULL);
- cpus_accel->create_vcpu_thread(cpu);
+ accel_create_vcpu_thread(NULL, cpu);
while (!cpu->created) {
qemu_cond_wait(&qemu_cpu_cond, &bql);
--
2.49.0
^ permalink raw reply related [flat|nested] 77+ messages in thread
* [RFC PATCH v2 30/48] accel: Introduce AccelOpsClass::cpu_thread_routine handler
2025-06-20 17:12 [RFC PATCH v2 00/48] accel: Preparatory cleanups for split-accel Philippe Mathieu-Daudé
` (28 preceding siblings ...)
2025-06-20 17:13 ` [RFC PATCH v2 29/48] accel: Factor accel_create_vcpu_thread() out Philippe Mathieu-Daudé
@ 2025-06-20 17:13 ` Philippe Mathieu-Daudé
2025-06-22 1:58 ` Richard Henderson
2025-06-20 17:13 ` [RFC PATCH v2 31/48] accel/dummy: Convert to AccelOpsClass::cpu_thread_routine Philippe Mathieu-Daudé
` (10 subsequent siblings)
40 siblings, 1 reply; 77+ messages in thread
From: Philippe Mathieu-Daudé @ 2025-06-20 17:13 UTC (permalink / raw)
To: qemu-devel
Cc: Alex Bennée, Alexander Graf, Richard Henderson,
Pierrick Bouvier, Peter Maydell, Thomas Huth, Cameron Esfahani,
Julian Armistead, Paolo Bonzini, Edgar E. Iglesias,
Philippe Mathieu-Daudé
In order to have a generic function creating threads,
introduce the thread_precreate() and cpu_thread_routine()
handlers.
Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
---
include/system/accel-ops.h | 5 ++++-
accel/accel-common.c | 16 +++++++++++++++-
system/cpus.c | 2 +-
3 files changed, 20 insertions(+), 3 deletions(-)
diff --git a/include/system/accel-ops.h b/include/system/accel-ops.h
index b1b9dce27d0..b1a55ebe333 100644
--- a/include/system/accel-ops.h
+++ b/include/system/accel-ops.h
@@ -39,7 +39,10 @@ struct AccelOpsClass {
bool (*cpu_target_realize)(CPUState *cpu, Error **errp);
void (*cpu_reset_hold)(CPUState *cpu);
- void (*create_vcpu_thread)(CPUState *cpu); /* MANDATORY NON-NULL */
+ /* Either cpu_thread_routine() or create_vcpu_thread() is mandatory */
+ void *(*cpu_thread_routine)(void *);
+ void (*thread_precreate)(CPUState *cpu);
+ void (*create_vcpu_thread)(CPUState *cpu);
void (*kick_vcpu_thread)(CPUState *cpu);
bool (*cpu_thread_is_idle)(CPUState *cpu);
diff --git a/accel/accel-common.c b/accel/accel-common.c
index d719917063e..24038acf4aa 100644
--- a/accel/accel-common.c
+++ b/accel/accel-common.c
@@ -11,6 +11,7 @@
#include "qemu/accel.h"
#include "qemu/target-info.h"
#include "system/accel-ops.h"
+#include "system/cpus.h"
#include "accel/accel-cpu.h"
#include "accel-internal.h"
@@ -104,7 +105,20 @@ void accel_create_vcpu_thread(AccelState *accel, CPUState *cpu)
if (ac->ops->create_vcpu_thread != NULL) {
ac->ops->create_vcpu_thread(cpu);
} else {
- g_assert_not_reached();
+ char thread_name[VCPU_THREAD_NAME_SIZE];
+
+ assert(ac->name);
+ assert(ac->ops->cpu_thread_routine);
+
+ if (ac->ops->thread_precreate) {
+ ac->ops->thread_precreate(cpu);
+ }
+
+ snprintf(thread_name, VCPU_THREAD_NAME_SIZE, "CPU %d/%s",
+ cpu->cpu_index, ac->name);
+ qemu_thread_create(cpu->thread, thread_name,
+ ac->ops->cpu_thread_routine,
+ cpu, QEMU_THREAD_JOINABLE);
}
}
diff --git a/system/cpus.c b/system/cpus.c
index 1721b32fc3f..bd3fd1b31b6 100644
--- a/system/cpus.c
+++ b/system/cpus.c
@@ -671,7 +671,7 @@ void cpu_remove_sync(CPUState *cpu)
void cpus_register_accel(const AccelOpsClass *ops)
{
assert(ops != NULL);
- assert(ops->create_vcpu_thread != NULL); /* mandatory */
+ assert(ops->create_vcpu_thread || ops->cpu_thread_routine);
cpus_accel = ops;
}
--
2.49.0
^ permalink raw reply related [flat|nested] 77+ messages in thread
* [RFC PATCH v2 31/48] accel/dummy: Convert to AccelOpsClass::cpu_thread_routine
2025-06-20 17:12 [RFC PATCH v2 00/48] accel: Preparatory cleanups for split-accel Philippe Mathieu-Daudé
` (29 preceding siblings ...)
2025-06-20 17:13 ` [RFC PATCH v2 30/48] accel: Introduce AccelOpsClass::cpu_thread_routine handler Philippe Mathieu-Daudé
@ 2025-06-20 17:13 ` Philippe Mathieu-Daudé
2025-06-22 1:59 ` Richard Henderson
2025-06-20 17:13 ` [RFC PATCH v2 32/48] accel/tcg: " Philippe Mathieu-Daudé
` (9 subsequent siblings)
40 siblings, 1 reply; 77+ messages in thread
From: Philippe Mathieu-Daudé @ 2025-06-20 17:13 UTC (permalink / raw)
To: qemu-devel
Cc: Alex Bennée, Alexander Graf, Richard Henderson,
Pierrick Bouvier, Peter Maydell, Thomas Huth, Cameron Esfahani,
Julian Armistead, Paolo Bonzini, Edgar E. Iglesias,
Philippe Mathieu-Daudé
By converting to AccelOpsClass::cpu_thread_routine we can
let the common accel_create_vcpu_thread() create the thread.
Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
---
include/system/cpus.h | 4 +---
accel/dummy-cpus.c | 14 +-------------
accel/qtest/qtest.c | 3 ++-
accel/xen/xen-all.c | 3 ++-
4 files changed, 6 insertions(+), 18 deletions(-)
diff --git a/include/system/cpus.h b/include/system/cpus.h
index bfaa339dd73..e7ca9f4d684 100644
--- a/include/system/cpus.h
+++ b/include/system/cpus.h
@@ -9,9 +9,7 @@ const AccelOpsClass *cpus_get_accel(void);
/* accel/dummy-cpus.c */
void dummy_thread_precreate(CPUState *cpu);
-
-/* Create a dummy vcpu for AccelOpsClass->create_vcpu_thread */
-void dummy_start_vcpu_thread(CPUState *);
+void *dummy_cpu_thread_routine(void *arg);
/* interface available for cpus accelerator threads */
diff --git a/accel/dummy-cpus.c b/accel/dummy-cpus.c
index 7c34e6c0fc5..c6756252550 100644
--- a/accel/dummy-cpus.c
+++ b/accel/dummy-cpus.c
@@ -18,7 +18,7 @@
#include "qemu/main-loop.h"
#include "hw/core/cpu.h"
-static void *dummy_cpu_thread_fn(void *arg)
+void *dummy_cpu_thread_routine(void *arg)
{
CPUState *cpu = arg;
@@ -70,15 +70,3 @@ void dummy_thread_precreate(CPUState *cpu)
qemu_sem_init(&cpu->sem, 0);
#endif
}
-
-void dummy_start_vcpu_thread(CPUState *cpu)
-{
- char thread_name[VCPU_THREAD_NAME_SIZE];
-
- dummy_thread_precreate(cpu);
-
- snprintf(thread_name, VCPU_THREAD_NAME_SIZE, "CPU %d/DUMMY",
- cpu->cpu_index);
- qemu_thread_create(cpu->thread, thread_name, dummy_cpu_thread_fn, cpu,
- QEMU_THREAD_JOINABLE);
-}
diff --git a/accel/qtest/qtest.c b/accel/qtest/qtest.c
index c5a53ecb6dd..6930cc4cf3e 100644
--- a/accel/qtest/qtest.c
+++ b/accel/qtest/qtest.c
@@ -63,7 +63,8 @@ static void qtest_accel_ops_class_init(ObjectClass *oc, const void *data)
{
AccelOpsClass *ops = ACCEL_OPS_CLASS(oc);
- ops->create_vcpu_thread = dummy_start_vcpu_thread;
+ ops->thread_precreate = dummy_thread_precreate;
+ ops->cpu_thread_routine = dummy_cpu_thread_routine;
ops->get_virtual_clock = qtest_get_virtual_clock;
ops->set_virtual_clock = qtest_set_virtual_clock;
};
diff --git a/accel/xen/xen-all.c b/accel/xen/xen-all.c
index de52a8f882a..3bd91889925 100644
--- a/accel/xen/xen-all.c
+++ b/accel/xen/xen-all.c
@@ -151,7 +151,8 @@ static void xen_accel_ops_class_init(ObjectClass *oc, const void *data)
{
AccelOpsClass *ops = ACCEL_OPS_CLASS(oc);
- ops->create_vcpu_thread = dummy_start_vcpu_thread;
+ ops->thread_precreate = dummy_thread_precreate;
+ ops->cpu_thread_routine = dummy_cpu_thread_routine;
}
static const TypeInfo xen_accel_ops_type = {
--
2.49.0
^ permalink raw reply related [flat|nested] 77+ messages in thread
* [RFC PATCH v2 32/48] accel/tcg: Convert to AccelOpsClass::cpu_thread_routine
2025-06-20 17:12 [RFC PATCH v2 00/48] accel: Preparatory cleanups for split-accel Philippe Mathieu-Daudé
` (30 preceding siblings ...)
2025-06-20 17:13 ` [RFC PATCH v2 31/48] accel/dummy: Convert to AccelOpsClass::cpu_thread_routine Philippe Mathieu-Daudé
@ 2025-06-20 17:13 ` Philippe Mathieu-Daudé
2025-06-22 2:03 ` Richard Henderson
2025-06-20 17:13 ` [RFC PATCH v2 33/48] accel/hvf: " Philippe Mathieu-Daudé
` (8 subsequent siblings)
40 siblings, 1 reply; 77+ messages in thread
From: Philippe Mathieu-Daudé @ 2025-06-20 17:13 UTC (permalink / raw)
To: qemu-devel
Cc: Alex Bennée, Alexander Graf, Richard Henderson,
Pierrick Bouvier, Peter Maydell, Thomas Huth, Cameron Esfahani,
Julian Armistead, Paolo Bonzini, Edgar E. Iglesias,
Philippe Mathieu-Daudé
By converting to AccelOpsClass::cpu_thread_routine we can
let the common accel_create_vcpu_thread() create the thread.
Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
---
accel/tcg/tcg-accel-ops-mttcg.h | 3 +--
accel/tcg/tcg-accel-ops-mttcg.c | 16 +---------------
accel/tcg/tcg-accel-ops.c | 3 ++-
3 files changed, 4 insertions(+), 18 deletions(-)
diff --git a/accel/tcg/tcg-accel-ops-mttcg.h b/accel/tcg/tcg-accel-ops-mttcg.h
index 8ffa7a9a9fe..8bf2452c886 100644
--- a/accel/tcg/tcg-accel-ops-mttcg.h
+++ b/accel/tcg/tcg-accel-ops-mttcg.h
@@ -13,7 +13,6 @@
/* kick MTTCG vCPU thread */
void mttcg_kick_vcpu_thread(CPUState *cpu);
-/* start an mttcg vCPU thread */
-void mttcg_start_vcpu_thread(CPUState *cpu);
+void *mttcg_cpu_thread_routine(void *arg);
#endif /* TCG_ACCEL_OPS_MTTCG_H */
diff --git a/accel/tcg/tcg-accel-ops-mttcg.c b/accel/tcg/tcg-accel-ops-mttcg.c
index 462be7596b9..96ce065eb59 100644
--- a/accel/tcg/tcg-accel-ops-mttcg.c
+++ b/accel/tcg/tcg-accel-ops-mttcg.c
@@ -61,7 +61,7 @@ static void mttcg_force_rcu(Notifier *notify, void *data)
* current CPUState for a given thread.
*/
-static void *mttcg_cpu_thread_fn(void *arg)
+void *mttcg_cpu_thread_routine(void *arg)
{
MttcgForceRcuNotifier force_rcu;
CPUState *cpu = arg;
@@ -128,17 +128,3 @@ void mttcg_kick_vcpu_thread(CPUState *cpu)
{
cpu_exit(cpu);
}
-
-void mttcg_start_vcpu_thread(CPUState *cpu)
-{
- char thread_name[VCPU_THREAD_NAME_SIZE];
-
- tcg_vcpu_thread_precreate(cpu);
-
- /* create a thread per vCPU with TCG (MTTCG) */
- snprintf(thread_name, VCPU_THREAD_NAME_SIZE, "CPU %d/TCG",
- cpu->cpu_index);
-
- qemu_thread_create(cpu->thread, thread_name, mttcg_cpu_thread_fn,
- cpu, QEMU_THREAD_JOINABLE);
-}
diff --git a/accel/tcg/tcg-accel-ops.c b/accel/tcg/tcg-accel-ops.c
index 861996649b7..4931e536beb 100644
--- a/accel/tcg/tcg-accel-ops.c
+++ b/accel/tcg/tcg-accel-ops.c
@@ -204,7 +204,7 @@ static void tcg_accel_ops_init(AccelClass *ac)
AccelOpsClass *ops = ac->ops;
if (qemu_tcg_mttcg_enabled()) {
- ops->create_vcpu_thread = mttcg_start_vcpu_thread;
+ ops->cpu_thread_routine = mttcg_cpu_thread_routine;
ops->kick_vcpu_thread = mttcg_kick_vcpu_thread;
ops->handle_interrupt = tcg_handle_interrupt;
} else {
@@ -222,6 +222,7 @@ static void tcg_accel_ops_init(AccelClass *ac)
ops->cpu_common_realize = tcg_exec_realizefn;
ops->cpu_common_unrealize = tcg_exec_unrealizefn;
+ ops->thread_precreate = tcg_vcpu_thread_precreate;
ops->cpu_reset_hold = tcg_cpu_reset_hold;
ops->insert_breakpoint = tcg_insert_breakpoint;
ops->remove_breakpoint = tcg_remove_breakpoint;
--
2.49.0
^ permalink raw reply related [flat|nested] 77+ messages in thread
* Re: [RFC PATCH v2 32/48] accel/tcg: Convert to AccelOpsClass::cpu_thread_routine
2025-06-20 17:13 ` [RFC PATCH v2 32/48] accel/tcg: " Philippe Mathieu-Daudé
@ 2025-06-22 2:03 ` Richard Henderson
0 siblings, 0 replies; 77+ messages in thread
From: Richard Henderson @ 2025-06-22 2:03 UTC (permalink / raw)
To: Philippe Mathieu-Daudé, qemu-devel
On 6/20/25 10:13, Philippe Mathieu-Daudé wrote:
> By converting toAccelOpsClass::cpu_thread_routine we can
> let the common accel_create_vcpu_thread() create the thread.
>
> Signed-off-by: Philippe Mathieu-Daudé<philmd@linaro.org>
> ---
> accel/tcg/tcg-accel-ops-mttcg.h | 3 +--
> accel/tcg/tcg-accel-ops-mttcg.c | 16 +---------------
> accel/tcg/tcg-accel-ops.c | 3 ++-
> 3 files changed, 4 insertions(+), 18 deletions(-)
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
r~
^ permalink raw reply [flat|nested] 77+ messages in thread
* [RFC PATCH v2 33/48] accel/hvf: Convert to AccelOpsClass::cpu_thread_routine
2025-06-20 17:12 [RFC PATCH v2 00/48] accel: Preparatory cleanups for split-accel Philippe Mathieu-Daudé
` (31 preceding siblings ...)
2025-06-20 17:13 ` [RFC PATCH v2 32/48] accel/tcg: " Philippe Mathieu-Daudé
@ 2025-06-20 17:13 ` Philippe Mathieu-Daudé
2025-06-22 2:04 ` Richard Henderson
2025-06-20 17:13 ` [RFC PATCH v2 34/48] accel/kvm: " Philippe Mathieu-Daudé
` (7 subsequent siblings)
40 siblings, 1 reply; 77+ messages in thread
From: Philippe Mathieu-Daudé @ 2025-06-20 17:13 UTC (permalink / raw)
To: qemu-devel
Cc: Alex Bennée, Alexander Graf, Richard Henderson,
Pierrick Bouvier, Peter Maydell, Thomas Huth, Cameron Esfahani,
Julian Armistead, Paolo Bonzini, Edgar E. Iglesias,
Philippe Mathieu-Daudé
By converting to AccelOpsClass::cpu_thread_routine we can
let the common accel_create_vcpu_thread() create the thread.
Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
---
accel/hvf/hvf-accel-ops.c | 18 +-----------------
1 file changed, 1 insertion(+), 17 deletions(-)
diff --git a/accel/hvf/hvf-accel-ops.c b/accel/hvf/hvf-accel-ops.c
index 78bf0ac6cba..6bf7fcd7331 100644
--- a/accel/hvf/hvf-accel-ops.c
+++ b/accel/hvf/hvf-accel-ops.c
@@ -471,22 +471,6 @@ static void *hvf_cpu_thread_fn(void *arg)
return NULL;
}
-static void hvf_start_vcpu_thread(CPUState *cpu)
-{
- char thread_name[VCPU_THREAD_NAME_SIZE];
-
- /*
- * HVF currently does not support TCG, and only runs in
- * unrestricted-guest mode.
- */
- assert(hvf_enabled());
-
- snprintf(thread_name, VCPU_THREAD_NAME_SIZE, "CPU %d/HVF",
- cpu->cpu_index);
- qemu_thread_create(cpu->thread, thread_name, hvf_cpu_thread_fn,
- cpu, QEMU_THREAD_JOINABLE);
-}
-
static int hvf_insert_breakpoint(CPUState *cpu, int type, vaddr addr, vaddr len)
{
struct hvf_sw_breakpoint *bp;
@@ -605,7 +589,7 @@ static void hvf_accel_ops_class_init(ObjectClass *oc, const void *data)
ops->cpu_target_realize = hvf_arch_cpu_realize;
- ops->create_vcpu_thread = hvf_start_vcpu_thread;
+ ops->cpu_thread_routine = hvf_cpu_thread_fn,
ops->kick_vcpu_thread = hvf_kick_vcpu_thread;
ops->synchronize_post_reset = hvf_cpu_synchronize_post_reset;
--
2.49.0
^ permalink raw reply related [flat|nested] 77+ messages in thread
* Re: [RFC PATCH v2 33/48] accel/hvf: Convert to AccelOpsClass::cpu_thread_routine
2025-06-20 17:13 ` [RFC PATCH v2 33/48] accel/hvf: " Philippe Mathieu-Daudé
@ 2025-06-22 2:04 ` Richard Henderson
0 siblings, 0 replies; 77+ messages in thread
From: Richard Henderson @ 2025-06-22 2:04 UTC (permalink / raw)
To: Philippe Mathieu-Daudé, qemu-devel
On 6/20/25 10:13, Philippe Mathieu-Daudé wrote:
> By converting toAccelOpsClass::cpu_thread_routine we can
> let the common accel_create_vcpu_thread() create the thread.
>
> Signed-off-by: Philippe Mathieu-Daudé<philmd@linaro.org>
> ---
> accel/hvf/hvf-accel-ops.c | 18 +-----------------
> 1 file changed, 1 insertion(+), 17 deletions(-)
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
r~
^ permalink raw reply [flat|nested] 77+ messages in thread
* [RFC PATCH v2 34/48] accel/kvm: Convert to AccelOpsClass::cpu_thread_routine
2025-06-20 17:12 [RFC PATCH v2 00/48] accel: Preparatory cleanups for split-accel Philippe Mathieu-Daudé
` (32 preceding siblings ...)
2025-06-20 17:13 ` [RFC PATCH v2 33/48] accel/hvf: " Philippe Mathieu-Daudé
@ 2025-06-20 17:13 ` Philippe Mathieu-Daudé
2025-06-22 2:05 ` Richard Henderson
2025-06-20 17:13 ` [RFC PATCH v2 35/48] accel/nvmm: " Philippe Mathieu-Daudé
` (6 subsequent siblings)
40 siblings, 1 reply; 77+ messages in thread
From: Philippe Mathieu-Daudé @ 2025-06-20 17:13 UTC (permalink / raw)
To: qemu-devel
Cc: Alex Bennée, Alexander Graf, Richard Henderson,
Pierrick Bouvier, Peter Maydell, Thomas Huth, Cameron Esfahani,
Julian Armistead, Paolo Bonzini, Edgar E. Iglesias,
Philippe Mathieu-Daudé
By converting to AccelOpsClass::cpu_thread_routine we can
let the common accel_create_vcpu_thread() create the thread.
Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
---
accel/kvm/kvm-accel-ops.c | 12 +-----------
1 file changed, 1 insertion(+), 11 deletions(-)
diff --git a/accel/kvm/kvm-accel-ops.c b/accel/kvm/kvm-accel-ops.c
index be960bde5c4..21ff3af306f 100644
--- a/accel/kvm/kvm-accel-ops.c
+++ b/accel/kvm/kvm-accel-ops.c
@@ -63,16 +63,6 @@ static void *kvm_vcpu_thread_fn(void *arg)
return NULL;
}
-static void kvm_start_vcpu_thread(CPUState *cpu)
-{
- char thread_name[VCPU_THREAD_NAME_SIZE];
-
- snprintf(thread_name, VCPU_THREAD_NAME_SIZE, "CPU %d/KVM",
- cpu->cpu_index);
- qemu_thread_create(cpu->thread, thread_name, kvm_vcpu_thread_fn,
- cpu, QEMU_THREAD_JOINABLE);
-}
-
static bool kvm_vcpu_thread_is_idle(CPUState *cpu)
{
return !kvm_halt_in_kernel();
@@ -89,7 +79,7 @@ static void kvm_accel_ops_class_init(ObjectClass *oc, const void *data)
{
AccelOpsClass *ops = ACCEL_OPS_CLASS(oc);
- ops->create_vcpu_thread = kvm_start_vcpu_thread;
+ ops->cpu_thread_routine = kvm_vcpu_thread_fn;
ops->cpu_thread_is_idle = kvm_vcpu_thread_is_idle;
ops->synchronize_post_reset = kvm_cpu_synchronize_post_reset;
ops->synchronize_post_init = kvm_cpu_synchronize_post_init;
--
2.49.0
^ permalink raw reply related [flat|nested] 77+ messages in thread
* Re: [RFC PATCH v2 34/48] accel/kvm: Convert to AccelOpsClass::cpu_thread_routine
2025-06-20 17:13 ` [RFC PATCH v2 34/48] accel/kvm: " Philippe Mathieu-Daudé
@ 2025-06-22 2:05 ` Richard Henderson
0 siblings, 0 replies; 77+ messages in thread
From: Richard Henderson @ 2025-06-22 2:05 UTC (permalink / raw)
To: Philippe Mathieu-Daudé, qemu-devel
On 6/20/25 10:13, Philippe Mathieu-Daudé wrote:
> By converting toAccelOpsClass::cpu_thread_routine we can
> let the common accel_create_vcpu_thread() create the thread.
>
> Signed-off-by: Philippe Mathieu-Daudé<philmd@linaro.org>
> ---
> accel/kvm/kvm-accel-ops.c | 12 +-----------
> 1 file changed, 1 insertion(+), 11 deletions(-)
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
r~
^ permalink raw reply [flat|nested] 77+ messages in thread
* [RFC PATCH v2 35/48] accel/nvmm: Convert to AccelOpsClass::cpu_thread_routine
2025-06-20 17:12 [RFC PATCH v2 00/48] accel: Preparatory cleanups for split-accel Philippe Mathieu-Daudé
` (33 preceding siblings ...)
2025-06-20 17:13 ` [RFC PATCH v2 34/48] accel/kvm: " Philippe Mathieu-Daudé
@ 2025-06-20 17:13 ` Philippe Mathieu-Daudé
2025-06-22 2:05 ` Richard Henderson
2025-06-20 17:13 ` [RFC PATCH v2 36/48] accel/whpx: " Philippe Mathieu-Daudé
` (5 subsequent siblings)
40 siblings, 1 reply; 77+ messages in thread
From: Philippe Mathieu-Daudé @ 2025-06-20 17:13 UTC (permalink / raw)
To: qemu-devel
Cc: Alex Bennée, Alexander Graf, Richard Henderson,
Pierrick Bouvier, Peter Maydell, Thomas Huth, Cameron Esfahani,
Julian Armistead, Paolo Bonzini, Edgar E. Iglesias,
Philippe Mathieu-Daudé
By converting to AccelOpsClass::cpu_thread_routine we can
let the common accel_create_vcpu_thread() create the thread.
Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
---
target/i386/nvmm/nvmm-accel-ops.c | 12 +-----------
1 file changed, 1 insertion(+), 11 deletions(-)
diff --git a/target/i386/nvmm/nvmm-accel-ops.c b/target/i386/nvmm/nvmm-accel-ops.c
index 21443078b72..bef6f61b776 100644
--- a/target/i386/nvmm/nvmm-accel-ops.c
+++ b/target/i386/nvmm/nvmm-accel-ops.c
@@ -61,16 +61,6 @@ static void *qemu_nvmm_cpu_thread_fn(void *arg)
return NULL;
}
-static void nvmm_start_vcpu_thread(CPUState *cpu)
-{
- char thread_name[VCPU_THREAD_NAME_SIZE];
-
- snprintf(thread_name, VCPU_THREAD_NAME_SIZE, "CPU %d/NVMM",
- cpu->cpu_index);
- qemu_thread_create(cpu->thread, thread_name, qemu_nvmm_cpu_thread_fn,
- cpu, QEMU_THREAD_JOINABLE);
-}
-
/*
* Abort the call to run the virtual processor by another thread, and to
* return the control to that thread.
@@ -85,7 +75,7 @@ static void nvmm_accel_ops_class_init(ObjectClass *oc, const void *data)
{
AccelOpsClass *ops = ACCEL_OPS_CLASS(oc);
- ops->create_vcpu_thread = nvmm_start_vcpu_thread;
+ ops->cpu_thread_routine = qemu_nvmm_cpu_thread_fn;
ops->kick_vcpu_thread = nvmm_kick_vcpu_thread;
ops->synchronize_post_reset = nvmm_cpu_synchronize_post_reset;
--
2.49.0
^ permalink raw reply related [flat|nested] 77+ messages in thread
* Re: [RFC PATCH v2 35/48] accel/nvmm: Convert to AccelOpsClass::cpu_thread_routine
2025-06-20 17:13 ` [RFC PATCH v2 35/48] accel/nvmm: " Philippe Mathieu-Daudé
@ 2025-06-22 2:05 ` Richard Henderson
0 siblings, 0 replies; 77+ messages in thread
From: Richard Henderson @ 2025-06-22 2:05 UTC (permalink / raw)
To: Philippe Mathieu-Daudé, qemu-devel
On 6/20/25 10:13, Philippe Mathieu-Daudé wrote:
> By converting toAccelOpsClass::cpu_thread_routine we can
> let the common accel_create_vcpu_thread() create the thread.
>
> Signed-off-by: Philippe Mathieu-Daudé<philmd@linaro.org>
> ---
> target/i386/nvmm/nvmm-accel-ops.c | 12 +-----------
> 1 file changed, 1 insertion(+), 11 deletions(-)
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
r~
^ permalink raw reply [flat|nested] 77+ messages in thread
* [RFC PATCH v2 36/48] accel/whpx: Convert to AccelOpsClass::cpu_thread_routine
2025-06-20 17:12 [RFC PATCH v2 00/48] accel: Preparatory cleanups for split-accel Philippe Mathieu-Daudé
` (34 preceding siblings ...)
2025-06-20 17:13 ` [RFC PATCH v2 35/48] accel/nvmm: " Philippe Mathieu-Daudé
@ 2025-06-20 17:13 ` Philippe Mathieu-Daudé
2025-06-22 2:05 ` Richard Henderson
2025-06-22 2:10 ` Richard Henderson
2025-06-20 17:13 ` [RFC PATCH v2 37/48] accel/nvmm: Expose nvmm_enabled() to common code Philippe Mathieu-Daudé
` (4 subsequent siblings)
40 siblings, 2 replies; 77+ messages in thread
From: Philippe Mathieu-Daudé @ 2025-06-20 17:13 UTC (permalink / raw)
To: qemu-devel
Cc: Alex Bennée, Alexander Graf, Richard Henderson,
Pierrick Bouvier, Peter Maydell, Thomas Huth, Cameron Esfahani,
Julian Armistead, Paolo Bonzini, Edgar E. Iglesias,
Philippe Mathieu-Daudé
By converting to AccelOpsClass::cpu_thread_routine we can
let the common accel_create_vcpu_thread() create the thread.
Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
---
target/i386/whpx/whpx-accel-ops.c | 12 +-----------
1 file changed, 1 insertion(+), 11 deletions(-)
diff --git a/target/i386/whpx/whpx-accel-ops.c b/target/i386/whpx/whpx-accel-ops.c
index b8bebe403c9..c1b27d1b89d 100644
--- a/target/i386/whpx/whpx-accel-ops.c
+++ b/target/i386/whpx/whpx-accel-ops.c
@@ -61,16 +61,6 @@ static void *whpx_cpu_thread_fn(void *arg)
return NULL;
}
-static void whpx_start_vcpu_thread(CPUState *cpu)
-{
- char thread_name[VCPU_THREAD_NAME_SIZE];
-
- snprintf(thread_name, VCPU_THREAD_NAME_SIZE, "CPU %d/WHPX",
- cpu->cpu_index);
- qemu_thread_create(cpu->thread, thread_name, whpx_cpu_thread_fn,
- cpu, QEMU_THREAD_JOINABLE);
-}
-
static void whpx_kick_vcpu_thread(CPUState *cpu)
{
if (!qemu_cpu_is_self(cpu)) {
@@ -87,7 +77,7 @@ static void whpx_accel_ops_class_init(ObjectClass *oc, const void *data)
{
AccelOpsClass *ops = ACCEL_OPS_CLASS(oc);
- ops->create_vcpu_thread = whpx_start_vcpu_thread;
+ ops->cpu_thread_routine = whpx_cpu_thread_fn;
ops->kick_vcpu_thread = whpx_kick_vcpu_thread;
ops->cpu_thread_is_idle = whpx_vcpu_thread_is_idle;
--
2.49.0
^ permalink raw reply related [flat|nested] 77+ messages in thread
* Re: [RFC PATCH v2 36/48] accel/whpx: Convert to AccelOpsClass::cpu_thread_routine
2025-06-20 17:13 ` [RFC PATCH v2 36/48] accel/whpx: " Philippe Mathieu-Daudé
@ 2025-06-22 2:05 ` Richard Henderson
2025-06-22 2:10 ` Richard Henderson
1 sibling, 0 replies; 77+ messages in thread
From: Richard Henderson @ 2025-06-22 2:05 UTC (permalink / raw)
To: Philippe Mathieu-Daudé, qemu-devel
On 6/20/25 10:13, Philippe Mathieu-Daudé wrote:
> By converting toAccelOpsClass::cpu_thread_routine we can
> let the common accel_create_vcpu_thread() create the thread.
>
> Signed-off-by: Philippe Mathieu-Daudé<philmd@linaro.org>
> ---
> target/i386/whpx/whpx-accel-ops.c | 12 +-----------
> 1 file changed, 1 insertion(+), 11 deletions(-)
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
r~
^ permalink raw reply [flat|nested] 77+ messages in thread
* Re: [RFC PATCH v2 36/48] accel/whpx: Convert to AccelOpsClass::cpu_thread_routine
2025-06-20 17:13 ` [RFC PATCH v2 36/48] accel/whpx: " Philippe Mathieu-Daudé
2025-06-22 2:05 ` Richard Henderson
@ 2025-06-22 2:10 ` Richard Henderson
2025-06-23 12:31 ` Philippe Mathieu-Daudé
1 sibling, 1 reply; 77+ messages in thread
From: Richard Henderson @ 2025-06-22 2:10 UTC (permalink / raw)
To: Philippe Mathieu-Daudé, qemu-devel
On 6/20/25 10:13, Philippe Mathieu-Daudé wrote:
> By converting to AccelOpsClass::cpu_thread_routine we can
> let the common accel_create_vcpu_thread() create the thread.
>
> Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
> ---
> target/i386/whpx/whpx-accel-ops.c | 12 +-----------
> 1 file changed, 1 insertion(+), 11 deletions(-)
>
> diff --git a/target/i386/whpx/whpx-accel-ops.c b/target/i386/whpx/whpx-accel-ops.c
> index b8bebe403c9..c1b27d1b89d 100644
> --- a/target/i386/whpx/whpx-accel-ops.c
> +++ b/target/i386/whpx/whpx-accel-ops.c
> @@ -61,16 +61,6 @@ static void *whpx_cpu_thread_fn(void *arg)
> return NULL;
> }
>
> -static void whpx_start_vcpu_thread(CPUState *cpu)
> -{
> - char thread_name[VCPU_THREAD_NAME_SIZE];
> -
> - snprintf(thread_name, VCPU_THREAD_NAME_SIZE, "CPU %d/WHPX",
> - cpu->cpu_index);
> - qemu_thread_create(cpu->thread, thread_name, whpx_cpu_thread_fn,
> - cpu, QEMU_THREAD_JOINABLE);
> -}
> -
> static void whpx_kick_vcpu_thread(CPUState *cpu)
> {
> if (!qemu_cpu_is_self(cpu)) {
> @@ -87,7 +77,7 @@ static void whpx_accel_ops_class_init(ObjectClass *oc, const void *data)
> {
> AccelOpsClass *ops = ACCEL_OPS_CLASS(oc);
>
> - ops->create_vcpu_thread = whpx_start_vcpu_thread;
> + ops->cpu_thread_routine = whpx_cpu_thread_fn;
> ops->kick_vcpu_thread = whpx_kick_vcpu_thread;
> ops->cpu_thread_is_idle = whpx_vcpu_thread_is_idle;
>
After this, create_vcpu_thread is unused, correct?
r~
^ permalink raw reply [flat|nested] 77+ messages in thread
* Re: [RFC PATCH v2 36/48] accel/whpx: Convert to AccelOpsClass::cpu_thread_routine
2025-06-22 2:10 ` Richard Henderson
@ 2025-06-23 12:31 ` Philippe Mathieu-Daudé
0 siblings, 0 replies; 77+ messages in thread
From: Philippe Mathieu-Daudé @ 2025-06-23 12:31 UTC (permalink / raw)
To: Richard Henderson, qemu-devel
On 22/6/25 04:10, Richard Henderson wrote:
> On 6/20/25 10:13, Philippe Mathieu-Daudé wrote:
>> By converting to AccelOpsClass::cpu_thread_routine we can
>> let the common accel_create_vcpu_thread() create the thread.
>>
>> Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
>> ---
>> target/i386/whpx/whpx-accel-ops.c | 12 +-----------
>> 1 file changed, 1 insertion(+), 11 deletions(-)
>>
>> diff --git a/target/i386/whpx/whpx-accel-ops.c b/target/i386/whpx/
>> whpx-accel-ops.c
>> index b8bebe403c9..c1b27d1b89d 100644
>> --- a/target/i386/whpx/whpx-accel-ops.c
>> +++ b/target/i386/whpx/whpx-accel-ops.c
>> @@ -61,16 +61,6 @@ static void *whpx_cpu_thread_fn(void *arg)
>> return NULL;
>> }
>> -static void whpx_start_vcpu_thread(CPUState *cpu)
>> -{
>> - char thread_name[VCPU_THREAD_NAME_SIZE];
>> -
>> - snprintf(thread_name, VCPU_THREAD_NAME_SIZE, "CPU %d/WHPX",
>> - cpu->cpu_index);
>> - qemu_thread_create(cpu->thread, thread_name, whpx_cpu_thread_fn,
>> - cpu, QEMU_THREAD_JOINABLE);
>> -}
>> -
>> static void whpx_kick_vcpu_thread(CPUState *cpu)
>> {
>> if (!qemu_cpu_is_self(cpu)) {
>> @@ -87,7 +77,7 @@ static void whpx_accel_ops_class_init(ObjectClass
>> *oc, const void *data)
>> {
>> AccelOpsClass *ops = ACCEL_OPS_CLASS(oc);
>> - ops->create_vcpu_thread = whpx_start_vcpu_thread;
>> + ops->cpu_thread_routine = whpx_cpu_thread_fn;
>> ops->kick_vcpu_thread = whpx_kick_vcpu_thread;
>> ops->cpu_thread_is_idle = whpx_vcpu_thread_is_idle;
>
> After this, create_vcpu_thread is unused, correct?
Only RR left, which is a bit different:
339 void rr_start_vcpu_thread(CPUState *cpu)
340 {
341 char thread_name[VCPU_THREAD_NAME_SIZE];
342 static QemuCond *single_tcg_halt_cond;
343 static QemuThread *single_tcg_cpu_thread;
344
345 tcg_vcpu_thread_precreate(cpu);
346
347 if (!single_tcg_cpu_thread) {
348 single_tcg_halt_cond = cpu->halt_cond;
349 single_tcg_cpu_thread = cpu->thread;
350
351 /* share a single thread for all cpus with TCG */
352 snprintf(thread_name, VCPU_THREAD_NAME_SIZE, "ALL CPUs/TCG");
353 qemu_thread_create(cpu->thread, thread_name,
354 rr_cpu_thread_fn,
355 cpu, QEMU_THREAD_JOINABLE);
356 } else {
357 /* we share the thread, dump spare data */
358 g_free(cpu->thread);
359 qemu_cond_destroy(cpu->halt_cond);
360 g_free(cpu->halt_cond);
361 cpu->thread = single_tcg_cpu_thread;
362 cpu->halt_cond = single_tcg_halt_cond;
363
364 /* copy the stuff done at start of rr_cpu_thread_fn */
365 cpu->thread_id = first_cpu->thread_id;
366 cpu->neg.can_do_io = 1;
367 cpu->created = true;
368 }
369 }
^ permalink raw reply [flat|nested] 77+ messages in thread
* [RFC PATCH v2 37/48] accel/nvmm: Expose nvmm_enabled() to common code
2025-06-20 17:12 [RFC PATCH v2 00/48] accel: Preparatory cleanups for split-accel Philippe Mathieu-Daudé
` (35 preceding siblings ...)
2025-06-20 17:13 ` [RFC PATCH v2 36/48] accel/whpx: " Philippe Mathieu-Daudé
@ 2025-06-20 17:13 ` Philippe Mathieu-Daudé
2025-06-22 2:06 ` Richard Henderson
2025-06-20 17:13 ` [RFC PATCH v2 38/48] accel/whpx: Expose whpx_enabled() " Philippe Mathieu-Daudé
` (3 subsequent siblings)
40 siblings, 1 reply; 77+ messages in thread
From: Philippe Mathieu-Daudé @ 2025-06-20 17:13 UTC (permalink / raw)
To: qemu-devel
Cc: Alex Bennée, Alexander Graf, Richard Henderson,
Pierrick Bouvier, Peter Maydell, Thomas Huth, Cameron Esfahani,
Julian Armistead, Paolo Bonzini, Edgar E. Iglesias,
Philippe Mathieu-Daudé
Currently nvmm_enabled() is restricted to target-specific code.
By defining CONFIG_NVMM_IS_POSSIBLE we allow its use anywhere.
Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
---
include/system/nvmm.h | 23 ++++++++++++-----------
accel/stubs/nvmm-stub.c | 12 ++++++++++++
target/i386/nvmm/nvmm-all.c | 6 ------
accel/stubs/meson.build | 1 +
4 files changed, 25 insertions(+), 17 deletions(-)
create mode 100644 accel/stubs/nvmm-stub.c
diff --git a/include/system/nvmm.h b/include/system/nvmm.h
index 6971ddb3a5a..7390def9adb 100644
--- a/include/system/nvmm.h
+++ b/include/system/nvmm.h
@@ -13,17 +13,18 @@
#define QEMU_NVMM_H
#ifdef COMPILING_PER_TARGET
-
-#ifdef CONFIG_NVMM
-
-int nvmm_enabled(void);
-
-#else /* CONFIG_NVMM */
-
-#define nvmm_enabled() (0)
-
-#endif /* CONFIG_NVMM */
-
+# ifdef CONFIG_NVMM
+# define CONFIG_NVMM_IS_POSSIBLE
+# endif /* !CONFIG_NVMM */
+#else
+# define CONFIG_NVMM_IS_POSSIBLE
#endif /* COMPILING_PER_TARGET */
+#ifdef CONFIG_NVMM_IS_POSSIBLE
+extern bool nvmm_allowed;
+#define nvmm_enabled() (nvmm_allowed)
+#else /* !CONFIG_NVMM_IS_POSSIBLE */
+#define nvmm_enabled() 0
+#endif /* !CONFIG_NVMM_IS_POSSIBLE */
+
#endif /* QEMU_NVMM_H */
diff --git a/accel/stubs/nvmm-stub.c b/accel/stubs/nvmm-stub.c
new file mode 100644
index 00000000000..cc58114ceb3
--- /dev/null
+++ b/accel/stubs/nvmm-stub.c
@@ -0,0 +1,12 @@
+/*
+ * NVMM stubs for QEMU
+ *
+ * Copyright (c) Linaro
+ *
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ */
+
+#include "qemu/osdep.h"
+#include "system/hvf.h"
+
+bool nvmm_allowed;
diff --git a/target/i386/nvmm/nvmm-all.c b/target/i386/nvmm/nvmm-all.c
index 5c8e2857a8b..46a57c78feb 100644
--- a/target/i386/nvmm/nvmm-all.c
+++ b/target/i386/nvmm/nvmm-all.c
@@ -1192,12 +1192,6 @@ nvmm_accel_init(MachineState *ms, AccelState *as)
return 0;
}
-int
-nvmm_enabled(void)
-{
- return nvmm_allowed;
-}
-
static void
nvmm_accel_class_init(ObjectClass *oc, const void *data)
{
diff --git a/accel/stubs/meson.build b/accel/stubs/meson.build
index 8ca1a4529e2..4c34287215f 100644
--- a/accel/stubs/meson.build
+++ b/accel/stubs/meson.build
@@ -3,5 +3,6 @@ system_stubs_ss.add(when: 'CONFIG_XEN', if_false: files('xen-stub.c'))
system_stubs_ss.add(when: 'CONFIG_KVM', if_false: files('kvm-stub.c'))
system_stubs_ss.add(when: 'CONFIG_TCG', if_false: files('tcg-stub.c'))
system_stubs_ss.add(when: 'CONFIG_HVF', if_false: files('hvf-stub.c'))
+system_stubs_ss.add(when: 'CONFIG_NVMM', if_false: files('nvmm-stub.c'))
specific_ss.add_all(when: ['CONFIG_SYSTEM_ONLY'], if_true: system_stubs_ss)
--
2.49.0
^ permalink raw reply related [flat|nested] 77+ messages in thread
* Re: [RFC PATCH v2 37/48] accel/nvmm: Expose nvmm_enabled() to common code
2025-06-20 17:13 ` [RFC PATCH v2 37/48] accel/nvmm: Expose nvmm_enabled() to common code Philippe Mathieu-Daudé
@ 2025-06-22 2:06 ` Richard Henderson
0 siblings, 0 replies; 77+ messages in thread
From: Richard Henderson @ 2025-06-22 2:06 UTC (permalink / raw)
To: Philippe Mathieu-Daudé, qemu-devel
On 6/20/25 10:13, Philippe Mathieu-Daudé wrote:
> Currently nvmm_enabled() is restricted to target-specific code.
> By defining CONFIG_NVMM_IS_POSSIBLE we allow its use anywhere.
>
> Signed-off-by: Philippe Mathieu-Daudé<philmd@linaro.org>
> ---
> include/system/nvmm.h | 23 ++++++++++++-----------
> accel/stubs/nvmm-stub.c | 12 ++++++++++++
> target/i386/nvmm/nvmm-all.c | 6 ------
> accel/stubs/meson.build | 1 +
> 4 files changed, 25 insertions(+), 17 deletions(-)
> create mode 100644 accel/stubs/nvmm-stub.c
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
r~
^ permalink raw reply [flat|nested] 77+ messages in thread
* [RFC PATCH v2 38/48] accel/whpx: Expose whpx_enabled() to common code
2025-06-20 17:12 [RFC PATCH v2 00/48] accel: Preparatory cleanups for split-accel Philippe Mathieu-Daudé
` (36 preceding siblings ...)
2025-06-20 17:13 ` [RFC PATCH v2 37/48] accel/nvmm: Expose nvmm_enabled() to common code Philippe Mathieu-Daudé
@ 2025-06-20 17:13 ` Philippe Mathieu-Daudé
2025-06-22 2:07 ` Richard Henderson
2025-06-20 17:13 ` [RFC PATCH v2 39/48] accel/system: Introduce hwaccel_enabled() helper Philippe Mathieu-Daudé
` (2 subsequent siblings)
40 siblings, 1 reply; 77+ messages in thread
From: Philippe Mathieu-Daudé @ 2025-06-20 17:13 UTC (permalink / raw)
To: qemu-devel
Cc: Alex Bennée, Alexander Graf, Richard Henderson,
Pierrick Bouvier, Peter Maydell, Thomas Huth, Cameron Esfahani,
Julian Armistead, Paolo Bonzini, Edgar E. Iglesias,
Philippe Mathieu-Daudé
Currently whpx_enabled() is restricted to target-specific code.
By defining CONFIG_WHPX_IS_POSSIBLE we allow its use anywhere.
Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
---
include/system/whpx.h | 27 ++++++++++++++-------------
accel/stubs/whpx-stub.c | 12 ++++++++++++
target/i386/whpx/whpx-all.c | 5 -----
accel/stubs/meson.build | 1 +
4 files changed, 27 insertions(+), 18 deletions(-)
create mode 100644 accel/stubs/whpx-stub.c
diff --git a/include/system/whpx.h b/include/system/whpx.h
index 00ff409b682..00f6a3e5236 100644
--- a/include/system/whpx.h
+++ b/include/system/whpx.h
@@ -16,19 +16,20 @@
#define QEMU_WHPX_H
#ifdef COMPILING_PER_TARGET
-
-#ifdef CONFIG_WHPX
-
-int whpx_enabled(void);
-bool whpx_apic_in_platform(void);
-
-#else /* CONFIG_WHPX */
-
-#define whpx_enabled() (0)
-#define whpx_apic_in_platform() (0)
-
-#endif /* CONFIG_WHPX */
-
+# ifdef CONFIG_WHPX
+# define CONFIG_WHPX_IS_POSSIBLE
+# endif /* !CONFIG_WHPX */
+#else
+# define CONFIG_WHPX_IS_POSSIBLE
#endif /* COMPILING_PER_TARGET */
+#ifdef CONFIG_WHPX_IS_POSSIBLE
+extern bool whpx_allowed;
+#define whpx_enabled() (whpx_allowed)
+bool whpx_apic_in_platform(void);
+#else /* !CONFIG_WHPX_IS_POSSIBLE */
+#define whpx_enabled() 0
+#define whpx_apic_in_platform() (0)
+#endif /* !CONFIG_WHPX_IS_POSSIBLE */
+
#endif /* QEMU_WHPX_H */
diff --git a/accel/stubs/whpx-stub.c b/accel/stubs/whpx-stub.c
new file mode 100644
index 00000000000..c564c89fd0b
--- /dev/null
+++ b/accel/stubs/whpx-stub.c
@@ -0,0 +1,12 @@
+/*
+ * WHPX stubs for QEMU
+ *
+ * Copyright (c) Linaro
+ *
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ */
+
+#include "qemu/osdep.h"
+#include "system/whpx.h"
+
+bool whpx_allowed;
diff --git a/target/i386/whpx/whpx-all.c b/target/i386/whpx/whpx-all.c
index 77af84a87d4..feea5a57429 100644
--- a/target/i386/whpx/whpx-all.c
+++ b/target/i386/whpx/whpx-all.c
@@ -2688,11 +2688,6 @@ error:
return ret;
}
-int whpx_enabled(void)
-{
- return whpx_allowed;
-}
-
bool whpx_apic_in_platform(void) {
return whpx_global.apic_in_platform;
}
diff --git a/accel/stubs/meson.build b/accel/stubs/meson.build
index 4c34287215f..9dfc4f9ddaf 100644
--- a/accel/stubs/meson.build
+++ b/accel/stubs/meson.build
@@ -4,5 +4,6 @@ system_stubs_ss.add(when: 'CONFIG_KVM', if_false: files('kvm-stub.c'))
system_stubs_ss.add(when: 'CONFIG_TCG', if_false: files('tcg-stub.c'))
system_stubs_ss.add(when: 'CONFIG_HVF', if_false: files('hvf-stub.c'))
system_stubs_ss.add(when: 'CONFIG_NVMM', if_false: files('nvmm-stub.c'))
+system_stubs_ss.add(when: 'CONFIG_WHPX', if_false: files('whpx-stub.c'))
specific_ss.add_all(when: ['CONFIG_SYSTEM_ONLY'], if_true: system_stubs_ss)
--
2.49.0
^ permalink raw reply related [flat|nested] 77+ messages in thread
* Re: [RFC PATCH v2 38/48] accel/whpx: Expose whpx_enabled() to common code
2025-06-20 17:13 ` [RFC PATCH v2 38/48] accel/whpx: Expose whpx_enabled() " Philippe Mathieu-Daudé
@ 2025-06-22 2:07 ` Richard Henderson
0 siblings, 0 replies; 77+ messages in thread
From: Richard Henderson @ 2025-06-22 2:07 UTC (permalink / raw)
To: Philippe Mathieu-Daudé, qemu-devel
On 6/20/25 10:13, Philippe Mathieu-Daudé wrote:
> Currently whpx_enabled() is restricted to target-specific code.
> By defining CONFIG_WHPX_IS_POSSIBLE we allow its use anywhere.
>
> Signed-off-by: Philippe Mathieu-Daudé<philmd@linaro.org>
> ---
> include/system/whpx.h | 27 ++++++++++++++-------------
> accel/stubs/whpx-stub.c | 12 ++++++++++++
> target/i386/whpx/whpx-all.c | 5 -----
> accel/stubs/meson.build | 1 +
> 4 files changed, 27 insertions(+), 18 deletions(-)
> create mode 100644 accel/stubs/whpx-stub.c
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
r~
^ permalink raw reply [flat|nested] 77+ messages in thread
* [RFC PATCH v2 39/48] accel/system: Introduce hwaccel_enabled() helper
2025-06-20 17:12 [RFC PATCH v2 00/48] accel: Preparatory cleanups for split-accel Philippe Mathieu-Daudé
` (37 preceding siblings ...)
2025-06-20 17:13 ` [RFC PATCH v2 38/48] accel/whpx: Expose whpx_enabled() " Philippe Mathieu-Daudé
@ 2025-06-20 17:13 ` Philippe Mathieu-Daudé
2025-06-22 2:08 ` Richard Henderson
2025-06-20 17:13 ` [RFC PATCH v2 40/48] accel: Factor accel_cpu_realize() out Philippe Mathieu-Daudé
2025-06-20 17:13 ` [RFC PATCH v2 41/48] accel/tcg: Factor tcg_vcpu_init() out for re-use Philippe Mathieu-Daudé
40 siblings, 1 reply; 77+ messages in thread
From: Philippe Mathieu-Daudé @ 2025-06-20 17:13 UTC (permalink / raw)
To: qemu-devel
Cc: Alex Bennée, Alexander Graf, Richard Henderson,
Pierrick Bouvier, Peter Maydell, Thomas Huth, Cameron Esfahani,
Julian Armistead, Paolo Bonzini, Edgar E. Iglesias,
Philippe Mathieu-Daudé
hwaccel_enabled() return whether any hardware accelerator
is available.
Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
---
include/system/hw_accel.h | 21 +++++++++++++++++++++
1 file changed, 21 insertions(+)
diff --git a/include/system/hw_accel.h b/include/system/hw_accel.h
index 574c9738408..49556b026e0 100644
--- a/include/system/hw_accel.h
+++ b/include/system/hw_accel.h
@@ -28,7 +28,28 @@
void cpu_synchronize_state(CPUState *cpu);
void cpu_synchronize_pre_loadvm(CPUState *cpu);
+/**
+ * cpu_synchronize_post_reset:
+ * cpu_synchronize_post_init:
+ * @cpu: The vCPU to synchronize.
+ *
+ * Request to synchronize QEMU vCPU registers to the hardware accelerator
+ * (QEMU is the reference).
+ */
void cpu_synchronize_post_reset(CPUState *cpu);
void cpu_synchronize_post_init(CPUState *cpu);
+/**
+ * hwaccel_enabled:
+ *
+ * Returns: %true if a hardware accelerator is enabled, %false otherwise.
+ */
+static inline bool hwaccel_enabled(void)
+{
+ return hvf_enabled()
+ || kvm_enabled()
+ || nvmm_enabled()
+ || whpx_enabled();
+}
+
#endif /* QEMU_HW_ACCEL_H */
--
2.49.0
^ permalink raw reply related [flat|nested] 77+ messages in thread
* Re: [RFC PATCH v2 39/48] accel/system: Introduce hwaccel_enabled() helper
2025-06-20 17:13 ` [RFC PATCH v2 39/48] accel/system: Introduce hwaccel_enabled() helper Philippe Mathieu-Daudé
@ 2025-06-22 2:08 ` Richard Henderson
0 siblings, 0 replies; 77+ messages in thread
From: Richard Henderson @ 2025-06-22 2:08 UTC (permalink / raw)
To: Philippe Mathieu-Daudé, qemu-devel
On 6/20/25 10:13, Philippe Mathieu-Daudé wrote:
> hwaccel_enabled() return whether any hardware accelerator
> is available.
>
> Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
> ---
> include/system/hw_accel.h | 21 +++++++++++++++++++++
> 1 file changed, 21 insertions(+)
>
> diff --git a/include/system/hw_accel.h b/include/system/hw_accel.h
> index 574c9738408..49556b026e0 100644
> --- a/include/system/hw_accel.h
> +++ b/include/system/hw_accel.h
> @@ -28,7 +28,28 @@
> void cpu_synchronize_state(CPUState *cpu);
> void cpu_synchronize_pre_loadvm(CPUState *cpu);
>
> +/**
> + * cpu_synchronize_post_reset:
> + * cpu_synchronize_post_init:
> + * @cpu: The vCPU to synchronize.
> + *
> + * Request to synchronize QEMU vCPU registers to the hardware accelerator
> + * (QEMU is the reference).
> + */
> void cpu_synchronize_post_reset(CPUState *cpu);
> void cpu_synchronize_post_init(CPUState *cpu);
This belongs to a previous patch.
>
> +/**
> + * hwaccel_enabled:
> + *
> + * Returns: %true if a hardware accelerator is enabled, %false otherwise.
> + */
> +static inline bool hwaccel_enabled(void)
> +{
> + return hvf_enabled()
> + || kvm_enabled()
> + || nvmm_enabled()
> + || whpx_enabled();
> +}
> +
> #endif /* QEMU_HW_ACCEL_H */
But the rest is ok.
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
r~
^ permalink raw reply [flat|nested] 77+ messages in thread
* [RFC PATCH v2 40/48] accel: Factor accel_cpu_realize() out
2025-06-20 17:12 [RFC PATCH v2 00/48] accel: Preparatory cleanups for split-accel Philippe Mathieu-Daudé
` (38 preceding siblings ...)
2025-06-20 17:13 ` [RFC PATCH v2 39/48] accel/system: Introduce hwaccel_enabled() helper Philippe Mathieu-Daudé
@ 2025-06-20 17:13 ` Philippe Mathieu-Daudé
2025-06-22 2:14 ` Richard Henderson
2025-06-20 17:13 ` [RFC PATCH v2 41/48] accel/tcg: Factor tcg_vcpu_init() out for re-use Philippe Mathieu-Daudé
40 siblings, 1 reply; 77+ messages in thread
From: Philippe Mathieu-Daudé @ 2025-06-20 17:13 UTC (permalink / raw)
To: qemu-devel
Cc: Alex Bennée, Alexander Graf, Richard Henderson,
Pierrick Bouvier, Peter Maydell, Thomas Huth, Cameron Esfahani,
Julian Armistead, Paolo Bonzini, Edgar E. Iglesias,
Philippe Mathieu-Daudé
Factor accel_cpu_realize() out of accel_cpu_common_realize()
for re-use.
Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
---
accel/accel-internal.h | 2 ++
accel/accel-common.c | 15 ++++++++++++---
2 files changed, 14 insertions(+), 3 deletions(-)
diff --git a/accel/accel-internal.h b/accel/accel-internal.h
index d3a4422cbf7..b541377c349 100644
--- a/accel/accel-internal.h
+++ b/accel/accel-internal.h
@@ -14,4 +14,6 @@
void accel_init_ops_interfaces(AccelClass *ac);
+bool accel_cpu_realize(AccelState *accel, CPUState *cpu, Error **errp);
+
#endif /* ACCEL_SYSTEM_H */
diff --git a/accel/accel-common.c b/accel/accel-common.c
index 24038acf4aa..0f2aa783ab2 100644
--- a/accel/accel-common.c
+++ b/accel/accel-common.c
@@ -122,10 +122,14 @@ void accel_create_vcpu_thread(AccelState *accel, CPUState *cpu)
}
}
-bool accel_cpu_common_realize(CPUState *cpu, Error **errp)
+bool accel_cpu_realize(AccelState *accel, CPUState *cpu, Error **errp)
{
- AccelState *accel = current_accel();
- AccelClass *acc = ACCEL_GET_CLASS(accel);
+ AccelClass *acc;
+
+ if (!accel) {
+ accel = current_accel();
+ }
+ acc = ACCEL_GET_CLASS(accel);
/* target specific realization */
if (cpu->cc->accel_cpu
@@ -147,6 +151,11 @@ bool accel_cpu_common_realize(CPUState *cpu, Error **errp)
return true;
}
+bool accel_cpu_common_realize(CPUState *cpu, Error **errp)
+{
+ return accel_cpu_realize(NULL, cpu, errp);
+}
+
void accel_cpu_common_unrealize(CPUState *cpu)
{
AccelState *accel = current_accel();
--
2.49.0
^ permalink raw reply related [flat|nested] 77+ messages in thread
* Re: [RFC PATCH v2 40/48] accel: Factor accel_cpu_realize() out
2025-06-20 17:13 ` [RFC PATCH v2 40/48] accel: Factor accel_cpu_realize() out Philippe Mathieu-Daudé
@ 2025-06-22 2:14 ` Richard Henderson
2025-06-23 14:16 ` Philippe Mathieu-Daudé
0 siblings, 1 reply; 77+ messages in thread
From: Richard Henderson @ 2025-06-22 2:14 UTC (permalink / raw)
To: Philippe Mathieu-Daudé, qemu-devel
Cc: Alex Bennée, Alexander Graf, Pierrick Bouvier, Peter Maydell,
Thomas Huth, Cameron Esfahani, Julian Armistead, Paolo Bonzini,
Edgar E. Iglesias
On 6/20/25 10:13, Philippe Mathieu-Daudé wrote:
> Factor accel_cpu_realize() out of accel_cpu_common_realize()
> for re-use.
>
> Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
> ---
> accel/accel-internal.h | 2 ++
> accel/accel-common.c | 15 ++++++++++++---
> 2 files changed, 14 insertions(+), 3 deletions(-)
>
> diff --git a/accel/accel-internal.h b/accel/accel-internal.h
> index d3a4422cbf7..b541377c349 100644
> --- a/accel/accel-internal.h
> +++ b/accel/accel-internal.h
> @@ -14,4 +14,6 @@
>
> void accel_init_ops_interfaces(AccelClass *ac);
>
> +bool accel_cpu_realize(AccelState *accel, CPUState *cpu, Error **errp);
> +
> #endif /* ACCEL_SYSTEM_H */
> diff --git a/accel/accel-common.c b/accel/accel-common.c
> index 24038acf4aa..0f2aa783ab2 100644
> --- a/accel/accel-common.c
> +++ b/accel/accel-common.c
> @@ -122,10 +122,14 @@ void accel_create_vcpu_thread(AccelState *accel, CPUState *cpu)
> }
> }
>
> -bool accel_cpu_common_realize(CPUState *cpu, Error **errp)
> +bool accel_cpu_realize(AccelState *accel, CPUState *cpu, Error **errp)
> {
> - AccelState *accel = current_accel();
> - AccelClass *acc = ACCEL_GET_CLASS(accel);
> + AccelClass *acc;
> +
> + if (!accel) {
> + accel = current_accel();
> + }
> + acc = ACCEL_GET_CLASS(accel);
>
> /* target specific realization */
> if (cpu->cc->accel_cpu
> @@ -147,6 +151,11 @@ bool accel_cpu_common_realize(CPUState *cpu, Error **errp)
> return true;
> }
>
> +bool accel_cpu_common_realize(CPUState *cpu, Error **errp)
> +{
> + return accel_cpu_realize(NULL, cpu, errp);
Why pass null here, and why check for it in the new function?
r~
> +}
> +
> void accel_cpu_common_unrealize(CPUState *cpu)
> {
> AccelState *accel = current_accel();
^ permalink raw reply [flat|nested] 77+ messages in thread
* Re: [RFC PATCH v2 40/48] accel: Factor accel_cpu_realize() out
2025-06-22 2:14 ` Richard Henderson
@ 2025-06-23 14:16 ` Philippe Mathieu-Daudé
0 siblings, 0 replies; 77+ messages in thread
From: Philippe Mathieu-Daudé @ 2025-06-23 14:16 UTC (permalink / raw)
To: Richard Henderson, qemu-devel
Cc: Alex Bennée, Alexander Graf, Pierrick Bouvier, Peter Maydell,
Thomas Huth, Cameron Esfahani, Julian Armistead, Paolo Bonzini,
Edgar E. Iglesias
On 22/6/25 04:14, Richard Henderson wrote:
> On 6/20/25 10:13, Philippe Mathieu-Daudé wrote:
>> Factor accel_cpu_realize() out of accel_cpu_common_realize()
>> for re-use.
>>
>> Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
>> ---
>> accel/accel-internal.h | 2 ++
>> accel/accel-common.c | 15 ++++++++++++---
>> 2 files changed, 14 insertions(+), 3 deletions(-)
>>
>> diff --git a/accel/accel-internal.h b/accel/accel-internal.h
>> index d3a4422cbf7..b541377c349 100644
>> --- a/accel/accel-internal.h
>> +++ b/accel/accel-internal.h
>> @@ -14,4 +14,6 @@
>> void accel_init_ops_interfaces(AccelClass *ac);
>> +bool accel_cpu_realize(AccelState *accel, CPUState *cpu, Error **errp);
>> +
>> #endif /* ACCEL_SYSTEM_H */
>> diff --git a/accel/accel-common.c b/accel/accel-common.c
>> index 24038acf4aa..0f2aa783ab2 100644
>> --- a/accel/accel-common.c
>> +++ b/accel/accel-common.c
>> @@ -122,10 +122,14 @@ void accel_create_vcpu_thread(AccelState *accel,
>> CPUState *cpu)
>> }
>> }
>> -bool accel_cpu_common_realize(CPUState *cpu, Error **errp)
>> +bool accel_cpu_realize(AccelState *accel, CPUState *cpu, Error **errp)
>> {
>> - AccelState *accel = current_accel();
>> - AccelClass *acc = ACCEL_GET_CLASS(accel);
>> + AccelClass *acc;
>> +
>> + if (!accel) {
>> + accel = current_accel();
>> + }
>> + acc = ACCEL_GET_CLASS(accel);
>> /* target specific realization */
>> if (cpu->cc->accel_cpu
>> @@ -147,6 +151,11 @@ bool accel_cpu_common_realize(CPUState *cpu,
>> Error **errp)
>> return true;
>> }
>> +bool accel_cpu_common_realize(CPUState *cpu, Error **errp)
>> +{
>> + return accel_cpu_realize(NULL, cpu, errp);
>
> Why pass null here, and why check for it in the new function?
Indeed ;)
^ permalink raw reply [flat|nested] 77+ messages in thread
* [RFC PATCH v2 41/48] accel/tcg: Factor tcg_vcpu_init() out for re-use
2025-06-20 17:12 [RFC PATCH v2 00/48] accel: Preparatory cleanups for split-accel Philippe Mathieu-Daudé
` (39 preceding siblings ...)
2025-06-20 17:13 ` [RFC PATCH v2 40/48] accel: Factor accel_cpu_realize() out Philippe Mathieu-Daudé
@ 2025-06-20 17:13 ` Philippe Mathieu-Daudé
40 siblings, 0 replies; 77+ messages in thread
From: Philippe Mathieu-Daudé @ 2025-06-20 17:13 UTC (permalink / raw)
To: qemu-devel
Cc: Alex Bennée, Alexander Graf, Richard Henderson,
Pierrick Bouvier, Peter Maydell, Thomas Huth, Cameron Esfahani,
Julian Armistead, Paolo Bonzini, Edgar E. Iglesias,
Philippe Mathieu-Daudé
Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
---
accel/tcg/tcg-accel-ops.h | 2 ++
accel/tcg/tcg-accel-ops-mttcg.c | 4 +++-
accel/tcg/tcg-accel-ops-rr.c | 4 +++-
accel/tcg/tcg-accel-ops.c | 7 +++++++
4 files changed, 15 insertions(+), 2 deletions(-)
diff --git a/accel/tcg/tcg-accel-ops.h b/accel/tcg/tcg-accel-ops.h
index 129af89c3e7..1263a666774 100644
--- a/accel/tcg/tcg-accel-ops.h
+++ b/accel/tcg/tcg-accel-ops.h
@@ -20,4 +20,6 @@ int tcg_cpu_exec(CPUState *cpu);
void tcg_handle_interrupt(CPUState *cpu, int mask);
void tcg_cpu_init_cflags(CPUState *cpu, bool parallel);
+int tcg_vcpu_init(CPUState *cpu);
+
#endif /* TCG_ACCEL_OPS_H */
diff --git a/accel/tcg/tcg-accel-ops-mttcg.c b/accel/tcg/tcg-accel-ops-mttcg.c
index 96ce065eb59..4de506a80ca 100644
--- a/accel/tcg/tcg-accel-ops-mttcg.c
+++ b/accel/tcg/tcg-accel-ops-mttcg.c
@@ -79,8 +79,10 @@ void *mttcg_cpu_thread_routine(void *arg)
qemu_thread_get_self(cpu->thread);
cpu->thread_id = qemu_get_thread_id();
- cpu->neg.can_do_io = true;
current_cpu = cpu;
+
+ tcg_vcpu_init(cpu);
+
cpu_thread_signal_created(cpu);
qemu_guest_random_seed_thread_part2(cpu->random_seed);
diff --git a/accel/tcg/tcg-accel-ops-rr.c b/accel/tcg/tcg-accel-ops-rr.c
index fc33a13e4e8..9578bc639cb 100644
--- a/accel/tcg/tcg-accel-ops-rr.c
+++ b/accel/tcg/tcg-accel-ops-rr.c
@@ -192,7 +192,9 @@ static void *rr_cpu_thread_fn(void *arg)
qemu_thread_get_self(cpu->thread);
cpu->thread_id = qemu_get_thread_id();
- cpu->neg.can_do_io = true;
+
+ tcg_vcpu_init(cpu);
+
cpu_thread_signal_created(cpu);
qemu_guest_random_seed_thread_part2(cpu->random_seed);
diff --git a/accel/tcg/tcg-accel-ops.c b/accel/tcg/tcg-accel-ops.c
index 4931e536beb..83fb2d1362c 100644
--- a/accel/tcg/tcg-accel-ops.c
+++ b/accel/tcg/tcg-accel-ops.c
@@ -76,6 +76,13 @@ void tcg_vcpu_thread_precreate(CPUState *cpu)
tcg_cpu_init_cflags(cpu, current_machine->smp.max_cpus > 1);
}
+int tcg_vcpu_init(CPUState *cpu)
+{
+ cpu->neg.can_do_io = true;
+
+ return 0;
+}
+
void tcg_cpu_destroy(CPUState *cpu)
{
cpu_thread_signal_destroyed(cpu);
--
2.49.0
^ permalink raw reply related [flat|nested] 77+ messages in thread