Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp14532868ybl; Mon, 30 Dec 2019 11:54:59 -0800 (PST) X-Google-Smtp-Source: APXvYqyeHZpBFHaeYe1aRwnfjhhMDapm9NDAFsfv63bcX0XkvdeUetkqTnVwR4lcvIx6w5eZpWbI X-Received: by 2002:a9d:7b4a:: with SMTP id f10mr79756111oto.4.1577735699042; Mon, 30 Dec 2019 11:54:59 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1577735699; cv=none; d=google.com; s=arc-20160816; b=qXk9riG1jGAOMDT72nlzJUWBJZD+XKUF6TIfb/VnMROTnJuO3P1oj4FEZrmjw38Ec+ rWv5nmhs7ZasIK6Y+EJN5B6Ch7VnM/86ClPL9u9aRtvmdaD6pChUsmc/zlGj7HmYSE/V E0IcuXR5EgBhHvOXCq2K7l1cwtvn+pf+HXm1//pFkphoFG37yYYN14IKFXhGHbNvY/rU wdS0ROZetleSOW3VtT/cNAU4vZQ27SL/1Hzg82EJnokNUDvYrRMMnXId513kULiYtXrG jmxZ5Agf2/4dxfr4Z5ozFDhDeIXanCauN4obsVpEWvYM7RovYvc0uHMbsuftTFJ8+eBN Kp0Q== 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=XKCuT7K0ULZ+TUj+OGBg4bsgVGrV1PnBx6CgIY/Pdm0=; b=Qbzp7yvAbxWBAxh/8BvJPvVttJ/lCj3KxXT4wfkR2TWeWhkXNiBe4HXO9aZZzFF0YT Luodw+a+ABsCR8gvuFANVuG3vVyGL9vquuJT+f14SOyW6nmZfBretNl8uCRzuHMzcvFK 21/CI16B2yaOTnxKZDxA5nd3mCG2/K5WvdQmB5qeg29Cx5SIgH40TvQMqlWfw9ncCC7l jZX4Oh7/nOCDmhZYuZCOtSMkWaCeLTwHq6mYdKiWCBw6JfOe9WX67onmCM/9BL71pWYD o/DM+jItZAqKqu/WM2vvVUYwe3yAPwkP3oM1EFHokPthfzO28zxXPNZe6rmYTelevxz0 zAGQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@oracle.com header.s=corp-2019-08-05 header.b=pb9dO9fP; 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 k2si24154651otb.272.2019.12.30.11.54.46; Mon, 30 Dec 2019 11:54:59 -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=pb9dO9fP; 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 S1727744AbfL3TyA (ORCPT + 99 others); Mon, 30 Dec 2019 14:54:00 -0500 Received: from aserp2120.oracle.com ([141.146.126.78]:58802 "EHLO aserp2120.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727684AbfL3Txx (ORCPT ); Mon, 30 Dec 2019 14:53:53 -0500 Received: from pps.filterd (aserp2120.oracle.com [127.0.0.1]) by aserp2120.oracle.com (8.16.0.27/8.16.0.27) with SMTP id xBUJnI18140850; Mon, 30 Dec 2019 19:52:49 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=XKCuT7K0ULZ+TUj+OGBg4bsgVGrV1PnBx6CgIY/Pdm0=; b=pb9dO9fPXP5p7eLb0Be1+o1tFsX6s8pCxYGTe4t+UuVt6LyCni0lGPvH9dOkoaV7BcGL Z31fvBeePFhjEFXorjtq+uXTRvL6lXsW96h63jPI0uU3o6BO63Juzwn0KOvciqA8IhDA O1TXat3fzGnqKJXpukfLsW94Sps09fKvCeyEkdNhdpyh4ZXToBCKmZkf1js6DFdt9I/k xaQBgI98eTOS9npm8CYFUBK3bFUnB/pZASFGPEA34smH3SWC5U4xW1umQ50M7yoH5dt7 iI1wJ+yIz6PnrxrMuRmurvJkUt+xtOolfII5juZ5nYXeALzAsc5V04jtoKkGoZY9j0PS mQ== Received: from userp3020.oracle.com (userp3020.oracle.com [156.151.31.79]) by aserp2120.oracle.com with ESMTP id 2x5y0pexkf-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 (userp3020.oracle.com [127.0.0.1]) by userp3020.oracle.com (8.16.0.27/8.16.0.27) with SMTP id xBUJnGpI180871; Mon, 30 Dec 2019 19:52:48 GMT Received: from aserv0121.oracle.com (aserv0121.oracle.com [141.146.126.235]) by userp3020.oracle.com with ESMTP id 2x6h6q3491-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 aserv0121.oracle.com (8.14.4/8.13.8) with ESMTP id xBUJqYNt026057; Mon, 30 Dec 2019 19:52:34 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:33 -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 4/5] locking/qspinlock: Introduce starvation avoidance into CNA Date: Mon, 30 Dec 2019 14:40:41 -0500 Message-Id: <20191230194042.67789-5-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 Keep track of the number of intra-node lock handoffs, and force inter-node handoff once this number reaches a preset threshold. The default value for the threshold can be overridden with the new kernel boot command-line option "numa_spinlock_threshold". Signed-off-by: Alex Kogan Reviewed-by: Steve Sistare --- .../admin-guide/kernel-parameters.txt | 8 ++++ kernel/locking/qspinlock.c | 3 ++ kernel/locking/qspinlock_cna.h | 41 ++++++++++++++++++- 3 files changed, 51 insertions(+), 1 deletion(-) diff --git a/Documentation/admin-guide/kernel-parameters.txt b/Documentation/admin-guide/kernel-parameters.txt index b68cb80e477f..30d79819a3b0 100644 --- a/Documentation/admin-guide/kernel-parameters.txt +++ b/Documentation/admin-guide/kernel-parameters.txt @@ -3200,6 +3200,14 @@ Not specifying this option is equivalent to numa_spinlock=auto. + numa_spinlock_threshold= [NUMA, PV_OPS] + Set the threshold for the number of intra-node + lock hand-offs before the NUMA-aware spinlock + is forced to be passed to a thread on another NUMA node. + Valid values are in the [0..31] range. Smaller values + result in a more fair, but less performant spinlock, and + vice versa. The default value is 16. + cpu0_hotplug [X86] Turn on CPU0 hotplug feature when CONFIG_BOOTPARAM_HOTPLUG_CPU0 is off. Some features depend on CPU0. Known dependencies are: diff --git a/kernel/locking/qspinlock.c b/kernel/locking/qspinlock.c index 609980a53841..e382d8946ccc 100644 --- a/kernel/locking/qspinlock.c +++ b/kernel/locking/qspinlock.c @@ -597,6 +597,9 @@ EXPORT_SYMBOL(queued_spin_lock_slowpath); #if !defined(_GEN_CNA_LOCK_SLOWPATH) && defined(CONFIG_NUMA_AWARE_SPINLOCKS) #define _GEN_CNA_LOCK_SLOWPATH +#undef pv_init_node +#define pv_init_node cna_init_node + #undef pv_wait_head_or_lock #define pv_wait_head_or_lock cna_pre_scan diff --git a/kernel/locking/qspinlock_cna.h b/kernel/locking/qspinlock_cna.h index 3c99a4a6184b..30feff02865d 100644 --- a/kernel/locking/qspinlock_cna.h +++ b/kernel/locking/qspinlock_cna.h @@ -51,13 +51,25 @@ struct cna_node { int numa_node; u32 encoded_tail; u32 pre_scan_result; /* encoded tail or enum val */ + u32 intra_count; }; enum { LOCAL_WAITER_FOUND = 2, /* 0 and 1 are reserved for @locked */ + FLUSH_SECONDARY_QUEUE = 3, MIN_ENCODED_TAIL }; +/* + * Controls the threshold for the number of intra-node lock hand-offs before + * the NUMA-aware variant of spinlock is forced to be passed to a thread on + * another NUMA node. By default, the chosen value provides reasonable + * long-term fairness without sacrificing performance compared to a lock + * that does not have any fairness guarantees. The default setting can + * be changed with the "numa_spinlock_threshold" boot option. + */ +int intra_node_handoff_threshold __ro_after_init = 1 << 16; + static void __init cna_init_nodes_per_cpu(unsigned int cpu) { struct mcs_spinlock *base = per_cpu_ptr(&qnodes[0].mcs, cpu); @@ -97,6 +109,11 @@ static int __init cna_init_nodes(void) } early_initcall(cna_init_nodes); +static __always_inline void cna_init_node(struct mcs_spinlock *node) +{ + ((struct cna_node *)node)->intra_count = 0; +} + /* this function is called only when the primary queue is empty */ static inline bool cna_try_change_tail(struct qspinlock *lock, u32 val, struct mcs_spinlock *node) @@ -233,7 +250,9 @@ __always_inline u32 cna_pre_scan(struct qspinlock *lock, { struct cna_node *cn = (struct cna_node *)node; - cn->pre_scan_result = cna_scan_main_queue(node, node); + cn->pre_scan_result = + cn->intra_count == intra_node_handoff_threshold ? + FLUSH_SECONDARY_QUEUE : cna_scan_main_queue(node, node); return 0; } @@ -263,6 +282,9 @@ static inline void cna_pass_lock(struct mcs_spinlock *node, * if we acquired the MCS lock when its queue was empty */ val = node->locked ? node->locked : 1; + /* inc @intra_count if the secondary queue is not empty */ + ((struct cna_node *)next_holder)->intra_count = + cn->intra_count + (node->locked > 1); } else if (node->locked > 1) { /* if secondary queue is not empty */ /* next holder will be the first node in the secondary queue */ tail_2nd = decode_tail(node->locked); @@ -317,3 +339,20 @@ void cna_configure_spin_lock_slowpath(void) pr_info("Enabling CNA spinlock\n"); } } + +static int __init numa_spinlock_threshold_setup(char *str) +{ + int new_threshold_param; + + if (get_option(&str, &new_threshold_param)) { + /* valid value is between 0 and 31 */ + if (new_threshold_param < 0 || new_threshold_param > 31) + return 0; + + intra_node_handoff_threshold = 1 << new_threshold_param; + return 1; + } + + return 0; +} +__setup("numa_spinlock_threshold=", numa_spinlock_threshold_setup); -- 2.21.0 (Apple Git-122.2)