Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp6479824rwb; Tue, 22 Nov 2022 14:06:30 -0800 (PST) X-Google-Smtp-Source: AA0mqf5FcqslpLzyDafGDIzfACGt4jPzbDOI2cbfq4vzn6/Go+LmlPvDl98hraQdGRnHddffbNO+ X-Received: by 2002:a17:90a:67c1:b0:212:d484:b410 with SMTP id g1-20020a17090a67c100b00212d484b410mr33989403pjm.211.1669154790013; Tue, 22 Nov 2022 14:06:30 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669154790; cv=none; d=google.com; s=arc-20160816; b=dpI8v1GHNy6K6l+zbuiJcUlcvDSJfHRRWzTchOH4RlN/JxJjBGTem0p+Fnb0q8wfZP Zhb2SMlu6hJsWch4CY9TX4ujq7HcibDqUltwiMkIetZqyROQQjyGtI42WlqIf61UjgL1 a4tUmuFEs+TInat+UEs4iI4+97xX/Xbat+NvmRUkRghs0AH0XEFWTNDme0kAvHLkg+sV mWpUiLhc/xCDEhK19Y1d8Uadu0j7ZZCGRYO2qSYiJprajaJSCiSnPTwWHVxMvUYfy1IN 9bc4B2fXNPh/owagai1YNXLnwZBo76NwmYzbMo2FJm3561wIfNfRYWqtQrPTAjib4ne7 0IIQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:subject:cc:to:from:date; bh=DgqiUc72TxeGMz/F2S86GK20SBvCJrT+b9WGlTP07+I=; b=yxVLMsq6GyONCY2trJ2j2ffRsWztBNkplrEwLu6uRCVUstm8lbFbAl84CLzjPgPGGC mIZEO8kwjiTXNfokNjCOxSPPWjeKTm3YJy6RGjlM3uVs8tkAIO2p2I0RSVg4n/2C6fxw 0huDu9z1I8pnHJORLjsNcshKhSzv+vcQ/UrpN0oU5sLRPYaTKo8kDvwtLtzrrS9jMETG Igz8/Jj6L54JtUmHcDI8Zx3fy+zml7FNO4gryfiofn33doE5dYg03eD1TkgemlnCoyRr CYNU05v7bSQTPMqrSEfYlRuCamGsr0c3wHJLcFEDq+cUarT/nz1TklP3tnXE3VxYUwM6 /kMQ== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id h18-20020a656392000000b00476c94abbc5si15304390pgv.681.2022.11.22.14.06.17; Tue, 22 Nov 2022 14:06:29 -0800 (PST) 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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234718AbiKVVOx (ORCPT + 89 others); Tue, 22 Nov 2022 16:14:53 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42264 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232491AbiKVVOv (ORCPT ); Tue, 22 Nov 2022 16:14:51 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CD85B2EF78 for ; Tue, 22 Nov 2022 13:14:49 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 251A3618D9 for ; Tue, 22 Nov 2022 21:14:49 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id C6FECC433D6; Tue, 22 Nov 2022 21:14:47 +0000 (UTC) Date: Tue, 22 Nov 2022 16:14:46 -0500 From: Steven Rostedt To: Uros Bizjak Cc: linux-kernel@vger.kernel.org, Peter Zijlstra , Josh Poimboeuf , Jason Baron , Ard Biesheuvel Subject: Re: [PATCH] jump_label: use atomic_try_cmpxchg in static_key_slow_inc_cpuslocked Message-ID: <20221122161446.28907755@gandalf.local.home> In-Reply-To: <20221019140850.3395-1-ubizjak@gmail.com> References: <20221019140850.3395-1-ubizjak@gmail.com> X-Mailer: Claws Mail 3.17.8 (GTK+ 2.24.33; x86_64-pc-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-6.7 required=5.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,RCVD_IN_DNSWL_HI,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 On Wed, 19 Oct 2022 16:08:50 +0200 Uros Bizjak wrote: > 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. > > Cc: Peter Zijlstra > Cc: Josh Poimboeuf > Cc: Jason Baron > Cc: Steven Rostedt > Cc: Ard Biesheuvel > Signed-off-by: Uros Bizjak > --- > 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 714ac4c3b556..4d6c6f5f60db 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; ) Although it's permitted by the compiler, the kernel style is to not add declarations in conditionals. Please keep the "int v;" at the beginning. > + if (likely(atomic_try_cmpxchg(&key->enabled, &v, v + 1))) I'm fine with this change. -- Steve > return; > - } > > jump_label_lock(); > if (atomic_read(&key->enabled) == 0) {