Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp4541090ybl; Sat, 21 Dec 2019 08:39:39 -0800 (PST) X-Google-Smtp-Source: APXvYqzKrmPrKR4CdaAeSk7AfsSMSMrwTrMv5oJHSIlT5exJNqSz/RzgKWe+zWOsXqzUdI+70pzs X-Received: by 2002:a9d:133:: with SMTP id 48mr21121496otu.15.1576946379682; Sat, 21 Dec 2019 08:39:39 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1576946379; cv=none; d=google.com; s=arc-20160816; b=okFu7MhGLuhIlVcXl2sxDuWPG21VCt4H3goEkqfH9/LiXgdsYmD1AZn3qQlozUL4NQ hfZ4b87D3vcW+83HMNrN5CpV7uVK/RzW4QHYdkl1CzM/Bn+dS5yoYnpsvKEiHU4WgyZB NYpqYBY3GWs5H6QRddy2nsI0s0N1cq8pqlsnXIBVeOSZIRzMEr8L0H/HGE4XnJYox3gm S2IepTHg4gkt3W3nbc2gdLk3Jbv3xWOvQpkKrXRg8BtPF8KwgFvLOE93y39+uHfRO0Ji A0mRMFhQ9FJTRG9hTFht4SGTApvzlR2firJhbCzPoIsWMW6AQho4AAMTWhjH/A1v37TB PlxA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=Ncxg9b/1MfJvBW44JauWnlBevZqV28zJC8M4jJXK7AU=; b=XoTBTicCykUV7YVmwbm/yb0Frx8ZTCunN4Ah6ZCgh4DRmZlod4yHn8lXmPCcUqvwZm WfM5ecDjun+/U1RGD3nqYaWz+GZuuP6m+y5rBou5dwGPmvznhFPqqqfXbIU96rv5jxmT edl01/YcKsemxjdid7mmIci0m8uE+MY/oY2mZUXxX4WB2yX2knGan0XR6cRlx4ZTfriE 93KLAziCvQv28ydklAjcg3dtId668vo6qah6HiHBS4b0HbWznLq0ma8xjKLgt6h72jS9 GzMBszFrM0QBUFLIU6aFo5MNurdjUyY5V66jXPmdwF+1skhcJsbjucAWhkmBwBGhEWrY ZkrQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=FvbhtHCQ; 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=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id j3si363871otn.154.2019.12.21.08.39.19; Sat, 21 Dec 2019 08:39:39 -0800 (PST) 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=@gmail.com header.s=20161025 header.b=FvbhtHCQ; 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=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727029AbfLUQPz (ORCPT + 99 others); Sat, 21 Dec 2019 11:15:55 -0500 Received: from mail-wr1-f68.google.com ([209.85.221.68]:46502 "EHLO mail-wr1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726319AbfLUQPz (ORCPT ); Sat, 21 Dec 2019 11:15:55 -0500 Received: by mail-wr1-f68.google.com with SMTP id z7so12252743wrl.13; Sat, 21 Dec 2019 08:15:53 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=Ncxg9b/1MfJvBW44JauWnlBevZqV28zJC8M4jJXK7AU=; b=FvbhtHCQgtXGCh0eEOrpAGnUQAHGTua77oXGFZMlB/Knx7xIX4j1W+VcsDf0DQDD3b gzE1/AAo9arZxTvFR+aL5S0jhkYSkLRD3bhg9dc4V0Hm9gN9qxprcfx8PdBhrm+7nXgP ArEQ7o3eXDa19NMivu5L6x9rQYe5KP+qoS/GluYXLi5aw/DUmb9dv7t9npAd+MzsUpwz 2vOiegH0NDh/1AVZEBgdpVZBhWB2H3Ap6+5kDewD72EWC41sFqTlxj0QXrgZ5ILr/3KF KyRgvFq6eeUcQpUzC7GlVL09mn5wQZ0VywvnNMfOBTjIl6eVJ1TyGKKs6/84qPOzlYts CDBQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=Ncxg9b/1MfJvBW44JauWnlBevZqV28zJC8M4jJXK7AU=; b=q8X/+UvVVxBDrxJAe9lHq5QNRUwG9Vv0f116zHZCKNzVOUgtTDJ8gBsQCDSLd/29u8 +iEAmzbftdNPMrPoXTgsNnkIS8FQkgqqcmWh14J2dqUkKfCkUcfodV06GcE10I87GPqN DfQ+YY45VYRCnfh30vuYwRxfpIUpIJGdjcjVhilEbuciNLouAyUkomYls15imM7cx/oE seIBiOmGySV08AncOx2HWhAbWjYKEiRK69iZjKM4mx8ZpqfAfF1ITbntxUIQlhavNF2G Xe/G0R6F8lYYnFwkjbzX1HAMinHk1uF0A3zpcYi74tn39pEgOxz4lMEK4KfiwxO1hiC6 ++2g== X-Gm-Message-State: APjAAAWkszYnsIZRr40wqAHE5oKbY2+qRMKLuZ2AR+c7iRWzLicRV59U c+sLl2kDegUBH8Z3IMW3K2kIfdrY X-Received: by 2002:adf:c147:: with SMTP id w7mr22034564wre.389.1576944953116; Sat, 21 Dec 2019 08:15:53 -0800 (PST) Received: from localhost.localdomain ([109.126.149.134]) by smtp.gmail.com with ESMTPSA id o129sm13831260wmb.1.2019.12.21.08.15.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 21 Dec 2019 08:15:52 -0800 (PST) From: Pavel Begunkov To: Jens Axboe , io-uring@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Tejun Heo , Dennis Zhou , Christoph Lameter Subject: [PATCH v2 1/3] pcpu_ref: add percpu_ref_tryget_many() Date: Sat, 21 Dec 2019 19:15:07 +0300 Message-Id: <8f663b99e6f30dc51d41456771d4a94567ab31f4.1576944502.git.asml.silence@gmail.com> X-Mailer: git-send-email 2.24.0 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Add percpu_ref_tryget_many(), which works the same way as percpu_ref_tryget(), but grabs specified number of refs. Signed-off-by: Pavel Begunkov Acked-by: Tejun Heo Acked-by: Dennis Zhou Cc: Christoph Lameter --- include/linux/percpu-refcount.h | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/include/linux/percpu-refcount.h b/include/linux/percpu-refcount.h index 390031e816dc..22d9d183950d 100644 --- a/include/linux/percpu-refcount.h +++ b/include/linux/percpu-refcount.h @@ -210,15 +210,17 @@ static inline void percpu_ref_get(struct percpu_ref *ref) } /** - * percpu_ref_tryget - try to increment a percpu refcount + * percpu_ref_tryget_many - try to increment a percpu refcount * @ref: percpu_ref to try-get + * @nr: number of references to get * - * Increment a percpu refcount unless its count already reached zero. + * Increment a percpu refcount by @nr unless its count already reached zero. * Returns %true on success; %false on failure. * * This function is safe to call as long as @ref is between init and exit. */ -static inline bool percpu_ref_tryget(struct percpu_ref *ref) +static inline bool percpu_ref_tryget_many(struct percpu_ref *ref, + unsigned long nr) { unsigned long __percpu *percpu_count; bool ret; @@ -226,10 +228,10 @@ static inline bool percpu_ref_tryget(struct percpu_ref *ref) rcu_read_lock(); if (__ref_is_percpu(ref, &percpu_count)) { - this_cpu_inc(*percpu_count); + this_cpu_add(*percpu_count, nr); ret = true; } else { - ret = atomic_long_inc_not_zero(&ref->count); + ret = atomic_long_add_unless(&ref->count, nr, 0); } rcu_read_unlock(); @@ -237,6 +239,20 @@ static inline bool percpu_ref_tryget(struct percpu_ref *ref) return ret; } +/** + * percpu_ref_tryget - try to increment a percpu refcount + * @ref: percpu_ref to try-get + * + * Increment a percpu refcount unless its count already reached zero. + * Returns %true on success; %false on failure. + * + * This function is safe to call as long as @ref is between init and exit. + */ +static inline bool percpu_ref_tryget(struct percpu_ref *ref) +{ + return percpu_ref_tryget_many(ref, 1); +} + /** * percpu_ref_tryget_live - try to increment a live percpu refcount * @ref: percpu_ref to try-get -- 2.24.0