From patchwork Thu Dec 15 18:55:54 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Jason A. Donenfeld" X-Patchwork-Id: 9477145 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id A176960825 for ; Fri, 16 Dec 2016 00:36:23 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A415E28888 for ; Fri, 16 Dec 2016 00:36:23 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 98C8B288A6; Fri, 16 Dec 2016 00:36:23 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.1 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_MED,T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id D38BF28888 for ; Fri, 16 Dec 2016 00:36:22 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 813446EAC5; Fri, 16 Dec 2016 00:36:21 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from frisell.zx2c4.com (frisell.zx2c4.com [192.95.5.64]) by gabe.freedesktop.org (Postfix) with ESMTPS id 97D326EA72 for ; Thu, 15 Dec 2016 18:56:02 +0000 (UTC) Received: by frisell.zx2c4.com (ZX2C4 Mail Server) with ESMTP id 84021f5a; Thu, 15 Dec 2016 18:49:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=zx2c4.com; h=from:to:cc :subject:date:message-id; s=mail; bh=h82WgzZkI5pum3mRBjiMcP9LijQ =; b=uGQp80rD1bjJrJGIta6ILBU9WoAxeJuMRroCV2wZXWwBXmuqDUJSBeshLzS 8NNhFGo8UEYJDgf7WO+qyIA9+XQsOtegNd2kfOhefYE+AGVxsf0ehHBkSW1INTrE 5m+e0rbGAhYy0rzGHhxaHGB66eVrrjKnkk/3/Jntx47Gq/VvD7zju11bIzBh51g2 OdisNngWVJdyMy/oVY5FQ0knsr2WRoWjKe88r09T1HKsWDd+DRLELr6NkGRw68pK NNSgLpqEZFm3aorJHYJw2Aq5Xbeq8S97bi9xDHrD6BHca8o0BTChaZbGh3qWjkPG 3spen8cFGEC6AD9qHyeCY5ZEoAA== Received: by frisell.zx2c4.com (ZX2C4 Mail Server) with ESMTPSA id 43ad9aa2 (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256:NO); Thu, 15 Dec 2016 18:49:33 +0000 (UTC) From: "Jason A. Donenfeld" To: Christoph Hellwig , Thomas Hellstrom , dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, Daniel Vetter , gregkh@linuxfoundation.org Subject: [PATCH] kref: prefer atomic_inc_not_zero to atomic_add_unless Date: Thu, 15 Dec 2016 19:55:54 +0100 Message-Id: <20161215185554.21931-1-Jason@zx2c4.com> X-Mailer: git-send-email 2.11.0 X-Mailman-Approved-At: Fri, 16 Dec 2016 00:32:30 +0000 Cc: "Jason A. Donenfeld" X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" X-Virus-Scanned: ClamAV using ClamSMTP On most platforms, there exists this ifdef: #define atomic_inc_not_zero(v) atomic_add_unless((v), 1, 0) This makes this patch functionally useless. However, on PPC, there is actually an explicit definition of atomic_inc_not_zero with its own assembly that is slightly more optimized than atomic_add_unless. So, this patch changes kref to use atomic_inc_not_zero instead, for PPC and any future platforms that might provide an explicit implementation. This also puts this usage of kref more in line with a verbatim reading of the examples in Paul McKenney's paper [1] in the section titled "2.4 Atomic Counting With Check and Release Memory Barrier", which uses atomic_inc_not_zero. [1] http://open-std.org/jtc1/sc22/wg21/docs/papers/2007/n2167.pdf Signed-off-by: Jason A. Donenfeld Reviewed-by: Thomas Hellstrom Reviewed-by: Christoph Hellwig --- Sorry to submit this again, but people keep reviewing it saying it's fine, but then point to somebody else to actually merge this. At the end of the chain of fingerpointing is usually Greg. "Just have Greg do it." At this point I'm confused, but it's certainly been sufficiently reviewed and accepted. So can one of you just respond saying "I'll take it!" include/linux/kref.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/linux/kref.h b/include/linux/kref.h index e15828fd71f1..62f0a84ae94e 100644 --- a/include/linux/kref.h +++ b/include/linux/kref.h @@ -133,6 +133,6 @@ static inline int kref_put_mutex(struct kref *kref, */ static inline int __must_check kref_get_unless_zero(struct kref *kref) { - return atomic_add_unless(&kref->refcount, 1, 0); + return atomic_inc_not_zero(&kref->refcount); } #endif /* _KREF_H_ */