Received: by 2002:a5b:505:0:0:0:0:0 with SMTP id o5csp7144320ybp; Wed, 16 Oct 2019 04:33:56 -0700 (PDT) X-Google-Smtp-Source: APXvYqzyyTocBkM1ncvzosM8SNyuF3pG6+//CNjVg3SBTQBU2Ssa5+/f/ITtOg6SU1756ZndiMZo X-Received: by 2002:a50:b083:: with SMTP id j3mr38461614edd.15.1571225636397; Wed, 16 Oct 2019 04:33:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1571225636; cv=none; d=google.com; s=arc-20160816; b=hE2K8QCXsqLm0O+OdSsyV4vm2HumhrXTHfLP6BQ4Akaz+22+szJf6KEhbEmz14kK+M DnAwWZYElhPMJh70tUkLnZXI0rR2eFEAiQGIc1eDp5M5GYJj6MWTxt3wVjknpfVPdgna yf1kpVz8jEI6rBiSns3uZHotAW053wdUGnh/pTjl3yOnZRk6dnwlpZBUDXmD0yRxhiTs q/qIgSjo3d9pGZst+jD9r/aKuLNwb012LMW8rrjnanVbjOhx/S5dwTmgCkaqQCFy9yvR 849F+U14LaYHNNmHGsndTGapSSY1YHkVPyufWgawRVN1yoeD777WJhk7nXUFAUcCzalz xB3Q== 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=R/fl3/e/tumWGOl5RHojvBvQAbaC+/s8svgyi4+7QQE=; b=p6d9jI4a2nDN3N1LZt+4NQthzSF20ycTCl3BA22zFI/jHpM0HTMGvwKF49EIOzZ1Y7 UAzFHrs+ct6Rg6kxvJGGXWgCUk1t7ZU5Mnw5vf8teljKr0pTKq1NLaJRpUTOJYcKDdhX hMPCVDSs3LdRE+yIypk6D3Bc2Dp1KLlb6pnftYXOGiHRBHL48J79IEWCbc4ryLhcgwKb cgNj23nRuntNz44qSF0CoBtdL1Z+4h1msOw1Oft1ciEeUD8Oc3gIgGkuznoymkedHvie S22MiQLU6Gh7rK3Ne7+6Vo/BrlNi0oCu0PcYE9y4LZbIDOFFyMKYu5gmGa3haF+21Jyl aYlw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@oracle.com header.s=corp-2019-08-05 header.b=FimOnT1n; 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 z26si17179829edz.99.2019.10.16.04.33.32; Wed, 16 Oct 2019 04:33:56 -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=pass header.i=@oracle.com header.s=corp-2019-08-05 header.b=FimOnT1n; 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 S2389865AbfJPEci (ORCPT + 99 others); Wed, 16 Oct 2019 00:32:38 -0400 Received: from userp2130.oracle.com ([156.151.31.86]:34124 "EHLO userp2130.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2389479AbfJPEci (ORCPT ); Wed, 16 Oct 2019 00:32:38 -0400 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 x9G4SbLK179700; Wed, 16 Oct 2019 04:31:20 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=R/fl3/e/tumWGOl5RHojvBvQAbaC+/s8svgyi4+7QQE=; b=FimOnT1ndI72ICOrsMf5KnoIMV5KOZHJo9uWKHIKDo4JP6yc8SlQE1isr7isuENjuyh7 psyDnipg/c3wC9LFh1ypDcZqBAQoNMx7WxkhN2B0SD9bWoiH5vKOU3nfyN4E+Q5a6kak PxUlYpPSb6FARBZx5FU87djj96SjL16CYewL1boCiOQyVgEtXaDtVwFTzqxW1RGGHz8L EhO+lh/IZgLDQe4GK24iVdM7+0uZsmUNpIkq38Lz58z7vdWU8tmhICi+gqtoyO/1N3Jr hAvuVCvbYumInShlUioL/D/GvBLWb7QDgiRrsNeXzOTCuV2YYTbXQCZVc8MLaeUCUQqu KQ== Received: from userp3030.oracle.com (userp3030.oracle.com [156.151.31.80]) by userp2130.oracle.com with ESMTP id 2vk68um48n-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 16 Oct 2019 04:31:20 +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 x9G4RtQA043194; Wed, 16 Oct 2019 04:31:20 GMT Received: from userv0122.oracle.com (userv0122.oracle.com [156.151.31.75]) by userp3030.oracle.com with ESMTP id 2vn8epsv7b-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 16 Oct 2019 04:31:20 +0000 Received: from abhmp0002.oracle.com (abhmp0002.oracle.com [141.146.116.8]) by userv0122.oracle.com (8.14.4/8.14.4) with ESMTP id x9G4V8eV028623; Wed, 16 Oct 2019 04:31:08 GMT Received: from neelam.us.oracle.com (/10.152.128.16) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Tue, 15 Oct 2019 21:31:08 -0700 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, rahul.x.yadav@oracle.com Subject: [PATCH v5 2/5] locking/qspinlock: Refactor the qspinlock slow path Date: Wed, 16 Oct 2019 00:29:00 -0400 Message-Id: <20191016042903.61081-3-alex.kogan@oracle.com> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20191016042903.61081-1-alex.kogan@oracle.com> References: <20191016042903.61081-1-alex.kogan@oracle.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9411 signatures=668684 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-1908290000 definitions=main-1910160040 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9411 signatures=668684 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 priorityscore=1501 malwarescore=0 suspectscore=0 phishscore=0 bulkscore=0 spamscore=0 clxscore=1011 lowpriorityscore=0 mlxscore=0 impostorscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1908290000 definitions=main-1910160040 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.11.0 (Apple Git-81)