Received: by 2002:a05:7412:da14:b0:e2:908c:2ebd with SMTP id fe20csp2365390rdb; Tue, 10 Oct 2023 01:27:54 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGgNEo0mobK7fYxx0oSX6p29B7KAs60VimgqYwFVaEu5NmwT9QlqXiskZ6jEo14nlcZxxbE X-Received: by 2002:a17:902:c946:b0:1c8:7bb8:321a with SMTP id i6-20020a170902c94600b001c87bb8321amr18973112pla.27.1696926474653; Tue, 10 Oct 2023 01:27:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696926474; cv=none; d=google.com; s=arc-20160816; b=JZRiDShB1NVIqUL3eDQG8UTktW6L747TIrlVkwmZjCwot2hQDaq1xLxHagEdlUTk39 qktctgzskP0H/KPoN2xMtNf+hnCDTyMfx8qkEH6EOR50a9zDNqbaQyJHpWxl+yKQcbx7 aBAydowlp29zuScN7GyZPIZyDC9TqU81LZKvaQNTixEC8wZrq3+3I7HzTutCJe+TA3y4 6gdqdRYEa33VTRjiZ2dWq1j7ewDtTVuqyoWaD0RByQUZmtCZr7tqKPtk2GwlWZ9moLM/ 5BoK4PfihMo3IfBXTa8nZQkUp1gJ8H5sxlBDmFB31y7W+O5U/sjL7UUQuWodLZJknLli oPVg== 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; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Return-Path: Received: from pete.vger.email (pete.vger.email. [23.128.96.36]) by mx.google.com with ESMTPS id bv3-20020a632e03000000b0057745d87b50si8789100pgb.139.2023.10.10.01.27.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Oct 2023 01:27:54 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 as permitted sender) client-ip=23.128.96.36; 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; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 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 DFC1B80239B4; Tue, 10 Oct 2023 01:27:46 -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 S1442810AbjJJI1R (ORCPT + 99 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 ); 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" 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 , Ingo Molnar , Peter Zijlstra , "Paul E. McKenney" , 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: Robot-Unsubscribe: Contact 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: 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:27:47 -0700 (PDT) X-Spam-Level: ** 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 AuthorDate: Tue, 09 May 2023 17:02:55 +02:00 Committer: Ingo Molnar 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 a3: 31 c0 xor %eax,%eax to: 9a: f0 0f b1 0b lock cmpxchg %ecx,(%rbx) 9e: 75 4c jne ec a0: b0 01 mov $0x1,%al No functional change intended. Signed-off-by: Uros Bizjak Signed-off-by: Ingo Molnar Cc: Peter Zijlstra Cc: Paul E. McKenney 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; /*