qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Gleb Natapov <gleb@redhat.com>
To: Avi Kivity <avi@redhat.com>
Cc: "Michael S. Tsirkin" <mst@redhat.com>,
	qemu-devel@nongnu.org, liu ping fan <qemulist@gmail.com>,
	Blue Swirl <blauwirbel@gmail.com>,
	Anthony Liguori <anthony@codemonkey.ws>,
	Paolo Bonzini <pbonzini@redhat.com>
Subject: Re: [Qemu-devel] [RFC v1 07/22] memory: maintain a list of address spaces
Date: Thu, 4 Oct 2012 12:17:11 +0200	[thread overview]
Message-ID: <20121004101711.GZ23096@redhat.com> (raw)
In-Reply-To: <1349280245-16341-8-git-send-email-avi@redhat.com>

On Wed, Oct 03, 2012 at 06:03:50PM +0200, Avi Kivity wrote:
> Instead of embedding knowledge of the memory and I/O address spaces in the
> memory core, maintain a list of all address spaces.  This list will later
> be extended dynamically for other but masters.
------------------------------------^ bus?

> 
> Signed-off-by: Avi Kivity <avi@redhat.com>
> ---
>  memory.c | 75 +++++++++++++++++++++++++++++++++++++++-------------------------
>  memory.h |  2 ++
>  2 files changed, 48 insertions(+), 29 deletions(-)
> 
> diff --git a/memory.c b/memory.c
> index 431a867..b58b97c 100644
> --- a/memory.c
> +++ b/memory.c
> @@ -28,6 +28,9 @@
>  static QTAILQ_HEAD(memory_listeners, MemoryListener) memory_listeners
>      = QTAILQ_HEAD_INITIALIZER(memory_listeners);
>  
> +static QTAILQ_HEAD(, AddressSpace) address_spaces
> +    = QTAILQ_HEAD_INITIALIZER(address_spaces);
> +
>  typedef struct AddrRange AddrRange;
>  
>  /*
> @@ -449,14 +452,15 @@ static void memory_region_iorange_destructor(IORange *iorange)
>  
>  static AddressSpace *memory_region_to_address_space(MemoryRegion *mr)
>  {
> +    AddressSpace *as;
> +
>      while (mr->parent) {
>          mr = mr->parent;
>      }
> -    if (mr == address_space_memory.root) {
> -        return &address_space_memory;
> -    }
> -    if (mr == address_space_io.root) {
> -        return &address_space_io;
> +    QTAILQ_FOREACH(as, &address_spaces, address_spaces_link) {
> +        if (mr == as->root) {
> +            return as;
> +        }
>      }
>      abort();
>  }
> @@ -729,16 +733,15 @@ void memory_region_transaction_begin(void)
>  
>  void memory_region_transaction_commit(void)
>  {
> +    AddressSpace *as;
> +
>      assert(memory_region_transaction_depth);
>      --memory_region_transaction_depth;
>      if (!memory_region_transaction_depth) {
>          MEMORY_LISTENER_CALL_GLOBAL(begin, Forward);
>  
> -        if (address_space_memory.root) {
> -            address_space_update_topology(&address_space_memory);
> -        }
> -        if (address_space_io.root) {
> -            address_space_update_topology(&address_space_io);
> +        QTAILQ_FOREACH(as, &address_spaces, address_spaces_link) {
> +            address_space_update_topology(as);
>          }
>  
>          MEMORY_LISTENER_CALL_GLOBAL(commit, Forward);
> @@ -1072,12 +1075,14 @@ void memory_region_set_dirty(MemoryRegion *mr, target_phys_addr_t addr,
>  
>  void memory_region_sync_dirty_bitmap(MemoryRegion *mr)
>  {
> +    AddressSpace *as;
>      FlatRange *fr;
>  
> -    FOR_EACH_FLAT_RANGE(fr, address_space_memory.current_map) {
> -        if (fr->mr == mr) {
> -            MEMORY_LISTENER_UPDATE_REGION(fr, &address_space_memory,
> -                                          Forward, log_sync);
> +    QTAILQ_FOREACH(as, &address_spaces, address_spaces_link) {
> +        FOR_EACH_FLAT_RANGE(fr, as->current_map) {
> +            if (fr->mr == mr) {
> +                MEMORY_LISTENER_UPDATE_REGION(fr, as, Forward, log_sync);
> +            }
>          }
>      }
>  }
> @@ -1120,13 +1125,13 @@ void *memory_region_get_ram_ptr(MemoryRegion *mr)
>      return qemu_get_ram_ptr(mr->ram_addr & TARGET_PAGE_MASK);
>  }
>  
> -static void memory_region_update_coalesced_range(MemoryRegion *mr)
> +static void memory_region_update_coalesced_range_as(MemoryRegion *mr, AddressSpace *as)
>  {
>      FlatRange *fr;
>      CoalescedMemoryRange *cmr;
>      AddrRange tmp;
>  
> -    FOR_EACH_FLAT_RANGE(fr, address_space_memory.current_map) {
> +    FOR_EACH_FLAT_RANGE(fr, as->current_map) {
>          if (fr->mr == mr) {
>              qemu_unregister_coalesced_mmio(int128_get64(fr->addr.start),
>                                             int128_get64(fr->addr.size));
> @@ -1145,6 +1150,15 @@ static void memory_region_update_coalesced_range(MemoryRegion *mr)
>      }
>  }
>  
> +static void memory_region_update_coalesced_range(MemoryRegion *mr)
> +{
> +    AddressSpace *as;
> +
> +    QTAILQ_FOREACH(as, &address_spaces, address_spaces_link) {
> +        memory_region_update_coalesced_range_as(mr, as);
> +    }
> +}
> +
>  void memory_region_set_coalescing(MemoryRegion *mr)
>  {
>      memory_region_clear_coalescing(mr);
> @@ -1450,10 +1464,6 @@ static void listener_add_address_space(MemoryListener *listener,
>  {
>      FlatRange *fr;
>  
> -    if (!as->root) {
> -        return;
> -    }
> -
>      if (listener->address_space_filter
>          && listener->address_space_filter != as->root) {
>          return;
> @@ -1478,6 +1488,7 @@ static void listener_add_address_space(MemoryListener *listener,
>  void memory_listener_register(MemoryListener *listener, MemoryRegion *filter)
>  {
>      MemoryListener *other = NULL;
> +    AddressSpace *as;
>  
>      listener->address_space_filter = filter;
>      if (QTAILQ_EMPTY(&memory_listeners)
> @@ -1492,8 +1503,10 @@ void memory_listener_register(MemoryListener *listener, MemoryRegion *filter)
>          }
>          QTAILQ_INSERT_BEFORE(other, listener, link);
>      }
> -    listener_add_address_space(listener, &address_space_memory);
> -    listener_add_address_space(listener, &address_space_io);
> +
> +    QTAILQ_FOREACH(as, &address_spaces, address_spaces_link) {
> +        listener_add_address_space(listener, as);
> +    }
>  }
>  
>  void memory_listener_unregister(MemoryListener *listener)
> @@ -1507,17 +1520,21 @@ void address_space_init(AddressSpace *as, MemoryRegion *root)
>      as->root = root;
>      as->current_map = g_new(FlatView, 1);
>      flatview_init(as->current_map);
> +    QTAILQ_INSERT_TAIL(&address_spaces, as, address_spaces_link);
> +    as->name = NULL;
>      memory_region_transaction_commit();
>  }
>  
>  void set_system_memory_map(MemoryRegion *mr)
>  {
>      address_space_init(&address_space_memory, mr);
> +    address_space_memory.name = "memory";
>  }
>  
>  void set_system_io_map(MemoryRegion *mr)
>  {
>      address_space_init(&address_space_io, mr);
> +    address_space_io.name = "I/O";
>  }
>  
>  uint64_t io_mem_read(MemoryRegion *mr, target_phys_addr_t addr, unsigned size)
> @@ -1637,16 +1654,16 @@ void mtree_info(fprintf_function mon_printf, void *f)
>  {
>      MemoryRegionListHead ml_head;
>      MemoryRegionList *ml, *ml2;
> +    AddressSpace *as;
>  
>      QTAILQ_INIT(&ml_head);
>  
> -    mon_printf(f, "memory\n");
> -    mtree_print_mr(mon_printf, f, address_space_memory.root, 0, 0, &ml_head);
> -
> -    if (address_space_io.root &&
> -        !QTAILQ_EMPTY(&address_space_io.root->subregions)) {
> -        mon_printf(f, "I/O\n");
> -        mtree_print_mr(mon_printf, f, address_space_io.root, 0, 0, &ml_head);
> +    QTAILQ_FOREACH(as, &address_spaces, address_spaces_link) {
> +        if (!as->name) {
> +            continue;
> +        }
> +        mon_printf(f, "%s\n", as->name);
> +        mtree_print_mr(mon_printf, f, as->root, 0, 0, &ml_head);
>      }
>  
>      mon_printf(f, "aliases\n");
> diff --git a/memory.h b/memory.h
> index a1d75e7..46bc5e1 100644
> --- a/memory.h
> +++ b/memory.h
> @@ -164,10 +164,12 @@ typedef struct AddressSpace AddressSpace;
>   */
>  struct AddressSpace {
>      /* All fields are private. */
> +    const char *name;
>      MemoryRegion *root;
>      struct FlatView *current_map;
>      int ioeventfd_nb;
>      struct MemoryRegionIoeventfd *ioeventfds;
> +    QTAILQ_ENTRY(AddressSpace) address_spaces_link;
>  };
>  
>  typedef struct MemoryRegionSection MemoryRegionSection;
> -- 
> 1.7.12
> 

