Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp90916yba; Mon, 1 Apr 2019 02:22:31 -0700 (PDT) X-Google-Smtp-Source: APXvYqwhuNb2YIEAcoEM2UAglsQL/dXBc3GIp5bNeDYmm88paZKuuvagzJyoGxuDs9H6JpKYRJog X-Received: by 2002:a63:da4e:: with SMTP id l14mr18814241pgj.96.1554110551048; Mon, 01 Apr 2019 02:22:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1554110551; cv=none; d=google.com; s=arc-20160816; b=ehkc0YbvQNbAWFLHCQM5HsQ8Khj5IG61rjzxfcmEfneLdtrmz2PgXTHJSyPW2DpL/g Nnc9odHfnIq2FYFfyKC61rB34LDxbCMulR9FQGXzc2fMvsY9f0W74aCG5zWy6tHeOCgO wqRBn/BCCZ04GSEwDNa9KNqjXFj282h4062S61YGW5c2jIHhYGdA0Wni1Zi7sbiSTG8k trbAgbW53u9TzxGzVL8MF+mWV/uLQJiHnXKO6sYGkCwO2YMhjicsTz/BuwRGmEhlmNXJ 5mgPH5AbmEKECEVFP22K9VpOVwK00C4popWAYy5lYic0Jx0lMNV2Ygm6nB/E5hxVK9Ut XE1g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=UdqfqcqBuRUK6eRe3zfitc0Tv5Sfj4VsCq/y5wFNUWQ=; b=0glNDo9FYQgVzRSW18s6zKaeqUCddNZtWyi63qKX8j2jQ7B4wJQyKEdKnDua8azI4V BWd2WK7b/aZ8stEWrWrcAkrI+Edo09a0DYKqPiiZfkoGjghAyD0EgAn9BL19Q3JlP2lK 8T4Rrj1IFtrZtyTOTzHo3HMPxyOAqRuJSGKCpUxRT9RSPWNtUnUOeY/GZAZnuVkhV4ib xYTf8Vtj7x7NCE6VDYpInZuWdNqVnmlJqo6kEcOdWsOTCYje8wGh9fas8x7ErLb4qU1F yiYZoq7kZ1xWEYw0xdst80PhlurT5RHuDoC402YK0XSCUb/PD1b38pT5Z2Xb1U2Vmeps 2evQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@infradead.org header.s=bombadil.20170209 header.b="D/5HSQzK"; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 91si8431856pla.14.2019.04.01.02.22.15; Mon, 01 Apr 2019 02:22:31 -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=fail header.i=@infradead.org header.s=bombadil.20170209 header.b="D/5HSQzK"; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726530AbfDAJV0 (ORCPT + 99 others); Mon, 1 Apr 2019 05:21:26 -0400 Received: from bombadil.infradead.org ([198.137.202.133]:39134 "EHLO bombadil.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725821AbfDAJVZ (ORCPT ); Mon, 1 Apr 2019 05:21:25 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20170209; h=In-Reply-To:Content-Type:MIME-Version :References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=UdqfqcqBuRUK6eRe3zfitc0Tv5Sfj4VsCq/y5wFNUWQ=; b=D/5HSQzKsreWwbw0JR02bezLe hzajNFCd1ARYyFH9V3avOtnvNt87/EjYY73QZG2+yI9pgI+DNK3QuQvzxiUKZQR7fgyYJ2ICQBPQ3 t2HmSikTY6demZG359XGfAmbKKdp73tJA9zsvfXAt6iLcVFJ5zeqi0mBcnhuP5e9zlGq3iEclXmAJ ojYgfgb4TYmw22t968PY+tinp+XoAFN7+ApNbPj7/s8EdCNXXx7Qoa1p+nsPXYwvIcx4sF7o5cagN aLMeEQou5NiEEjZTHxKmzUnbVVLgciWJ2welWQ2RIaP5pI+FPzbgnFSKe+TPbX9aQdjLq2DrdULuD BrJkIgJxg==; 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 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 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-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20190329152006.110370-4-alex.kogan@oracle.com> User-Agent: Mutt/1.10.1 (2018-07-13) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@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 ().