From patchwork Wed Dec 2 13:48:21 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Glauber Costa X-Patchwork-Id: 40080 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 E8C93B7BE6 for ; Thu, 3 Dec 2009 03:58:34 +1100 (EST) Received: from localhost ([127.0.0.1]:52660 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NFsXA-0004RK-2z for incoming@patchwork.ozlabs.org; Wed, 02 Dec 2009 11:58:32 -0500 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1NFpZZ-0006gN-4P for qemu-devel@nongnu.org; Wed, 02 Dec 2009 08:48:49 -0500 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1NFpZR-0006Ym-Sq for qemu-devel@nongnu.org; Wed, 02 Dec 2009 08:48:45 -0500 Received: from [199.232.76.173] (port=58163 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NFpZR-0006Y4-04 for qemu-devel@nongnu.org; Wed, 02 Dec 2009 08:48:41 -0500 Received: from mx1.redhat.com ([209.132.183.28]:41411) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1NFpZQ-0004HG-LP for qemu-devel@nongnu.org; Wed, 02 Dec 2009 08:48:40 -0500 Received: from int-mx05.intmail.prod.int.phx2.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.18]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id nB2DmdlT007269 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Wed, 2 Dec 2009 08:48:39 -0500 Received: from localhost.localdomain (ovpn01.gateway.prod.ext.phx2.redhat.com [10.5.9.1]) by int-mx05.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id nB2DmN2P026291; Wed, 2 Dec 2009 08:48:38 -0500 From: Glauber Costa To: qemu-devel@nongnu.org Date: Wed, 2 Dec 2009 11:48:21 -0200 Message-Id: <1259761702-4041-11-git-send-email-glommer@redhat.com> In-Reply-To: <1259761702-4041-10-git-send-email-glommer@redhat.com> References: <1259761702-4041-1-git-send-email-glommer@redhat.com> <1259761702-4041-2-git-send-email-glommer@redhat.com> <1259761702-4041-3-git-send-email-glommer@redhat.com> <1259761702-4041-4-git-send-email-glommer@redhat.com> <1259761702-4041-5-git-send-email-glommer@redhat.com> <1259761702-4041-6-git-send-email-glommer@redhat.com> <1259761702-4041-7-git-send-email-glommer@redhat.com> <1259761702-4041-8-git-send-email-glommer@redhat.com> <1259761702-4041-9-git-send-email-glommer@redhat.com> <1259761702-4041-10-git-send-email-glommer@redhat.com> X-Scanned-By: MIMEDefang 2.67 on 10.5.11.18 X-detected-operating-system: by monty-python.gnu.org: Genre and OS details not recognized. Cc: aliguori@us.ibm.com, avi@redhat.com Subject: [Qemu-devel] [PATCH 10/11] Use __thread where available. 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 It is much faster than pthread_{g,s}et_specific. Signed-off-by: Glauber Costa --- configure | 17 +++++++++++++++++ vl.c | 16 ++++++++++++++++ 2 files changed, 33 insertions(+), 0 deletions(-) diff --git a/configure b/configure index dca5a43..ce7bcc4 100755 --- a/configure +++ b/configure @@ -233,6 +233,7 @@ blobs="yes" pkgversion="" check_utests="no" user_pie="no" +tls_thread="yes" # OS specific if check_define __linux__ ; then @@ -1017,6 +1018,19 @@ EOF fi ########################################## +# Check for availability of the __thread keyword +cat > $TMPC < $TMPC <> $config_host_mak if test "$mixemu" = "yes" ; then echo "CONFIG_MIXEMU=y" >> $config_host_mak fi +if test "$tls_thread" = "yes" ; then + echo "CONFIG_TLS_HAS_THREAD=y" >> $config_host_mak +fi if test "$vnc_tls" = "yes" ; then echo "CONFIG_VNC_TLS=y" >> $config_host_mak echo "VNC_TLS_CFLAGS=$vnc_tls_cflags" >> $config_host_mak diff --git a/vl.c b/vl.c index ad2e7d6..16a41e3 100644 --- a/vl.c +++ b/vl.c @@ -3445,21 +3445,37 @@ static void block_io_signals(void); static void unblock_io_signals(void); static int tcg_has_work(void); +#ifdef CONFIG_TLS_HAS_THREAD +static __thread CPUState *current_env; +#else static pthread_key_t current_env; +#endif static CPUState *qemu_get_current_env(void) { +#ifdef CONFIG_TLS_HAS_THREAD + return current_env; +#else return pthread_getspecific(current_env); +#endif } static void qemu_set_current_env(CPUState *env) { +#ifdef CONFIG_TLS_HAS_THREAD + current_env = env; +#else pthread_setspecific(current_env, env); +#endif } static void qemu_init_current_env(void) { +#ifdef CONFIG_TLS_HAS_THREAD + current_env = NULL; +#else pthread_key_create(¤t_env, NULL); +#endif } static int qemu_init_main_loop(void)