qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Paolo Bonzini <pbonzini@redhat.com>
To: qemu-devel@nongnu.org
Cc: edgar.iglesias@gmail.com, mtosatti@redhat.com, jan.kiszka@web.de
Subject: [Qemu-devel] [PATCH 3/3] really fix -icount in the iothread case
Date: Sat,  5 Mar 2011 18:14:15 +0100	[thread overview]
Message-ID: <1299345255-577-4-git-send-email-pbonzini@redhat.com> (raw)
In-Reply-To: <1299345255-577-1-git-send-email-pbonzini@redhat.com>

The correct fix for -icount is obvious once you consider the biggest
difference between iothread and non-iothread modes.  In the traditional
model, CPUs run _before_ the iothread calls select.  In the iothread
model, CPUs run while the iothread isn't holding the mutex, i.e. _during_
those same calls.

So, the iothread should always block as long as possible to let
the CPUs run smoothly---the timeout might as well be infinite---and
either the OS or the CPU thread itself will let the iothread know
when something happens.  At this point, the iothread will wake up and
interrupt execution of the emulated CPU(s).

This is exactly the approach that this patch takes.  When a vm_clock
deadline is met, tcg_cpu_exec will stop executing instructions
(count == 0) so that cpu_exec_all will return very soon.  The TCG
thread should then check if this is the case and, if so, wake up
the iothread to process the timers.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
 cpus.c |    3 +++
 1 files changed, 3 insertions(+), 0 deletions(-)

diff --git a/cpus.c b/cpus.c
index 0f33945..a953bac 100644
--- a/cpus.c
+++ b/cpus.c
@@ -861,6 +861,9 @@ static void *qemu_tcg_cpu_thread_fn(void *arg)
 
     while (1) {
         cpu_exec_all();
+        if (use_icount && qemu_next_deadline() <= 0) {
+            qemu_notify_event();
+        }
         qemu_tcg_wait_io_event();
     }
 
-- 
1.7.4

      parent reply	other threads:[~2011-03-05 17:14 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-03-05 17:14 [Qemu-devel] [PATCH 0/3] really fix -icount with iothread Paolo Bonzini
2011-03-05 17:14 ` [Qemu-devel] [PATCH 1/3] qemu_next_deadline should not consider host-time timers Paolo Bonzini
2011-03-05 18:07   ` [Qemu-devel] " Jan Kiszka
2011-03-09 13:40     ` Paolo Bonzini
2011-03-05 17:14 ` [Qemu-devel] [PATCH 2/3] Revert wrong fix for -icount in the iothread case Paolo Bonzini
2011-03-05 17:14 ` Paolo Bonzini [this message]

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=1299345255-577-4-git-send-email-pbonzini@redhat.com \
    --to=pbonzini@redhat.com \
    --cc=edgar.iglesias@gmail.com \
    --cc=jan.kiszka@web.de \
    --cc=mtosatti@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).