qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Liu Ping Fan <qemulist@gmail.com>
To: qemu-devel@nongnu.org
Cc: Vasilis Liaskovitis <vasilis.liaskovitis@profitbricks.com>,
	Stefan Hajnoczi <stefanha@gmail.com>, Avi Kivity <avi@redhat.com>,
	Anthony Liguori <anthony@codemonkey.ws>
Subject: [Qemu-devel] [RFC v1 1/3] bouce buffer has fine grain lock
Date: Fri,  9 Nov 2012 11:14:28 +0800	[thread overview]
Message-ID: <1352430870-10129-2-git-send-email-qemulist@gmail.com> (raw)
In-Reply-To: <1352430870-10129-1-git-send-email-qemulist@gmail.com>

From: Liu Ping Fan <pingfank@linux.vnet.ibm.com>

Signed-off-by: Liu Ping Fan <pingfank@linux.vnet.ibm.com>
---
 exec.c |   21 +++++++++++++--------
 1 files changed, 13 insertions(+), 8 deletions(-)

diff --git a/exec.c b/exec.c
index 73d5242..fe84718 100644
--- a/exec.c
+++ b/exec.c
@@ -3296,6 +3296,15 @@ void address_space_destroy_dispatch(AddressSpace *as)
     as->dispatch = NULL;
 }
 
+typedef struct {
+    QemuMutex lock;
+    void *buffer;
+    target_phys_addr_t addr;
+    target_phys_addr_t len;
+} BounceBuffer;
+
+static BounceBuffer bounce;
+
 static void memory_map_init(void)
 {
     system_memory = g_malloc(sizeof(*system_memory));
@@ -3308,6 +3317,8 @@ static void memory_map_init(void)
     address_space_init(&address_space_io, system_io);
     address_space_io.name = "I/O";
 
+    qemu_mutex_init(&bounce.lock);
+
     memory_listener_register(&core_memory_listener, &address_space_memory);
     memory_listener_register(&io_memory_listener, &address_space_io);
     memory_listener_register(&tcg_memory_listener, &address_space_memory);
@@ -3671,14 +3682,6 @@ void cpu_physical_memory_write_rom(target_phys_addr_t addr,
     }
 }
 
-typedef struct {
-    void *buffer;
-    target_phys_addr_t addr;
-    target_phys_addr_t len;
-} BounceBuffer;
-
-static BounceBuffer bounce;
-
 typedef struct MapClient {
     void *opaque;
     void (*callback)(void *opaque);
@@ -3747,6 +3750,7 @@ void *address_space_map(AddressSpace *as,
         section = &mr_obj;
 
         if (!(memory_region_is_ram(section->mr) && !section->readonly)) {
+            qemu_mutex_lock(&bounce.lock);
             if (todo || bounce.buffer) {
                 break;
             }
@@ -3807,6 +3811,7 @@ void address_space_unmap(AddressSpace *as, void *buffer, target_phys_addr_t len,
     }
     qemu_vfree(bounce.buffer);
     bounce.buffer = NULL;
+    qemu_mutex_unlock(&bounce.lock);
     cpu_notify_map_clients();
 }
 
-- 
1.7.4.4

  reply	other threads:[~2012-11-09  3:14 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-11-09  3:14 [Qemu-devel] [RFC v1 0/3] make address_space_map() safe without biglock's protection Liu Ping Fan
2012-11-09  3:14 ` Liu Ping Fan [this message]
2012-11-10  1:49   ` [Qemu-devel] [RFC v1 1/3] bouce buffer has fine grain lock Paolo Bonzini
2012-11-12  6:23     ` liu ping fan
2012-11-12  8:53       ` Paolo Bonzini
2012-11-09  3:14 ` [Qemu-devel] [RFC v1 2/3] ramlist: apply fine grain lock for ram_list Liu Ping Fan
2012-11-10  1:54   ` Paolo Bonzini
2012-11-12  6:22     ` liu ping fan
2012-11-12  8:48       ` Paolo Bonzini
2012-11-13  6:07         ` liu ping fan
2012-11-09  3:14 ` [Qemu-devel] [RFC v1 3/3] make address_space_map safe Liu Ping Fan
     [not found]   ` <20130213121214.GC4576@dhcp-192-168-178-175.profitbricks.localdomain>
2013-03-07  1:59     ` liu ping fan

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=1352430870-10129-2-git-send-email-qemulist@gmail.com \
    --to=qemulist@gmail.com \
    --cc=anthony@codemonkey.ws \
    --cc=avi@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=stefanha@gmail.com \
    --cc=vasilis.liaskovitis@profitbricks.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).