xen-devel.lists.xenproject.org archive mirror
 help / color / mirror / Atom feed
From: Bernhard Beschow <shentey@gmail.com>
To: "BALATON Zoltan" <balaton@eik.bme.hu>,
	"Philippe Mathieu-Daudé" <f4bug@amsat.org>
Cc: qemu-devel@nongnu.org, "Michael S. Tsirkin" <mst@redhat.com>,
	"Magnus Damm" <magnus.damm@gmail.com>,
	"Aleksandar Rikalo" <aleksandar.rikalo@syrmia.com>,
	"Bandan Das" <bsd@redhat.com>,
	"Matthew Rosato" <mjrosato@linux.ibm.com>,
	"Daniel Henrique Barboza" <danielhb413@gmail.com>,
	"Sergio Lopez" <slp@redhat.com>,
	"Alexey Kardashevskiy" <aik@ozlabs.ru>,
	"Xiaojuan Yang" <yangxiaojuan@loongson.cn>,
	"Cameron Esfahani" <dirty@apple.com>,
	"Michael Rolnik" <mrolnik@gmail.com>,
	"Song Gao" <gaosong@loongson.cn>,
	"Jagannathan Raman" <jag.raman@oracle.com>,
	"Greg Kurz" <groug@kaod.org>,
	"Kamil Rytarowski" <kamil@netbsd.org>,
	"Peter Xu" <peterx@redhat.com>, "Joel Stanley" <joel@jms.id.au>,
	"Alistair Francis" <Alistair.Francis@wdc.com>,
	"Dr. David Alan Gilbert" <dgilbert@redhat.com>,
	"Paolo Bonzini" <pbonzini@redhat.com>,
	haxm-team@intel.com, "Roman Bolshakov" <r.bolshakov@yadro.com>,
	"Markus Armbruster" <armbru@redhat.com>,
	"Eric Auger" <eric.auger@redhat.com>,
	"David Gibson" <david@gibson.dropbear.id.au>,
	"Daniel P. Berrangé" <berrange@redhat.com>,
	"Christian Borntraeger" <borntraeger@linux.ibm.com>,
	"Cédric Le Goater" <clg@kaod.org>,
	"Stefan Hajnoczi" <stefanha@redhat.com>,
	qemu-block@nongnu.org, "Eduardo Habkost" <eduardo@habkost.net>,
	"Hervé Poussineau" <hpoussin@reactos.org>,
	qemu-ppc@nongnu.org, "Cornelia Huck" <cohuck@redhat.com>,
	"Palmer Dabbelt" <palmer@dabbelt.com>,
	"Helge Deller" <deller@gmx.de>,
	"Stefano Stabellini" <sstabellini@kernel.org>,
	qemu-riscv@nongnu.org, "Stafford Horne" <shorne@gmail.com>,
	"Paul Durrant" <paul@xen.org>,
	"Havard Skinnemoen" <hskinnemoen@google.com>,
	"Elena Ufimtseva" <elena.ufimtseva@oracle.com>,
	"Alexander Graf" <agraf@csgraf.de>,
	"Thomas Huth" <thuth@redhat.com>,
	"Alex Williamson" <alex.williamson@redhat.com>,
	"Wenchao Wang" <wenchao.wang@intel.com>,
	"Tony Krowiak" <akrowiak@linux.ibm.com>,
	"Marcel Apfelbaum" <marcel.apfelbaum@gmail.com>,
	qemu-s390x@nongnu.org,
	"Marc-André Lureau" <marcandre.lureau@redhat.com>,
	"Mark Cave-Ayland" <mark.cave-ayland@ilande.co.uk>,
	"Eric Farman" <farman@linux.ibm.com>,
	"Reinoud Zandijk" <reinoud@netbsd.org>,
	"Alexander Bulekov" <alxndr@bu.edu>,
	"Yanan Wang" <wangyanan55@huawei.com>,
	"Edgar E. Iglesias" <edgar.iglesias@gmail.com>,
	"Gerd Hoffmann" <kraxel@redhat.com>,
	"Tyrone Ting" <kfting@nuvoton.com>,
	xen-devel@lists.xenproject.org,
	"Yoshinori Sato" <ysato@users.sourceforge.jp>,
	"John Snow" <jsnow@redhat.com>,
	"Richard Henderson" <richard.henderson@linaro.org>,
	"Darren Kenny" <darren.kenny@oracle.com>,
	kvm@vger.kernel.org, "Qiuhao Li" <Qiuhao.Li@outlook.com>,
	"John G Johnson" <john.g.johnson@oracle.com>,
	"Bin Meng" <bin.meng@windriver.com>,
	"Sunil Muthuswamy" <sunilmut@microsoft.com>,
	"Max Filippov" <jcmvbkbc@gmail.com>,
	qemu-arm@nongnu.org, "Marcelo Tosatti" <mtosatti@redhat.com>,
	"Peter Maydell" <peter.maydell@linaro.org>,
	"Anthony Perard" <anthony.perard@citrix.com>,
	"Andrew Jeffery" <andrew@aj.id.au>,
	"Artyom Tarasenko" <atar4qemu@gmail.com>,
	"Halil Pasic" <pasic@linux.ibm.com>,
	"Maciej S. Szmigiero" <maciej.szmigiero@oracle.com>,
	"Jason Wang" <jasowang@redhat.com>,
	"David Hildenbrand" <david@redhat.com>,
	"Laurent Vivier" <laurent@vivier.eu>,
	"Alistair Francis" <alistair@alistair23.me>,
	"Jason Herne" <jjherne@linux.ibm.com>
