From patchwork Thu Dec 15 05:01:10 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: 9477149 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 CB7F960825 for ; Fri, 16 Dec 2016 00:37:34 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id CC2762889F for ; Fri, 16 Dec 2016 00:37:34 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id BC9F3288A7; Fri, 16 Dec 2016 00:37:34 +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 E412D28891 for ; Fri, 16 Dec 2016 00:37:33 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 4D45E6EAC9; Fri, 16 Dec 2016 00:37:32 +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 59EE96E238 for ; Thu, 15 Dec 2016 05:07:57 +0000 (UTC) Received: by frisell.zx2c4.com (ZX2C4 Mail Server) with ESMTP id f05e3e47; Thu, 15 Dec 2016 04:54:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=zx2c4.com; h=from:to:cc :subject:date:message-id:in-reply-to:references; s=mail; bh=B06C W+/KHy5R3ALkzTGPZ2MMZrw=; b=o9fHtUzD85oFg3IDD54yc8Lf3fYhRasReZ4H lvmJNLV3bzrCCxVhN22rNeI8cJzsSRTAe5SJfUYByvHLbDFcXM05DsM3rHJSCHyS wexaK+ULZrkgEB8Zv+hGFe8dsUiklSgyNc9p79a3oSVouBYGEKyFdhvK6shIvajo +zVnXCqCPUOO9n6qqbviLgU8ljcAb5Am5/+BGij/NPQ1QMblG6OWj+lA1l/MgIua hF6H1OE6w7J7eTjGj/z3jNocBJkSvjsRK8JkEHAqKLLT1301x0SnMvgtDXh1Xxxa /vUPsvq6XuI711sw7+XtQzGVkCw0jq+7DqRCbWBrzVbf0P6ZRw== Received: by frisell.zx2c4.com (ZX2C4 Mail Server) with ESMTPSA id 3009313d (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256:NO); Thu, 15 Dec 2016 04:54:53 +0000 (UTC) From: "Jason A. Donenfeld" To: Thomas Hellstrom , "dri-devel@lists.freedesktop.org" Subject: [PATCH] kref: prefer atomic_inc_not_zero to atomic_add_unless Date: Thu, 15 Dec 2016 06:01:10 +0100 Message-Id: <20161215050110.3241-1-Jason@zx2c4.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20160712122817.GT23520@phenom.ffwll.local> References: <20160712122817.GT23520@phenom.ffwll.local> 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 --- This was reviewed favorably 14 months ago but never picked up. I'm resubmitting it now in hopes that you can finally queue it up for 4.10. 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_ */