From: Paolo Bonzini <pbonzini@redhat.com>
To: liu ping fan <qemulist@gmail.com>
Cc: Vasilis Liaskovitis <vasilis.liaskovitis@profitbricks.com>,
Stefan Hajnoczi <stefanha@gmail.com>,
qemu-devel@nongnu.org, Anthony Liguori <anthony@codemonkey.ws>,
Avi Kivity <avi@redhat.com>
Subject: Re: [Qemu-devel] [RFC v1 1/3] bouce buffer has fine grain lock
Date: Mon, 12 Nov 2012 09:53:27 +0100 [thread overview]
Message-ID: <50A0B907.1090304@redhat.com> (raw)
In-Reply-To: <CAJnKYQ=fS6HqNnAG02sQgwRNhvWa_YJrRXMi5yfNQKy=dW-_Jg@mail.gmail.com>
Il 12/11/2012 07:23, liu ping fan ha scritto:
>> > Also, you do not need to keep the lock after address_space_map exits.
>> > In fact, it can be released as soon as bounce.buffer is written to.
>> > After that point, bounce will not be touched (the lock only serves to
>> > serialize writes to bounce.buffer). That is,
>> >
> But w/o the lock, the content in bounce.buffer for threadA, can be
> flushed with thread B.
It doesn't matter _which_ thread calls address_space_unmap. As long as
it's only one, you do not need a lock. In fact, it is perfectly fine
for thread A to call address_space_map and pass the address to thread B.
Thread B will later call address_space_unmap.
The important thing is that only one thread will call
address_space_unmap with buffer == bounce.buffer. So you do not need a
lock to serialize the writes in address_space_unmap.
See thread-pool.c for a similar trick:
/* Moving state out of THREAD_QUEUED is protected by lock. After
* that, only the worker thread can write to it. Reads and writes
* of state and ret are ordered with memory barriers.
*/
enum ThreadState state;
int ret;
...
qemu_mutex_lock(&lock);
...
req->state = THREAD_ACTIVE;
qemu_mutex_unlock(&lock);
req->ret = req->func(req->arg);
smp_wmb();
req->state = THREAD_DONE;
Paolo
next prev parent reply other threads:[~2012-11-12 8:53 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 ` [Qemu-devel] [RFC v1 1/3] bouce buffer has fine grain lock Liu Ping Fan
2012-11-10 1:49 ` Paolo Bonzini
2012-11-12 6:23 ` liu ping fan
2012-11-12 8:53 ` Paolo Bonzini [this message]
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=50A0B907.1090304@redhat.com \
--to=pbonzini@redhat.com \
--cc=anthony@codemonkey.ws \
--cc=avi@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=qemulist@gmail.com \
--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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.