Received: by 2002:a05:6a10:17d3:0:0:0:0 with SMTP id hz19csp2279795pxb; Mon, 12 Apr 2021 20:36:37 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxnj8bFWNcsZAoQa9oUOKJLwHlTF/SA85SdFqfyTLYTZofH2g4VJ2z27k9gryw84WuKg7wF X-Received: by 2002:a17:906:6818:: with SMTP id k24mr11210403ejr.245.1618284997475; Mon, 12 Apr 2021 20:36:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1618284997; cv=none; d=google.com; s=arc-20160816; b=vTSIkZMepT2+gGcLfYVMfxlMiQvOHrWBENty+cAM2EO4G9KQh9t4m5KMPeaQteJ5SL 6j8k5nzBZrUwXZHq2+uZBJLQFg5+VFQ4aPCosIYcWM05YexIKdQg9itiOreFZATaPln0 Rx909wFdJNt7zJ3vtltJnwzILmvn3ud6qo0MwXsce8sEld8yYvqicli6wEn6TzesHzpc WnLvnll5/ldjU8SIIponOd3odJWJpU01R7GtUZTmcArTyCfROHhLeMtz/3czDpmUy42w y4fo+8IHoE2siXwbqZLavYTtLd1cshr+x20lPcgzsMuw43h336N24ExEBJfJtCyX6sIT Lo6Q== 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-transfer-encoding :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=rRe7DVuz4nyczLVADh65ma4uSYCAgh2zkUam7lUOvyY=; b=ploUtvdiRmq2laReZlaCv6mrzQ3riCu2jWVZqNboG2ndNXIhfuDsC7T7yKd9NWAJ7K CqKJzqCktzjS8/amsYqPndsmOXRlLXz5pcu82SahC1GBtnssEkJCnlwjMNTO1uK2u4nl +3evp3dsBnasGTwZYYlh/M9GzZAugm2dBoLmQJu2IHyUfY4JAAoFfgrPdlm3KF10nH/9 3xiBYJMSyMpLs+bCkBaVeG2Vv/twNnYEMl1Z8dutCa6vQ2mQ3ptD1jjsqqc40uuqu3cf Ve2MLWbO5Jix0s4NWVzeVEBtpjdP/jcO06lOOtjFM48i5pHyIx8dvHn3/hTLDP5Frjbc buYA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=desiato.20200630 header.b=R3LBdCUV; 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 z15si1167606ejr.444.2021.04.12.20.36.13; Mon, 12 Apr 2021 20:36:37 -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=desiato.20200630 header.b=R3LBdCUV; 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 S242394AbhDLOwW (ORCPT + 99 others); Mon, 12 Apr 2021 10:52:22 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59954 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239030AbhDLOwU (ORCPT ); Mon, 12 Apr 2021 10:52:20 -0400 Received: from desiato.infradead.org (desiato.infradead.org [IPv6:2001:8b0:10b:1:d65d:64ff:fe57:4e05]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F33C3C061574 for ; Mon, 12 Apr 2021 07:52:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=desiato.20200630; h=In-Reply-To:Content-Transfer-Encoding: Content-Type:MIME-Version:References:Message-ID:Subject:Cc:To:From:Date: Sender:Reply-To:Content-ID:Content-Description; bh=rRe7DVuz4nyczLVADh65ma4uSYCAgh2zkUam7lUOvyY=; b=R3LBdCUV40azrDJv++zfvrx8FB 0bRWVwjYXBHLVYGTpAm49md6wc0enxHpgdnNinMcxVBujd28mmXjxYw5rbVPHeamE/6gVb+lt3JrY 1zafgCfqMylsXMuPOcQ/aQX8jBOp9x/ree0Xpo11QapNfq+jo44g7rEDx6pbYZP/Ar9LneOGEnYcj n9oW4EHssghlrktoos+dBVg0ldRc6z1MCc/QoPvllPbKnPR1FRJ4YCwNhwCgj1e7bPyB3fW0XIah6 1LqpEBAeH/PfA6BmGj8A2U+sNFwfiADri/A+awnNmgzXD6gsN11Dj3/2bLY1xrhG9RzPiHdtmElkF HJ2+HwvA==; Received: from j217100.upc-j.chello.nl ([24.132.217.100] helo=noisy.programming.kicks-ass.net) by desiato.infradead.org with esmtpsa (Exim 4.94 #2 (Red Hat Linux)) id 1lVxuv-0070VF-9F; Mon, 12 Apr 2021 14:51:57 +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 D6D8D300036; Mon, 12 Apr 2021 16:51:55 +0200 (CEST) Received: by hirez.programming.kicks-ass.net (Postfix, from userid 1000) id 8283A2040BB0F; Mon, 12 Apr 2021 16:51:55 +0200 (CEST) Date: Mon, 12 Apr 2021 16:51:55 +0200 From: Peter Zijlstra To: Christoph =?iso-8859-1?Q?M=FCllner?= Cc: Palmer Dabbelt , Anup Patel , Guo Ren , linux-riscv , Linux Kernel Mailing List , Guo Ren , catalin.marinas@arm.com, will.deacon@arm.com, Arnd Bergmann Subject: Re: [PATCH] riscv: locks: introduce ticket-based spinlock implementation Message-ID: References: MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Please fix your mailer to properly flow text. Reflowed it for you. On Mon, Apr 12, 2021 at 03:32:27PM +0200, Christoph M?llner wrote: > This discussion came up again a few weeks ago because I've been > stumbling over the test-and-set implementation and was wondering if > nobody cared to improve that yet. > Then I saw, that there have been a few attempts so far, but they did > not land. So I brought this up in RVI's platform group meeting and > the attendees showed big interest to get at least fairness. I assume > Guo sent out his new patchset as a reaction to this call (1 or 2 days > later). > > We have the same situation on OpenSBI, where we've agreed (with Anup) > to go for a ticket lock implementation. A series for that can be > found here (the implementation was tested in the kernel): > http://lists.infradead.org/pipermail/opensbi/2021-April/000789.html > > In the mentioned RVI call, I've asked the question if ticket locks or > MCF locks are preferred. And the feedback was to go for > qspinlock/qrwlock. One good argument to do so would be, to not have to > maintain an RV-specific implementation, but to use a well-tested > in-kernel mechanism. qrwlock does not depend on qspinlock; any fair spinlock implementation works, including ticket. > The feedback in the call is also aligned with the previous attempts to > enable MCF-locks on RV. However, the kernel's implementation requires > sub-word atomics. And here is, where we are. The discussion last week > was about changing the generic kernel code to loosen its requirements > (not accepted because of performance regressions on e.g. x86) and if > RV actually can provide sub-word atomics in form of LL/SC loops (yes, > that's possible). So qspinlock is a complex and fickle beast. Yes it works on x86 and arm64 (Will and Catalin put a _lot_ of effort into that), but IMO using such a complex thing needs to be provably better than the trivial and simple thing (tickets, test-and-set). Part of that is fwd progress, if you don't have that, stay with test-and-set. Will fixed a number of issues there, and -RT actually hit at least one. Debugging non-deterministic lock behaviour is not on the fun list. Having something simple (ticket) to fall back to to prove it's your lock going 'funneh' is very useful. > Providing sub-word xchg() can be done within a couple of hours (some > solutions are already on the list), but that was not enough from the > initial patchset from Michael on (e.g. Christoph Hellwig asked back > then for moving arch-independent parts into lib, which is a good idea > given other archs do the same). So I expect this might require some > more time until there is a solution, that's accepted by a broad range > of maintainers. Using a lib/ cmpxchg based xchg16 is daft. Per the very same arguments I made elsewhere in the thread. cmpxchg() based loops have very difficult fwd progress guarantees, esp. so on LL/SC architectures. What I would do is create a common inline helper to compute that {addr, mask, val} setup with a comment on how to use it. (As is, we have at least 2 different ways of dealing with ENDIAN-ness) > I've been working on a new MCF-lock series last week. It is working, > but I did not publish it yet, because I wanted to go through the 130+ > emails on the riscv-linux list and check for overseen review comments > and validate the patch authors. > You can find the current state here: > https://github.com/cmuellner/linux/pull/new/riscv-spinlocks That's not public. But if that's not qspinlock, how are you justifying a complex spinlock implementation? Does it perform better than ticket? > So, if you insist on ticket locks, then let's coordinate who will do > that and how it will be tested (RV32/RV64, qemu vs real hw). Real hardware is all that counts :-)