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=-2.2 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS,URIBL_BLOCKED,USER_AGENT_SANE_1 autolearn=no 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 7C6D3C76192 for ; Tue, 16 Jul 2019 15:59:19 +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 541A320880 for ; Tue, 16 Jul 2019 15:59:19 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="bwOxlb/Z" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 541A320880 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=infradead.org 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:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:In-Reply-To:MIME-Version:References: Message-ID:Subject:To:From:Date:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=vTPmrGemKNrhPBl2jYXX5aZXsAzvUYDLca53CO2wzMM=; b=bwOxlb/Zx/fHIE 7WirqYCFwrG+lLckqQTqF0ybEGBe81k8g+V9A4FWWXUXlfAzI/Q7A44q3n3102GjPV4u5f9IjHHLe EQ4kmC9Bo5hQzvbj5IuW641iHgyPZhrSFLHI8Le4pOsuPHMNwxJ9mT9gqeBre6OwrFSytlZpz4ncu u7yaz59vv7px9Hw2sUzRzo3Tl+948bszkshgrnLm3uLSKGiQJZAPgyl4oan3kSfNVPlf8X/Z6lTdz jiJe23bD/G4UXusruN1Cd0Pr3uL/m6LiRwLNhxZqwd3QA3cKNg20t0UjQkj2GDgQQsV0gHauVnG2h cFVC65VzYc+eIFgvRvyg==; 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 1hnPrK-0001Go-Jy; Tue, 16 Jul 2019 15:59:18 +0000 Received: from j217100.upc-j.chello.nl ([24.132.217.100] helo=hirez.programming.kicks-ass.net) by bombadil.infradead.org with esmtpsa (Exim 4.92 #3 (Red Hat Linux)) id 1hnPr4-00015I-B2; Tue, 16 Jul 2019 15:59:02 +0000 Received: by hirez.programming.kicks-ass.net (Postfix, from userid 1000) id B55F12059DEA3; Tue, 16 Jul 2019 17:59:00 +0200 (CEST) Date: Tue, 16 Jul 2019 17:59:00 +0200 From: Peter Zijlstra To: Alex Kogan Subject: Re: [PATCH v3 4/5] locking/qspinlock: Introduce starvation avoidance into CNA Message-ID: <20190716155900.GS3419@hirez.programming.kicks-ass.net> References: <20190715192536.104548-1-alex.kogan@oracle.com> <20190715192536.104548-5-alex.kogan@oracle.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20190715192536.104548-5-alex.kogan@oracle.com> User-Agent: Mutt/1.10.1 (2018-07-13) 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: linux-arch@vger.kernel.org, guohanjun@huawei.com, arnd@arndb.de, dave.dice@oracle.com, jglauber@marvell.com, x86@kernel.org, will.deacon@arm.com, linux@armlinux.org.uk, steven.sistare@oracle.com, linux-kernel@vger.kernel.org, rahul.x.yadav@oracle.com, mingo@redhat.com, bp@alien8.de, hpa@zytor.com, longman@redhat.com, tglx@linutronix.de, daniel.m.jordan@oracle.com, linux-arm-kernel@lists.infradead.org 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 On Mon, Jul 15, 2019 at 03:25:35PM -0400, Alex Kogan wrote: > @@ -36,6 +37,33 @@ struct cna_node { > > #define CNA_NODE(ptr) ((struct cna_node *)(ptr)) > > +/* Per-CPU pseudo-random number seed */ > +static DEFINE_PER_CPU(u32, seed); > + > +/* > + * Controls the probability for intra-node lock hand-off. It can be > + * tuned and depend, e.g., on the number of CPUs per node. For now, > + * choose a value that provides reasonable long-term fairness without > + * sacrificing performance compared to a version that does not have any > + * fairness guarantees. > + */ > +#define INTRA_NODE_HANDOFF_PROB_ARG 0x10000 > + > +/* > + * Return false with probability 1 / @range. > + * @range must be a power of 2. > + */ > +static bool probably(unsigned int range) > +{ > + u32 s; > + > + s = this_cpu_read(seed); > + s = next_pseudo_random32(s); > + this_cpu_write(seed, s); > + > + return s & (range - 1); This is fragile, better to take a number of bits as argument. > +} > + > static void cna_init_node(struct mcs_spinlock *node) > { > struct cna_node *cn = CNA_NODE(node); > @@ -140,7 +168,13 @@ static inline void cna_pass_mcs_lock(struct mcs_spinlock *node, > u64 *var = &next->locked; > u64 val = 1; > > - succ = find_successor(node); > + /* > + * 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. > + */ > + if (probably(INTRA_NODE_HANDOFF_PROB_ARG)) > + succ = find_successor(node); > > if (succ) { > var = &succ->mcs.locked; And this is where that tertiary condition comes from.. I think. _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel