Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp704955pxj; Fri, 14 May 2021 13:38:36 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwWG2nJKQ5HJkmuIujfNN3s8EKbl5EBsQbCn3XHHyoLN+jw2Sz0FZaEouhi0h1rrwhU5IeI X-Received: by 2002:a92:3002:: with SMTP id x2mr44178744ile.116.1621024716279; Fri, 14 May 2021 13:38:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1621024716; cv=none; d=google.com; s=arc-20160816; b=wYEIP5vGcYJe1QuRkJTYRjDmdmOnFDzvAR5q6eDbiphZeb9fYf7zOBidKsiIvkxXqn YuISnyRvT1wpIENMPgU5u/KhtoH9yhZyoNiDfJdI2PTh5emgZrCo+C7wKXJ3b+SBJTnI OQ1nHpN87stWZ0x5z+PlxHHn1dACZOFehYo0jvgwOJc7+SOSdpIJyh2/yAOvmWXJwStq qfcwJmXYqsEFIqShGtabg3EHv58cIkHMf2orBq4nPxppMxvYuh8E4AhlD2s01UGGL+pR 3b5U5hceLOfworOEXAkHm5jn5c2GyH9e0tOrWNOzDzWPTzV2yPsYszciq86z7hILfqpu 2y5g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=zQ/1/2J6jL75I15gPTt4mjOOyd9HZEC6PKJACaHwExw=; b=nE0CTczpmI4fywbeNfoxaf0qYzUoIkKb8QpHyKkK5H6+d1k+BqJ+ymUiJypkbiGVyc 4MD1ykbIQ7LHdc+ps4Mr/gHSPF/4KWzgYTrd+DcoXK1aAbmcRs2xD4iS5S4zbeXf2NUH LVi5Smc0tHpJtcwosXlm+8p2+KL8dlE9M+g13n/+YN+ihC/wJ1CZKwxde42o9mNFMUdl Cc+XBtTE6uMmY7smkos0cejLAzJuuRzu8d1lB3dNxmd3cNegurboW+RbbNbX0F0gRbVE tKTLCK90rSnTSC7l+DeeG/uX0vGyVgxOI0Nbk24aowUO88l0NmWs7UdEid4cHerJGWw9 YUhg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@oracle.com header.s=corp-2020-01-29 header.b=BezBi4M2; 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 z8si8805297ilq.2.2021.05.14.13.38.22; Fri, 14 May 2021 13:38:36 -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=BezBi4M2; 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 S231744AbhENUKT (ORCPT + 99 others); Fri, 14 May 2021 16:10:19 -0400 Received: from aserp2120.oracle.com ([141.146.126.78]:53682 "EHLO aserp2120.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230426AbhENUKS (ORCPT ); Fri, 14 May 2021 16:10:18 -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 14EK4wSe151546; Fri, 14 May 2021 20:08:08 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=zQ/1/2J6jL75I15gPTt4mjOOyd9HZEC6PKJACaHwExw=; b=BezBi4M2HtknJ58WpEZ94/xJBKPmImjUEy6t+w10zwB9g5CrVIV3US2bWFtGZPIUuN+q kz92pffc9i+4/Vs1JWkusHplZG4ymamUCHVJxOYIJYCQ5jPnwpqTrnniG/ZhxxO/RFGW 2Jvdj0j7KWkJgwQs+1riqlVAl7TlzL4JmwnMOqXvUCOQIkMMamXKXsSDW6OGxQqXq9oi kQFsPmNaMd+gsbf/NiLBKLOKyBilrykdbhPbJkRbSyePRwNvtp/39xXe6zPD5lIPkSQd SVlxirdGxQZTYyyK4wlEMAfYL0w2hMb2Q78Ku+zGakY4/cbbWK1bGEmC35YRwONui3ST Bw== Received: from userp3020.oracle.com (userp3020.oracle.com [156.151.31.79]) by aserp2120.oracle.com with ESMTP id 38gpnxw8j7-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 14 May 2021 20:08:08 +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 14EK6Cxc098986; Fri, 14 May 2021 20:08:07 GMT Received: from pps.reinject (localhost [127.0.0.1]) by userp3020.oracle.com with ESMTP id 38gpphgtuy-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 14 May 2021 20:08:07 +0000 Received: from userp3020.oracle.com (userp3020.oracle.com [127.0.0.1]) by pps.reinject (8.16.0.36/8.16.0.36) with SMTP id 14EK7LaX100292; Fri, 14 May 2021 20:08:07 GMT Received: from userv0121.oracle.com (userv0121.oracle.com [156.151.31.72]) by userp3020.oracle.com with ESMTP id 38gpphgtuk-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 14 May 2021 20:08:07 +0000 Received: from abhmp0014.oracle.com (abhmp0014.oracle.com [141.146.116.20]) by userv0121.oracle.com (8.14.4/8.13.8) with ESMTP id 14EK7xRE011960; Fri, 14 May 2021 20:07:59 GMT Received: from neelam.us.oracle.com (/10.152.128.16) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Fri, 14 May 2021 13:07:59 -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 Subject: [PATCH v15 5/6] locking/qspinlock: Avoid moving certain threads between waiting queues in CNA Date: Fri, 14 May 2021 16:07:42 -0400 Message-Id: <20210514200743.3026725-6-alex.kogan@oracle.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210514200743.3026725-1-alex.kogan@oracle.com> References: <20210514200743.3026725-1-alex.kogan@oracle.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Proofpoint-GUID: xuu9t5RUNNTjssDrPPvistR2qAfhAMQO X-Proofpoint-ORIG-GUID: xuu9t5RUNNTjssDrPPvistR2qAfhAMQO X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=9984 signatures=668683 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 lowpriorityscore=0 bulkscore=0 adultscore=0 priorityscore=1501 phishscore=0 malwarescore=0 spamscore=0 impostorscore=0 mlxlogscore=999 mlxscore=0 clxscore=1011 suspectscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2104190000 definitions=main-2105140159 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Prohibit moving certain threads (e.g., in irq and nmi contexts) to the secondary queue. Those prioritized threads will always stay in the primary queue, and so will have a shorter wait time for the lock. Signed-off-by: Alex Kogan Reviewed-by: Steve Sistare Reviewed-by: Waiman Long --- kernel/locking/qspinlock_cna.h | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/kernel/locking/qspinlock_cna.h b/kernel/locking/qspinlock_cna.h index 0b991c340fb1..ffc5c3301f0f 100644 --- a/kernel/locking/qspinlock_cna.h +++ b/kernel/locking/qspinlock_cna.h @@ -6,6 +6,7 @@ #include #include #include +#include /* * Implement a NUMA-aware version of MCS (aka CNA, or compact NUMA-aware lock). @@ -37,7 +38,8 @@ * running on the same NUMA node. If it is not, that waiter is detached from the * main queue and moved into the tail of the secondary queue. This way, we * gradually filter the primary queue, leaving only waiters running on the same - * preferred NUMA node. + * preferred NUMA node. Note that certain priortized waiters (e.g., in + * irq and nmi contexts) are excluded from being moved to the secondary queue. * * We change the NUMA node preference after a waiter at the head of the * secondary queue spins for a certain amount of time (1ms, by default). @@ -53,6 +55,8 @@ #define FLUSH_SECONDARY_QUEUE 1 +#define CNA_PRIORITY_NODE 0xffff + struct cna_node { struct mcs_spinlock mcs; u16 numa_node; @@ -111,9 +115,10 @@ static int __init cna_init_nodes(void) static __always_inline void cna_init_node(struct mcs_spinlock *node) { + bool priority = !in_task() || irqs_disabled() || rt_task(current); struct cna_node *cn = (struct cna_node *)node; - cn->numa_node = cn->real_numa_node; + cn->numa_node = priority ? CNA_PRIORITY_NODE : cn->real_numa_node; cn->start_time = 0; } @@ -252,7 +257,7 @@ static int cna_order_queue(struct mcs_spinlock *node) numa_node = cn->numa_node; next_numa_node = ((struct cna_node *)next)->numa_node; - if (next_numa_node != numa_node) { + if (next_numa_node != numa_node && next_numa_node != CNA_PRIORITY_NODE) { struct mcs_spinlock *nnext = READ_ONCE(next->next); if (nnext) @@ -272,6 +277,13 @@ static __always_inline u32 cna_wait_head_or_lock(struct qspinlock *lock, struct cna_node *cn = (struct cna_node *)node; if (!cn->start_time || !intra_node_threshold_reached(cn)) { + /* + * We are at the head of the wait queue, no need to use + * the fake NUMA node ID. + */ + if (cn->numa_node == CNA_PRIORITY_NODE) + cn->numa_node = cn->real_numa_node; + /* * Try and put the time otherwise spent spin waiting on * _Q_LOCKED_PENDING_MASK to use by sorting our lists. -- 2.24.3 (Apple Git-128)