Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp3330209yba; Sun, 28 Apr 2019 23:42:52 -0700 (PDT) X-Google-Smtp-Source: APXvYqzi8cakM+GzfIf+GUUv8b+XPGsTnzXAcnI2VE6UZWipcMGqv+F4lE4KD3MKhqq9ie1ElXkJ X-Received: by 2002:a17:902:868e:: with SMTP id g14mr43390074plo.183.1556520172117; Sun, 28 Apr 2019 23:42:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1556520172; cv=none; d=google.com; s=arc-20160816; b=jJSm7dFKusJ5ktOTPaECv59x4OO0b4tTIBKftQ982OK+/zYfNODIJGqKhoc2HZ/w3r fm6172UDOV7xjmU3X6hAktJt5KKmzGCUbq8DpBzhyjlNAsjdb1HjC8LNtJf/HlpBgmwA bHnGW5qMWmtLvS9t86XBzlGLR7VwFr2tloKOVDyOrUKs+fHPCeZMLV8WDvPgPuBueT6F KGvSODg5zP0DcAtOE22xqO1RhDpZNb0Ac/UjPmCs40WCfvJ/z/G2/l2pb2YrPdX1gkyI BEwt/fY7ZH/zHGnY2l1pj8wSRUwyDe+SMNCtopCi0VNkYvrVNJnHfsqvjzzJ6T5PgLBU K+DA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-disposition :content-transfer-encoding:mime-version:robot-unsubscribe:robot-id :git-commit-id:subject:to:references:in-reply-to:reply-to:cc :message-id:from:date:dkim-signature:dkim-filter; bh=qcDvF/824BNWLAG3lmtXcJpnih50CQefhcIgfq+xZqQ=; b=xNDXgWNsahr5grmYHHkSb8DQDWiMCcOsauCGb3CucsZWPuJC25CBG9ektpKh7TdHll KQQ6F9G/OsWXU5iqcR1ko6fOx8y9hYUViWLQqm++MX4726q28bIfuC2r9cg36Fsie7BB tWyiHTzbNWL6FVS7NglB4nxD5O+FaoP2pkAEdury4VIPzKluei2nzaTBAxGglttCTMUH VYJ8C0OpZP6455/Oy64XjPftrIADYvvG0hIc8HO5W+tsYIuN0VMPiuK2QNniogcXI01e Jfaje8W4H8iPKPqsqHyDMEhmU757DVZIfgWvvLwZhugAZEZEIpvYNCEMSNOjbVejW3qH GcFQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@zytor.com header.s=2019041745 header.b=Y2+blOIV; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=zytor.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id o9si17268160pgp.35.2019.04.28.23.42.36; Sun, 28 Apr 2019 23:42:52 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@zytor.com header.s=2019041745 header.b=Y2+blOIV; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=zytor.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727472AbfD2Gld (ORCPT + 99 others); Mon, 29 Apr 2019 02:41:33 -0400 Received: from terminus.zytor.com ([198.137.202.136]:51183 "EHLO terminus.zytor.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726712AbfD2Glc (ORCPT ); Mon, 29 Apr 2019 02:41:32 -0400 Received: from terminus.zytor.com (localhost [127.0.0.1]) by terminus.zytor.com (8.15.2/8.15.2) with ESMTPS id x3T6fGVF784582 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NO); Sun, 28 Apr 2019 23:41:16 -0700 DKIM-Filter: OpenDKIM Filter v2.11.0 terminus.zytor.com x3T6fGVF784582 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=zytor.com; s=2019041745; t=1556520077; bh=qcDvF/824BNWLAG3lmtXcJpnih50CQefhcIgfq+xZqQ=; h=Date:From:Cc:Reply-To:In-Reply-To:References:To:Subject:From; b=Y2+blOIVzVD0af8CVM19FvoUjrk1nrXbef8KRAXXG9DSsaKYN7f5GQ0VaXWVADtgE +xz1G2Zc7526vXS4cuI0aNBYesx7jyZexbEwwG21wyuOtqlGvs0esRlPXVtbflo9YU XvSy8/pi3k0oZ3sEX4KzCbet2qCiyjM9mJHBLg/hIZOY6lCLxgBoBxnAeZHriRWZpl PWc0TB5gXnQz3Ub7jatM8nXEbZMwlDohuVYs4VVqwDm/h8bsViW+2Ni30OTiCB2Wb6 kXOGURHs5ZJ+IGCLoGIXgRJRjm3XnQhjovKotxta1z0aStayPzl8D0XmGotm7pTKb2 504YrToZrJwcQ== Received: (from tipbot@localhost) by terminus.zytor.com (8.15.2/8.15.2/Submit) id x3T6fFgn784577; Sun, 28 Apr 2019 23:41:16 -0700 Date: Sun, 28 Apr 2019 23:41:16 -0700 X-Authentication-Warning: terminus.zytor.com: tipbot set sender to tipbot@zytor.com using -f From: tip-bot for Jakub Kicinski Message-ID: Cc: tglx@linutronix.de, mingo@kernel.org, linux-kernel@vger.kernel.org, paulmck@linux.vnet.ibm.com, simon.horman@netronome.com, peterz@infradead.org, will.deacon@arm.com, hpa@zytor.com, jakub.kicinski@netronome.com, torvalds@linux-foundation.org, akpm@linux-foundation.org Reply-To: simon.horman@netronome.com, paulmck@linux.vnet.ibm.com, linux-kernel@vger.kernel.org, peterz@infradead.org, tglx@linutronix.de, mingo@kernel.org, akpm@linux-foundation.org, torvalds@linux-foundation.org, will.deacon@arm.com, jakub.kicinski@netronome.com, hpa@zytor.com In-Reply-To: <20190330000854.30142-3-jakub.kicinski@netronome.com> References: <20190330000854.30142-3-jakub.kicinski@netronome.com> To: linux-tip-commits@vger.kernel.org Subject: [tip:locking/core] locking/static_key: Factor out the fast path of static_key_slow_dec() Git-Commit-ID: b92e793bbe4a1c49dbf78d8d526561e7a7dd568a X-Mailer: tip-git-log-daemon Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset=UTF-8 Content-Disposition: inline X-Spam-Status: No, score=-3.1 required=5.0 tests=ALL_TRUSTED,BAYES_00, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, T_DATE_IN_FUTURE_96_Q autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on terminus.zytor.com Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Commit-ID: b92e793bbe4a1c49dbf78d8d526561e7a7dd568a Gitweb: https://git.kernel.org/tip/b92e793bbe4a1c49dbf78d8d526561e7a7dd568a Author: Jakub Kicinski AuthorDate: Fri, 29 Mar 2019 17:08:53 -0700 Committer: Ingo Molnar CommitDate: Mon, 29 Apr 2019 08:29:21 +0200 locking/static_key: Factor out the fast path of static_key_slow_dec() static_key_slow_dec() checks if the atomic enable count is larger than 1, and if so there decrements it before taking the jump_label_lock. Move this logic into a helper for reuse in rate limitted keys. Signed-off-by: Jakub Kicinski Signed-off-by: Peter Zijlstra (Intel) Reviewed-by: Simon Horman Cc: Andrew Morton Cc: Linus Torvalds Cc: Paul E. McKenney Cc: Peter Zijlstra Cc: Thomas Gleixner Cc: Will Deacon Cc: alexei.starovoitov@gmail.com Cc: ard.biesheuvel@linaro.org Cc: oss-drivers@netronome.com Cc: yamada.masahiro@socionext.com Link: https://lkml.kernel.org/r/20190330000854.30142-3-jakub.kicinski@netronome.com Signed-off-by: Ingo Molnar --- kernel/jump_label.c | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/kernel/jump_label.c b/kernel/jump_label.c index 73bbbaddbd9c..02c3d11264dd 100644 --- a/kernel/jump_label.c +++ b/kernel/jump_label.c @@ -202,13 +202,13 @@ void static_key_disable(struct static_key *key) } EXPORT_SYMBOL_GPL(static_key_disable); -static void __static_key_slow_dec_cpuslocked(struct static_key *key, - unsigned long rate_limit, - struct delayed_work *work) +static bool static_key_slow_try_dec(struct static_key *key) { int val; - lockdep_assert_cpus_held(); + val = atomic_fetch_add_unless(&key->enabled, -1, 1); + if (val == 1) + return false; /* * The negative count check is valid even when a negative @@ -217,11 +217,18 @@ static void __static_key_slow_dec_cpuslocked(struct static_key *key, * returns is unbalanced, because all other static_key_slow_inc() * instances block while the update is in progress. */ - val = atomic_fetch_add_unless(&key->enabled, -1, 1); - if (val != 1) { - WARN(val < 0, "jump label: negative count!\n"); + WARN(val < 0, "jump label: negative count!\n"); + return true; +} + +static void __static_key_slow_dec_cpuslocked(struct static_key *key, + unsigned long rate_limit, + struct delayed_work *work) +{ + lockdep_assert_cpus_held(); + + if (static_key_slow_try_dec(key)) return; - } jump_label_lock(); if (atomic_dec_and_test(&key->enabled)) {