From patchwork Fri Oct 28 06:41:32 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: tip-bot2 for Thomas Gleixner X-Patchwork-Id: 12091 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp658537wru; Thu, 27 Oct 2022 23:42:59 -0700 (PDT) X-Google-Smtp-Source: AMsMyM5gMsELAZM/no4644x49kvlhlVfvpSt6zjMwYoAwt4cVF6ovTqXU2m/7/8KxtFIRuPgf/9i X-Received: by 2002:a17:90b:3b4c:b0:213:f05:6a8 with SMTP id ot12-20020a17090b3b4c00b002130f0506a8mr14340138pjb.108.1666939378869; Thu, 27 Oct 2022 23:42:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666939378; cv=none; d=google.com; s=arc-20160816; b=wNMLStnLGOcHA6GdJPFQiwkPhWkLZQLYj72UVayv3oh+oWhOwubp28A1GR+lRyi0rC DWYxo4/3JJzzsseZd90JRuP0YRwtWOqDWCkleaBnw3k0+ev1Ad5bHJW9Fbwdt56/8nhh DoxqFwWy3Dpy8/bSeYcwo1S7XT8xs4+xODwYSOYvV/CETUlu2utfCRD3elVocmDCNmU0 qUIiZws5NnEnU7Tyjvpokhf3LJuuqeEgW3Qad0j9eepzUQdXpGV7NxOIxOZ9AfKzHiwd 4YWoTnYxLMIwgI0mDQFoSDNhJokxB406WDPZTO/YX0ZEQRsg2ykJHvIB8/4hma1uZwP/ SJGA== 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=418PeG1m3KiESUjrABGHYXcYvntC5lkqgItingIMeP8=; b=eF76pkM4uBGd7tGB/wFZRTRSydJez6JKKphagEknyiTHaQWsnyLuw70JeidQsxCVmi RIA7CpdKFtofufdS1jLfGrrWrzKf64zqPKUSf5OIFm3to6IKKe/Rp32bqC7+QRLQM+l8 Uh/DdMO9+6TiaafTklsj6q9HfC+ECEcVmpnsrGNZbvtOdgcStg7mW0AzgJJoCIwq510G lk6VJKC1x5MNGx9NLVNWlW/cmZQRPXpC8qgMPa7a/gItUQ6hUR7PqSrnho/8CcrNCBrS EGHyAzmwFSnOwV8dtiG7fdBXKHwqFlZltL6GKskvnuf4kn5ZVKkYS9RLbOrwyU0fgX5m ilfA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=m4blkYTV; dkim=neutral (no key) header.i=@linutronix.de header.b=QIBf+Z9P; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id d22-20020a056a0024d600b0055fc3dedac1si4660209pfv.381.2022.10.27.23.42.45; Thu, 27 Oct 2022 23:42:58 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=m4blkYTV; dkim=neutral (no key) header.i=@linutronix.de header.b=QIBf+Z9P; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229850AbiJ1GmH (ORCPT + 99 others); Fri, 28 Oct 2022 02:42:07 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51980 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229755AbiJ1Glj (ORCPT ); Fri, 28 Oct 2022 02:41:39 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 70D8DB1DCD; Thu, 27 Oct 2022 23:41:35 -0700 (PDT) Date: Fri, 28 Oct 2022 06:41:32 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1666939293; 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=418PeG1m3KiESUjrABGHYXcYvntC5lkqgItingIMeP8=; b=m4blkYTVRISE9h01oLV9GZUua+GHJSmoj6X8r/1p1W+1fbMc9IKf3uAtgW3I4Bno4/kJNS MV/vaB2Cc/6LU+6/q/+Nn7am/k6Sz/du4Y8Le+i9t8dr9vwueyRPYkf5pgnvABnYfPGXYy x8fo+Jpo6xNUtJJhwqgxF8WS+mwJ2Plb0Hq8o1lfijpRXqJ0TpIgD4ypqtqxQJ7HJfhcQn xlTK8sFn/uZqStU01ycqfdmgzTSJ/Pp3+YTDYg9Z5iacuNLGrC8UbaUNK2/IrULUcEXHDd 6RQ8tEAIkkPHCh0X7g1lmqeG5sdOy4BggHNNZEnImM+ZMo94xvknM9aY3KDrlw== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1666939293; 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=418PeG1m3KiESUjrABGHYXcYvntC5lkqgItingIMeP8=; b=QIBf+Z9PgrlliPNlwsv+LK5jWP/olRmOyprkpIRaJhXg9HRsgMmmS2/b82RNhds8adi44m nn3I74QEhvCXm8Dw== 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] jump_label: Use atomic_try_cmpxchg() in static_key_slow_inc_cpuslocked() Cc: Uros Bizjak , "Peter Zijlstra (Intel)" , x86@kernel.org, linux-kernel@vger.kernel.org In-Reply-To: <20221019140850.3395-1-ubizjak@gmail.com> References: <20221019140850.3395-1-ubizjak@gmail.com> MIME-Version: 1.0 Message-ID: <166693929232.29415.8209039784382977219.tip-bot2@tip-bot2> Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1747912626038051905?= X-GMAIL-MSGID: =?utf-8?q?1747912626038051905?= The following commit has been merged into the locking/core branch of tip: Commit-ID: d0c006402e7941558e5283ae434e2847c7999378 Gitweb: https://git.kernel.org/tip/d0c006402e7941558e5283ae434e2847c7999378 Author: Uros Bizjak AuthorDate: Wed, 19 Oct 2022 16:08:50 +02:00 Committer: Peter Zijlstra CommitterDate: Thu, 27 Oct 2022 10:35:41 +02:00 jump_label: Use atomic_try_cmpxchg() in static_key_slow_inc_cpuslocked() Use atomic_try_cmpxchg() instead of atomic_cmpxchg (*ptr, old, new) == old in static_key_slow_inc_cpuslocked(). x86 CMPXCHG instruction returns success in ZF flag, so this change saves a compare after cmpxchg (and related move instruction in front of cmpxchg). Also, atomic_try_cmpxchg() implicitly assigns old *ptr value to "old" when cmpxchg fails, enabling further code simplifications. No functional change intended. Signed-off-by: Uros Bizjak Signed-off-by: Peter Zijlstra (Intel) Link: https://lkml.kernel.org/r/20221019140850.3395-1-ubizjak@gmail.com --- kernel/jump_label.c | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/kernel/jump_label.c b/kernel/jump_label.c index 714ac4c..4d6c6f5 100644 --- a/kernel/jump_label.c +++ b/kernel/jump_label.c @@ -115,8 +115,6 @@ EXPORT_SYMBOL_GPL(static_key_count); void static_key_slow_inc_cpuslocked(struct static_key *key) { - int v, v1; - STATIC_KEY_CHECK_USE(key); lockdep_assert_cpus_held(); @@ -132,11 +130,9 @@ void static_key_slow_inc_cpuslocked(struct static_key *key) * so it counts as "enabled" in jump_label_update(). Note that * atomic_inc_unless_negative() checks >= 0, so roll our own. */ - for (v = atomic_read(&key->enabled); v > 0; v = v1) { - v1 = atomic_cmpxchg(&key->enabled, v, v + 1); - if (likely(v1 == v)) + for (int v = atomic_read(&key->enabled); v > 0; ) + if (likely(atomic_try_cmpxchg(&key->enabled, &v, v + 1))) return; - } jump_label_lock(); if (atomic_read(&key->enabled) == 0) {