Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp4656821ybi; Mon, 15 Jul 2019 12:30:16 -0700 (PDT) X-Google-Smtp-Source: APXvYqyNw/sZBB8FXstyaKeddu6igYjlIzwfSYqrv5zaNF4RJxQ3Og/2BX1qkL8RVItEpPl5fONd X-Received: by 2002:a17:902:a504:: with SMTP id s4mr8522048plq.117.1563219016592; Mon, 15 Jul 2019 12:30:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1563219016; cv=none; d=google.com; s=arc-20160816; b=0oAim0zbM2tO+9p9PLOJrgSmtVwdA2RmFfWl2V9n4dddJU4LbfzMHYdVnXGsD4mwfK sE1IaobfvKSPG2lT+5ZjCewAd5PNOdGIafJI/Zce0m4QJa1tnCJSg1jjXdzju3R6vs2K W7nAYGWuabakGFRD/rJsHc0r7mbewSEfsa+CqKAzYvobH90KLckHhx24O7kR/AKbGhCA RamsvQ/Q669LL+GE+HpLHra5qzttIq8GgcghQjrcM75RB4vT87lbGYo3vQwRH1uhgAN6 c5DpDVm8UJ4i8VjdzFUXlh2J3+K4abteCkSXBHeG9bPLmzlZo9FXHYhmoIXfzxw96nEp G7ZQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature; bh=UpYz68J9SXKjrbYmMLBu27WLSWRHESOgO2cA0Dv9rEc=; b=uDN9sPZyVzA6REleGtvkhnmb02zDeXSBD6pAkjk9drnnCJRL//vQC7NCdzFadSkRlr kRa/pLLQuN5K75XuQY04bbJQcaQSsdkeLHiwTI+QFuvzGb2QIbYG/yh1fonXLVq7c7g2 +J5nfviQMVlsQN87oJdhvFPv69hGfouKIOnfGFyn2uC0D9KCahgbEQruoIeQJa0AJoz8 +ALjlwyMF/NHQ0F2GrDV8qPbX1Z5mI81Ij6J9i/wO0MuJphEWp0m6sR9BT19gjoYcTfD sOW8KsjVqttWRhPNtSxD87smVpfVp20OPZDc9aXNfq9DzN9kn5YOCWwXz2FmJ0CQZl0U z1iA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@oracle.com header.s=corp-2018-07-02 header.b=PqyiOrfc; 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 k15si17553466pga.99.2019.07.15.12.30.00; Mon, 15 Jul 2019 12:30: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-2018-07-02 header.b=PqyiOrfc; 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 S1730477AbfGOT2t (ORCPT + 99 others); Mon, 15 Jul 2019 15:28:49 -0400 Received: from userp2130.oracle.com ([156.151.31.86]:40592 "EHLO userp2130.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729598AbfGOT2t (ORCPT ); Mon, 15 Jul 2019 15:28:49 -0400 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 x6FJO7Di018305; Mon, 15 Jul 2019 19:28: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=UpYz68J9SXKjrbYmMLBu27WLSWRHESOgO2cA0Dv9rEc=; b=PqyiOrfciKLM+Eu7h/+ffnZYAhF0Jhb8559fZ1toCjPSk5Sbs+46wJVoDd3qN3VcUBfq hiZYqojPjKGHAohKUfotJQ+r8QmWiYS6CbDYCLmmI+nDQsMeIw0AqmixDHaE0Bcl8EcT zIdxC9+W57ciXJu3otB3CwHrr+aZUPaWsUQrZUfu2pxEo+44QRkeouQZh+p3ONS4qU+t 8r55ubLMvQaKaNSzJtlFWGJVeL3ZyognjQvaS3tXo+488S568jlFOT6dLAoCHX2nbmT1 PTjgfrLwFVYbfl5Ww7SX2VMenDxZ348U2xU/ksCC9S1ZnPER4nGHJWnd3jRffwMnR8Sh hw== Received: from aserp3020.oracle.com (aserp3020.oracle.com [141.146.126.70]) by userp2130.oracle.com with ESMTP id 2tq6qtgj73-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 15 Jul 2019 19:28:01 +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 x6FJMe6T056368; Mon, 15 Jul 2019 19:26:00 GMT Received: from aserv0122.oracle.com (aserv0122.oracle.com [141.146.126.236]) by aserp3020.oracle.com with ESMTP id 2tq742prtm-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 aserv0122.oracle.com (8.14.4/8.14.4) with ESMTP id x6FJPwo6031353; Mon, 15 Jul 2019 19:25:58 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: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 v3 5/5] locking/qspinlock: Introduce the shuffle reduction optimization into CNA Date: Mon, 15 Jul 2019 15:25:36 -0400 Message-Id: <20190715192536.104548-6-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 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 3de5be813a46..9e6bd9e6d82b 100644 --- a/kernel/locking/qspinlock_cna.h +++ b/kernel/locking/qspinlock_cna.h @@ -50,6 +50,15 @@ static DEFINE_PER_CPU(u32, seed); #define INTRA_NODE_HANDOFF_PROB_ARG 0x10000 /* + * 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 0x80 + +/* * Return false with probability 1 / @range. * @range must be a power of 2. */ @@ -169,6 +178,16 @@ static inline void cna_pass_mcs_lock(struct mcs_spinlock *node, u64 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 pass the lock to a thread running on the same node. * For long-term fairness, search for such a thread with high * probability rather than always. @@ -194,5 +213,6 @@ static inline void cna_pass_mcs_lock(struct mcs_spinlock *node, * in the main queue. */ +pass_lock: arch_mcs_spin_unlock_contended(var, val); } -- 2.11.0 (Apple Git-81)