qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: David Woodhouse <dwmw2@infradead.org>
To: "Philippe Mathieu-Daudé" <philmd@linaro.org>, qemu-devel@nongnu.org
Cc: "Thomas Huth" <thuth@redhat.com>,
	"Richard Henderson" <richard.henderson@linaro.org>,
	"Paolo Bonzini" <pbonzini@redhat.com>,
	"Alistair Francis" <alistair.francis@wdc.com>,
	qemu-arm@nongnu.org, qemu-riscv@nongnu.org,
	"Edgar E. Iglesias" <edgar.iglesias@gmail.com>,
	qemu-ppc@nongnu.org, "Eduardo Habkost" <eduardo@habkost.net>,
	"Michael S. Tsirkin" <mst@redhat.com>,
	qemu-s390x@nongnu.org, "Peter Maydell" <peter.maydell@linaro.org>,
	"Alex Bennée" <alex.bennee@linaro.org>,
	"Zhao Liu" <zhao1.liu@intel.com>,
	"Andrey Smirnov" <andrew.smirnov@gmail.com>,
	"Radoslaw Biernacki" <rad@semihalf.com>,
	"Leif Lindholm" <quic_llindhol@quicinc.com>,
	"Marcin Juszkiewicz" <marcin.juszkiewicz@linaro.org>,
	"Shannon Zhao" <shannon.zhaosl@gmail.com>,
	"Igor Mammedov" <imammedo@redhat.com>,
	"Ani Sinha" <anisinha@redhat.com>,
	"Alistair Francis" <alistair@alistair23.me>,
	"Paul Durrant" <paul@xen.org>,
	"Marcel Apfelbaum" <marcel.apfelbaum@gmail.com>,
	"Palmer Dabbelt" <palmer@dabbelt.com>,
	"Bin Meng" <bin.meng@windriver.com>,
	"Weiwei Li" <liweiwei@iscas.ac.cn>,
	"Daniel Henrique Barboza" <dbarboza@ventanamicro.com>,
	"Liu Zhiwei" <zhiwei_liu@linux.alibaba.com>,
	"Song Gao" <gaosong@loongson.cn>,
	"Thomas Huth" <huth@tuxfamily.org>,
	"Christian Borntraeger" <borntraeger@linux.ibm.com>,
	"Halil Pasic" <pasic@linux.ibm.com>,
	"Eric Farman" <farman@linux.ibm.com>,
	"David Hildenbrand" <david@redhat.com>,
	"Ilya Leoshkevich" <iii@linux.ibm.com>,
	"Yanan Wang" <wangyanan55@huawei.com>,
	"Dr. David Alan Gilbert" <dave@treblig.org>,
	"Marcelo Tosatti" <mtosatti@redhat.com>,
	"Aurelien Jarno" <aurelien@aurel32.net>,
	"Jiaxun Yang" <jiaxun.yang@flygoat.com>,
	"Aleksandar Rikalo" <aleksandar.rikalo@syrmia.com>,
	kvm@vger.kernel.org
Subject: Re: [RFC PATCH 01/19] cpus: Add argument to qemu_get_cpu() to filter CPUs by QOM type
Date: Mon, 23 Oct 2023 16:12:52 +0100	[thread overview]
Message-ID: <c6e43893a5c8661aced1685fb97adf63ab224689.camel@infradead.org> (raw)
In-Reply-To: <20231020163643.86105-2-philmd@linaro.org>

[-- Attachment #1: Type: text/plain, Size: 2682 bytes --]

On Fri, 2023-10-20 at 18:36 +0200, Philippe Mathieu-Daudé wrote:
> Heterogeneous machines have different type of CPU.
> qemu_get_cpu() returning unfiltered CPUs doesn't make
> sense anymore. Add a 'type' argument to filter CPU by
> QOM type.
> 
> Type in "hw/core/cpu.h" and implementation in cpu-common.c
> modified manually, then convert all call sites by passing
> a NULL argument using the following coccinelle script:
> 
>   @@
>   expression index;
>   @@
>   -   qemu_get_cpu(index)
>   +   qemu_get_cpu(index, NULL)
> 
> Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
> ---
> RFC: Is this hot path code? What is the cost of this QOM cast check?

A bunch of them in the Xen emulation code are during interrupt
delivery. So yes, kind of hot path :)

