From: Paolo Bonzini <pbonzini@redhat.com>
To: qemu-devel@nongnu.org
Subject: [Qemu-devel] [PATCH 1/2] iothread: replace fair_mutex with a condition variable
Date: Thu, 9 Jun 2011 13:10:24 +0200 [thread overview]
Message-ID: <1307617825-17149-2-git-send-email-pbonzini@redhat.com> (raw)
In-Reply-To: <1307617825-17149-1-git-send-email-pbonzini@redhat.com>
This conveys the intention better, and scales to more than >1
threads contending the mutex with the iothread (as long as all
of them have a "quiescent point" like the TCG thread has).
Also, on Mac OS X the fair_mutex somehow didn't work as intended
and deadlocked.
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Tested-by: Alexander Graf <agraf@suse.de>
---
cpus.c | 24 +++++++++---------------
1 files changed, 9 insertions(+), 15 deletions(-)
diff --git a/cpus.c b/cpus.c
index 1fc34b7..d2ba933 100644
--- a/cpus.c
+++ b/cpus.c
@@ -626,7 +626,8 @@ void vm_stop(int reason)
#else /* CONFIG_IOTHREAD */
QemuMutex qemu_global_mutex;
-static QemuMutex qemu_fair_mutex;
+static QemuCond qemu_io_proceeded_cond;
+static bool iothread_requesting_mutex;
static QemuThread io_thread;
@@ -662,7 +663,7 @@ int qemu_init_main_loop(void)
qemu_cond_init(&qemu_system_cond);
qemu_cond_init(&qemu_pause_cond);
qemu_cond_init(&qemu_work_cond);
- qemu_mutex_init(&qemu_fair_mutex);
+ qemu_cond_init(&qemu_io_proceeded_cond);
qemu_mutex_init(&qemu_global_mutex);
qemu_mutex_lock(&qemu_global_mutex);
@@ -745,17 +746,9 @@ static void qemu_tcg_wait_io_event(void)
qemu_cond_wait(tcg_halt_cond, &qemu_global_mutex);
}
- qemu_mutex_unlock(&qemu_global_mutex);
-
- /*
- * Users of qemu_global_mutex can be starved, having no chance
- * to acquire it since this path will get to it first.
- * So use another lock to provide fairness.
- */
- qemu_mutex_lock(&qemu_fair_mutex);
- qemu_mutex_unlock(&qemu_fair_mutex);
-
- qemu_mutex_lock(&qemu_global_mutex);
+ while (iothread_requesting_mutex) {
+ qemu_cond_wait(&qemu_io_proceeded_cond, &qemu_global_mutex);
+ }
for (env = first_cpu; env != NULL; env = env->next_cpu) {
qemu_wait_io_event_common(env);
@@ -898,12 +891,13 @@ void qemu_mutex_lock_iothread(void)
if (kvm_enabled()) {
qemu_mutex_lock(&qemu_global_mutex);
} else {
- qemu_mutex_lock(&qemu_fair_mutex);
+ iothread_requesting_mutex = true;
if (qemu_mutex_trylock(&qemu_global_mutex)) {
qemu_cpu_kick_thread(first_cpu);
qemu_mutex_lock(&qemu_global_mutex);
}
- qemu_mutex_unlock(&qemu_fair_mutex);
+ iothread_requesting_mutex = false;
+ qemu_cond_broadcast(&qemu_io_proceeded_cond);
}
}
--
1.7.4.4
next prev parent reply other threads:[~2011-06-09 11:10 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-06-09 11:10 [Qemu-devel] [PATCH 0/2] iothread improvements for Mac OS X Paolo Bonzini
2011-06-09 11:10 ` Paolo Bonzini [this message]
2011-06-09 11:10 ` [Qemu-devel] [PATCH 2/2] qemu-timer: change unix timer to dynticks Paolo Bonzini
2011-06-27 14:07 ` [Qemu-devel] [PATCH 0/2] iothread improvements for Mac OS X Paolo Bonzini
2011-06-29 4:26 ` Alexandre Raymond
2011-07-23 16:54 ` Anthony Liguori
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=1307617825-17149-2-git-send-email-pbonzini@redhat.com \
--to=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).