From patchwork Tue Sep 8 20:13:39 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Glauber Costa X-Patchwork-Id: 33144 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 bilbo.ozlabs.org (Postfix) with ESMTPS id 2B7FDB6F34 for ; Wed, 9 Sep 2009 05:50:22 +1000 (EST) Received: from localhost ([127.0.0.1]:43315 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Ml6hn-0001v2-8f for incoming@patchwork.ozlabs.org; Tue, 08 Sep 2009 15:50:19 -0400 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1Ml6f0-0001FV-Kz for qemu-devel@nongnu.org; Tue, 08 Sep 2009 15:47:26 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1Ml6ev-0001Co-Tt for qemu-devel@nongnu.org; Tue, 08 Sep 2009 15:47:26 -0400 Received: from [199.232.76.173] (port=50356 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Ml6ev-0001Ci-P9 for qemu-devel@nongnu.org; Tue, 08 Sep 2009 15:47:21 -0400 Received: from mx1.redhat.com ([209.132.183.28]:52151) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1Ml6ev-0003vX-8j for qemu-devel@nongnu.org; Tue, 08 Sep 2009 15:47:21 -0400 Received: from int-mx04.intmail.prod.int.phx2.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.17]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id n88JlJ5h012009; Tue, 8 Sep 2009 15:47:19 -0400 Received: from localhost.localdomain (virtlab1.virt.bos.redhat.com [10.16.72.21]) by int-mx04.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id n88JlItL008149; Tue, 8 Sep 2009 15:47:18 -0400 From: Glauber Costa To: qemu-devel@nongnu.org Date: Tue, 8 Sep 2009 16:13:39 -0400 Message-Id: <1252440819-15923-1-git-send-email-glommer@redhat.com> X-Scanned-By: MIMEDefang 2.67 on 10.5.11.17 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 1/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 a894285..604e996 100644 --- a/vl.c +++ b/vl.c @@ -3803,9 +3803,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)