Received: by 2002:a25:c593:0:0:0:0:0 with SMTP id v141csp1135133ybe; Fri, 6 Sep 2019 12:23:16 -0700 (PDT) X-Google-Smtp-Source: APXvYqxOd4sTuorpP78yLCXJX7IhX3FDJbyrnj0o9KZ2P9p+zyLHbcOmVpit+Qp4If7YVF+hWLih X-Received: by 2002:a17:902:aa03:: with SMTP id be3mr11231923plb.84.1567797796234; Fri, 06 Sep 2019 12:23:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1567797796; cv=none; d=google.com; s=arc-20160816; b=EBzLdAeAO4rk544NezT0AseMpwZBrFSsXSZcU8ruWGPy36QmJgsHwULA+4Fp3d8ho0 2MCT4c36ujcKqgzSppDPgWEFvpFsgzz6tHIHe1esmqx/hrZMiQrxUqEUnGnmXGSKDyM0 lBoHipnnWw1NISKgm6UYkeW0FiDcODsWaT7zAXdUWXYZ+hpXWuL/JYnI/vXpfx45uHWC nyqDARrqvnsMPtbcl563DxHE/Wgph7pGuguT0mVrHMP2HYrkVedsVj/98Pn2zW5Pai1d l3qyZcdAkXb6/iK3Z+91y3IkcX25XGSjZtlqRwDQtYD0WY5FP5q4AYbuHlWNZ6/Whrfb VhOg== 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=w5Vu/fbczNwoQcE3H6hN/D9dx7OzQsmQPWGC5Uj8C14=; b=UazjHeDM0w2C0uNLBFzLdJ/zH52cwcoORoJiKF4D+LFC8cj+pKYwC2JS0WPsH9LMyZ ALBGdra036zZvBag4CqVA+Vs5b/5jZ7reluGXlKxVZ90if2OPnvetv80yvS8pdlZ8+qs eKzS3yhVHayJxN7oZtfhdyeYjKyGBT3UTfCtpmg5Zmtq1I4N07BJts/AdoyF3zpSv0KO 2ps1BT3fRxHdPAwsgZaopfsR7Oor7cpNWMo2J5HlvPcMnpSh/JXyIKjyfVF8JKqM1iVi zUF895molvZ20VNLcrn/ZHJOYbVJNmmJjGyhIKBNXyZLqjV94UjP9oC201X7tOV425vI 5HbQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@oracle.com header.s=corp-2019-08-05 header.b=NZhrmRf1; 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 i13si6655882pfq.54.2019.09.06.12.23.01; Fri, 06 Sep 2019 12:23:16 -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=NZhrmRf1; 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 S2394500AbfIFOhe (ORCPT + 99 others); Fri, 6 Sep 2019 10:37:34 -0400 Received: from aserp2120.oracle.com ([141.146.126.78]:38192 "EHLO aserp2120.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731943AbfIFOhc (ORCPT ); Fri, 6 Sep 2019 10:37:32 -0400 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 x86EY7Be032545; Fri, 6 Sep 2019 14:36:45 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=w5Vu/fbczNwoQcE3H6hN/D9dx7OzQsmQPWGC5Uj8C14=; b=NZhrmRf1W50Q/ZfNJSn3dGFcD7saeYNzsPB0KvZ9at5iuo/aGmDpqd1yx1LPDLf2tm4t bO2LdLi9AmxA5zRZrFdtG/kNNXwcjRXRUCaW8CoGsBSty9VHlmfbDmfhsPRH5nPq7xk3 tt9wbt7QX0ccqFKRoVoz2tuO0/eCafs+RWbcWzYlVcFSyehAtFsjjjmdr7Sju3/X2GxO IA6j+yUKeN5MO9Fura2quWyCNfYi+3xLw+F7zijzNWKTKqvtlYPaYR+3BkRH+13Mi3XD WWyzrjKCBCRWqKHdcg9kp0g0gmM0/n1MAmsxCM+KFzCDwlT9OCXAxfTyj9T2JZlczv43 Yw== Received: from aserp3020.oracle.com (aserp3020.oracle.com [141.146.126.70]) by aserp2120.oracle.com with ESMTP id 2uus4kg3n1-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 06 Sep 2019 14:36:45 +0000 Received: from pps.filterd (aserp3020.oracle.com [127.0.0.1]) by aserp3020.oracle.com (8.16.0.27/8.16.0.27) with SMTP id x86EXR7d079676; Fri, 6 Sep 2019 14:34:44 GMT Received: from userv0122.oracle.com (userv0122.oracle.com [156.151.31.75]) by aserp3020.oracle.com with ESMTP id 2uud7pk6h6-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 06 Sep 2019 14:34:44 +0000 Received: from abhmp0009.oracle.com (abhmp0009.oracle.com [141.146.116.15]) by userv0122.oracle.com (8.14.4/8.14.4) with ESMTP id x86EWwLi026054; Fri, 6 Sep 2019 14:32:58 GMT Received: from neelam.us.oracle.com (/10.152.128.16) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Fri, 06 Sep 2019 07:32:58 -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 v4 5/5] locking/qspinlock: Introduce the shuffle reduction optimization into CNA Date: Fri, 6 Sep 2019 10:25:41 -0400 Message-Id: <20190906142541.34061-6-alex.kogan@oracle.com> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20190906142541.34061-1-alex.kogan@oracle.com> References: <20190906142541.34061-1-alex.kogan@oracle.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9372 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-1906280000 definitions=main-1909060153 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9372 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-1906280000 definitions=main-1909060154 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org This optimization reduces the probability threads will be shuffled between the main and secondary queues when the secondary queue is empty. It is helpful when the lock is only lightly contended. Signed-off-by: Alex Kogan Reviewed-by: Steve Sistare --- kernel/locking/qspinlock_cna.h | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/kernel/locking/qspinlock_cna.h b/kernel/locking/qspinlock_cna.h index e86182e6163b..1c3a8905b2ca 100644 --- a/kernel/locking/qspinlock_cna.h +++ b/kernel/locking/qspinlock_cna.h @@ -64,6 +64,15 @@ static DEFINE_PER_CPU(u32, seed); #define INTRA_NODE_HANDOFF_PROB_ARG (16) /* + * Controls the probability for enabling the scan of the main queue when + * the secondary queue is empty. The chosen value reduces the amount of + * unnecessary shuffling of threads between the two waiting queues when + * the contention is low, while responding fast enough and enabling + * the shuffling when the contention is high. + */ +#define SHUFFLE_REDUCTION_PROB_ARG (7) + +/* * Return false with probability 1 / 2^@num_bits. * Intuitively, the larger @num_bits the less likely false is to be returned. * @num_bits must be a number between 0 and 31. @@ -230,6 +239,16 @@ static inline void cna_pass_lock(struct mcs_spinlock *node, u32 val = 1; /* + * Limit thread shuffling when the secondary queue is empty. + * This copes with the overhead the shuffling creates when the + * lock is only lightly contended, and threads do not stay + * in the secondary queue long enough to reap the benefit of moving + * them there. + */ + if (node->locked <= 1 && probably(SHUFFLE_REDUCTION_PROB_ARG)) + goto pass_lock; + + /* * Try to find a successor running on the same NUMA node * as the current lock holder. For long-term fairness, * search for such a thread with high probability rather than always. @@ -252,5 +271,6 @@ static inline void cna_pass_lock(struct mcs_spinlock *node, ((struct cna_node *)next_holder)->tail->mcs.next = next; } +pass_lock: arch_mcs_pass_lock(&next_holder->locked, val); } -- 2.11.0 (Apple Git-81)