--
			Gleb.

  reply	other threads:[~2012-10-04 10:17 UTC|newest]

Thread overview: 70+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-10-03 16:03 [Qemu-devel] [RFC v1 00/22] Integrate DMA into the memory API Avi Kivity
2012-10-03 16:03 ` [Qemu-devel] [RFC v1 01/22] memory: rename 'exec-obsolete.h' Avi Kivity
2012-10-04 13:58   ` Anthony Liguori
2012-10-03 16:03 ` [Qemu-devel] [RFC v1 02/22] vhost: use MemoryListener filtering to only monitor RAM address space Avi Kivity
2012-10-03 16:03 ` [Qemu-devel] [RFC v1 03/22] kvm: use separate MemoryListeners for memory and I/O Avi Kivity
2012-10-03 20:16   ` Blue Swirl
2012-10-04  6:33     ` Avi Kivity
2012-10-04 16:44       ` Blue Swirl
2012-10-04 16:58         ` Avi Kivity
2012-10-03 16:03 ` [Qemu-devel] [RFC v1 04/22] xen_pt: " Avi Kivity
2012-10-03 16:03 ` [Qemu-devel] [RFC v1 05/22] memory: prepare AddressSpace for exporting Avi Kivity
2012-10-04 14:01   ` Anthony Liguori
2012-10-03 16:03 ` [Qemu-devel] [RFC v1 06/22] memory: export AddressSpace Avi Kivity
2012-10-04 14:02   ` Anthony Liguori
2012-10-03 16:03 ` [Qemu-devel] [RFC v1 07/22] memory: maintain a list of address spaces Avi Kivity
2012-10-04 10:17   ` Gleb Natapov [this message]
2012-10-04 10:19     ` Avi Kivity
2012-10-04 14:03   ` Anthony Liguori
2012-10-03 16:03 ` [Qemu-devel] [RFC v1 08/22] memory: provide defaults for MemoryListener operations Avi Kivity
2012-10-04 14:05   ` Anthony Liguori
2012-10-04 14:29     ` Avi Kivity
2012-10-09 15:14       ` Anthony Liguori
2012-10-09 15:28         ` Avi Kivity
2012-10-09 18:34           ` Anthony Liguori
2012-10-03 16:03 ` [Qemu-devel] [RFC v1 09/22] memory: use new MEMORY_LISTENER_DEFAULT_OPS Avi Kivity
2012-10-03 16:03 ` [Qemu-devel] [RFC v1 10/22] vfio: " Avi Kivity
2012-10-04 15:45   ` Alex Williamson
2012-10-03 16:03 ` [Qemu-devel] [RFC v1 11/22] xen_pt: " Avi Kivity
2012-10-03 16:03 ` [Qemu-devel] [RFC v1 12/22] kvm: " Avi Kivity
2012-10-03 16:03 ` [Qemu-devel] [RFC v1 13/22] xen: " Avi Kivity
2012-10-03 16:03 ` [Qemu-devel] [RFC v1 14/22] memory: manage coalesced mmio via a MemoryListener Avi Kivity
2012-10-04 14:08   ` Anthony Liguori
2012-10-04 14:33     ` Avi Kivity
2012-10-03 16:03 ` [Qemu-devel] [RFC v1 15/22] memory: move address_space_memory and address_space_io out of memory core Avi Kivity
2012-10-04 14:08   ` Anthony Liguori
2012-10-03 16:03 ` [Qemu-devel] [RFC v1 16/22] memory: move tcg flush into a tcg memory listener Avi Kivity
2012-10-03 16:04 ` [Qemu-devel] [RFC v1 17/22] memory: use AddressSpace for MemoryListener filtering Avi Kivity
2012-10-03 20:16   ` Blue Swirl
2012-10-04 10:17     ` Avi Kivity
2012-10-04 16:57       ` Blue Swirl
2012-10-04 14:09   ` Anthony Liguori
2012-10-03 16:04 ` [Qemu-devel] [RFC v1 18/22] s390: avoid reaching into memory core internals Avi Kivity
2012-10-04  8:12   ` Christian Borntraeger
2012-10-03 16:04 ` [Qemu-devel] [RFC v1 19/22] memory: per-AddressSpace dispatch Avi Kivity
2012-10-03 20:24   ` Blue Swirl
2012-10-04  6:38     ` Avi Kivity
2012-10-04  8:47       ` Peter Maydell
2012-10-04 10:15         ` Avi Kivity
2012-10-04 10:29           ` Peter Maydell
2012-10-04 10:30             ` Avi Kivity
2012-10-04 17:13       ` Blue Swirl
2012-10-04 17:19         ` Avi Kivity
2012-10-04 17:42           ` Blue Swirl
2012-10-04 19:05             ` Anthony Liguori
2012-10-04 19:15               ` Blue Swirl
2012-10-04 19:16               ` Peter Maydell
2012-10-07 10:34                 ` Avi Kivity
2012-10-04 14:13   ` Anthony Liguori
2012-10-04 14:43     ` Avi Kivity
2012-10-09 15:17       ` Anthony Liguori
2012-10-03 16:04 ` [Qemu-devel] [RFC v1 20/22] dma: make dma access its own address space Avi Kivity
2012-10-04 14:15   ` Anthony Liguori
2012-10-03 16:04 ` [Qemu-devel] [RFC v1 21/22] pci: give each device " Avi Kivity
2012-10-03 16:04 ` [Qemu-devel] [RFC v1 22/22] pci: honor PCI_COMMAND_MASTER Avi Kivity
2012-10-03 20:26 ` [Qemu-devel] [RFC v1 00/22] Integrate DMA into the memory API Blue Swirl
2012-10-04 10:18   ` Avi Kivity
2012-10-04  6:41 ` Avi Kivity
2012-10-04  8:13 ` Paolo Bonzini
2012-10-04 14:16   ` Anthony Liguori
2012-10-04 14:36     ` Avi Kivity

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=20121004101711.GZ23096@redhat.com \
    --to=gleb@redhat.com \
    --cc=anthony@codemonkey.ws \
    --cc=avi@redhat.com \
    --cc=blauwirbel@gmail.com \
    --cc=mst@redhat.com \
    --cc=pbonzini@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=qemulist@gmail.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).