From patchwork Thu Aug 2 00:48:36 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Andreas_F=C3=A4rber?= X-Patchwork-Id: 174636 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id D1CD72C0090 for ; Thu, 2 Aug 2012 11:41:03 +1000 (EST) Received: from localhost ([::1]:36304 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SwjbW-0001Ig-Nw for incoming@patchwork.ozlabs.org; Wed, 01 Aug 2012 20:49:30 -0400 Received: from eggs.gnu.org ([208.118.235.92]:60192) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Swjau-0000H5-Ab for qemu-devel@nongnu.org; Wed, 01 Aug 2012 20:48:53 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Swjas-00076J-Fv for qemu-devel@nongnu.org; Wed, 01 Aug 2012 20:48:52 -0400 Received: from cantor2.suse.de ([195.135.220.15]:32962 helo=mx2.suse.de) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Swjas-00076C-2F for qemu-devel@nongnu.org; Wed, 01 Aug 2012 20:48:50 -0400 Received: from relay1.suse.de (unknown [195.135.220.254]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mx2.suse.de (Postfix) with ESMTP id 7F878A30B9; Thu, 2 Aug 2012 02:48:49 +0200 (CEST) From: =?UTF-8?q?Andreas=20F=C3=A4rber?= To: qemu-devel@nongnu.org Date: Thu, 2 Aug 2012 02:48:36 +0200 Message-Id: <1343868517-11852-4-git-send-email-afaerber@suse.de> X-Mailer: git-send-email 1.7.7 In-Reply-To: <1343868517-11852-1-git-send-email-afaerber@suse.de> References: <1343868517-11852-1-git-send-email-afaerber@suse.de> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.4-2.6 X-Received-From: 195.135.220.15 Cc: =?UTF-8?q?Andreas=20F=C3=A4rber?= , anthony@codemonkey.ws Subject: [Qemu-devel] [PATCH for-1.2 3/4] cpu: Move thread field into CPUState X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Signed-off-by: Andreas Färber --- cpu-defs.h | 1 - cpus.c | 40 +++++++++++++++++++++++----------------- include/qemu/cpu.h | 1 + 3 files changed, 24 insertions(+), 18 deletions(-) diff --git a/cpu-defs.h b/cpu-defs.h index d0dd781..be89684 100644 --- a/cpu-defs.h +++ b/cpu-defs.h @@ -208,7 +208,6 @@ typedef struct CPUWatchpoint { uint32_t created; \ uint32_t stop; /* Stop request */ \ uint32_t stopped; /* Artificially stopped */ \ - struct QemuThread *thread; \ struct QemuCond *halt_cond; \ int thread_kicked; \ struct qemu_work_item *queued_work_first, *queued_work_last; \ diff --git a/cpus.c b/cpus.c index 7042fb5..565abb4 100644 --- a/cpus.c +++ b/cpus.c @@ -728,10 +728,11 @@ static void qemu_kvm_wait_io_event(CPUArchState *env) static void *qemu_kvm_cpu_thread_fn(void *arg) { CPUArchState *env = arg; + CPUState *cpu = ENV_GET_CPU(env); int r; qemu_mutex_lock(&qemu_global_mutex); - qemu_thread_get_self(env->thread); + qemu_thread_get_self(cpu->thread); env->thread_id = qemu_get_thread_id(); cpu_single_env = env; @@ -767,11 +768,12 @@ static void *qemu_dummy_cpu_thread_fn(void *arg) exit(1); #else CPUArchState *env = arg; + CPUState *cpu = ENV_GET_CPU(env); sigset_t waitset; int r; qemu_mutex_lock_iothread(); - qemu_thread_get_self(env->thread); + qemu_thread_get_self(cpu->thread); env->thread_id = qemu_get_thread_id(); sigemptyset(&waitset); @@ -807,9 +809,10 @@ static void tcg_exec_all(void); static void *qemu_tcg_cpu_thread_fn(void *arg) { CPUArchState *env = arg; + CPUState *cpu = ENV_GET_CPU(env); qemu_tcg_init_cpu_signals(); - qemu_thread_get_self(env->thread); + qemu_thread_get_self(cpu->thread); /* signal CPU creation */ qemu_mutex_lock(&qemu_global_mutex); @@ -842,17 +845,17 @@ static void *qemu_tcg_cpu_thread_fn(void *arg) static void qemu_cpu_kick_thread(CPUArchState *env) { + CPUState *cpu = ENV_GET_CPU(env); #ifndef _WIN32 int err; - err = pthread_kill(env->thread->thread, SIG_IPI); + err = pthread_kill(cpu->thread->thread, SIG_IPI); if (err) { fprintf(stderr, "qemu:%s: %s", __func__, strerror(err)); exit(1); } #else /* _WIN32 */ if (!qemu_cpu_is_self(env)) { - CPUState *cpu = ENV_GET_CPU(env); SuspendThread(cpu->hThread); cpu_signal(0); ResumeThread(cpu->hThread); @@ -888,8 +891,9 @@ void qemu_cpu_kick_self(void) int qemu_cpu_is_self(void *_env) { CPUArchState *env = _env; + CPUState *cpu = ENV_GET_CPU(env); - return qemu_thread_is_self(env->thread); + return qemu_thread_is_self(cpu->thread); } void qemu_mutex_lock_iothread(void) @@ -975,37 +979,37 @@ void resume_all_vcpus(void) static void qemu_tcg_init_vcpu(void *_env) { CPUArchState *env = _env; -#ifdef _WIN32 CPUState *cpu = ENV_GET_CPU(env); -#endif /* share a single thread for all cpus with TCG */ if (!tcg_cpu_thread) { - env->thread = g_malloc0(sizeof(QemuThread)); + cpu->thread = g_malloc0(sizeof(QemuThread)); env->halt_cond = g_malloc0(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, + qemu_thread_create(cpu->thread, qemu_tcg_cpu_thread_fn, env, QEMU_THREAD_JOINABLE); #ifdef _WIN32 - cpu->hThread = qemu_thread_get_handle(env->thread); + cpu->hThread = qemu_thread_get_handle(cpu->thread); #endif while (env->created == 0) { qemu_cond_wait(&qemu_cpu_cond, &qemu_global_mutex); } - tcg_cpu_thread = env->thread; + tcg_cpu_thread = cpu->thread; } else { - env->thread = tcg_cpu_thread; + cpu->thread = tcg_cpu_thread; env->halt_cond = tcg_halt_cond; } } static void qemu_kvm_start_vcpu(CPUArchState *env) { - env->thread = g_malloc0(sizeof(QemuThread)); + CPUState *cpu = ENV_GET_CPU(env); + + cpu->thread = g_malloc0(sizeof(QemuThread)); env->halt_cond = g_malloc0(sizeof(QemuCond)); qemu_cond_init(env->halt_cond); - qemu_thread_create(env->thread, qemu_kvm_cpu_thread_fn, env, + qemu_thread_create(cpu->thread, qemu_kvm_cpu_thread_fn, env, QEMU_THREAD_JOINABLE); while (env->created == 0) { qemu_cond_wait(&qemu_cpu_cond, &qemu_global_mutex); @@ -1014,10 +1018,12 @@ static void qemu_kvm_start_vcpu(CPUArchState *env) static void qemu_dummy_start_vcpu(CPUArchState *env) { - env->thread = g_malloc0(sizeof(QemuThread)); + CPUState *cpu = ENV_GET_CPU(env); + + cpu->thread = g_malloc0(sizeof(QemuThread)); env->halt_cond = g_malloc0(sizeof(QemuCond)); qemu_cond_init(env->halt_cond); - qemu_thread_create(env->thread, qemu_dummy_cpu_thread_fn, env, + qemu_thread_create(cpu->thread, qemu_dummy_cpu_thread_fn, env, QEMU_THREAD_JOINABLE); while (env->created == 0) { qemu_cond_wait(&qemu_cpu_cond, &qemu_global_mutex); diff --git a/include/qemu/cpu.h b/include/qemu/cpu.h index 5d52e1c..d20644b 100644 --- a/include/qemu/cpu.h +++ b/include/qemu/cpu.h @@ -62,6 +62,7 @@ struct CPUState { Object parent_obj; /*< public >*/ + struct QemuThread *thread; #ifdef _WIN32 HANDLE hThread; #endif