From: Fam Zheng <famz@redhat.com>
To: qemu-devel@nongnu.org
Cc: Paolo Bonzini <pbonzini@redhat.com>
Subject: [Qemu-devel] [PATCH v2 2/4] exec: Atomic access to map_client_list
Date: Fri, 13 Mar 2015 09:38:41 +0800 [thread overview]
Message-ID: <1426210723-16735-3-git-send-email-famz@redhat.com> (raw)
In-Reply-To: <1426210723-16735-1-git-send-email-famz@redhat.com>
Change map_client_list to QSLIST which supports atomic operations.
There are two access points to map_client_list. One is
cpu_register_map_client, the other is cpu_notify_map_clients called
after releasing the global bounce buffer in address_space_unmap. Each
is now converted to a single atomic operation.
Signed-off-by: Fam Zheng <famz@redhat.com>
---
exec.c | 27 ++++++++++++---------------
1 file changed, 12 insertions(+), 15 deletions(-)
diff --git a/exec.c b/exec.c
index 8d4e134..93ccd5a 100644
--- a/exec.c
+++ b/exec.c
@@ -2489,11 +2489,11 @@ static BounceBuffer bounce;
typedef struct MapClient {
void *opaque;
void (*callback)(void *opaque);
- QLIST_ENTRY(MapClient) link;
+ QSLIST_ENTRY(MapClient) link;
} MapClient;
-static QLIST_HEAD(map_client_list, MapClient) map_client_list
- = QLIST_HEAD_INITIALIZER(map_client_list);
+static QSLIST_HEAD(map_client_list, MapClient) map_client_list
+ = QSLIST_HEAD_INITIALIZER(map_client_list);
void *cpu_register_map_client(void *opaque, void (*callback)(void *opaque))
{
@@ -2501,26 +2501,23 @@ void *cpu_register_map_client(void *opaque, void (*callback)(void *opaque))
client->opaque = opaque;
client->callback = callback;
- QLIST_INSERT_HEAD(&map_client_list, client, link);
+ QSLIST_INSERT_HEAD_ATOMIC(&map_client_list, client, link);
return client;
}
-static void cpu_unregister_map_client(void *_client)
-{
- MapClient *client = (MapClient *)_client;
-
- QLIST_REMOVE(client, link);
- g_free(client);
-}
-
static void cpu_notify_map_clients(void)
{
MapClient *client;
+ QSLIST_HEAD(, MapClient) mclist;
- while (!QLIST_EMPTY(&map_client_list)) {
- client = QLIST_FIRST(&map_client_list);
+ /* Only the bounce buffer owner thread could possibly call this, but we
+ * should also coordinate with cpu_register_map_client. */
+ QSLIST_MOVE_ATOMIC(&mclist, &map_client_list);
+ while (!QSLIST_EMPTY(&mclist)) {
+ client = QSLIST_FIRST(&mclist);
client->callback(client->opaque);
- cpu_unregister_map_client(client);
+ QSLIST_REMOVE_HEAD(&mclist, link);
+ g_free(client);
}
}
--
1.9.3
next prev parent reply other threads:[~2015-03-13 1:38 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-03-13 1:38 [Qemu-devel] [PATCH v2 0/4] exec: Make bounce buffer thread safe Fam Zheng
2015-03-13 1:38 ` [Qemu-devel] [PATCH v2 1/4] exec: Atomic access to bounce buffer Fam Zheng
2015-03-13 8:09 ` Paolo Bonzini
2015-03-13 8:16 ` Fam Zheng
2015-03-13 8:32 ` Paolo Bonzini
2015-03-13 8:38 ` Fam Zheng
2015-03-13 8:41 ` Paolo Bonzini
2015-03-13 1:38 ` Fam Zheng [this message]
2015-03-13 8:11 ` [Qemu-devel] [PATCH v2 2/4] exec: Atomic access to map_client_list Paolo Bonzini
2015-03-13 1:38 ` [Qemu-devel] [PATCH v2 3/4] exec: Notify cpu_register_map_client caller if the bounce buffer is available Fam Zheng
2015-03-13 8:12 ` Paolo Bonzini
2015-03-13 1:38 ` [Qemu-devel] [PATCH v2 4/4] dma-helpers: Move reschedule_dma BH to blk's AioContext Fam Zheng
2015-03-13 8:13 ` Paolo Bonzini
2015-03-13 8:58 ` Fam Zheng
2015-03-13 10:48 ` Paolo Bonzini
2015-03-13 12:33 ` Paolo Bonzini
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=1426210723-16735-3-git-send-email-famz@redhat.com \
--to=famz@redhat.com \
--cc=pbonzini@redhat.com \
--cc=qemu-devel@nongnu.org \
/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).