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=-9.8 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,UNPARSEABLE_RELAY,USER_AGENT_GIT 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 6D962C76191 for ; Mon, 15 Jul 2019 19:27:05 +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 4512D2083D for ; Mon, 15 Jul 2019 19:27:05 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="IakPYlsK"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=oracle.com header.i=@oracle.com header.b="NGGwCIz0" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 4512D2083D Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=oracle.com 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:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:References: In-Reply-To:Message-Id:Date:Subject:To:From:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=WkHYUIqswQ7JOstS1pPpdkG6MlK4haEgOAFq8SqH8Mg=; b=IakPYlsKzrR3fdirnGjYL2QFlS vBHqjON3IL/g+B0EUwQLew+DCO0FFMak8rCaqcNrUASM+wblW3d6M8wCoVv5N3Cp64S4UBe5aZ/xt eROImQTQe7U+0J7bD8lI4T1hMoq0vTP93eCqvjWIzhZVWF1GNMiFd4vGQC/PVX4CjvxcScB9sUFLk Ozc1SRtVOMUGjcPwBQJKmosRZihIGMUE0vKbHB5G2jPbNGXgHkJwmPm/B1cmUSsU0HlUgumUl4OE9 qd6SbuucuBTN53CbEJY43qn0ptPXowqiE4TR3ou15x7n9LnbYl90zb4YqHQnJSCuY/nG7Mt+ngN7n V/L1n3FQ==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.92 #3 (Red Hat Linux)) id 1hn6cm-0004uq-IJ; Mon, 15 Jul 2019 19:27:00 +0000 Received: from userp2130.oracle.com ([156.151.31.86]) by bombadil.infradead.org with esmtps (Exim 4.92 #3 (Red Hat Linux)) id 1hn6cj-0004tE-1i for linux-arm-kernel@lists.infradead.org; Mon, 15 Jul 2019 19:26:58 +0000 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 x6FJOdHx018491; Mon, 15 Jul 2019 19:26:01 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; s=corp-2018-07-02; bh=wRf1OAZyxbFwGPam2s6jhgORpRyKZydMuCtiU+UituY=; b=NGGwCIz0YycmENfUgJpt7Vz/BXNTXpEIuK8+y8A5vU+yrp83xL2kwk35cnfQRDYJ3U6Q qZgiYIDJCcUSey+G6FRSY/i1AZmcqDiWYC2GWf2ecYQT/Tgupobfgm7WZbyxQDZSspwa vi1QjBoBsRHnAjKVsLtZ297mQKv44sI1JARrlzYD+V6XLzmwY831JJTRU9vbZ96j5L12 kAfPMMgJ5ZQWSmZoN/gUdkFMvc1dPksXLJpIrDNiQbaCdfXekY05Sv+5k/yaNtyaO0PX zi7/7FVhEGmOoGLCJ+JAcMhW49J4z4V3l9p0Og2tIBnD3pdvT8VqRJ2uXvnfNVxHAbnb nA== Received: from userp3030.oracle.com (userp3030.oracle.com [156.151.31.80]) by userp2130.oracle.com with ESMTP id 2tq6qtghyj-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 15 Jul 2019 19:26:00 +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 x6FJMeim185347; Mon, 15 Jul 2019 19:26:00 GMT Received: from userv0122.oracle.com (userv0122.oracle.com [156.151.31.75]) by userp3030.oracle.com with ESMTP id 2tq4dtg9hv-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 15 Jul 2019 19:26:00 +0000 Received: from abhmp0013.oracle.com (abhmp0013.oracle.com [141.146.116.19]) by userv0122.oracle.com (8.14.4/8.14.4) with ESMTP id x6FJPsdA007776; Mon, 15 Jul 2019 19:25:54 GMT Received: from ol-bur-x5-4.us.oracle.com (/10.152.128.37) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Mon, 15 Jul 2019 12:25:54 -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 Subject: [PATCH v3 2/5] locking/qspinlock: Refactor the qspinlock slow path Date: Mon, 15 Jul 2019 15:25:33 -0400 Message-Id: <20190715192536.104548-3-alex.kogan@oracle.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190715192536.104548-1-alex.kogan@oracle.com> References: <20190715192536.104548-1-alex.kogan@oracle.com> X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9319 signatures=668688 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-1810050000 definitions=main-1907150221 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9319 signatures=668688 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-1810050000 definitions=main-1907150222 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190715_122657_187412_659B4AE6 X-CRM114-Status: GOOD ( 16.87 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: alex.kogan@oracle.com, dave.dice@oracle.com, rahul.x.yadav@oracle.com, steven.sistare@oracle.com, daniel.m.jordan@oracle.com MIME-Version: 1.0 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 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 | 40 ++++++++++++++++++++++++++++++++++++++-- 1 file changed, 38 insertions(+), 2 deletions(-) diff --git a/kernel/locking/qspinlock.c b/kernel/locking/qspinlock.c index 961781624638..5668466b3006 100644 --- a/kernel/locking/qspinlock.c +++ b/kernel/locking/qspinlock.c @@ -297,6 +297,36 @@ static __always_inline u32 __pv_wait_head_or_lock(struct qspinlock *lock, #define queued_spin_lock_slowpath native_queued_spin_lock_slowpath #endif +/* + * set_locked_empty_mcs - Try to set the spinlock value to _Q_LOCKED_VAL, + * and by doing that unlock the MCS lock when its waiting queue is empty + * @lock: Pointer to queued spinlock structure + * @val: Current value of the lock + * @node: Pointer to the MCS node of the lock holder + * + * *,*,* -> 0,0,1 + */ +static __always_inline bool __set_locked_empty_mcs(struct qspinlock *lock, + u32 val, + struct mcs_spinlock *node) +{ + return atomic_try_cmpxchg_relaxed(&lock->val, &val, _Q_LOCKED_VAL); +} + +/* + * pass_mcs_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 __pass_mcs_lock(struct mcs_spinlock *node, + struct mcs_spinlock *next) +{ + arch_mcs_spin_unlock_contended(&next->locked, 1); +} + +#define set_locked_empty_mcs __set_locked_empty_mcs +#define pass_mcs_lock __pass_mcs_lock + #endif /* _GEN_PV_LOCK_SLOWPATH */ /** @@ -541,7 +571,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 (set_locked_empty_mcs(lock, val, node)) goto release; /* No contention */ } @@ -558,7 +588,7 @@ void queued_spin_lock_slowpath(struct qspinlock *lock, u32 val) if (!next) next = smp_cond_load_relaxed(&node->next, (VAL)); - arch_mcs_spin_unlock_contended(&next->locked, 1); + pass_mcs_lock(node, next); pv_kick_node(lock, next); release: @@ -583,6 +613,12 @@ EXPORT_SYMBOL(queued_spin_lock_slowpath); #undef pv_kick_node #undef pv_wait_head_or_lock +#undef set_locked_empty_mcs +#define set_locked_empty_mcs __set_locked_empty_mcs + +#undef pass_mcs_lock +#define pass_mcs_lock __pass_mcs_lock + #undef queued_spin_lock_slowpath #define queued_spin_lock_slowpath __pv_queued_spin_lock_slowpath -- 2.11.0 (Apple Git-81) _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel