Received: by 2002:a25:ab43:0:0:0:0:0 with SMTP id u61csp6815056ybi; Wed, 5 Jun 2019 06:51:45 -0700 (PDT) X-Google-Smtp-Source: APXvYqz6Gz3FNp1moDq/yFoN4BbotVQHZoUmXbm4SgQ3MfK+wo/5/5PY+UZWyqDNTQs69WSavT5q X-Received: by 2002:a17:90a:2ec3:: with SMTP id h3mr44580172pjs.101.1559742705294; Wed, 05 Jun 2019 06:51:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1559742705; cv=none; d=google.com; s=arc-20160816; b=ixsyfYdEbzy1FXgPt79gE0MwNrkWwddLat7+ZrXaCH5K1CIXesVhP9D/3VSL/44kMx ZkaLnm1cWsfBs82uqNfQxfT7f1ipgR/D2dw5GFjPMJjWEpoWkXV3UFbdA6iqS7WTtPnx Afl548TzO51fPym8oMPz86L1sqvrMOpvAam/hnF95zwClRgssywZfHBy3e4sofvKWks2 z/Xh2HkmmasiahmKkmCeiWaZ9Kl/nug5LrkGqiiI/CFN+3jar7KvTaurG+t3k7rEMM3b QnwymVD8ZJqasBFqi9CBVi+478mX/AGxnyKTv75d6DZfQKHHT/0CxZbBHQ4OCtOzqDx0 1O6Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=PS+SP8qKjNHVQq+aPqdJmHyqgZlHPN/YqkgQhNa5DEA=; b=h6esNGsE34bPHyY8UNdxmOF9a/eziP1QViIckXdO76Fj7qE97gpRG4yy5lH9xypqt6 zYfS1aKix9s8EY4yBXRe/V6gJYX8tn2oxTUxeC05tMrhswsD8g2UlNhBzNDi7Irs8nEB 1ePfokC+eZNm0jfnF3IF0D2pRixlpbSBAR83JWlJMPAAYGxsmr6QOa+70UdhvBGyn2jU zDibMv2W1kEAx8x4LDq+2NRfexmLCBtcnhRdt3dbmHDFi6uw85F+jUNcHrfYsMJbi9aJ ncT5N259gKc6BLLUGNEKtYZJaewwu7kIOoi4RHjDEojpi71PjKo5xiHMshM+ZQTu84J2 zMMw== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b=u9jPeWqR; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id m9si28834523pgs.288.2019.06.05.06.51.27; Wed, 05 Jun 2019 06:51:45 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b=u9jPeWqR; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728174AbfFENtt (ORCPT + 99 others); Wed, 5 Jun 2019 09:49:49 -0400 Received: from mail-wr1-f68.google.com ([209.85.221.68]:36023 "EHLO mail-wr1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726442AbfFENts (ORCPT ); Wed, 5 Jun 2019 09:49:48 -0400 Received: by mail-wr1-f68.google.com with SMTP id n4so16514674wrs.3 for ; Wed, 05 Jun 2019 06:49:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=PS+SP8qKjNHVQq+aPqdJmHyqgZlHPN/YqkgQhNa5DEA=; b=u9jPeWqR0lwSManzDR+WTQ466I/ii45H2wQR8nPJcgYVoDJ7Y7VZrsVkkiJJBINMe4 jPCUu3biGGvvtR5GIQYAUHJQhCsg6jfMSTTg3YW564OV7KAkkKoBHC58E57+SvG1zEVH BHdA1g1WMAUM89s+QR5jNs/QvmmbRB75nfEokQNAu0YIUicB4RCgd/Ye8ziupDfrXTmA 5KTsvVxn3+rWWmsbyy/1S12Pt1otunQrAerFHgrygah9G/pxZPbsk7UIJ9GUrDNPfqgo 8q65pjp8Ns/FR5jSeBqQOjZxqUoge9nqvfgfZ55N5XrMsRMRcF2+oTXhgOWdgVpQEhEW N/iw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=PS+SP8qKjNHVQq+aPqdJmHyqgZlHPN/YqkgQhNa5DEA=; b=BLtd3xVHVzDwN/nJncT+B3GLxHM5HQ2itBSUiSqhbgwbaF6EWP2GydsYQffCVLw3Zg NDi37vqiCLKrUjpRRLATJC0j8v2S0yT4s0cwzz05laaoLKN5R4axrUSVuEdxWvsLexFI th3Dr8iRv5gcTSVOSg3AcOr544pF6+6GEN3RPO8Q4X2fHitxO/paPLqoUABRFg8mgKys Q6/F4BAASXjQZTJoJkOy8KtK0w7CUKt01BhwbnAihIXC9/aw6d7N6eUNX5TOuuv6mJD5 7wFdv9oIU9/xWkzElgjQvxgZYxVfNMCYbEefJ4+1kMHZwXWgerqcX6M9lcsKp4AXyQDY ECUg== X-Gm-Message-State: APjAAAWBk2YRKa110GUTDhNwStoGu4IH+OSkr3MecqfHiTMjokimlWRY T21cqx7+9/mU8B2xtj1uiNQ4DfIF X-Received: by 2002:adf:c606:: with SMTP id n6mr24719655wrg.62.1559742586743; Wed, 05 Jun 2019 06:49:46 -0700 (PDT) Received: from localhost.localdomain (dslb-088-067-134-229.088.067.pools.vodafone-ip.de. [88.67.134.229]) by smtp.gmail.com with ESMTPSA id w14sm4912607wrt.59.2019.06.05.06.49.45 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 05 Jun 2019 06:49:46 -0700 (PDT) From: Jan Glauber X-Google-Original-From: Jan Glauber To: linux-kernel@vger.kernel.org Cc: Catalin Marinas , Will Deacon , linux-arm-kernel@lists.infradead.org, Linus Torvalds , Jayachandran Chandrasekharan Nair , Jan Glauber Subject: [PATCH] lockref: Limit number of cmpxchg loop retries Date: Wed, 5 Jun 2019 15:48:49 +0200 Message-Id: <20190605134849.28108-1-jglauber@marvell.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The lockref cmpxchg loop is unbound as long as the spinlock is not taken. Depending on the hardware implementation of compare-and-swap a high number of loop retries might happen. Add an upper bound to the loop to force the fallback to spinlocks after some time. A retry value of 100 should not impact any hardware that does not have this issue. With the retry limit the performance of an open-close testcase improved between 60-70% on ThunderX2. Suggested-by: Linus Torvalds Signed-off-by: Jan Glauber --- lib/lockref.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/lib/lockref.c b/lib/lockref.c index 3d468b53d4c9..5b34bbd3eba8 100644 --- a/lib/lockref.c +++ b/lib/lockref.c @@ -9,6 +9,7 @@ * failure case. */ #define CMPXCHG_LOOP(CODE, SUCCESS) do { \ + int retry = 100; \ struct lockref old; \ BUILD_BUG_ON(sizeof(old) != 8); \ old.lock_count = READ_ONCE(lockref->lock_count); \ @@ -21,6 +22,8 @@ if (likely(old.lock_count == prev.lock_count)) { \ SUCCESS; \ } \ + if (!--retry) \ + break; \ cpu_relax(); \ } \ } while (0) -- 2.21.0