Subject: Re: [PATCH 8/9] softmmu/physmem: Let SysBusState absorb memory region and address space singletons
Date: Tue, 20 Sep 2022 23:13:04 +0000	[thread overview]
Message-ID: <D64FE5B4-84EF-4E6A-8400-E9501FA8C0E9@gmail.com> (raw)
In-Reply-To: <fcb592e-a346-2ae-47e9-8af4b9f5ba3@eik.bme.hu>

Am 20. September 2022 08:50:01 UTC schrieb BALATON Zoltan <balaton@eik.bme.hu>:
>
>
>On Tue, 20 Sep 2022, Philippe Mathieu-Daudé via wrote:
>
>> On 20/9/22 01:17, Bernhard Beschow wrote:
>>> These singletons are actually properties of the system bus but so far it
>>> hasn't been modelled that way. Fix this to make this relationship very
>>> obvious.
>>> 
>>> The idea of the patch is to restrain futher proliferation of the use of
>>> get_system_memory() and get_system_io() which are "temprary interfaces"
>> 
>> "further", "temporary"
>> 
>>> "until a proper bus interface is available". This should now be the
>>> case.
>>> 
>>> Note that the new attributes are values rather than a pointers. This
>>> trades pointer dereferences for pointer arithmetic. The idea is to
>>> reduce cache misses - a rule of thumb says that every pointer
>>> dereference causes a cache miss while arithmetic is basically free.
>>> 
>>> Signed-off-by: Bernhard Beschow <shentey@gmail.com>
>>> ---
>>>   include/exec/address-spaces.h | 19 ++++++++++++---
>>>   include/hw/sysbus.h           |  6 +++++
>>>   softmmu/physmem.c             | 46 ++++++++++++++++++-----------------
>>>   3 files changed, 45 insertions(+), 26 deletions(-)
>>> 
>>> diff --git a/include/exec/address-spaces.h b/include/exec/address-spaces.h
>>> index d5c8cbd718..b31bd8dcf0 100644
>>> --- a/include/exec/address-spaces.h
>>> +++ b/include/exec/address-spaces.h
>>> @@ -23,17 +23,28 @@
>>>     #ifndef CONFIG_USER_ONLY
>>>   -/* Get the root memory region.  This interface should only be used temporarily
>>> - * until a proper bus interface is available.
>>> +/**
>>> + * Get the root memory region.  This is a legacy function, provided for
>>> + * compatibility. Prefer using SysBusState::system_memory directly.
>>>    */
>>>   MemoryRegion *get_system_memory(void);
>> 
>>> diff --git a/include/hw/sysbus.h b/include/hw/sysbus.h
>>> index 5bb3b88501..516e9091dc 100644
>>> --- a/include/hw/sysbus.h
>>> +++ b/include/hw/sysbus.h
>>> @@ -17,6 +17,12 @@ struct SysBusState {
>>>       /*< private >*/
>>>       BusState parent_obj;
>>>       /*< public >*/
>>> +
>>> +    MemoryRegion system_memory;
>>> +    MemoryRegion system_io;
>>> +
>>> +    AddressSpace address_space_io;
>>> +    AddressSpace address_space_memory;
>> 
>> Alternatively (renaming doc accordingly):
>> 
>>       struct {
>>           MemoryRegion mr;
>>           AddressSpace as;
>>       } io, memory;
>
>Do we really need that? Isn't mr just the same as as.root so it would be enough to store as only? Or is caching mr and not going through as to get it saves time in accessing these?

as.root is just a pointer. That's why we need mr as a value as well.

> Now we'll go through SysBusState anyway instead of accessing globals so is there a performance impact?

Good question. Since both attributes are now next to each another I'd hope for an improvement ;-) That depends on on many things of course, such as if they are located in the same cache line. As written in the commit messages I tried to minimize pointer dereferences.

Best regards,
Bernhard
>
>Regards,
>BALATON Zoltan
>
>>>   };
>>>     #define TYPE_SYS_BUS_DEVICE "sys-bus-device"
>>> diff --git a/softmmu/physmem.c b/softmmu/physmem.c
>>> index 0ac920d446..07e9a9171c 100644
>>> --- a/softmmu/physmem.c
>>> +++ b/softmmu/physmem.c
>>> @@ -86,12 +86,6 @@
>>>    */
>>>   RAMList ram_list = { .blocks = QLIST_HEAD_INITIALIZER(ram_list.blocks) };
>>>   -static MemoryRegion *system_memory;
>>> -static MemoryRegion *system_io;
>>> -
>>> -static AddressSpace address_space_io;
>>> -static AddressSpace address_space_memory;
>>> -
>>>   static MemoryRegion io_mem_unassigned;
>>>     typedef struct PhysPageEntry PhysPageEntry;
>>> @@ -146,7 +140,7 @@ typedef struct subpage_t {
>>>   #define PHYS_SECTION_UNASSIGNED 0
>>>     static void io_mem_init(void);
>>> -static void memory_map_init(void);
>>> +static void memory_map_init(SysBusState *sysbus);
>>>   static void tcg_log_global_after_sync(MemoryListener *listener);
>>>   static void tcg_commit(MemoryListener *listener);
>>>   @@ -2667,37 +2661,45 @@ static void tcg_commit(MemoryListener *listener)
>>>       tlb_flush(cpuas->cpu);
>>>   }
>>>   -static void memory_map_init(void)
>>> +static void memory_map_init(SysBusState *sysbus)
>>>   {
>> 
>> No need to pass a singleton by argument.
>> 
>>       assert(current_machine);
>> 
>> You can use get_system_memory() and get_system_io() in place :)
>> 
>> LGTM otherwise, great!
>> 
>>> -    system_memory = g_malloc(sizeof(*system_memory));
>>> +    MemoryRegion *system_memory = &sysbus->system_memory;
>>> +    MemoryRegion *system_io = &sysbus->system_io;
>>>         memory_region_init(system_memory, NULL, "system", UINT64_MAX);
>>> -    address_space_init(&address_space_memory, system_memory, "memory");
>>> +    address_space_init(&sysbus->address_space_memory, system_memory, "memory");
>>>   -    system_io = g_malloc(sizeof(*system_io));
>>>       memory_region_init_io(system_io, NULL, &unassigned_io_ops, NULL, "io",
>>>                             65536);
>>> -    address_space_init(&address_space_io, system_io, "I/O");
>>> +    address_space_init(&sysbus->address_space_io, system_io, "I/O");
>>>   }
>>>     MemoryRegion *get_system_memory(void)
>>>   {
>>> -    return system_memory;
>>> +    assert(current_machine);
>>> +
>>> +    return &current_machine->main_system_bus.system_memory;
>>>   }
>>>     MemoryRegion *get_system_io(void)
>>>   {
>>> -    return system_io;
>>> +    assert(current_machine);
>>> +
>>> +    return &current_machine->main_system_bus.system_io;
>>>   }
>>>     AddressSpace *get_address_space_memory(void)
>>>   {
>>> -    return &address_space_memory;
>>> +    assert(current_machine);
>>> +
>>> +    return &current_machine->main_system_bus.address_space_memory;
>>>   }
>>>     AddressSpace *get_address_space_io(void)
>>>   {
>>> -    return &address_space_io;
>>> +    assert(current_machine);
>>> +
>>> +    return &current_machine->main_system_bus.address_space_io;
>>>   }
>> 
>> 
>> 


  reply	other threads:[~2022-09-20 23:13 UTC|newest]

Thread overview: 34+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-09-19 23:17 [PATCH 0/9] Deprecate sysbus_get_default() and get_system_memory() et. al Bernhard Beschow
2022-09-19 23:17 ` [PATCH 1/9] hw/riscv/sifive_e: Fix inheritance of SiFiveEState Bernhard Beschow
2022-09-19 23:31   ` Alistair Francis
2022-09-20 11:36     ` Markus Armbruster
2022-09-20 23:23       ` Bernhard Beschow
2022-09-21  4:55         ` Markus Armbruster
2022-09-22  7:55           ` B
2022-09-20  4:47   ` Philippe Mathieu-Daudé
2022-09-19 23:17 ` [PATCH 2/9] exec/hwaddr.h: Add missing include Bernhard Beschow
2022-09-20  4:50   ` Philippe Mathieu-Daudé
2022-09-20 23:03     ` Bernhard Beschow
2022-09-19 23:17 ` [PATCH 3/9] hw/core/sysbus: Resolve main_system_bus singleton Bernhard Beschow
2022-09-20  4:52   ` Philippe Mathieu-Daudé
2022-09-19 23:17 ` [PATCH 4/9] hw/ppc/spapr: Fix code style problems reported by checkpatch Bernhard Beschow
2022-09-20 14:00   ` Daniel Henrique Barboza
2022-09-19 23:17 ` [PATCH 5/9] exec/address-spaces: Wrap address space singletons into functions Bernhard Beschow
2022-09-20  5:36   ` Philippe Mathieu-Daudé
2022-09-19 23:17 ` [PATCH 6/9] target/loongarch/cpu: Remove unneeded include directive Bernhard Beschow
2022-09-20  4:57   ` Philippe Mathieu-Daudé
2022-09-19 23:17 ` [PATCH 7/9] hw/sysbus: Introduce dedicated struct SysBusState for TYPE_SYSTEM_BUS Bernhard Beschow
2022-09-19 23:17 ` [PATCH 8/9] softmmu/physmem: Let SysBusState absorb memory region and address space singletons Bernhard Beschow
2022-09-20  5:11   ` Philippe Mathieu-Daudé
2022-09-20  8:50     ` BALATON Zoltan
2022-09-20 23:13       ` Bernhard Beschow [this message]
2022-09-19 23:17 ` [PATCH 9/9] exec/address-spaces: Inline legacy functions Bernhard Beschow
2022-09-20  5:15   ` Philippe Mathieu-Daudé
2022-09-20  5:29     ` Philippe Mathieu-Daudé
2022-09-20  9:02     ` BALATON Zoltan
2022-09-20 23:20       ` Bernhard Beschow
2022-09-20  9:55 ` [PATCH 0/9] Deprecate sysbus_get_default() and get_system_memory() et. al Peter Maydell
2022-09-20 15:36   ` Mark Cave-Ayland
2022-09-20 22:59     ` Bernhard Beschow
2022-09-20 22:50   ` Bernhard Beschow
2022-09-21  9:47     ` Peter Maydell

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=D64FE5B4-84EF-4E6A-8400-E9501FA8C0E9@gmail.com \
    --to=shentey@gmail.com \
    --cc=Alistair.Francis@wdc.com \
    --cc=Qiuhao.Li@outlook.com \
    --cc=agraf@csgraf.de \
    --cc=aik@ozlabs.ru \
    --cc=akrowiak@linux.ibm.com \
    --cc=aleksandar.rikalo@syrmia.com \
    --cc=alex.williamson@redhat.com \
    --cc=alistair@alistair23.me \
    --cc=alxndr@bu.edu \
    --cc=andrew@aj.id.au \
    --cc=anthony.perard@citrix.com \
    --cc=armbru@redhat.com \
    --cc=atar4qemu@gmail.com \
    --cc=balaton@eik.bme.hu \
    --cc=berrange@redhat.com \
    --cc=bin.meng@windriver.com \
    --cc=borntraeger@linux.ibm.com \
    --cc=bsd@redhat.com \
    --cc=clg@kaod.org \
    --cc=cohuck@redhat.com \
    --cc=danielhb413@gmail.com \
    --cc=darren.kenny@oracle.com \
    --cc=david@gibson.dropbear.id.au \
    --cc=david@redhat.com \
    --cc=deller@gmx.de \
    --cc=dgilbert@redhat.com \
    --cc=dirty@apple.com \
    --cc=edgar.iglesias@gmail.com \
    --cc=eduardo@habkost.net \
    --cc=elena.ufimtseva@oracle.com \
    --cc=eric.auger@redhat.com \
    --cc=f4bug@amsat.org \
    --cc=farman@linux.ibm.com \
    --cc=gaosong@loongson.cn \
    --cc=groug@kaod.org \
    --cc=haxm-team@intel.com \
    --cc=hpoussin@reactos.org \
    --cc=hskinnemoen@google.com \
    --cc=jag.raman@oracle.com \
    --cc=jasowang@redhat.com \
    --cc=jcmvbkbc@gmail.com \
    --cc=jjherne@linux.ibm.com \
    --cc=joel@jms.id.au \
    --cc=john.g.johnson@oracle.com \
    --cc=jsnow@redhat.com \
    --cc=kamil@netbsd.org \
    --cc=kfting@nuvoton.com \
    --cc=kraxel@redhat.com \
    --cc=kvm@vger.kernel.org \
    --cc=laurent@vivier.eu \
    --cc=maciej.szmigiero@oracle.com \
    --cc=magnus.damm@gmail.com \
    --cc=marcandre.lureau@redhat.com \
    --cc=marcel.apfelbaum@gmail.com \
    --cc=mark.cave-ayland@ilande.co.uk \
    --cc=mjrosato@linux.ibm.com \
    --cc=mrolnik@gmail.com \
    --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=peterx@redhat.com \
    --cc=qemu-arm@nongnu.org \
    --cc=qemu-block@nongnu.org \
    --cc=qemu-devel@nongnu.org \
    --cc=qemu-ppc@nongnu.org \
    --cc=qemu-riscv@nongnu.org \
    --cc=qemu-s390x@nongnu.org \
    --cc=r.bolshakov@yadro.com \
    --cc=reinoud@netbsd.org \
    --cc=richard.henderson@linaro.org \
    --cc=shorne@gmail.com \
    --cc=slp@redhat.com \
    --cc=sstabellini@kernel.org \
    --cc=stefanha@redhat.com \
    --cc=sunilmut@microsoft.com \
    --cc=thuth@redhat.com \
    --cc=wangyanan55@huawei.com \
    --cc=wenchao.wang@intel.com \
    --cc=xen-devel@lists.xenproject.org \
    --cc=yangxiaojuan@loongson.cn \
    --cc=ysato@users.sourceforge.jp \
    /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).