[RFC PATCH v2 39/48] accel/system: Introduce hwaccel_enabled() helper

Philippe Mathieu-Daudé posted 48 patches 4 months, 3 weeks ago
Only 41 patches received!
There is a newer version of this series
[RFC PATCH v2 39/48] accel/system: Introduce hwaccel_enabled() helper
Posted by Philippe Mathieu-Daudé 4 months, 3 weeks ago
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


Re: [RFC PATCH v2 39/48] accel/system: Introduce hwaccel_enabled() helper
Posted by Richard Henderson 4 months, 3 weeks ago
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~