qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Marcelo Tosatti <mtosatti@redhat.com>
To: Anthony Liguori <anthony@codemonkey.ws>
Cc: qemu-devel@nongnu.org
Subject: [Qemu-devel] Re: [patch 2/7] qemu: separate thread for io
Date: Fri, 20 Mar 2009 21:06:17 -0300	[thread overview]
Message-ID: <20090321000617.GA26654@amt.cnet> (raw)
In-Reply-To: <49C3D5D5.4020006@codemonkey.ws>

On Fri, Mar 20, 2009 at 12:43:49PM -0500, Anthony Liguori wrote:
>> +    qemu_mutex_lock(&qemu_fair_mutex);
>> +    qemu_mutex_unlock(&qemu_fair_mutex);
>>   
>
> This is extremely subtle.  I think it can be made a bit more explicit  
> via something like:
>
> int generation = qemu_io_generation() + 1;
>
> qemu_mutex_unlock(&qemu_global_mutex);
>
> if (timeout && !has_work(env))
>     wait_signal(timeout);
>
> qemu_mutex_lock(&qemu_global_mutex)
>
> while (qemu_io_generation() < generation)
>    qemu_cond_wait(&qemu_io_generation_cond, &qemu_global_mutex);
>
> Then, in main_loop_wait():
>
>>  void main_loop_wait(int timeout)
>>  {
>>      IOHandlerRecord *ioh;
>> @@ -3660,7 +3806,7 @@ void main_loop_wait(int timeout)
>>       */
>>      qemu_mutex_unlock(&qemu_global_mutex);
>>      ret = select(nfds + 1, &rfds, &wfds, &xfds, &tv);
>> -    qemu_mutex_lock(&qemu_global_mutex);
>>   
>
> qemu_mutex_lock(&qemu_global_mutex);
> qemu_io_generation_add();
> qemu_cond_signal(&qemu_io_generation_cond);
>
> This will ensure that the TCG loop backs off of qemu_global_mutex for at  
> least one main_loop_wait() iteration.

I don't see much benefit. It has the disadvantage of introducing more
state (the generation counter, the conditional), and the potential
problems associated with this state such as:

- If there is no event for the iothread to process, TCG will throttle
  unnecessarily (i can't see how that could happen, but is a
  possibility) until some event breaks it out of select() thus
  increasing the generation counter.

- Its possible to miss signals (again, I can't see in happening 
  in the scheme you suggest), but..

Also note there is no need to be completly fair. It is fine to
eventually be unfair.

Do you worry about interaction between the two locks? Can make the lock
ordering documented.

Will spend some time thinking about this, need to take multiple
"starved" threads into account.

Thanks.

  reply	other threads:[~2009-03-21  0:06 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-03-19 14:57 [Qemu-devel] [patch 0/7] separate thread for io v2 mtosatti
2009-03-19 14:57 ` [Qemu-devel] [patch 1/7] qemu: mutex/thread/cond wrappers mtosatti
2009-03-19 15:59   ` Avi Kivity
2009-03-19 18:49     ` Jamie Lokier
2009-03-23 23:17     ` Marcelo Tosatti
2009-03-24  7:43       ` Avi Kivity
2009-03-19 14:57 ` [Qemu-devel] [patch 2/7] qemu: separate thread for io mtosatti
2009-03-20 17:43   ` [Qemu-devel] " Anthony Liguori
2009-03-21  0:06     ` Marcelo Tosatti [this message]
2009-03-21  1:04       ` Anthony Liguori
2009-03-21  1:44         ` Marcelo Tosatti
2009-03-21  1:50           ` Anthony Liguori
2009-03-22  8:48             ` Avi Kivity
2009-03-22 11:17               ` Anthony Liguori
2009-03-19 14:57 ` [Qemu-devel] [patch 3/7] qemu: main thread does io and cpu thread is spawned mtosatti
2009-03-19 14:57 ` [Qemu-devel] [patch 4/7] qemu: handle reset/poweroff/shutdown in iothread mtosatti
2009-03-19 14:57 ` [Qemu-devel] [patch 5/7] qemu: pause and resume cpu thread(s) mtosatti
2009-03-19 14:57 ` [Qemu-devel] [patch 6/7] qemu: handle vmstop from cpu context mtosatti
2009-03-19 14:57 ` [Qemu-devel] [patch 7/7] qemu: use pipe to wakeup io thread mtosatti

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=20090321000617.GA26654@amt.cnet \
    --to=mtosatti@redhat.com \
    --cc=anthony@codemonkey.ws \
    --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).