Received: by 2002:a05:6a10:5bc5:0:0:0:0 with SMTP id os5csp726687pxb; Thu, 21 Oct 2021 08:21:10 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxNHzLWPNau8UJ1NGDj3Ro1nkng5qVWgLWPHd0h80ikl6nCQjlFIDJULGdso+iNqQIXkeSN X-Received: by 2002:a17:90a:9303:: with SMTP id p3mr1910133pjo.201.1634829670272; Thu, 21 Oct 2021 08:21:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1634829670; cv=none; d=google.com; s=arc-20160816; b=CS1S7XezIsrnXYHwqhOssLW450UvIThi/9jln/RVUd5fpfX/QLt6Q9BxKfrY30O3ps 8dt8V3zzQKGEXp0jEPXeSwTdDMmbAnLGnIk+MqLelkKm+NQPnmMouyj7zrxDgfybtrWy Nb/gIluSh46jX8LfaGAwZ5kd8WHZ030w3Oc3KwFhUxEyR3YWCsWZR8RRjwmWRETJHRnI Y4kU2zi1dE1hjreY0O4FiicGL4xqK0thT+zNwlm796TwCt6/bhskHas63ElzBrJXULde 4NMfDLAnsyllJmevsF7nMeiYfObw5i5cRbiBDw2lZmQRS/BrBDxxnXa6WuO5CIsFX0Rh BWMQ== 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=NLJ71Cg5LEnHqcIFkkZXwV1AtdUcW7tx8BbmnW6dm2g=; b=aRpyTccZ1kpzb9sSmH7IGKzL3fRkKl3TbcBfvdhM0Ezqa5c8Jpa7U8Skz3nVdjba4u hTBQ3i+nDwkQvCQFrbAEB8ivOWH/bIELzl+8bMYqUfi8Fc2zN5XKL7apnmdW2lj8mmaa O9dOxAIWZho4lD9ex5mKrgvlnY+OVB1JlXIieSE8gYx2TjE3q1UBO/HmHyZ5ovMC7Msz tzaHgrSUVZUPDjDHjnJ7qfGHr2jOkUKtWVZ8U6bm3QIJp+NrPfGpo+JmiUExcuzzggLx bAsV7zYKmYHf2qvQ9rg2/hEM/VGzQkdK7+DwHjpKOx47vG8+1owyPETgGMPkD1U6Ngqm e5Hw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b=LlXZjS8m; 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 j6si11366250pji.43.2021.10.21.08.20.51; Thu, 21 Oct 2021 08:21:10 -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=LlXZjS8m; 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 S231702AbhJUPV4 (ORCPT + 99 others); Thu, 21 Oct 2021 11:21:56 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51298 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231239AbhJUPVz (ORCPT ); Thu, 21 Oct 2021 11:21:55 -0400 Received: from casper.infradead.org (casper.infradead.org [IPv6:2001:8b0:10b:1236::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6A80BC061764; Thu, 21 Oct 2021 08:19:39 -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=NLJ71Cg5LEnHqcIFkkZXwV1AtdUcW7tx8BbmnW6dm2g=; b=LlXZjS8mpvPBPAcm9fAJMVVIEX GW9IxpiIaNNbRWFpiiSrlTQAisFo2nBmhFeRJTVLmPD3snhgYjgXfnh5+Tppkpkldh2CtnayBpvZU 5VHsyKd64d1lhCkh2nspl7xw3HumC1xR2FmEPtMaRFc0FuBNTaijLVDqndEt1Xt7RasRb+gxhJSve tOKrfkwzfTuEfudSGXk/vzEgRdjLGuVswaaowf9Dd2xcJypZr51wI2BcTsmx0BUa1WiVCmok0aP4i u+v+vQl85dvR1aFijH7mbSgbGRIpGymJSZJWNLdMavXimToVlBQVcebHmtAT3g/7GQQmVBnMZ6U42 798BlBkg==; 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 #2 (Red Hat Linux)) id 1mdZmI-00DLc1-I2; Thu, 21 Oct 2021 15:15:48 +0000 Received: from hirez.programming.kicks-ass.net (hirez.programming.kicks-ass.net [192.168.1.225]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (Client did not present a certificate) by noisy.programming.kicks-ass.net (Postfix) with ESMTPS id 30C283002BC; Thu, 21 Oct 2021 17:14:45 +0200 (CEST) Received: by hirez.programming.kicks-ass.net (Postfix, from userid 1000) id 0920B2C103FF6; Thu, 21 Oct 2021 17:14:45 +0200 (CEST) Date: Thu, 21 Oct 2021 17:14:44 +0200 From: Peter Zijlstra To: Arnd Bergmann Cc: Will Deacon , Boqun Feng , Ingo Molnar , Waiman Long , linux-arch , Linux Kernel Mailing List , Guo Ren , Palmer Dabbelt , Anup Patel , linux-riscv , Christoph =?iso-8859-1?Q?M=FCllner?= , Stafford Horne Subject: Re: [PATCH] locking: Generic ticket lock Message-ID: References: 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 Thu, Oct 21, 2021 at 03:49:51PM +0200, Arnd Bergmann wrote: > On Thu, Oct 21, 2021 at 3:05 PM Peter Zijlstra wrote: > > > > Therefore provide ticket locks, which depend on a single atomic > > operation (fetch_add) while still providing fairness. > > Nice! > > Aside from the qspinlock vs ticket-lock question, can you describe the > tradeoffs between this generic ticket lock and a custom implementation > in architecture code? Should we convert most architectures over > to the generic code in the long run, or is there something they > can usually do better with an inline asm based ticket lock I think for a load-store arch this thing should generate pretty close to optimal code. x86 can do ticket_unlock() slightly better using a single INCW (or ADDW 1) on the owner subword, where this implementation will to separate load-add-store instructions. If that is actually measurable is something else entirely. > or a trivial test-and-set? If your SMP arch is halfway sane (no fwd progress issues etc..) then ticket should behave well and avoid the starvation/variablilty of TaS lock. The big exception there is virtualized architectures, ticket is absolutely horrendous for 'guests' (any fair lock is for that matter).