From: Daniel Henrique Barboza <dbarboza@ventanamicro.com>
To: "Richard Henderson" <richard.henderson@linaro.org>,
"Philippe Mathieu-Daudé" <philmd@linaro.org>,
qemu-devel@nongnu.org
Cc: qemu-riscv@nongnu.org, alistair.francis@wdc.com,
bmeng@tinylab.org, liweiwei@iscas.ac.cn,
zhiwei_liu@linux.alibaba.com, palmer@rivosinc.com
Subject: Re: [PATCH 2/2] hw/riscv/virt.c: fix non-KVM --enable-debug build
Date: Wed, 30 Aug 2023 06:34:50 -0300 [thread overview]
Message-ID: <7a309a5c-c88e-4cfc-7811-5643a53def81@ventanamicro.com> (raw)
In-Reply-To: <d2f1ad02-eb03-138f-9d08-db676deeed05@linaro.org>
On 8/29/23 22:26, Richard Henderson wrote:
> On 8/29/23 16:51, Daniel Henrique Barboza wrote:
>>> The compiler certainly does eliminate 0 && foo(), even at -O0.
>>>
>>> There must be something else going on.
>>> Pointer to your tree?
>>
>> It's this tree:
>>
>> https://github.com/alistair23/qemu/tree/riscv-to-apply.next
>
>
> Ok, so while -O0 will eliminate 0 && foo(), it doesn't eliminate with bar() && foo(), where bar must be inlined (multiple times in this case) to find the 0.
>
> Moreover in the case of
>
>> /usr/bin/ld: libqemu-riscv64-softmmu.fa.p/hw_intc_riscv_aplic.c.o: in function `riscv_kvm_aplic_request':
>> /home/danielhb/work/qemu/build/../hw/intc/riscv_aplic.c:486: undefined reference to `kvm_set_irq'
>
> this one, where foo (aka riscv_kvm_aplic_request) would have to be eliminated as well. But the compiler won't eliminate entire unused functions with -O0.
>
> This seems to do the trick. Whether it is aesthetically better than what you had with your patches, I will leave to someone else.
>
>
> r~
>
>
> diff --git a/hw/intc/riscv_aplic.c b/hw/intc/riscv_aplic.c
> index 592c3ce768..0e22dcaf8a 100644
> --- a/hw/intc/riscv_aplic.c
> +++ b/hw/intc/riscv_aplic.c
> @@ -481,10 +481,14 @@ static uint32_t riscv_aplic_idc_claimi(RISCVAPLICState *aplic, uint32_t idc)
> return topi;
> }
>
> +#ifdef CONFIG_KVM
> static void riscv_kvm_aplic_request(void *opaque, int irq, int level)
> {
> kvm_set_irq(kvm_state, irq, !!level);
> }
> +#else
> +#define riscv_kvm_aplic_request ({ qemu_build_not_reached(); NULL; })
> +#endif
>
> static void riscv_aplic_request(void *opaque, int irq, int level)
> {
> diff --git a/hw/riscv/virt.c b/hw/riscv/virt.c
> index 388e52a294..b787ae38c2 100644
> --- a/hw/riscv/virt.c
> +++ b/hw/riscv/virt.c
> @@ -782,7 +782,7 @@ static void create_fdt_sockets(RISCVVirtState *s, const MemMapEntry *memmap,
> }
>
> /* KVM AIA only has one APLIC instance */
> - if (virt_use_kvm_aia(s)) {
> + if (kvm_enabled() && virt_use_kvm_aia(s)) {
> create_fdt_socket_aplic(s, memmap, 0,
> msi_m_phandle, msi_s_phandle, phandle,
> &intc_phandles[0], xplic_phandles,
> @@ -1461,7 +1461,7 @@ static void virt_machine_init(MachineState *machine)
> }
> }
>
> - if (virt_use_kvm_aia(s)) {
> + if (kvm_enabled() && virt_use_kvm_aia(s)) {
> kvm_riscv_aia_create(machine, IMSIC_MMIO_GROUP_MIN_SHIFT,
> VIRT_IRQCHIP_NUM_SOURCES, VIRT_IRQCHIP_NUM_MSIS,
> memmap[VIRT_APLIC_S].base,
>
I'll leave to Alistair to decide, both seems good to me.
TBH I'm bothered why this doesn't work:
diff --git a/hw/intc/riscv_aplic.c b/hw/intc/riscv_aplic.c
index 592c3ce768..251e08ddc4 100644
--- a/hw/intc/riscv_aplic.c
+++ b/hw/intc/riscv_aplic.c
@@ -839,12 +839,16 @@ static void riscv_aplic_realize(DeviceState *dev, Error **errp)
* Only root APLICs have hardware IRQ lines. All non-root APLICs
* have IRQ lines delegated by their parent APLIC.
*/
- if (!aplic->parent) {
- if (is_kvm_aia(aplic->msimode)) {
- qdev_init_gpio_in(dev, riscv_kvm_aplic_request, aplic->num_irqs);
- } else {
- qdev_init_gpio_in(dev, riscv_aplic_request, aplic->num_irqs);
+ if (kvm_enabled()) {
+ if (!aplic->parent) {
+ if (is_kvm_aia(aplic->msimode)) {
+ qdev_init_gpio_in(dev, riscv_kvm_aplic_request, aplic->num_irqs);
+ } else {
+ qdev_init_gpio_in(dev, riscv_aplic_request, aplic->num_irqs);
+ }
}
+ } else if (!aplic->parent) {
+ qdev_init_gpio_in(dev, riscv_aplic_request, aplic->num_irqs);
}
Why is the compiler refusing to crop an "if kvm_enabled()" block? There's no other
conditionals to handle, and it is able to crop "if (kvm_enabled() && virt_use_kvm_aia(s))".
Is this solely because riscv_kvm_aplic_request() will be an unused function if the crop
happens and, as you said above, "the compiler won't eliminate entire unused functions with
-O0"?
Thanks,
Daniel
next prev parent reply other threads:[~2023-08-30 9:35 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-08-29 12:21 [PATCH 0/2] riscv: fix --enable-debug in riscv-to-apply.next Daniel Henrique Barboza
2023-08-29 12:21 ` [PATCH 1/2] hw/intc/riscv_aplic.c fix non-KVM --enable-debug build Daniel Henrique Barboza
2023-08-29 14:17 ` Philippe Mathieu-Daudé
2023-08-29 22:35 ` Daniel Henrique Barboza
2023-08-29 12:21 ` [PATCH 2/2] hw/riscv/virt.c: " Daniel Henrique Barboza
2023-08-29 14:18 ` Philippe Mathieu-Daudé
2023-08-29 23:09 ` Daniel Henrique Barboza
2023-08-29 23:30 ` Richard Henderson
2023-08-29 23:51 ` Daniel Henrique Barboza
2023-08-30 1:26 ` Richard Henderson
2023-08-30 9:34 ` Daniel Henrique Barboza [this message]
2023-08-30 13:49 ` Richard Henderson
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=7a309a5c-c88e-4cfc-7811-5643a53def81@ventanamicro.com \
--to=dbarboza@ventanamicro.com \
--cc=alistair.francis@wdc.com \
--cc=bmeng@tinylab.org \
--cc=liweiwei@iscas.ac.cn \
--cc=palmer@rivosinc.com \
--cc=philmd@linaro.org \
--cc=qemu-devel@nongnu.org \
--cc=qemu-riscv@nongnu.org \
--cc=richard.henderson@linaro.org \
--cc=zhiwei_liu@linux.alibaba.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.