[PATCH] hw/riscv/virt-acpi-build.c: Use kvm timer frequency when kvm enabled

Yicong Yang posted 1 patch 1 week, 1 day ago
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/qemu tags/patchew/20260325081314.57089-1-yang.yicong@picoheart.com
Maintainers: Sunil V L <sunilvl@ventanamicro.com>, Palmer Dabbelt <palmer@dabbelt.com>, Alistair Francis <alistair.francis@wdc.com>, Weiwei Li <liwei1518@gmail.com>, Daniel Henrique Barboza <daniel.barboza@oss.qualcomm.com>, Liu Zhiwei <zhiwei_liu@linux.alibaba.com>, Chao Liu <chao.liu.zevorn@gmail.com>
hw/riscv/virt-acpi-build.c | 7 ++++++-
1 file changed, 6 insertions(+), 1 deletion(-)
[PATCH] hw/riscv/virt-acpi-build.c: Use kvm timer frequency when kvm enabled
Posted by Yicong Yang 1 week, 1 day ago
The timer frequency is decided by the host(kvm) rather than a fixed
RISCV_ACLINT_DEFAULT_TIMEBASE_FREQ on kvm accelerated VM. So build
RCHT with KVM provided timer frequency if KVM is enabled, just like
how we build the timer node on DT based VM.

Fixes: ebfd39289370 ("hw/riscv/virt: virt-acpi-build.c: Add RHCT Table")
Signed-off-by: Yicong Yang <yang.yicong@picoheart.com>
---
 hw/riscv/virt-acpi-build.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/hw/riscv/virt-acpi-build.c b/hw/riscv/virt-acpi-build.c
index f1406cb68339..fd6ca5dbc4ff 100644
--- a/hw/riscv/virt-acpi-build.c
+++ b/hw/riscv/virt-acpi-build.c
@@ -35,9 +35,11 @@
 #include "hw/riscv/virt.h"
 #include "hw/riscv/numa.h"
 #include "hw/virtio/virtio-acpi.h"
+#include "kvm/kvm_riscv.h"
 #include "migration/vmstate.h"
 #include "qapi/error.h"
 #include "qemu/error-report.h"
+#include "system/kvm.h"
 #include "system/reset.h"
 
 #define ACPI_BUILD_TABLE_SIZE             0x20000
@@ -296,7 +298,10 @@ static void build_rhct(GArray *table_data,
 
     /* Time Base Frequency */
     build_append_int_noprefix(table_data,
-                              RISCV_ACLINT_DEFAULT_TIMEBASE_FREQ, 8);
+                              kvm_enabled() ?
+                              kvm_riscv_get_timebase_frequency(&s->soc->harts[0]) :
+                              RISCV_ACLINT_DEFAULT_TIMEBASE_FREQ,
+                              8);
 
     /* ISA + N hart info */
     num_rhct_nodes = 1 + ms->smp.cpus;
-- 
2.34.1
Re: [PATCH] hw/riscv/virt-acpi-build.c: Use kvm timer frequency when kvm enabled
Posted by Alistair Francis 1 day, 20 hours ago
On Wed, Mar 25, 2026 at 10:34 PM Yicong Yang <yang.yicong@picoheart.com> wrote:
>
> The timer frequency is decided by the host(kvm) rather than a fixed
> RISCV_ACLINT_DEFAULT_TIMEBASE_FREQ on kvm accelerated VM. So build
> RCHT with KVM provided timer frequency if KVM is enabled, just like
> how we build the timer node on DT based VM.
>
> Fixes: ebfd39289370 ("hw/riscv/virt: virt-acpi-build.c: Add RHCT Table")
> Signed-off-by: Yicong Yang <yang.yicong@picoheart.com>

Thanks!

Applied to riscv-to-apply.next

Alistair

