From: Jan Kiszka <jan.kiszka@web.de>
To: qemu-devel <qemu-devel@nongnu.org>,
Anthony Liguori <aliguori@us.ibm.com>
Cc: Paolo Bonzini <pbonzini@redhat.com>, Gleb Natapov <gleb@redhat.com>
Subject: [Qemu-devel] [PATCH v2] Replace qemu_system_cond with VCPU stop mechanism
Date: Sat, 23 Jul 2011 12:40:04 +0200 [thread overview]
Message-ID: <4E2AA504.9000205@web.de> (raw)
In-Reply-To: <4E295F23.8060508@siemens.com>
From: Jan Kiszka <jan.kiszka@siemens.com>
We can express the VCPU thread wakeup with the stop mechanism, saving
both qemu_system_ready and the qemu_system_cond. For KVM threads, we can
just enter the main loop as long as the thread is stopped. The central
TCG thread is better held back before the loop as there can be side
effects of the services called even when all CPUs are stopped.
Creating VCPUs in stopped state will also be required for proper CPU
hotplugging support.
Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
---
Changes in v2:
- move tcg_halt_cond initialization to avoid crash in tcg mode
cpus.c | 20 ++++++--------------
1 files changed, 6 insertions(+), 14 deletions(-)
diff --git a/cpus.c b/cpus.c
index 0e54d6b..04c1278 100644
--- a/cpus.c
+++ b/cpus.c
@@ -643,11 +643,9 @@ static QemuThread io_thread;
static QemuThread *tcg_cpu_thread;
static QemuCond *tcg_halt_cond;
-static int qemu_system_ready;
/* cpu creation */
static QemuCond qemu_cpu_cond;
/* system init */
-static QemuCond qemu_system_cond;
static QemuCond qemu_pause_cond;
static QemuCond qemu_work_cond;
@@ -669,7 +667,6 @@ int qemu_init_main_loop(void)
}
qemu_cond_init(&qemu_cpu_cond);
- qemu_cond_init(&qemu_system_cond);
qemu_cond_init(&qemu_pause_cond);
qemu_cond_init(&qemu_work_cond);
qemu_mutex_init(&qemu_fair_mutex);
@@ -683,8 +680,7 @@ int qemu_init_main_loop(void)
void qemu_main_loop_start(void)
{
- qemu_system_ready = 1;
- qemu_cond_broadcast(&qemu_system_cond);
+ resume_all_vcpus();
}
void run_on_cpu(CPUState *env, void (*func)(void *data), void *data)
@@ -803,11 +799,6 @@ static void *qemu_kvm_cpu_thread_fn(void *arg)
env->created = 1;
qemu_cond_signal(&qemu_cpu_cond);
- /* and wait for machine initialization */
- while (!qemu_system_ready) {
- qemu_cond_wait(&qemu_system_cond, &qemu_global_mutex);
- }
-
while (1) {
if (cpu_can_run(env)) {
r = kvm_cpu_exec(env);
@@ -836,9 +827,9 @@ static void *qemu_tcg_cpu_thread_fn(void *arg)
}
qemu_cond_signal(&qemu_cpu_cond);
- /* and wait for machine initialization */
- while (!qemu_system_ready) {
- qemu_cond_wait(&qemu_system_cond, &qemu_global_mutex);
+ /* wait for initial kick-off after machine start */
+ while (!first_cpu->stopped) {
+ qemu_cond_wait(tcg_halt_cond, &qemu_global_mutex);
}
while (1) {
@@ -977,12 +968,12 @@ static void qemu_tcg_init_vcpu(void *_env)
env->thread = qemu_mallocz(sizeof(QemuThread));
env->halt_cond = qemu_mallocz(sizeof(QemuCond));
qemu_cond_init(env->halt_cond);
+ tcg_halt_cond = env->halt_cond;
qemu_thread_create(env->thread, qemu_tcg_cpu_thread_fn, env);
while (env->created == 0) {
qemu_cond_wait(&qemu_cpu_cond, &qemu_global_mutex);
}
tcg_cpu_thread = env->thread;
- tcg_halt_cond = env->halt_cond;
} else {
env->thread = tcg_cpu_thread;
env->halt_cond = tcg_halt_cond;
@@ -1006,6 +997,7 @@ void qemu_init_vcpu(void *_env)
env->nr_cores = smp_cores;
env->nr_threads = smp_threads;
+ env->stopped = 1;
if (kvm_enabled()) {
qemu_kvm_start_vcpu(env);
} else {
prev parent reply other threads:[~2011-07-23 10:40 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-07-22 11:29 [Qemu-devel] [PATCH] Replace qemu_system_cond with VCPU stop mechanism Jan Kiszka
2011-07-23 10:40 ` Jan Kiszka [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=4E2AA504.9000205@web.de \
--to=jan.kiszka@web.de \
--cc=aliguori@us.ibm.com \
--cc=gleb@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).