From patchwork Wed Dec 7 15:38:46 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Pranith Kumar X-Patchwork-Id: 703641 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)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3tYjPg1qZsz9t0p for ; Thu, 8 Dec 2016 02:40:36 +1100 (AEDT) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="ncmAy9mv"; dkim-atps=neutral Received: from localhost ([::1]:39548 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cEeKe-0001rI-Oe for incoming@patchwork.ozlabs.org; Wed, 07 Dec 2016 10:40:32 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:42881) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cEeK1-0001Uh-9U for qemu-devel@nongnu.org; Wed, 07 Dec 2016 10:39:54 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cEeJy-0007cx-6Y for qemu-devel@nongnu.org; Wed, 07 Dec 2016 10:39:53 -0500 Received: from mail-yw0-f195.google.com ([209.85.161.195]:36714) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1cEeJy-0007cW-2s for qemu-devel@nongnu.org; Wed, 07 Dec 2016 10:39:50 -0500 Received: by mail-yw0-f195.google.com with SMTP id r204so32400300ywb.3 for ; Wed, 07 Dec 2016 07:39:49 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=references:from:to:cc:subject:in-reply-to:date:message-id :mime-version:content-transfer-encoding; bh=qeTIVo9/A94Xe9fGppbgbyqJAfaD65pWgrwsNvxoDf4=; b=ncmAy9mvmcjurXr5EWq9C0a+/Udb/eXIbyDFYc0LdW3zT+GHlSGRoCPLmtgs+/Cw/H 40M048VixngFWjiMNLh4zScRbdJqFZU/0yhtC60hLyJplYtXhRMeO/mR7CdID1S3dOrZ ZiXYdSdMPBuZW/+LetyYQN4+V3xgJhAxpcT76cpvrZZx9c1Pxb1Wk8r/RFwjxZcMd3Kw sjHAkUU6nOP2yAOwYN5GG1A2Lcc2t4dDb7W+kD/bAnL8xnJfznZYCxtIfPpMtd8xUcNq R/Yu0pHn97be7Cd9oCldazrhVRVkSlV2Ioiocsjf+/6JCUnVyqyr1LP9SZ/4peYFlApR g76A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:references:from:to:cc:subject:in-reply-to:date :message-id:mime-version:content-transfer-encoding; bh=qeTIVo9/A94Xe9fGppbgbyqJAfaD65pWgrwsNvxoDf4=; b=kl/SQyuwFEjb/LFBX0hX9atYRyl2nEDO4MaDnUQy7/AFh+7fYFnei3ZxttF0rXdzV7 8L4o4g3A+C6jPW7X6G41AoMIpsgX/moOtUR0Kb2RjLwpfg24xhb3jTeANd/+gCnlZnLA qlP1S9wMDsyq47zzy8i5HFNpCbpFBGSh49eWh8d4vFe3VXENTlojk3uZc67z+fx8Crdo GNJjwMSQ0hw/9w6SbliW1p0bymU9oxRwz+uGizsCoTygzqxl/21EnqGWOTOEMEO5tYp1 3LslHu3EkFvzjzZnKenaJO+6B4v+omTE2z4yfuFY62/eAqbJkwFYwR6X2rhtm+iB/g/r sBSA== X-Gm-Message-State: AKaTC03cZ4ofXU6WklXwfJ3REsO75jmX1/3VSbWxpX/uxrdCwb3djnhukJjz2kmkufp2Hw== X-Received: by 10.13.198.71 with SMTP id i68mr74617609ywd.158.1481125128271; Wed, 07 Dec 2016 07:38:48 -0800 (PST) Received: from evgadesktop (c-73-207-178-95.hsd1.ga.comcast.net. [73.207.178.95]) by smtp.gmail.com with ESMTPSA id p3sm10291557ywc.22.2016.12.07.07.38.47 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 07 Dec 2016 07:38:47 -0800 (PST) References: <20161206205627.8443-1-bobby.prani@gmail.com> <20161206205627.8443-2-bobby.prani@gmail.com> <87a8c8yvxh.fsf@linaro.org> From: Pranith Kumar To: Alex =?utf-8?Q?Benn=C3=A9e?= In-reply-to: <87a8c8yvxh.fsf@linaro.org> Date: Wed, 07 Dec 2016 10:38:46 -0500 Message-ID: <8760mv92bd.fsf@gmail.com> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.85.161.195 Subject: Re: [Qemu-devel] [RFC PATCH 1/3] tcg: Release tb_lock in the order acquired X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: mst@redhat.com, cota@braap.org, qemu-devel@nongnu.org, rth@twiddle.net Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" Hi Alex, Alex Bennée writes: > > Do you have any numbers for this? The main reason being we are trying to > avoid bouncing the lock too much and while this is cleaner it could > cause more contention. I did not really consider performance while cleaning this up. However, I looked closer and I think we can remove the tb lock acquisition while adding the jump by using atomics. I've attached the patch below. This should remove any concern for a negative performance impact. I will include this patch if you think it's okay. Thanks, diff --git a/cpu-exec.c b/cpu-exec.c index 13cb15de0e..93debe64b6 100644 --- a/cpu-exec.c +++ b/cpu-exec.c @@ -365,9 +365,7 @@ static inline TranslationBlock *tb_find(CPUState *cpu, /* See if we can patch the calling TB. */ if (last_tb && !qemu_loglevel_mask(CPU_LOG_TB_NOCHAIN)) { if (!tb->invalid) { - tb_lock(); tb_add_jump(last_tb, tb_exit, tb); - tb_unlock(); } } return tb; diff --git a/include/exec/exec-all.h b/include/exec/exec-all.h index 84a3240df6..60597cb07e 100644 --- a/include/exec/exec-all.h +++ b/include/exec/exec-all.h @@ -336,7 +336,7 @@ static inline void tb_set_jmp_target(TranslationBlock *tb, static inline void tb_add_jump(TranslationBlock *tb, int n, TranslationBlock *tb_next) { - if (tb->jmp_list_next[n]) { + if (atomic_cmpxchg(&tb->jmp_list_next[n], 0, tb_next->jmp_list_first)) { /* Another thread has already done this while we were * outside of the lock; nothing to do in this case */ return; @@ -351,7 +351,6 @@ static inline void tb_add_jump(TranslationBlock *tb, int n, tb_set_jmp_target(tb, n, (uintptr_t)tb_next->tc_ptr); /* add in TB jmp circular list */ - tb->jmp_list_next[n] = tb_next->jmp_list_first; tb_next->jmp_list_first = (uintptr_t)tb | n; }