> ---
>  hw/riscv/virt-acpi-build.c | 7 ++++++-
>  1 file changed, 6 insertions(+), 1 deletion(-)
>
> diff --git a/hw/riscv/virt-acpi-build.c b/hw/riscv/virt-acpi-build.c
> index f1406cb68339..fd6ca5dbc4ff 100644
> --- a/hw/riscv/virt-acpi-build.c
> +++ b/hw/riscv/virt-acpi-build.c
> @@ -35,9 +35,11 @@
>  #include "hw/riscv/virt.h"
>  #include "hw/riscv/numa.h"
>  #include "hw/virtio/virtio-acpi.h"
> +#include "kvm/kvm_riscv.h"
>  #include "migration/vmstate.h"
>  #include "qapi/error.h"
>  #include "qemu/error-report.h"
> +#include "system/kvm.h"
>  #include "system/reset.h"
>
>  #define ACPI_BUILD_TABLE_SIZE             0x20000
> @@ -296,7 +298,10 @@ static void build_rhct(GArray *table_data,
>
>      /* Time Base Frequency */
>      build_append_int_noprefix(table_data,
> -                              RISCV_ACLINT_DEFAULT_TIMEBASE_FREQ, 8);
> +                              kvm_enabled() ?
> +                              kvm_riscv_get_timebase_frequency(&s->soc->harts[0]) :
> +                              RISCV_ACLINT_DEFAULT_TIMEBASE_FREQ,
> +                              8);
>
>      /* ISA + N hart info */
>      num_rhct_nodes = 1 + ms->smp.cpus;
> --
> 2.34.1
>
Re: [PATCH] hw/riscv/virt-acpi-build.c: Use kvm timer frequency when kvm enabled
Posted by Andrew Jones 5 days, 8 hours ago
On Wed, Mar 25, 2026 at 04:13:14PM +0800, Yicong Yang wrote:
> The timer frequency is decided by the host(kvm) rather than a fixed
> RISCV_ACLINT_DEFAULT_TIMEBASE_FREQ on kvm accelerated VM. So build
> RCHT with KVM provided timer frequency if KVM is enabled, just like
> how we build the timer node on DT based VM.
> 
> Fixes: ebfd39289370 ("hw/riscv/virt: virt-acpi-build.c: Add RHCT Table")
> Signed-off-by: Yicong Yang <yang.yicong@picoheart.com>
> ---
>  hw/riscv/virt-acpi-build.c | 7 ++++++-
>  1 file changed, 6 insertions(+), 1 deletion(-)
> 
> diff --git a/hw/riscv/virt-acpi-build.c b/hw/riscv/virt-acpi-build.c
> index f1406cb68339..fd6ca5dbc4ff 100644
> --- a/hw/riscv/virt-acpi-build.c
> +++ b/hw/riscv/virt-acpi-build.c
> @@ -35,9 +35,11 @@
>  #include "hw/riscv/virt.h"
>  #include "hw/riscv/numa.h"
>  #include "hw/virtio/virtio-acpi.h"
> +#include "kvm/kvm_riscv.h"
>  #include "migration/vmstate.h"
>  #include "qapi/error.h"
>  #include "qemu/error-report.h"
> +#include "system/kvm.h"
>  #include "system/reset.h"
>  
>  #define ACPI_BUILD_TABLE_SIZE             0x20000
> @@ -296,7 +298,10 @@ static void build_rhct(GArray *table_data,
>  
>      /* Time Base Frequency */
>      build_append_int_noprefix(table_data,
> -                              RISCV_ACLINT_DEFAULT_TIMEBASE_FREQ, 8);
> +                              kvm_enabled() ?
> +                              kvm_riscv_get_timebase_frequency(&s->soc->harts[0]) :
> +                              RISCV_ACLINT_DEFAULT_TIMEBASE_FREQ,
> +                              8);
>  
>      /* ISA + N hart info */
>      num_rhct_nodes = 1 + ms->smp.cpus;
> -- 
> 2.34.1
>

Reviewed-by: Andrew Jones <andrew.jones@oss.qualcomm.com>