From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([208.118.235.92]:44745) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SX1we-0000K7-1W for qemu-devel@nongnu.org; Tue, 22 May 2012 23:09:06 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1SX1wb-0005ZA-8F for qemu-devel@nongnu.org; Tue, 22 May 2012 23:09:03 -0400 Received: from cantor2.suse.de ([195.135.220.15]:35544 helo=mx2.suse.de) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SX1wa-0005YX-TI for qemu-devel@nongnu.org; Tue, 22 May 2012 23:09:01 -0400 Received: from relay2.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 D713B9735A for ; Wed, 23 May 2012 05:08:59 +0200 (CEST) From: =?UTF-8?q?Andreas=20F=C3=A4rber?= Date: Wed, 23 May 2012 05:07:26 +0200 Message-Id: <1337742502-28565-4-git-send-email-afaerber@suse.de> In-Reply-To: <1337742502-28565-1-git-send-email-afaerber@suse.de> References: <1337742502-28565-1-git-send-email-afaerber@suse.de> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Subject: [Qemu-devel] [PATCH qom-next 03/59] cpu: Move thread field into CPUState List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: =?UTF-8?q?Andreas=20F=C3=A4rber?= Signed-off-by: Andreas F=C3=A4rber --- 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 fcde874..b12890b 100644 --- a/cpus.c +++ b/cpus.c @@ -728,10 +728,11 @@ static void qemu_kvm_wait_io_event(CPUArchState *en= v) static void *qemu_kvm_cpu_thread_fn(void *arg) { CPUArchState *env =3D arg; + CPUState *cpu =3D ENV_GET_CPU(env); int r; =20 qemu_mutex_lock(&qemu_global_mutex); - qemu_thread_get_self(env->thread); + qemu_thread_get_self(cpu->thread); env->thread_id =3D qemu_get_thread_id(); cpu_single_env =3D env; =20 @@ -767,11 +768,12 @@ static void *qemu_dummy_cpu_thread_fn(void *arg) exit(1); #else CPUArchState *env =3D arg; + CPUState *cpu =3D ENV_GET_CPU(env); sigset_t waitset; int r; =20 qemu_mutex_lock_iothread(); - qemu_thread_get_self(env->thread); + qemu_thread_get_self(cpu->thread); env->thread_id =3D qemu_get_thread_id(); =20 sigemptyset(&waitset); @@ -807,9 +809,10 @@ static void tcg_exec_all(void); static void *qemu_tcg_cpu_thread_fn(void *arg) { CPUArchState *env =3D arg; + CPUState *cpu =3D ENV_GET_CPU(env); =20 qemu_tcg_init_cpu_signals(); - qemu_thread_get_self(env->thread); + qemu_thread_get_self(cpu->thread); =20 /* signal CPU creation */ qemu_mutex_lock(&qemu_global_mutex); @@ -842,17 +845,17 @@ static void *qemu_tcg_cpu_thread_fn(void *arg) =20 static void qemu_cpu_kick_thread(CPUArchState *env) { + CPUState *cpu =3D ENV_GET_CPU(env); #ifndef _WIN32 int err; =20 - err =3D pthread_kill(env->thread->thread, SIG_IPI); + err =3D 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 =3D 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 =3D _env; + CPUState *cpu =3D ENV_GET_CPU(env); =20 - return qemu_thread_is_self(env->thread); + return qemu_thread_is_self(cpu->thread); } =20 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 =3D _env; -#ifdef _WIN32 CPUState *cpu =3D ENV_GET_CPU(env); -#endif =20 /* share a single thread for all cpus with TCG */ if (!tcg_cpu_thread) { - env->thread =3D g_malloc0(sizeof(QemuThread)); + cpu->thread =3D g_malloc0(sizeof(QemuThread)); env->halt_cond =3D g_malloc0(sizeof(QemuCond)); qemu_cond_init(env->halt_cond); tcg_halt_cond =3D 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 =3D qemu_thread_get_handle(env->thread); + cpu->hThread =3D qemu_thread_get_handle(cpu->thread); #endif while (env->created =3D=3D 0) { qemu_cond_wait(&qemu_cpu_cond, &qemu_global_mutex); } - tcg_cpu_thread =3D env->thread; + tcg_cpu_thread =3D cpu->thread; } else { - env->thread =3D tcg_cpu_thread; + cpu->thread =3D tcg_cpu_thread; env->halt_cond =3D tcg_halt_cond; } } =20 static void qemu_kvm_start_vcpu(CPUArchState *env) { - env->thread =3D g_malloc0(sizeof(QemuThread)); + CPUState *cpu =3D ENV_GET_CPU(env); + + cpu->thread =3D g_malloc0(sizeof(QemuThread)); env->halt_cond =3D 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 =3D=3D 0) { qemu_cond_wait(&qemu_cpu_cond, &qemu_global_mutex); @@ -1014,10 +1018,12 @@ static void qemu_kvm_start_vcpu(CPUArchState *env= ) =20 static void qemu_dummy_start_vcpu(CPUArchState *env) { - env->thread =3D g_malloc0(sizeof(QemuThread)); + CPUState *cpu =3D ENV_GET_CPU(env); + + cpu->thread =3D g_malloc0(sizeof(QemuThread)); env->halt_cond =3D 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 =3D=3D 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 >*/ =20 + struct QemuThread *thread; #ifdef _WIN32 HANDLE hThread; #endif --=20 1.7.7