Received: by 2002:a25:1506:0:0:0:0:0 with SMTP id 6csp4711788ybv; Wed, 26 Feb 2020 01:48:37 -0800 (PST) X-Google-Smtp-Source: APXvYqxCGudr+ZrZpUv5jj4kfeMGXeYgjqdFOCl3UnuNPoKBPKP+QH8WO0SbXjd08w/nkxv5fdua X-Received: by 2002:aca:a9d4:: with SMTP id s203mr2396767oie.106.1582710517221; Wed, 26 Feb 2020 01:48:37 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1582710517; cv=none; d=google.com; s=arc-20160816; b=c5Mcm/HGdZOJ2bRsrWAmZeo8uSC3O7di7bZb9Vix8Ddl6jImhd/Pj+WgjZQMBhISdM vL/MLxVdFjB383NHu6e873k2ERWfYW21YLPqYXPjn0/zuH0va+aSB39qcwml2DGrMJvQ XrbUxkfQtGG2wx5J6532N0w7l0fHCwu2hIpc2PJ8MnOhMyuMJHVNRin5lBOkLdMGZYb3 3UjJaeX8b0y7hg87F+yVjWG3UUt7bq3sGJmq5/NP2BqFsvm8galNFCbbAKWXZ7gb1Qwp ZuRpsHhnqRA8lyaJzQcGih9ciYuP0QPk7PwJt42eH0gUQu2CQqUhEZZKMP4jEy1j/GZm LCWw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-transfer-encoding:content-disposition:mime-version :references:message-id:subject:cc:to:date:from; bh=KSPv9KWSBdRDuL5HfmylRHcHYTrbXi5lgP0dHvGTT3k=; b=zL9LqEr+tbgTt+8H8m4rqCn8cFJlWp8PUZvfWoyVvgvGU+xBzslzW+j21bLhJRKPAz cUhtiF8m6O7towJ4cgzKwhmFd/M7h8enlv7bA4n1VXrThpgFDoXIiDV+nlQ6vZJmC4Io JdrjK4GeJW0P6gtEFYRAqj8jcBNQqmqySgDWkfhNAYf3G4W1PYlH8iuVeM8pzfAWfwJ5 YtP2uUpner5+J7t5BUT4kwqQAzYL4Jsh1hJn8d5SUlMUm7JfJAVBiH1NhhQDmwKeudya LBrI9Q8W+KuYj21KCuCQUk6sZRRnxj5zApOQPHnv9AVV7ddhayWQoDLEPaQMdZ8YjHnY gpAQ== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id d83si827510oib.166.2020.02.26.01.48.25; Wed, 26 Feb 2020 01:48:37 -0800 (PST) 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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728049AbgBZJql (ORCPT + 99 others); Wed, 26 Feb 2020 04:46:41 -0500 Received: from mail2-relais-roc.national.inria.fr ([192.134.164.83]:45547 "EHLO mail2-relais-roc.national.inria.fr" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728008AbgBZJqj (ORCPT ); Wed, 26 Feb 2020 04:46:39 -0500 From: Luc Maranget X-IronPort-AV: E=Sophos;i="5.70,487,1574118000"; d="scan'208";a="437707730" Received: from yquem.paris.inria.fr (HELO yquem.inria.fr) ([128.93.101.33]) by mail2-relais-roc.national.inria.fr with ESMTP; 26 Feb 2020 10:46:37 +0100 Received: by yquem.inria.fr (Postfix, from userid 18041) id 9DB44E1AAB; Wed, 26 Feb 2020 10:46:37 +0100 (CET) Date: Wed, 26 Feb 2020 10:46:37 +0100 To: Alan Stern Cc: Luc Maranget , Boqun Feng , Andrea Parri , Jade Alglave , "Paul E. McKenney" , Kernel development list Subject: Re: More on reader-writer locks Message-ID: <20200226094637.rhli3jjuiim2noke@yquem.inria.fr> References: <20200225130102.wsz3bpyhjmcru7os@yquem.inria.fr> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: User-Agent: NeoMutt/20170113 (1.7.2) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi all, As far as I understand there is a contradiction between having a "platonic" implementation of locks (à la lock.cat) and a concrete one (for ordinary locks lock -> load acquire, unlock -> store release, + loop [difficult for herd] or filter clause). So if reader/writer locks are catified in a platonic way, we cannot use various atomic primitives. Instead, we give them an abstract semantics based upon some axiomatisation of their semantics, using cat means. Such an axionatisation does not seem straightforward because, by constrast with locks, there is an integer count hiddden, and not a simple boolean as for ordinary locks Some idea would be first to partition reader crtical sections, and then for each such partition, order elements of the partition and writer critical section. For one such choice there are still many possible rf relations... --Luc rf relation > On Tue, 25 Feb 2020, Luc Maranget wrote: > > > Hi, > > > > As far as I can remember I have implemented atomic_add_unless in herd7. > > Luc, have you considered whether we can use atomic_add_unless and > cmpxchg to implement reader-writer locks in the LKMM? I don't think we > can handle them the same way we handle ordinary locks now. > > Let's say that a lock variable holds 0 if it is unlocked, -1 if it is > write-locked, and a positive value if it is read-locked (the value is > the number of read locks currently in effect). Then operations like > write_lock, write_trylock, and so on could all be modeled using > variants of atomic_add_unless, atomic_dec, and cmpxchg. > > But will that work if the reads-from relation is computed by the cat > code in lock.cat? I suspect it won't. > > How would you approach this problem? > > Alan