Received: by 2002:a05:6a10:a841:0:0:0:0 with SMTP id d1csp3426543pxy; Mon, 26 Apr 2021 01:11:35 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxRcSFL+bj2rFUWlffpCdGiFW89NK/GgydiVoK1Y7YRrEROgeLFryA6dzFBGBAQKkXnprFv X-Received: by 2002:a05:6402:26d3:: with SMTP id x19mr19754119edd.349.1619424695078; Mon, 26 Apr 2021 01:11:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1619424695; cv=none; d=google.com; s=arc-20160816; b=N9aq/lYg03g+uUrrgW7Z6JqsbwzxRlPxJgdvgujyito+okJ/FXv5cPkcQWklac0h0P uy+J7/iXvJ+Mlk1322LdWeh3MXSElRYgMYmGXV+EylHtLdAjw4yV6E/6aNHu7vM3VYWa a1DusMaG+ZxCFseI7kRwhtVvxM7pedSfRW7/qgDLmig0bYJL0Pxf+PkISosV8Lmucpuu l5yK5TJF2aNyOMHAco/JlhA1fMskRkfbEiazs+ZQGIl639GU7kgBVUuPR3ivi5JoZPdO 14nvlzw1145MHqx1y333FKYcxSgQt0cnDf/vIgZlVhNpOzW+pWBdR/kN92mxIJmD8NzW Iasg== 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=mdNcf1AV82cZAqbKKVJR5a9TfZz/3J+tTladCWTiR98=; b=07aDSRlDtAB22jiomsjZeABzLSsqGi16AWIZK9ot7tnkhqyz5Ut06UGQ1c4KzMVZ1c G4GgC6UGG1JcoWVM/36eAmOzMi9NpGNQzDLRprBNeyJNd1PNTFXJJsfqSFiPG1lcQYMp xY4K48P4C8eFy70POPopzGPXXcVsHdM/UbwULlW9v1+yFyy1MpDJ483QDad1rvpYyXPE hhhzd5hvNTYbtFjCPSZBl11RmiUmozW+QSS1SaEfRLKli8iNoavEyBso9ageAMRZ0Vi+ 2Ah90Ez3p+5fZbJvvcevIEK4Wr9uq+dBOotP9lIQivm1ayhjS/PYNO4zuQxdHV2pqX0W WFFA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b=LRgz3EdA; 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 mp6si11792212ejc.146.2021.04.26.01.11.11; Mon, 26 Apr 2021 01:11:35 -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=LRgz3EdA; 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 S232377AbhDZIK3 (ORCPT + 99 others); Mon, 26 Apr 2021 04:10:29 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46654 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231171AbhDZIK2 (ORCPT ); Mon, 26 Apr 2021 04:10:28 -0400 Received: from casper.infradead.org (casper.infradead.org [IPv6:2001:8b0:10b:1236::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 77E8DC061574 for ; Mon, 26 Apr 2021 01:09:47 -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=mdNcf1AV82cZAqbKKVJR5a9TfZz/3J+tTladCWTiR98=; b=LRgz3EdAhWNWk9TSkxzT0qJNlm 6i3IPJ0Ehi54Vmv5Pb45pgVFW7oNjT2CC8t6CFZ46UCwekq+CuUnLIibEeQ5sTnikcdK75J46CqS5 vEM/V+dr8DPGUSlyLUbviCo8qe12c0tcT9PN9xLnIP2yyBWD+kU6L03M74+V/fXjqYfRty9A+5Ugx JtECoFuuJRFZl0+d7jvNq4TrcNxW3tVAA6Al3ihA3WOzqUkMcNXbEXB0gkfKw2to4nqyFylmGaOac BE/LLHDPM7TJUd9Bl0ZmbYoQgLms0GYV6/5a/Y2O+gpXI7PKmjS1pKXjLYPt2mVwZ9Z4UGbfay3zr 6GTgd0sw==; 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 1lawI6-005LqG-Gh; Mon, 26 Apr 2021 08:08: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)) (Client did not present a certificate) by noisy.programming.kicks-ass.net (Postfix) with ESMTPS id 2D900300212; Mon, 26 Apr 2021 10:08:26 +0200 (CEST) Received: by hirez.programming.kicks-ass.net (Postfix, from userid 1000) id 1432E2C988F39; Mon, 26 Apr 2021 10:08:26 +0200 (CEST) Date: Mon, 26 Apr 2021 10:08:26 +0200 From: Peter Zijlstra To: Waiman Long Cc: Ingo Molnar , Will Deacon , Boqun Feng , linux-kernel@vger.kernel.org, Borislav Petkov , Ali Saidi , Steve Capper Subject: Re: [PATCH] locking/qrwlock: queued_write_lock_slowpath() cleanup Message-ID: References: <20210425200637.31298-1-longman@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20210425200637.31298-1-longman@redhat.com> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sun, Apr 25, 2021 at 04:06:37PM -0400, Waiman Long wrote: > void queued_write_lock_slowpath(struct qrwlock *lock) > { > - int cnts; > + int cnts = 0; > > /* Put the writer into the wait queue */ > arch_spin_lock(&lock->wait_lock); > > /* Try to acquire the lock directly if no reader is present */ > if (!atomic_read(&lock->cnts) && > - (atomic_cmpxchg_acquire(&lock->cnts, 0, _QW_LOCKED) == 0)) > + atomic_try_cmpxchg_acquire(&lock->cnts, &cnts, _QW_LOCKED)) > goto unlock; Would not something like: if (!(cnts = atomic_read(&lock->cnts)) && atomic_try_cmpxchg_acquire(&lock->cnts, &cnts, _QW_LOCKED) goto unlock; Be clearer? > > - /* Set the waiting flag to notify readers that a writer is pending */ > - atomic_add(_QW_WAITING, &lock->cnts); > + /* > + * Set the waiting flag to notify readers that a writer is pending > + * > + * As only one writer who is the wait_lock owner can set the waiting > + * flag which will be cleared later on when acquiring the write lock, > + * we can easily replace atomic_or() by an atomic_add() if there is > + * an architecture where an atomic_add() performs better than an > + * atomic_or(). That might be a little overboard on the comment, but sure :-) I don't think there's any arch that doesn't have atomic_or(), like I wrote elsewhere, the one that's often an issue is atomic_fetch_or(). > + */ > + atomic_or(_QW_WAITING, &lock->cnts);