[tip:,locking/core] locking/atomics: Use atomic_try_cmpxchg_release() to micro-optimize rcuref_put_slowpath()
Message ID | 169692642491.3135.15300727916265365839.tip-bot2@tip-bot2 |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2908:b0:403:3b70:6f57 with SMTP id ib8csp41463vqb; Tue, 10 Oct 2023 01:28:16 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHuOMTVb3SLOnf2pXYxBQwebzmnae2rozMQMLsz1sk2zr28fy9sXt3t4LpkiyZBVdIAXm50 X-Received: by 2002:a05:6a00:2d1e:b0:68f:bb16:d16a with SMTP id fa30-20020a056a002d1e00b0068fbb16d16amr24694593pfb.5.1696926495832; Tue, 10 Oct 2023 01:28:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696926495; cv=none; d=google.com; s=arc-20160816; b=YjKIi2g3LyOjrpDyPrnPwmeyZoScBwm+h8QEtFMH7uCPAlqQSM1ZwZylyWV37MX1tH lzYhvG71Q9hE5NMh9/qnHDywan7NW39e+1Y1WO5OZUhy214eTgjo3phcr6FZr2A5ORuv usteN/Mv07pOa7q6U1Kg/ypqDoDR45Zq5QZHF09Ux9rVlLWTMWdMByQU9BTeVdRwhDYD u96pJXvaP9tFiaZV+xX3t25b/nrBG5kzZUNmer6qu8AscuYkuwaWXnzY5ya1RKyctXx9 V+bfhnw7gSwnLd+mVZalPjBdr8OrZPmupILT/EFiY/3suSbMc6nOApQ4dN0VwzI0aFDs q45A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:robot-unsubscribe :robot-id:message-id:mime-version:references:in-reply-to:cc:subject :to:reply-to:sender:from:dkim-signature:dkim-signature:date; bh=pNbc6lLzsql6snug0HQa1mxk/kzC8m7f+xiIcj20Lyo=; fh=n6srHf5u4Dk7ImzYzzB/+TUVyoo/czuCLFTz3AfPh5g=; b=SU/uFfGyevnVmBmlIkK9benBmgaQGr0Leq6YnHLbUnYGlNPe8KOyIo4FShhHUTmr2Y AlOm6F2AFwscIOHDUWtQbO83v0AnnfbC2eiLoPDPahhLmg4kvP4kcI4h5EPXLQrQukwO Nou3byPBCjquBdwwvF9ag6So28tmCelrINmtBNq0yjETKlGdmGiQQu2/IKaIqXJDL2au x5/EgLXJUBgJFK2qhi2kETi7YCnkS6W+U3qCBqGr/R/1m+1QyPpmwxZg1+fTgAQ0K6ju m79PueJl1SJAjj3jYHoYekhD4gyCsKHflyozhngG3UNr0a7rwIzRCDkiZSD5gy0NyErI GOUQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b="jjk/Std8"; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b="o8q/0BKh"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:6 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from pete.vger.email (pete.vger.email. [2620:137:e000::3:6]) by mx.google.com with ESMTPS id k28-20020a63ba1c000000b00588fa0def25si11128329pgf.797.2023.10.10.01.28.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Oct 2023 01:28:15 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:6 as permitted sender) client-ip=2620:137:e000::3:6; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b="jjk/Std8"; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b="o8q/0BKh"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:6 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by pete.vger.email (Postfix) with ESMTP id 7DA3480924B7; Tue, 10 Oct 2023 01:28:13 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at pete.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1442640AbjJJI1R (ORCPT <rfc822;rua109.linux@gmail.com> + 20 others); Tue, 10 Oct 2023 04:27:17 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59196 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1442824AbjJJI1K (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Tue, 10 Oct 2023 04:27:10 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C40FB107; Tue, 10 Oct 2023 01:27:07 -0700 (PDT) Date: Tue, 10 Oct 2023 08:27:04 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1696926425; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=pNbc6lLzsql6snug0HQa1mxk/kzC8m7f+xiIcj20Lyo=; b=jjk/Std83BJkeIWWgFLY87BoVtjAp+nGXoKw+esUF7jh9w0xLYWuD71Aovoqwz+3zCKBFd ae6xwOCeTLh5m9ROVQEPH97PMAqxfGbOEAcwV60UjqB35cDnBlq3hR9AAi94tn2kj7XHON vHbzJlTWRoBtVsqTUxZGFgdGSp1R77dzhRg9oOn71ArhVfXNEIv4MOA1k3dLYP8DAHDHK1 e4MAuHCrKOr9TyxmFjDx1jiMtSxM0RHwvr5fLHZCT0ADIsf53U0RJMQWAdH5aF/VI8+ngA GoU1QT9Vm+3E6qd/mlzPwqEc2r+spydF3M0lmXalLK1Ca8TWBMF/Ovc2PmOUtA== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1696926425; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=pNbc6lLzsql6snug0HQa1mxk/kzC8m7f+xiIcj20Lyo=; b=o8q/0BKhL6U+WadtrCgQLm20NqhAKcrWI58CKcS0uoxHu08QrdEMyOYDygQR0IHgkP2n05 VuuBOkVB1gQgvbCg== From: "tip-bot2 for Uros Bizjak" <tip-bot2@linutronix.de> Sender: tip-bot2@linutronix.de Reply-to: linux-kernel@vger.kernel.org To: linux-tip-commits@vger.kernel.org Subject: [tip: locking/core] locking/atomics: Use atomic_try_cmpxchg_release() to micro-optimize rcuref_put_slowpath() Cc: Uros Bizjak <ubizjak@gmail.com>, Ingo Molnar <mingo@kernel.org>, Peter Zijlstra <peterz@infradead.org>, "Paul E. McKenney" <paulmck@kernel.org>, x86@kernel.org, linux-kernel@vger.kernel.org In-Reply-To: <20230509150255.3691-1-ubizjak@gmail.com> References: <20230509150255.3691-1-ubizjak@gmail.com> MIME-Version: 1.0 Message-ID: <169692642491.3135.15300727916265365839.tip-bot2@tip-bot2> Robot-ID: <tip-bot2@linutronix.de> Robot-Unsubscribe: Contact <mailto:tglx@linutronix.de> to get blacklisted from these emails Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=2.7 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, RCVD_IN_SBL_CSS,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on pete.vger.email Precedence: bulk List-ID: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (pete.vger.email [0.0.0.0]); Tue, 10 Oct 2023 01:28:13 -0700 (PDT) X-Spam-Level: ** X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1779356397631886468 X-GMAIL-MSGID: 1779356397631886468 |
Series |
[tip:,locking/core] locking/atomics: Use atomic_try_cmpxchg_release() to micro-optimize rcuref_put_slowpath()
|
|
Commit Message
tip-bot2 for Thomas Gleixner
Oct. 10, 2023, 8:27 a.m. UTC
The following commit has been merged into the locking/core branch of tip: Commit-ID: 4fbf8b136ded943f8661cf48270482ad1f5ce7bd Gitweb: https://git.kernel.org/tip/4fbf8b136ded943f8661cf48270482ad1f5ce7bd Author: Uros Bizjak <ubizjak@gmail.com> AuthorDate: Tue, 09 May 2023 17:02:55 +02:00 Committer: Ingo Molnar <mingo@kernel.org> CommitterDate: Tue, 10 Oct 2023 10:14:27 +02:00 locking/atomics: Use atomic_try_cmpxchg_release() to micro-optimize rcuref_put_slowpath() Use atomic_try_cmpxchg() instead of atomic_cmpxchg(*ptr, old, new) == old in rcuref_put_slowpath(). On x86 the CMPXCHG instruction returns success in the ZF flag, so this change saves a compare after CMPXCHG. Additionaly, the compiler reorders some code blocks to follow likely/unlikely annotations in the atomic_try_cmpxchg() macro, improving the code from: 9a: f0 0f b1 0b lock cmpxchg %ecx,(%rbx) 9e: 83 f8 ff cmp $0xffffffff,%eax a1: 74 04 je a7 <rcuref_put_slowpath+0x27> a3: 31 c0 xor %eax,%eax to: 9a: f0 0f b1 0b lock cmpxchg %ecx,(%rbx) 9e: 75 4c jne ec <rcuref_put_slowpath+0x6c> a0: b0 01 mov $0x1,%al No functional change intended. Signed-off-by: Uros Bizjak <ubizjak@gmail.com> Signed-off-by: Ingo Molnar <mingo@kernel.org> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Paul E. McKenney <paulmck@kernel.org> Link: https://lore.kernel.org/r/20230509150255.3691-1-ubizjak@gmail.com --- lib/rcuref.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/lib/rcuref.c b/lib/rcuref.c index 5ec00a4..97f300e 100644 --- a/lib/rcuref.c +++ b/lib/rcuref.c @@ -248,7 +248,7 @@ bool rcuref_put_slowpath(rcuref_t *ref) * require a retry. If this fails the caller is not * allowed to deconstruct the object. */ - if (atomic_cmpxchg_release(&ref->refcnt, RCUREF_NOREF, RCUREF_DEAD) != RCUREF_NOREF) + if (!atomic_try_cmpxchg_release(&ref->refcnt, &cnt, RCUREF_DEAD)) return false; /*