[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [RFC PATCH v1 07/11] memory.c: Add address_space_init_share
From: |
Peter Crosthwaite |
Subject: |
[Qemu-devel] [RFC PATCH v1 07/11] memory.c: Add address_space_init_shareable() |
Date: |
Mon, 2 Jun 2014 19:10:25 -0700 |
This will either create a new AS or return a pointer to an
already existing equivalent one. Both name and root mr must
match.
The motivation is to reuse address spaces as much as possible.
Its going to be quite common that bus masters out in device land
have pointers to the same memory region for their mastering yet
each will need to create its own address space. Let the memory
API implement sharing for them.
Signed-off-by: Peter Crosthwaite <address@hidden>
---
I know this leaks memory. I'll fix that post RFC. I think we need
AS ref counters to do it properly if anyone has any input on how
that should be done.
We could change the equivalency test only match mr to support device
specific naming of these shared ASes. The singleton AS can ultimately
only have one name however. So perhaps some strcatting each time a new
sharer is added to the share. That or first-in-best-dressed.
include/exec/memory.h | 2 ++
memory.c | 24 ++++++++++++++++++++++++
2 files changed, 26 insertions(+)
diff --git a/include/exec/memory.h b/include/exec/memory.h
index 117c0d3..ae902b3 100644
--- a/include/exec/memory.h
+++ b/include/exec/memory.h
@@ -945,6 +945,8 @@ void mtree_info(fprintf_function mon_printf, void *f);
*/
void address_space_init(AddressSpace *as, MemoryRegion *root, const char
*name);
+AddressSpace *address_space_init_shareable(MemoryRegion *root,
+ const char *name);
/**
* address_space_destroy: destroy an address space
diff --git a/memory.c b/memory.c
index 6f5e0e5..33dde7b 100644
--- a/memory.c
+++ b/memory.c
@@ -1953,6 +1953,30 @@ void address_space_init(AddressSpace *as, MemoryRegion
*root, const char *name)
memory_region_transaction_commit();
}
+AddressSpace *address_space_init_shareable(MemoryRegion *root, const char
*name)
+{
+ AddressSpace *as;
+
+ if (!root) {
+ return NULL;
+ }
+
+ QTAILQ_FOREACH(as, &address_spaces, address_spaces_link) {
+ if (root == as->root && !strcmp(name ? name : "anonymous", as->name)) {
+ return as;
+ }
+ }
+
+ /* FIMXE: this leaks */
+ as = g_malloc0(sizeof *as);
+ address_space_init(as, root, name);
+ return as;
+}
+
+/* FIXME: patch this to be a ref decrementer, and when the AS runs out of
+ * refs do garbage collection
+ */
+
void address_space_destroy(AddressSpace *as)
{
/* Flush out anything from MemoryListeners listening in on this */
--
2.0.0
- [Qemu-devel] [RFC PATCH v1 00/11] Per Master Addressing (PMA), Peter Crosthwaite, 2014/06/02
- [Qemu-devel] [RFC PATCH v1 01/11] microblaze: ml605: Get rid of useless ddr_base variable, Peter Crosthwaite, 2014/06/02
- [Qemu-devel] [RFC PATCH v1 02/11] dma: axidma: Variablise repeated s->streams[i] sub-expr, Peter Crosthwaite, 2014/06/02
- [Qemu-devel] [RFC PATCH v1 03/11] exec: Parent root MRs to the machine, Peter Crosthwaite, 2014/06/02
- [Qemu-devel] [RFC PATCH v1 04/11] exec: dummy_section: Pass address space through., Peter Crosthwaite, 2014/06/02
- [Qemu-devel] [RFC PATCH v1 05/11] memory: Parent Memory Regions to their registered owners, Peter Crosthwaite, 2014/06/02
- [Qemu-devel] [RFC PATCH v1 06/11] memory: address_space_init: do nothing if no root region given, Peter Crosthwaite, 2014/06/02
- [Qemu-devel] [RFC PATCH v1 07/11] memory.c: Add address_space_init_shareable(),
Peter Crosthwaite <=
- [Qemu-devel] [RFC PATCH v1 08/11] qom/cpu: Add Memory Region Property, Peter Crosthwaite, 2014/06/02
- [Qemu-devel] [RFC PATCH v1 09/11] exec: use per-cpu address-spaces for cpuisms, Peter Crosthwaite, 2014/06/02
- [Qemu-devel] [RFC PATCH v1 10/11] microblaze: ml605: Convert to PMA, Peter Crosthwaite, 2014/06/02
- [Qemu-devel] [RFC PATCH v1 11/11] dma: axidma: Convert to PMA, Peter Crosthwaite, 2014/06/02
- Re: [Qemu-devel] [RFC PATCH v1 00/11] Per Master Addressing (PMA), Paolo Bonzini, 2014/06/03
- Re: [Qemu-devel] [RFC PATCH v1 00/11] Per Master Addressing (PMA), Peter Maydell, 2014/06/03