From mboxrd@z Thu Jan 1 00:00:00 1970 From: Peter Zijlstra Subject: Re: [PATCH v2 3/5] locking/qspinlock: Introduce CNA into the slow path of qspinlock Date: Mon, 1 Apr 2019 11:21:15 +0200 Message-ID: <20190401092115.GH11158@hirez.programming.kicks-ass.net> References: <20190329152006.110370-1-alex.kogan@oracle.com> <20190329152006.110370-4-alex.kogan@oracle.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Return-path: Content-Disposition: inline In-Reply-To: <20190329152006.110370-4-alex.kogan@oracle.com> Sender: linux-kernel-owner@vger.kernel.org To: Alex Kogan Cc: linux@armlinux.org.uk, mingo@redhat.com, will.deacon@arm.com, arnd@arndb.de, longman@redhat.com, linux-arch@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, tglx@linutronix.de, bp@alien8.de, hpa@zytor.com, x86@kernel.org, steven.sistare@oracle.com, daniel.m.jordan@oracle.com, dave.dice@oracle.com, rahul.x.yadav@oracle.com List-Id: linux-arch.vger.kernel.org On Fri, Mar 29, 2019 at 11:20:04AM -0400, Alex Kogan wrote: > +static inline void pass_mcs_lock(struct mcs_spinlock *node, > + struct mcs_spinlock *next) > +{ > + struct mcs_spinlock *succ = NULL; > + > + succ = find_successor(node); > + > + if (succ) { > + arch_mcs_spin_unlock_contended(&succ->locked, node->locked); > + } else if (node->locked > 1) { > + /* > + * If the secondary queue is not empty, pass the lock > + * to the first node in that queue. > + */ > + succ = MCS_NODE(node->locked); > + succ->tail->next = next; > + arch_mcs_spin_unlock_contended(&succ->locked, 1); > + } else { > + /* > + * Otherwise, pass the lock to the immediate successor > + * in the main queue. > + */ > + arch_mcs_spin_unlock_contended(&next->locked, 1); > + } > +} Note that something like: static inline void pass_mcs_lock(struct mcs_spinlock *node, struct mcs_spinlock *next) { struct mcs_spinlock *succ = NULL; uintptr_t *var = &next->locked; uintptr_t val = 1; succ = find_successor(node); if (succ) { var = &succ->locked; val = node->locked; } else if (node->locked > 1) { succ = MCS_NODE(node->locked); succ->tail->next = next; /* WRITE_ONCE() !?!? */ var = &node->locked; } arch_mcs_spin_unlock_contended(var, val); } is shorter and generates much better code if arch_mcs_spin_unlock_contended() is asm volatile (). From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.5 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_PASS, URIBL_BLOCKED,USER_AGENT_MUTT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id AE1BAC43381 for ; Mon, 1 Apr 2019 09:21:22 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 7C8F6213A2 for ; Mon, 1 Apr 2019 09:21:22 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="gw+9LJir" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 7C8F6213A2 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=infradead.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+infradead-linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:In-Reply-To:MIME-Version:References: Message-ID:Subject:To:From:Date:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=CDYEdyPyJ9iNE78lyP5GpbEVweBDgLVq0cWrESeACxI=; b=gw+9LJirVNSFRY uX9xXIjtEFx2E+v5CxPuifKIJAkvMeu3WOzHCBVjxVeGPoP5hhUXyAhy4g2U8F6wkonsc3DypUhXr XdC9xy3fCwDyBrkuVfMtslDahwPys0w4VjYpmC2QgCWqg51wHZSclCDQJ0Dr+wMEFNOFiypicUNS0 XF0RJWId1qNBki598BgliPTRVPAaUaJ4LSqCYKula1vQy/zVh9FX1r1u+di2mm1LxTW4+iulkJ2oM FSWXsVYayuhcRvvyhcZAJb7TFX5YUNmdQYZ/d3zgW1WQXhITX+qrE1+C6DI/mWtGoh7BYLg12ZRPC Xjvazc8ubudYmKwGgCEQ==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1hAt83-00045h-77; Mon, 01 Apr 2019 09:21:19 +0000 Received: from j217100.upc-j.chello.nl ([24.132.217.100] helo=hirez.programming.kicks-ass.net) by bombadil.infradead.org with esmtpsa (Exim 4.90_1 #2 (Red Hat Linux)) id 1hAt81-00045B-6y; Mon, 01 Apr 2019 09:21:17 +0000 Received: by hirez.programming.kicks-ass.net (Postfix, from userid 1000) id AF06F2026BE95; Mon, 1 Apr 2019 11:21:15 +0200 (CEST) Date: Mon, 1 Apr 2019 11:21:15 +0200 From: Peter Zijlstra To: Alex Kogan Subject: Re: [PATCH v2 3/5] locking/qspinlock: Introduce CNA into the slow path of qspinlock Message-ID: <20190401092115.GH11158@hirez.programming.kicks-ass.net> References: <20190329152006.110370-1-alex.kogan@oracle.com> <20190329152006.110370-4-alex.kogan@oracle.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20190329152006.110370-4-alex.kogan@oracle.com> User-Agent: Mutt/1.10.1 (2018-07-13) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-arch@vger.kernel.org, arnd@arndb.de, dave.dice@oracle.com, x86@kernel.org, will.deacon@arm.com, linux@armlinux.org.uk, steven.sistare@oracle.com, linux-kernel@vger.kernel.org, rahul.x.yadav@oracle.com, mingo@redhat.com, bp@alien8.de, hpa@zytor.com, longman@redhat.com, tglx@linutronix.de, daniel.m.jordan@oracle.com, linux-arm-kernel@lists.infradead.org Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+infradead-linux-arm-kernel=archiver.kernel.org@lists.infradead.org On Fri, Mar 29, 2019 at 11:20:04AM -0400, Alex Kogan wrote: > +static inline void pass_mcs_lock(struct mcs_spinlock *node, > + struct mcs_spinlock *next) > +{ > + struct mcs_spinlock *succ = NULL; > + > + succ = find_successor(node); > + > + if (succ) { > + arch_mcs_spin_unlock_contended(&succ->locked, node->locked); > + } else if (node->locked > 1) { > + /* > + * If the secondary queue is not empty, pass the lock > + * to the first node in that queue. > + */ > + succ = MCS_NODE(node->locked); > + succ->tail->next = next; > + arch_mcs_spin_unlock_contended(&succ->locked, 1); > + } else { > + /* > + * Otherwise, pass the lock to the immediate successor > + * in the main queue. > + */ > + arch_mcs_spin_unlock_contended(&next->locked, 1); > + } > +} Note that something like: static inline void pass_mcs_lock(struct mcs_spinlock *node, struct mcs_spinlock *next) { struct mcs_spinlock *succ = NULL; uintptr_t *var = &next->locked; uintptr_t val = 1; succ = find_successor(node); if (succ) { var = &succ->locked; val = node->locked; } else if (node->locked > 1) { succ = MCS_NODE(node->locked); succ->tail->next = next; /* WRITE_ONCE() !?!? */ var = &node->locked; } arch_mcs_spin_unlock_contended(var, val); } is shorter and generates much better code if arch_mcs_spin_unlock_contended() is asm volatile (). _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel