From patchwork Mon Sep 28 18:27:44 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Glauber Costa X-Patchwork-Id: 34385 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [199.232.76.165]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id E8F50B7BBD for ; Tue, 29 Sep 2009 04:31:38 +1000 (EST) Received: from localhost ([127.0.0.1]:35597 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1MsL0a-0001WW-4e for incoming@patchwork.ozlabs.org; Mon, 28 Sep 2009 14:31:36 -0400 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1MsKx2-0000FV-IY for qemu-devel@nongnu.org; Mon, 28 Sep 2009 14:27:56 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1MsKwy-0000Ed-Dg for qemu-devel@nongnu.org; Mon, 28 Sep 2009 14:27:56 -0400 Received: from [199.232.76.173] (port=48193 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1MsKwy-0000ET-6Z for qemu-devel@nongnu.org; Mon, 28 Sep 2009 14:27:52 -0400 Received: from mx1.redhat.com ([209.132.183.28]:14253) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1MsKwx-0006Dd-Iy for qemu-devel@nongnu.org; Mon, 28 Sep 2009 14:27:51 -0400 Received: from int-mx03.intmail.prod.int.phx2.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.16]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id n8SIRope015262; Mon, 28 Sep 2009 14:27:50 -0400 Received: from localhost.localdomain (vpn-13-41.rdu.redhat.com [10.11.13.41]) by int-mx03.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id n8SIRjaA019933; Mon, 28 Sep 2009 14:27:49 -0400 From: Glauber Costa To: qemu-devel@nongnu.org Date: Mon, 28 Sep 2009 15:27:44 -0300 Message-Id: <1254162464-20089-3-git-send-email-glommer@redhat.com> In-Reply-To: <1254162464-20089-2-git-send-email-glommer@redhat.com> References: <1254162464-20089-1-git-send-email-glommer@redhat.com> <1254162464-20089-2-git-send-email-glommer@redhat.com> X-Scanned-By: MIMEDefang 2.67 on 10.5.11.16 X-detected-operating-system: by monty-python.gnu.org: Genre and OS details not recognized. Cc: Glauber Costa , aliguori@us.ibm.com Subject: [Qemu-devel] [PATCH 2/2] do proper cpu_self check X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org From: Glauber Costa Currently, our check for qemu_cpu_self only checks if there is a cpu currently in execution (represented by cpu_single_env being set). While this might be okay for tcg, it is certainly not okay for kvm, since multiple cpus might be executing. Instead, I propose we use pthread primitives to test if the caller thread is the same as env->thread. For tcg, it will have the same semantics as before, since all CPUStates will point to the same thread, and we'll only have one in execution at a time. Signed-off-by: Glauber Costa --- vl.c | 9 +++++++-- 1 files changed, 7 insertions(+), 2 deletions(-) diff --git a/vl.c b/vl.c index f24a260..9448190 100644 --- a/vl.c +++ b/vl.c @@ -3582,9 +3582,14 @@ void qemu_cpu_kick(void *_env) qemu_thread_signal(env->thread, SIGUSR1); } -int qemu_cpu_self(void *env) +int qemu_cpu_self(void *_env) { - return (cpu_single_env != NULL); + CPUState *env = _env; + QemuThread this; + + qemu_thread_self(&this); + + return qemu_thread_equal(&this, env->thread); } static void cpu_signal(int sig)