From patchwork Wed May 4 19:43:41 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jan Kiszka X-Patchwork-Id: 754772 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter1.kernel.org (8.14.4/8.14.3) with ESMTP id p44Jisjp026562 for ; Wed, 4 May 2011 19:44:54 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755691Ab1EDTou (ORCPT ); Wed, 4 May 2011 15:44:50 -0400 Received: from fmmailgate03.web.de ([217.72.192.234]:40720 "EHLO fmmailgate03.web.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755538Ab1EDToO (ORCPT ); Wed, 4 May 2011 15:44:14 -0400 Received: from smtp04.web.de ( [172.20.0.225]) by fmmailgate03.web.de (Postfix) with ESMTP id C44B018E0288E; Wed, 4 May 2011 21:44:13 +0200 (CEST) Received: from [88.64.22.120] (helo=localhost.localdomain) by smtp04.web.de with asmtp (TLSv1:AES256-SHA:256) (WEB.DE 4.110 #2) id 1QHhzZ-0006mo-01; Wed, 04 May 2011 21:44:13 +0200 From: Jan Kiszka To: Avi Kivity , Marcelo Tosatti Cc: kvm@vger.kernel.org Subject: [PATCH 07/19] qemu-kvm: Start using qemu-thread services Date: Wed, 4 May 2011 21:43:41 +0200 Message-Id: <3fc5e3dda45bc7dc3de2ed47710c6b6bc66267bb.1304538230.git.jan.kiszka@web.de> X-Mailer: git-send-email 1.7.1 In-Reply-To: References: In-Reply-To: References: X-Sender: jan.kiszka@web.de X-Provags-ID: V01U2FsdGVkX18mf2SnpcEs0PyjeDhomTtMpzzexL9Nz/t4NsR2 nVENFJBmDJ1MAeq7Vq3j32PcLT/98lwptWVaWYLFj2l2n7MaAm jkq19cITc= Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.6 (demeter1.kernel.org [140.211.167.41]); Wed, 04 May 2011 19:44:54 +0000 (UTC) From: Jan Kiszka Convert VCPU thread creation to qemu_thread_create. This allows to drop the thread field from KVMCPUState. It requires us to rename qemu-kvm's qemu_cond_wait as a temporary solution until we find a common version. Signed-off-by: Jan Kiszka --- configure | 1 + cpu-defs.h | 1 - qemu-kvm-x86.c | 4 ++-- qemu-kvm.c | 29 ++++++++++++++--------------- 4 files changed, 17 insertions(+), 18 deletions(-) diff --git a/configure b/configure index 75071ad..2aa9075 100755 --- a/configure +++ b/configure @@ -3382,6 +3382,7 @@ case "$target_arch2" in \( "$target_arch2" = "x86_64" -a "$cpu" = "i386" \) -o \ \( "$target_arch2" = "i386" -a "$cpu" = "x86_64" \) \) ; then echo "CONFIG_KVM=y" >> $config_target_mak + echo "CONFIG_THREAD=y" >> $config_host_mak echo "KVM_CFLAGS=$kvm_cflags" >> $config_target_mak if test "$kvm_para" = "yes"; then echo "CONFIG_KVM_PARA=y" >> $config_target_mak diff --git a/cpu-defs.h b/cpu-defs.h index e3d3546..624fd1a 100644 --- a/cpu-defs.h +++ b/cpu-defs.h @@ -158,7 +158,6 @@ typedef struct CPUWatchpoint { struct qemu_work_item; struct KVMCPUState { - pthread_t thread; int signalled; struct qemu_work_item *queued_work_first, *queued_work_last; }; diff --git a/qemu-kvm-x86.c b/qemu-kvm-x86.c index d180630..9d546d0 100644 --- a/qemu-kvm-x86.c +++ b/qemu-kvm-x86.c @@ -486,7 +486,7 @@ void kvm_arch_load_regs(CPUState *env, int level) { int rc; - assert(kvm_cpu_is_stopped(env) || env->thread_id == kvm_get_thread_id()); + assert(kvm_cpu_is_stopped(env) || qemu_cpu_is_self(env)); kvm_getput_regs(env, 1); @@ -521,7 +521,7 @@ void kvm_arch_save_regs(CPUState *env) { int rc; - assert(kvm_cpu_is_stopped(env) || env->thread_id == kvm_get_thread_id()); + assert(kvm_cpu_is_stopped(env) || qemu_cpu_is_self(env)); kvm_getput_regs(env, 0); diff --git a/qemu-kvm.c b/qemu-kvm.c index e066582..d86fdcc 100644 --- a/qemu-kvm.c +++ b/qemu-kvm.c @@ -19,6 +19,7 @@ #include "gdbstub.h" #include "monitor.h" #include "cpus.h" +#include "qemu-thread.h" #include "qemu-kvm.h" #include "libkvm.h" @@ -498,7 +499,7 @@ int kvm_run(CPUState *env) } if (env->exit_request) { env->exit_request = 0; - pthread_kill(env->kvm_cpu_state.thread, SIG_IPI); + pthread_kill(env->thread->thread, SIG_IPI); } r = ioctl(fd, KVM_RUN, 0); @@ -1034,7 +1035,7 @@ unsigned long kvm_get_thread_id(void) return syscall(SYS_gettid); } -static void qemu_cond_wait(pthread_cond_t *cond) +static void kvm_cond_wait(pthread_cond_t *cond) { CPUState *env = cpu_single_env; @@ -1090,9 +1091,9 @@ void on_vcpu(CPUState *env, void (*func)(void *data), void *data) wi.next = NULL; wi.done = false; - pthread_kill(env->kvm_cpu_state.thread, SIG_IPI); + pthread_kill(env->thread->thread, SIG_IPI); while (!wi.done) { - qemu_cond_wait(&qemu_work_cond); + kvm_cond_wait(&qemu_work_cond); } } @@ -1153,8 +1154,8 @@ void kvm_update_interrupt_request(CPUState *env) if (signal) { env->kvm_cpu_state.signalled = 1; - if (env->kvm_cpu_state.thread) { - pthread_kill(env->kvm_cpu_state.thread, SIG_IPI); + if (env->thread) { + pthread_kill(env->thread->thread, SIG_IPI); } } } @@ -1272,7 +1273,7 @@ static void pause_all_threads(void) while (penv) { if (penv != cpu_single_env) { penv->stop = 1; - pthread_kill(penv->kvm_cpu_state.thread, SIG_IPI); + pthread_kill(penv->thread->thread, SIG_IPI); } else { penv->stop = 0; penv->stopped = 1; @@ -1282,7 +1283,7 @@ static void pause_all_threads(void) } while (!all_threads_paused()) { - qemu_cond_wait(&qemu_pause_cond); + kvm_cond_wait(&qemu_pause_cond); } } @@ -1295,7 +1296,7 @@ static void resume_all_threads(void) while (penv) { penv->stop = 0; penv->stopped = 0; - pthread_kill(penv->kvm_cpu_state.thread, SIG_IPI); + pthread_kill(penv->thread->thread, SIG_IPI); penv = (CPUState *) penv->next_cpu; } } @@ -1368,15 +1369,12 @@ static int kvm_main_loop_cpu(CPUState *env) static void *ap_main_loop(void *_env) { CPUState *env = _env; - sigset_t signals; #ifdef CONFIG_KVM_DEVICE_ASSIGNMENT struct ioperm_data *data = NULL; #endif current_env = env; env->thread_id = kvm_get_thread_id(); - sigfillset(&signals); - sigprocmask(SIG_BLOCK, &signals, NULL); #ifdef CONFIG_KVM_DEVICE_ASSIGNMENT /* do ioperm for io ports of assigned devices */ @@ -1398,7 +1396,7 @@ static void *ap_main_loop(void *_env) /* and wait for machine initialization */ while (!qemu_system_ready) { - qemu_cond_wait(&qemu_system_cond); + kvm_cond_wait(&qemu_system_cond); } /* re-initialize cpu_single_env after re-acquiring qemu_mutex */ @@ -1410,10 +1408,11 @@ static void *ap_main_loop(void *_env) int kvm_init_vcpu(CPUState *env) { - pthread_create(&env->kvm_cpu_state.thread, NULL, ap_main_loop, env); + env->thread = qemu_mallocz(sizeof(QemuThread)); + qemu_thread_create(env->thread, ap_main_loop, env); while (env->created == 0) { - qemu_cond_wait(&qemu_vcpu_cond); + kvm_cond_wait(&qemu_vcpu_cond); } return 0;