Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp299360pxf; Wed, 24 Mar 2021 05:34:22 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzqmQ4Hj88Ahy6eVAgrs5bbuQtrogDFl6iA0MtSLua/N1wcVPSz2Kz++BqXt9mykMCs/1AB X-Received: by 2002:a05:6402:22b5:: with SMTP id cx21mr3212155edb.27.1616589261860; Wed, 24 Mar 2021 05:34:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1616589261; cv=none; d=google.com; s=arc-20160816; b=VlhKxlBSgONBlWKCCprKKMMI+htiW0J+bWXorBDiD3//F1iBI2ZlN/RM3Xoxv5Ot0/ EFVtnlCYrNRUbCY7EqR5+AjsjcGsGm9zQAoj4eymaoLu7FtOXmkMzamSjDvjjVvdgX2v y9BltHy4j+XiZBL8NpPHCu6vq4ZJTfO1Gy1gj3Z2+GxJJAHHPrEgJ1aRHznJ43bkEzCN y+EVbaSbgNczlnMgDjkSx9hraMp+w7jhxFAuKWJI9zwnb9rlb//jBvuFssomReY9rKoi 5vob1OhcYtTLa+B2+kzPhHj55HxrxIbCR711CsJa6cQeHDdwzfA6BB2nO7DI/9mdLRt+ SI/A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=2ffc7nYszRPIxKliihnC5n90uCSWD4QXn2lTh95xNgA=; b=DysAWqcSc2GnPUMAB83z9nuKRAV6nelNUESydDoDcgYk5ZofAWXx6Z0Pr+tB913Zc+ H/jV4epEnqQNUVqxtEwtKMwhd+sovgiCmB67I1TK0DUSve5ey4lYUslsN9MLVzf3gyUW zl0eBt+9D97c3aDdEiBGSer79jRoP5B/Mj5zDqS9VWUpoeG4sUyIgXrKU+bHepo9DvDT aEOH4O5njbSbS4cpRrGg6It9dMpgBZa3uroE5nrRIraBs+G5TvFXOGSQ9gWAjbi7/Byp vFAlggxW6s39teAI2Cp7xdndInAUX4JPg/lJ4QNEc0euAa3U6S2iBwiU4385Mu2LMmX1 uFNA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b=Qxr93f8l; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id c25si1612753edw.293.2021.03.24.05.33.58; Wed, 24 Mar 2021 05:34:21 -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=@infradead.org header.s=casper.20170209 header.b=Qxr93f8l; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233240AbhCXMc1 (ORCPT + 99 others); Wed, 24 Mar 2021 08:32:27 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52630 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232207AbhCXMcW (ORCPT ); Wed, 24 Mar 2021 08:32:22 -0400 Received: from casper.infradead.org (casper.infradead.org [IPv6:2001:8b0:10b:1236::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B10D6C061763 for ; Wed, 24 Mar 2021 05:32:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=In-Reply-To:Content-Type:MIME-Version: References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=2ffc7nYszRPIxKliihnC5n90uCSWD4QXn2lTh95xNgA=; b=Qxr93f8l7eWrgFSC9F99sXFzXQ lC0604zmLZikerou9UaWz9R67NWKWhURTC2ORD5Oq9YMMwSvVYQJm5d5NuR8+/bMdULyw5eLEkslF M5LP/RLoRrBPX6G94aoG6mKJlqUGgdBoi/OiRJfm7GXhofAVBxZe+F/C2qwS5vPnjHgmW+lHp2HtP umiGhP4zSz9ZS9nXRp0PCmhcOjEl/pVh7dFfJS4EzZnrsBcucvxKcqaTIFISe20vBYrCXRMSTA/bj CqVMXS9uBeC9caiYK9zcL2TIrfMIYiBcaDsRlPSCyi5iKJ0j0AR4smCRkKfBkt5qlB85Nk/hWnscI AZMYQylg==; Received: from j217100.upc-j.chello.nl ([24.132.217.100] helo=noisy.programming.kicks-ass.net) by casper.infradead.org with esmtpsa (Exim 4.94 #2 (Red Hat Linux)) id 1lP2fS-00BKqV-6p; Wed, 24 Mar 2021 12:31:31 +0000 Received: from hirez.programming.kicks-ass.net (hirez.programming.kicks-ass.net [192.168.1.225]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by noisy.programming.kicks-ass.net (Postfix) with ESMTPS id 7E60330377D; Wed, 24 Mar 2021 13:31:21 +0100 (CET) Received: by hirez.programming.kicks-ass.net (Postfix, from userid 1000) id 44F6D2BF5B73E; Wed, 24 Mar 2021 13:31:21 +0100 (CET) Date: Wed, 24 Mar 2021 13:31:21 +0100 From: Peter Zijlstra To: Guo Ren Cc: Vitaly Wool , linux-riscv , LKML , Guo Ren , Catalin Marinas , Will Deacon , Palmer Dabbelt , Anup Patel , Arnd Bergmann Subject: Re: [PATCH] riscv: locks: introduce ticket-based spinlock implementation Message-ID: References: <1616580892-80815-1-git-send-email-guoren@kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Mar 24, 2021 at 08:24:34PM +0800, Guo Ren wrote: > On Wed, Mar 24, 2021 at 7:16 PM Vitaly Wool wrote: > > > > > > > > On Wed, Mar 24, 2021, 11:16 AM wrote: > >> > >> From: Guo Ren > >> > >> This patch introduces a ticket lock implementation for riscv, along the > >> same lines as the implementation for arch/arm & arch/csky. > > > > > > Could you please provide a rationale for this? Like, what is wrong with the current implementation. > Ticket based spinlock's principle is here: > https://lwn.net/Articles/267968/ > > Current implementation will cause cache line bouncing when many harts > are acquiring the same spinlock. > I'm seeking a solution, maybe not fitting the current RISC-V base ISA. Ticket locks as such don't solve the cacheline bouncing part, since they're all still spinning on the same line. The big improvement ticket locks bring is that the lock acquisition time becomes a function of the longest hold time, instead of being unbounded. However, combine it with the WFE (preferably the ARM64 variant) and you can avoid the worst of the bouncing. If you really want to get rid of the bouncing, go with qspinlock, which will spin on a cpu local line. That said, qspinlock is quite gnarly code, and only really wins from ticket when you have NUMA.