Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp14533176ybl; Mon, 30 Dec 2019 11:55:27 -0800 (PST) X-Google-Smtp-Source: APXvYqwDmxk7uCrsA+Wy1QpQTbJziXYIwiGc+uOungwhDybVBjjz7nq4j8LGcpIIZgMXsS4+rpgW X-Received: by 2002:a05:6830:1e30:: with SMTP id t16mr77322651otr.220.1577735727399; Mon, 30 Dec 2019 11:55:27 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1577735727; cv=none; d=google.com; s=arc-20160816; b=WnyY4CxjK275dJx+4wnA8inlJSNIGhOQ/EVvd7eeqFnOxea7q13bRW/sENomMPbfPs obs0w1VUogTTN9cSHNdYHT3j8DMLnhKsdZC4RVPH3s6yll8j96jNKFDa1PGfRUSrK+5P YiiHaZ9UTdLOm90dGQepN5vmfDf8Rk5PYr/A8L1owyESybTCGtDf1z6NhaU4/lAjWiFq UBl7UvqbscQhkHBVZmkYYIrRHOqnACuevKRb0TIynsIxWBV4XQ+gNcX57bm3SUQsbvcA 51mhieaO0CR7YDOzKoS5B+sWqCRI6kI85sTH+CNTYtDncNl2fnV15RqDpatYenZ+0FUg mbjQ== 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=aDqtQhY6qMLxFluKAtfnMI9ftLIuVqbwG/4ZTKUvZy8=; b=PXjNk4dXowLiLKaNgj35N00xeur2orKr5YRjfq2EefByEM4TXi1AuIgIH7vMl0eZwJ DW40T9OXMfedEmhO3nyat+8G6PG0Y9kchRgviohKrPYw2C1JyU3/R06ikIkAJWtWhOZC rmwcaw1qucfOUgxapf3zRIhtrsADbc8NNT/LGoBqHfw2frLIGvG3daf37oBYmHyd2KpJ KxVn/W7pulzU/s6+yo6p4s9+r2ABk83tqG0eKpCUQA/Ft6puVw4nmyg2unmpNWiHQ1Pp WueNBy0D1E+TQNAISvuOJS5hXJ5VGyov7kCcbn/fvRzxGooRjz3hO6WlLvGhmRD0MMpO K5AA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@oracle.com header.s=corp-2019-08-05 header.b=KSFe5RYb; 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=NONE dis=NONE) header.from=oracle.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id l16si20434849otj.59.2019.12.30.11.55.15; Mon, 30 Dec 2019 11:55:27 -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=@oracle.com header.s=corp-2019-08-05 header.b=KSFe5RYb; 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=NONE dis=NONE) header.from=oracle.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727725AbfL3Tx5 (ORCPT + 99 others); Mon, 30 Dec 2019 14:53:57 -0500 Received: from userp2130.oracle.com ([156.151.31.86]:45192 "EHLO userp2130.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727278AbfL3Txy (ORCPT ); Mon, 30 Dec 2019 14:53:54 -0500 Received: from pps.filterd (userp2130.oracle.com [127.0.0.1]) by userp2130.oracle.com (8.16.0.27/8.16.0.27) with SMTP id xBUJnDMm161155; Mon, 30 Dec 2019 19:52:48 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding; s=corp-2019-08-05; bh=aDqtQhY6qMLxFluKAtfnMI9ftLIuVqbwG/4ZTKUvZy8=; b=KSFe5RYbEtwkJdc3CpNNL31kRoocH6GKXt+utzaOxZTmHyoDOrhPmNWxcSFoorhL4NgJ uYcOvgZ5CdW5C2OnMl4eWZSNHKhhCgh1+Kb2SlJ6tY0JxgCFK3WxD/WOq+5ncSdo9Ww/ i6q+E1vWK0yYzomXHoromfM2YPw/e9Ra1xTORPcXON01F1DTAHiVToqjDnpEj9tgFoMt WkllllPl7TOTAIvb4Zgkuh4mEc1eSI8lTJAH479H9sEQpEOauVKiuVjNSNC2riMOtO7j SRuPn2q1KcC7biop29l+zpuQFYC4YhXdxDDOeXSVOHDaBWfQZlHCu2jqpeQksFanENNR 9g== Received: from userp3030.oracle.com (userp3030.oracle.com [156.151.31.80]) by userp2130.oracle.com with ESMTP id 2x5xftf2hn-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 30 Dec 2019 19:52:48 +0000 Received: from pps.filterd (userp3030.oracle.com [127.0.0.1]) by userp3030.oracle.com (8.16.0.27/8.16.0.27) with SMTP id xBUJmR8U115018; Mon, 30 Dec 2019 19:52:47 GMT Received: from aserv0122.oracle.com (aserv0122.oracle.com [141.146.126.236]) by userp3030.oracle.com with ESMTP id 2x6gh94hdv-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 30 Dec 2019 19:52:47 +0000 Received: from abhmp0003.oracle.com (abhmp0003.oracle.com [141.146.116.9]) by aserv0122.oracle.com (8.14.4/8.14.4) with ESMTP id xBUJqVpa021943; Mon, 30 Dec 2019 19:52:31 GMT Received: from neelam.us.oracle.com (/10.152.128.16) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Mon, 30 Dec 2019 11:52:31 -0800 From: Alex Kogan To: linux@armlinux.org.uk, peterz@infradead.org, 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, guohanjun@huawei.com, jglauber@marvell.com Cc: steven.sistare@oracle.com, daniel.m.jordan@oracle.com, alex.kogan@oracle.com, dave.dice@oracle.com Subject: [PATCH v8 2/5] locking/qspinlock: Refactor the qspinlock slow path Date: Mon, 30 Dec 2019 14:40:39 -0500 Message-Id: <20191230194042.67789-3-alex.kogan@oracle.com> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20191230194042.67789-1-alex.kogan@oracle.com> References: <20191230194042.67789-1-alex.kogan@oracle.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9486 signatures=668685 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=0 malwarescore=0 phishscore=0 bulkscore=0 spamscore=0 mlxscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1911140001 definitions=main-1912300178 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9486 signatures=668685 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 priorityscore=1501 malwarescore=0 suspectscore=0 phishscore=0 bulkscore=0 spamscore=0 clxscore=1015 lowpriorityscore=0 mlxscore=0 impostorscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1911140001 definitions=main-1912300178 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Move some of the code manipulating the spin lock into separate functions. This would allow easier integration of alternative ways to manipulate that lock. Signed-off-by: Alex Kogan Reviewed-by: Steve Sistare --- kernel/locking/qspinlock.c | 38 ++++++++++++++++++++++++++++++++++++-- 1 file changed, 36 insertions(+), 2 deletions(-) diff --git a/kernel/locking/qspinlock.c b/kernel/locking/qspinlock.c index 804c0fbd6328..c06d1e8075d9 100644 --- a/kernel/locking/qspinlock.c +++ b/kernel/locking/qspinlock.c @@ -288,6 +288,34 @@ static __always_inline u32 __pv_wait_head_or_lock(struct qspinlock *lock, #define queued_spin_lock_slowpath native_queued_spin_lock_slowpath #endif +/* + * __try_clear_tail - try to clear tail by setting the lock value to + * _Q_LOCKED_VAL. + * @lock: Pointer to the queued spinlock structure + * @val: Current value of the lock + * @node: Pointer to the MCS node of the lock holder + */ +static __always_inline bool __try_clear_tail(struct qspinlock *lock, + u32 val, + struct mcs_spinlock *node) +{ + return atomic_try_cmpxchg_relaxed(&lock->val, &val, _Q_LOCKED_VAL); +} + +/* + * __mcs_pass_lock - pass the MCS lock to the next waiter + * @node: Pointer to the MCS node of the lock holder + * @next: Pointer to the MCS node of the first waiter in the MCS queue + */ +static __always_inline void __mcs_pass_lock(struct mcs_spinlock *node, + struct mcs_spinlock *next) +{ + arch_mcs_pass_lock(&next->locked, 1); +} + +#define try_clear_tail __try_clear_tail +#define mcs_pass_lock __mcs_pass_lock + #endif /* _GEN_PV_LOCK_SLOWPATH */ /** @@ -532,7 +560,7 @@ void queued_spin_lock_slowpath(struct qspinlock *lock, u32 val) * PENDING will make the uncontended transition fail. */ if ((val & _Q_TAIL_MASK) == tail) { - if (atomic_try_cmpxchg_relaxed(&lock->val, &val, _Q_LOCKED_VAL)) + if (try_clear_tail(lock, val, node)) goto release; /* No contention */ } @@ -549,7 +577,7 @@ void queued_spin_lock_slowpath(struct qspinlock *lock, u32 val) if (!next) next = smp_cond_load_relaxed(&node->next, (VAL)); - arch_mcs_pass_lock(&next->locked, 1); + mcs_pass_lock(node, next); pv_kick_node(lock, next); release: @@ -574,6 +602,12 @@ EXPORT_SYMBOL(queued_spin_lock_slowpath); #undef pv_kick_node #undef pv_wait_head_or_lock +#undef try_clear_tail +#define try_clear_tail __try_clear_tail + +#undef mcs_pass_lock +#define mcs_pass_lock __mcs_pass_lock + #undef queued_spin_lock_slowpath #define queued_spin_lock_slowpath __pv_queued_spin_lock_slowpath -- 2.21.0 (Apple Git-122.2)