In hw/i386/kvm/xen_evtchn.c I they're almost all just looking up a CPU
with qemu_get_cpu() so that they can call kvm_arch_vcpu_id() to get its
APIC ID. Mostly to send an MSI there or otherwise talk to the kernel
about it.

Perhaps it could keep a simple array of { vCPU ID, APIC ID } instead.

There's one case in valid_vcpu() where it's checking that a given vCPU
does exist, which could use that same array.

In target/i386/kvm/xen-emu.c there are some slow paths which are less
interesting (xen_set_shared_info(), kvm_xen_has_vcpu_callback_vector(),
kvm_xen_set_vcpu_virq(), kvm_xen_hcall_evtchn_upcall_vector()

kvm_xen_hcall_vcpu_op() does have a fast path (the singleshot timer
handling, although most guests seem to use a different hypercall for
that). But it doesn't actually call qemu_get_cpu() for that fast path
anyway, since it'll use the CPU it was *called* on.

kvm_xen_get_vcpu_info_hva() wants a pointer stored in cpu->env, and is
called in *one* fast path in xen_evtchn.c, again interrupt delivery (in
set_port_pending). But only in the case where we're running on an old
kernel and don't just ask the kernel to deliver the event. So I can
live with not optimising that.

kvm_xen_set_callback_asserted() is only for the case where event
channels are being delivered to the guest via emulated GSI, so not the
high-performance case. And I still do want to hook that up properly to
the ack on the *interrupt controllers* anyway (qv¹).

Finally, kvm_xen_injecft_vcpu_callback_vector() is also only for older
kernels where we don't ask the kernel to deliver the event. 

tl;dr: we don't care about anything in xen.emu.c. So I think we could
live with just a fast lookup from vCPU# → APIC ID for the cases in
xen_evtchn.c.



¹ https://lore.kernel.org/all/70eb35a08a7c48993812b7f088fa9ae3f2c8b925.camel@infradead.org/T/




[-- Attachment #2: smime.p7s --]
[-- Type: application/pkcs7-signature, Size: 5965 bytes --]

  parent reply	other threads:[~2023-10-23 15:14 UTC|newest]

Thread overview: 27+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-10-20 16:36 [PATCH 00/19] cpus: Step toward removing global 'first_cpu' Philippe Mathieu-Daudé
2023-10-20 16:36 ` [RFC PATCH 01/19] cpus: Add argument to qemu_get_cpu() to filter CPUs by QOM type Philippe Mathieu-Daudé
2023-10-20 17:14   ` Peter Maydell
2023-10-20 17:29     ` Philippe Mathieu-Daudé
2023-10-20 17:40       ` Peter Maydell
2023-10-23 14:21   ` Zhao Liu
2023-10-23 15:12   ` David Woodhouse [this message]
2023-10-20 16:36 ` [PATCH 02/19] cpus: Filter for target specific CPU (generic) Philippe Mathieu-Daudé
2023-10-20 16:36 ` [PATCH 03/19] cpus: Filter for target specific CPU (arm) Philippe Mathieu-Daudé
2023-10-20 16:36 ` [PATCH 04/19] cpus: Filter for target specific CPU (loongarch) Philippe Mathieu-Daudé
2023-10-20 16:36 ` [PATCH 05/19] cpus: Filter for target specific CPU (mips) Philippe Mathieu-Daudé
2023-10-20 16:36 ` [PATCH 06/19] cpus: Filter for target specific CPU (s390x) Philippe Mathieu-Daudé
2023-10-20 16:36 ` [PATCH 07/19] cpus: Filter for target specific CPU (riscv) Philippe Mathieu-Daudé
2023-10-20 16:36 ` [PATCH 08/19] cpus: Filter for target specific CPU (ppc) Philippe Mathieu-Daudé
2023-10-20 16:36 ` [PATCH 09/19] cpus: Filter for target specific CPU (x86) Philippe Mathieu-Daudé
2023-10-20 16:36 ` [PATCH 10/19] cpus: Replace first_cpu by qemu_get_cpu(0, TYPE_ARM_CPU) Philippe Mathieu-Daudé
2023-10-20 16:53   ` Cédric Le Goater
2023-10-20 16:36 ` [PATCH 11/19] cpus: Replace first_cpu by qemu_get_cpu(0, TYPE_POWERPC_CPU) Philippe Mathieu-Daudé
2023-10-20 16:36 ` [PATCH 12/19] cpus: Replace first_cpu by qemu_get_cpu(0, TYPE_MIPS_CPU) Philippe Mathieu-Daudé
2023-10-20 16:36 ` [PATCH 13/19] cpus: Replace first_cpu by qemu_get_cpu(0, TYPE_M68K_CPU) Philippe Mathieu-Daudé
2023-10-20 16:36 ` [PATCH 14/19] cpus: Replace first_cpu by qemu_get_cpu(0, TYPE_S390X_CPU) Philippe Mathieu-Daudé
2023-10-20 16:36 ` [PATCH 15/19] cpus: Replace first_cpu by qemu_get_cpu(0, TYPE_RISCV_CPU) Philippe Mathieu-Daudé
2023-10-20 16:36 ` [PATCH 16/19] cpus: Replace first_cpu by qemu_get_cpu(0, TYPE_TRICORE_CPU) Philippe Mathieu-Daudé
2023-10-20 16:36 ` [PATCH 17/19] cpus: Replace first_cpu by qemu_get_cpu(0, TYPE_SUPERH_CPU) Philippe Mathieu-Daudé
2023-10-20 16:36 ` [PATCH 18/19] cpus: Replace first_cpu by qemu_get_cpu(0, TYPE_RX_CPU) Philippe Mathieu-Daudé
2023-10-20 16:36 ` [PATCH 19/19] cpus: Replace first_cpu by qemu_get_cpu(0, TYPE_X86_CPU) Philippe Mathieu-Daudé
2023-10-23 13:59 ` [PATCH 00/19] cpus: Step toward removing global 'first_cpu' Zhao Liu

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=c6e43893a5c8661aced1685fb97adf63ab224689.camel@infradead.org \
    --to=dwmw2@infradead.org \
    --cc=aleksandar.rikalo@syrmia.com \
    --cc=alex.bennee@linaro.org \
    --cc=alistair.francis@wdc.com \
    --cc=alistair@alistair23.me \
    --cc=andrew.smirnov@gmail.com \
    --cc=anisinha@redhat.com \
    --cc=aurelien@aurel32.net \
    --cc=bin.meng@windriver.com \
    --cc=borntraeger@linux.ibm.com \
    --cc=dave@treblig.org \
    --cc=david@redhat.com \
    --cc=dbarboza@ventanamicro.com \
    --cc=edgar.iglesias@gmail.com \
    --cc=eduardo@habkost.net \
    --cc=farman@linux.ibm.com \
    --cc=gaosong@loongson.cn \
    --cc=huth@tuxfamily.org \
    --cc=iii@linux.ibm.com \
    --cc=imammedo@redhat.com \
    --cc=jiaxun.yang@flygoat.com \
    --cc=kvm@vger.kernel.org \
    --cc=liweiwei@iscas.ac.cn \
    --cc=marcel.apfelbaum@gmail.com \
    --cc=marcin.juszkiewicz@linaro.org \
    --cc=mst@redhat.com \
    --cc=mtosatti@redhat.com \
    --cc=palmer@dabbelt.com \
    --cc=pasic@linux.ibm.com \
    --cc=paul@xen.org \
    --cc=pbonzini@redhat.com \
    --cc=peter.maydell@linaro.org \
    --cc=philmd@linaro.org \
    --cc=qemu-arm@nongnu.org \
    --cc=qemu-devel@nongnu.org \
    --cc=qemu-ppc@nongnu.org \
    --cc=qemu-riscv@nongnu.org \
    --cc=qemu-s390x@nongnu.org \
    --cc=quic_llindhol@quicinc.com \
    --cc=rad@semihalf.com \
    --cc=richard.henderson@linaro.org \
    --cc=shannon.zhaosl@gmail.com \
    --cc=thuth@redhat.com \
    --cc=wangyanan55@huawei.com \
    --cc=zhao1.liu@intel.com \
    --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 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).