From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.0 required=3.0 tests=DKIM_SIGNED,DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,T_DKIMWL_WL_HIGH,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9ABF8C28CC5 for ; Wed, 5 Jun 2019 13:49:57 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 7065020866 for ; Wed, 5 Jun 2019 13:49:57 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="HNc2WLI9"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="u9jPeWqR" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 7065020866 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=cavium.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+infradead-linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=X8p6EwXoCjLZBgaxQiHm/80Pm5NyBlXz/exc8aOewLM=; b=HNc2WLI9u1ahaO oRpnwJsWJBHdNgURl94kISrtf48wC6tNqt216z4lGMQXuficj5iJrv8G72t5Jz2L921gIu2znU9zz Ji+DtgaaQxv/lCgBxisEDi1lujq4OVtqydx8XAkFg7IoUYHDSXd/4x99fC8z4HcrpmkDYnYAOJQbZ GVJJFmZgG/yLFllHUCNV4/yEm3JEhKX6fELXPmAYL+j3Lib+ktfW8UEH8ovawK60jp+Bzyx8c/QEd +Pno5S1yEmjII5TfQXZzuLP8T65BuUctCA/Qtl6efIL3kyT6G6XsqoSMT3aiLqIsXs2Fa6RBGkVHh t0zPEVYw9WHaS6/nNeIA==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1hYWId-0006Cq-U8; Wed, 05 Jun 2019 13:49:55 +0000 Received: from mail-wr1-x444.google.com ([2a00:1450:4864:20::444]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1hYWIa-0006Bl-HS for linux-arm-kernel@lists.infradead.org; Wed, 05 Jun 2019 13:49:53 +0000 Received: by mail-wr1-x444.google.com with SMTP id m3so3726699wrv.2 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=l0wu4rbqBZf4H0BRmpemCV5+V9HKXZ8rRCRzjIa/LEciZjrF3pthARUA5uufd7fT5J KBDXPNgHsqL34K37cemGOl/olfXrC1tuP/SvOc+GO8muvEoA+2H2yj8yrBJWDMPzxSBT +N2CTmk2Kpiesbj0nhvKlqnnx9sNCCyb/m6UBnxuNICGr/OstSyattE4KLtVBsTMtBwI FDjg3RNuyehUjZqrtbWq2rCpb1jSt+xZ7sYHCaFA32Z3aXfJc4Ih/ozjXPRnDOiNSwxC 4JGbQl06o7A7VadDA7+nqNasno1kfEDyRFPggWDAua6W6qCI8qn4s2qJr3+N+lp9rKHe kKsA== X-Gm-Message-State: APjAAAWkqu+r54Fq+2J6KTIV1JQyDbAWTixhG6XcTtKbnKOFLfGSNaoK +u5a5cpZ+chUyWvJ6UvLdko= X-Google-Smtp-Source: APXvYqx1R2ddxjXl2YOzPr7tU7waVJgflYnjWmHroDaShEjCfEmRZikGcNyby1rISNrgfg3TmWlRsg== 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 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 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190605_064952_581933_ECFF6665 X-CRM114-Status: GOOD ( 12.43 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Catalin Marinas , Jan Glauber , Will Deacon , Jayachandran Chandrasekharan Nair , Linus Torvalds , linux-arm-kernel@lists.infradead.org Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+infradead-linux-arm-kernel=archiver.kernel.org@lists.infradead.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 _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel