Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp3162273pxk; Tue, 15 Sep 2020 11:38:38 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwW9TbHHvtLCZE1WIbrUxTHrT/k0dT1nZWZy1eFWDI8c+RyIacSu6nbSmft45nmjSOiJZeo X-Received: by 2002:a17:906:4093:: with SMTP id u19mr21882051ejj.520.1600195118649; Tue, 15 Sep 2020 11:38:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1600195118; cv=none; d=google.com; s=arc-20160816; b=mYI9m4cPaYn5ii55nsTA/XkudPysoLywekoFvuEMzBfSdOjqbx77yEnrVNznsotT6O 1C0lH5De2UMB2LR9fl+MfquH0mcSeUp3/gb2E0KCgWmYAjEswKIVjCugIZm2n0QPObZO OY30SHcZuvLU8U1Gvi04e7y7yvC2l1ootr6ySKV2FGeGyJD57UCBUhWRKnVA8+vAUFgR C4S97o4uHATLUz9Y28pQlbSHHDkdOnLcqeuNyJK4RXBgR1BMnQR2l5HZqc6jcWX89ejU gb1IQiCh1PEnm8hlblTB8ADOEeCrTTstY2p/hrlazIb3rgQAIvRDkdYF6D5IJh93udlK zcdA== 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=9RrM3XVtJaJVQEx5uPEy7VLkhE5jbv/mtEaRuPEx3B4=; b=U6EDxgRFofmCOOUPsOxVRG5KssM8rlYQu7yrMWt2esal0BSlU0EI0LtYy6tBTcA/tt slEhmh6yX8LjWfA1oGVQZhnPJ75Ypx0GOsKE+tstZNKvQb+86Jc4NP9QSSj5npZ9U3Sf +L8VUc5tvnf/habDGs2oIH7bBMsqowho/NGK5VnARkKny7DIUq6dluANkLAFhLtfg7Rd wPdBsGmv5zMA06e4gxZEINz2FZR/xyjQWkje9vVdW8NzEKSacgYPHtPSGdVwyEAdljTJ Y+QOOmdTM4XIS6LmLyh0OoQLBuzhUgpx4/Mjman0oNubpxgXvGXmsJcqS0/fKV2Uy+QX s00Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@oracle.com header.s=corp-2020-01-29 header.b=dEdzKanu; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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. [23.128.96.18]) by mx.google.com with ESMTP id d25si9586835eje.181.2020.09.15.11.38.15; Tue, 15 Sep 2020 11:38:38 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@oracle.com header.s=corp-2020-01-29 header.b=dEdzKanu; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 S1727876AbgIOShf (ORCPT + 99 others); Tue, 15 Sep 2020 14:37:35 -0400 Received: from aserp2120.oracle.com ([141.146.126.78]:41218 "EHLO aserp2120.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727973AbgIOSHG (ORCPT ); Tue, 15 Sep 2020 14:07:06 -0400 Received: from pps.filterd (aserp2120.oracle.com [127.0.0.1]) by aserp2120.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 08FHx5Je078606; Tue, 15 Sep 2020 18:05:55 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-2020-01-29; bh=9RrM3XVtJaJVQEx5uPEy7VLkhE5jbv/mtEaRuPEx3B4=; b=dEdzKanuUxpnXLt9j8lLVfNL3vtLDlGvNcRimZ+Uwj+K5E5G8mJO3boXURTJ+VYgLtvM TGLELrNnYeOtzEXncNdOfY+HSUCIIg1uy4DMR+lo2fzMrIZvJgSc3Qm6SevmoJizEg7F AXBJfj0WpXM9e5YM1Br28bsCGKMI4AWfDtOULfAI+7MM4ctMwDG/RODOlUWIFneXHFiN 6Uc6ESiZt7xSjqr8fiCEmPy6O34r1iGBKS94fVTq/xafQDjBOVqtZkbbOTE+80lvhazi eI+YjdZPCHrzcQZHex1NkiEa8u3MfnX2uQbHnLFIC81CkKlhA9f3AQZCyBBLc+JQJdrl /Q== Received: from userp3020.oracle.com (userp3020.oracle.com [156.151.31.79]) by aserp2120.oracle.com with ESMTP id 33gp9m6qpd-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Tue, 15 Sep 2020 18:05:55 +0000 Received: from pps.filterd (userp3020.oracle.com [127.0.0.1]) by userp3020.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 08FI5pDn062234; Tue, 15 Sep 2020 18:05:54 GMT Received: from userv0121.oracle.com (userv0121.oracle.com [156.151.31.72]) by userp3020.oracle.com with ESMTP id 33hm310msx-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 15 Sep 2020 18:05:54 +0000 Received: from abhmp0008.oracle.com (abhmp0008.oracle.com [141.146.116.14]) by userv0121.oracle.com (8.14.4/8.13.8) with ESMTP id 08FI5l8w000901; Tue, 15 Sep 2020 18:05:48 GMT Received: from neelam.us.oracle.com (/10.152.128.16) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Tue, 15 Sep 2020 18:05:47 +0000 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 v11 2/5] locking/qspinlock: Refactor the qspinlock slow path Date: Tue, 15 Sep 2020 14:05:32 -0400 Message-Id: <20200915180535.2975060-3-alex.kogan@oracle.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200915180535.2975060-1-alex.kogan@oracle.com> References: <20200915180535.2975060-1-alex.kogan@oracle.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9745 signatures=668679 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 spamscore=0 bulkscore=0 mlxlogscore=999 malwarescore=0 mlxscore=0 phishscore=0 adultscore=0 suspectscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2006250000 definitions=main-2009150146 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9745 signatures=668679 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 bulkscore=0 mlxlogscore=999 adultscore=0 malwarescore=0 clxscore=1015 lowpriorityscore=0 phishscore=0 spamscore=0 priorityscore=1501 suspectscore=0 impostorscore=0 mlxscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2006250000 definitions=main-2009150145 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 Reviewed-by: Waiman Long --- 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 435d696f9250..24b5802fc6f1 100644 --- a/kernel/locking/qspinlock.c +++ b/kernel/locking/qspinlock.c @@ -289,6 +289,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_lock_handoff - 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_lock_handoff(struct mcs_spinlock *node, + struct mcs_spinlock *next) +{ + arch_mcs_lock_handoff(&next->locked, 1); +} + +#define try_clear_tail __try_clear_tail +#define mcs_lock_handoff __mcs_lock_handoff + #endif /* _GEN_PV_LOCK_SLOWPATH */ /** @@ -533,7 +561,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 */ } @@ -550,7 +578,7 @@ void queued_spin_lock_slowpath(struct qspinlock *lock, u32 val) if (!next) next = smp_cond_load_relaxed(&node->next, (VAL)); - arch_mcs_lock_handoff(&next->locked, 1); + mcs_lock_handoff(node, next); pv_kick_node(lock, next); release: @@ -575,6 +603,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_lock_handoff +#define mcs_lock_handoff __mcs_lock_handoff + #undef queued_spin_lock_slowpath #define queued_spin_lock_slowpath __pv_queued_spin_lock_slowpath -- 2.21.1 (Apple Git-122.3)