* [PATCH 1/1] target/riscv/kvm.c: Fix the hart bit setting of AIA
@ 2024-04-15 6:52 Yong-Xuan Wang
2024-04-29 3:25 ` Alistair Francis
0 siblings, 1 reply; 3+ messages in thread
From: Yong-Xuan Wang @ 2024-04-15 6:52 UTC (permalink / raw)
To: qemu-devel, qemu-riscv
Cc: greentime.hu, vincent.chen, frank.chang, jim.shu, Yong-Xuan Wang,
Palmer Dabbelt, Alistair Francis, Bin Meng, Weiwei Li,
Daniel Henrique Barboza, Liu Zhiwei, Andrew Jones,
Philippe Mathieu-Daudé
The hart bit setting is different with Linux AIA driver[1] when the number
of hart is power of 2. For example, when the guest has 4 harts, the
estimated result of AIA driver is 2, whereas we pass 3 to RISC-V/KVM. Since
only 2 bits are needed to represent 4 harts, update the formula to get the
accurate result.
[1] https://lore.kernel.org/all/20240307140307.646078-1-apatel@ventanamicro.com/
Signed-off-by: Yong-Xuan Wang <yongxuan.wang@sifive.com>
---
target/riscv/kvm/kvm-cpu.c | 9 ++++++++-
1 file changed, 8 insertions(+), 1 deletion(-)
diff --git a/target/riscv/kvm/kvm-cpu.c b/target/riscv/kvm/kvm-cpu.c
index 6a6c6cae80f1..388c4ddaa145 100644
--- a/target/riscv/kvm/kvm-cpu.c
+++ b/target/riscv/kvm/kvm-cpu.c
@@ -1642,7 +1642,14 @@ void kvm_riscv_aia_create(MachineState *machine, uint64_t group_shift,
}
}
- hart_bits = find_last_bit(&max_hart_per_socket, BITS_PER_LONG) + 1;
+
+ if (max_hart_per_socket > 1) {
+ max_hart_per_socket--;
+ hart_bits = find_last_bit(&max_hart_per_socket, BITS_PER_LONG) + 1;
+ } else {
+ hart_bits = 0;
+ }
+
ret = kvm_device_access(aia_fd, KVM_DEV_RISCV_AIA_GRP_CONFIG,
KVM_DEV_RISCV_AIA_CONFIG_HART_BITS,
&hart_bits, true, NULL);
--
2.17.1
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH 1/1] target/riscv/kvm.c: Fix the hart bit setting of AIA
2024-04-15 6:52 [PATCH 1/1] target/riscv/kvm.c: Fix the hart bit setting of AIA Yong-Xuan Wang
@ 2024-04-29 3:25 ` Alistair Francis
2024-05-07 10:12 ` Yong-Xuan Wang
0 siblings, 1 reply; 3+ messages in thread
From: Alistair Francis @ 2024-04-29 3:25 UTC (permalink / raw)
To: Yong-Xuan Wang
Cc: qemu-devel, qemu-riscv, greentime.hu, vincent.chen, frank.chang,
jim.shu, Palmer Dabbelt, Alistair Francis, Bin Meng, Weiwei Li,
Daniel Henrique Barboza, Liu Zhiwei, Andrew Jones,
Philippe Mathieu-Daudé
On Mon, Apr 15, 2024 at 4:53 PM Yong-Xuan Wang <yongxuan.wang@sifive.com> wrote:
>
> The hart bit setting is different with Linux AIA driver[1] when the number
> of hart is power of 2. For example, when the guest has 4 harts, the
> estimated result of AIA driver is 2, whereas we pass 3 to RISC-V/KVM. Since
> only 2 bits are needed to represent 4 harts, update the formula to get the
> accurate result.
I don't really follow this.
Do you mind re-wording it to talk about what the specification says?
Not what Linux does.
>
> [1] https://lore.kernel.org/all/20240307140307.646078-1-apatel@ventanamicro.com/
>
> Signed-off-by: Yong-Xuan Wang <yongxuan.wang@sifive.com>
> ---
> target/riscv/kvm/kvm-cpu.c | 9 ++++++++-
> 1 file changed, 8 insertions(+), 1 deletion(-)
>
> diff --git a/target/riscv/kvm/kvm-cpu.c b/target/riscv/kvm/kvm-cpu.c
> index 6a6c6cae80f1..388c4ddaa145 100644
> --- a/target/riscv/kvm/kvm-cpu.c
> +++ b/target/riscv/kvm/kvm-cpu.c
> @@ -1642,7 +1642,14 @@ void kvm_riscv_aia_create(MachineState *machine, uint64_t group_shift,
> }
> }
>
> - hart_bits = find_last_bit(&max_hart_per_socket, BITS_PER_LONG) + 1;
> +
> + if (max_hart_per_socket > 1) {
> + max_hart_per_socket--;
Assuming there are an even number of cores (which there usually are)
won't this always result in a
> + hart_bits = find_last_bit(&max_hart_per_socket, BITS_PER_LONG) + 1;
1 being returned by find_last_bit()?
Alistair
> + } else {
> + hart_bits = 0;
> + }
> +
> ret = kvm_device_access(aia_fd, KVM_DEV_RISCV_AIA_GRP_CONFIG,
> KVM_DEV_RISCV_AIA_CONFIG_HART_BITS,
> &hart_bits, true, NULL);
> --
> 2.17.1
>
>
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH 1/1] target/riscv/kvm.c: Fix the hart bit setting of AIA
2024-04-29 3:25 ` Alistair Francis
@ 2024-05-07 10:12 ` Yong-Xuan Wang
0 siblings, 0 replies; 3+ messages in thread
From: Yong-Xuan Wang @ 2024-05-07 10:12 UTC (permalink / raw)
To: Alistair Francis
Cc: qemu-devel, qemu-riscv, greentime.hu, vincent.chen, frank.chang,
jim.shu, Palmer Dabbelt, Alistair Francis, Bin Meng, Weiwei Li,
Daniel Henrique Barboza, Liu Zhiwei, Andrew Jones,
Philippe Mathieu-Daudé
Hi Alistair,
On Mon, Apr 29, 2024 at 11:25 AM Alistair Francis <alistair23@gmail.com> wrote:
>
> On Mon, Apr 15, 2024 at 4:53 PM Yong-Xuan Wang <yongxuan.wang@sifive.com> wrote:
> >
> > The hart bit setting is different with Linux AIA driver[1] when the number
> > of hart is power of 2. For example, when the guest has 4 harts, the
> > estimated result of AIA driver is 2, whereas we pass 3 to RISC-V/KVM. Since
> > only 2 bits are needed to represent 4 harts, update the formula to get the
> > accurate result.
>
> I don't really follow this.
>
> Do you mind re-wording it to talk about what the specification says?
> Not what Linux does.
>
Sure!
> >
> > [1] https://lore.kernel.org/all/20240307140307.646078-1-apatel@ventanamicro.com/
> >
> > Signed-off-by: Yong-Xuan Wang <yongxuan.wang@sifive.com>
> > ---
> > target/riscv/kvm/kvm-cpu.c | 9 ++++++++-
> > 1 file changed, 8 insertions(+), 1 deletion(-)
> >
> > diff --git a/target/riscv/kvm/kvm-cpu.c b/target/riscv/kvm/kvm-cpu.c
> > index 6a6c6cae80f1..388c4ddaa145 100644
> > --- a/target/riscv/kvm/kvm-cpu.c
> > +++ b/target/riscv/kvm/kvm-cpu.c
> > @@ -1642,7 +1642,14 @@ void kvm_riscv_aia_create(MachineState *machine, uint64_t group_shift,
> > }
> > }
> >
> > - hart_bits = find_last_bit(&max_hart_per_socket, BITS_PER_LONG) + 1;
> > +
> > + if (max_hart_per_socket > 1) {
> > + max_hart_per_socket--;
>
> Assuming there are an even number of cores (which there usually are)
> won't this always result in a
>
> > + hart_bits = find_last_bit(&max_hart_per_socket, BITS_PER_LONG) + 1;
>
> 1 being returned by find_last_bit()?
>
find_last_bit() returns the position of the leftmost set bit. The
output will not be 1 when the given input is an odd number.
Regards,
Yong-Xuan
> Alistair
>
> > + } else {
> > + hart_bits = 0;
> > + }
> > +
> > ret = kvm_device_access(aia_fd, KVM_DEV_RISCV_AIA_GRP_CONFIG,
> > KVM_DEV_RISCV_AIA_CONFIG_HART_BITS,
> > &hart_bits, true, NULL);
> > --
> > 2.17.1
> >
> >
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2024-05-07 10:13 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-04-15 6:52 [PATCH 1/1] target/riscv/kvm.c: Fix the hart bit setting of AIA Yong-Xuan Wang
2024-04-29 3:25 ` Alistair Francis
2024-05-07 10:12 ` Yong-Xuan Wang
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).