Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp5561344yba; Thu, 11 Apr 2019 00:18:01 -0700 (PDT) X-Google-Smtp-Source: APXvYqy9cXxs9hySY2XjMxA/uyBqvpp1x7GZWmWDpthguSxWOK287+8NCcOwM0e1ZdGYaF9awvTs X-Received: by 2002:a65:64c8:: with SMTP id t8mr44990627pgv.248.1554967081103; Thu, 11 Apr 2019 00:18:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1554967081; cv=none; d=google.com; s=arc-20160816; b=EVEV0ssK6BJ1BCcja9gzxIS42XlA/JFNjMA+EzsfqcbzoysXA9/ujmtXaQL51raUGf GPkvFkh6CgyqZ9qc1ED0PR/mQLsjLED8HZKm1NLWrKnxARnyaZblT8ururakN+b/A60H 50ZIC3GyYmSTEGdyvjN2qkqajcpkNHHHZdcUA1RI5WfZ8ktQ6qTnY29cWtC+eC73AgxN 9LKeaOI0yDoWJ0hxhtUj/LY3jQqzQnwyuFyl3FepZGvApSf4jyA2t8jbzi+MRFNQiVds IpDmiNVfsiHZZ1ePCcD0EuJQRP/lbcX1S8+BclClMRsBD/hnpgDjCD5TEk8CfnTDqQ9W 7WaQ== 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-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=4mcNXJvlohQBdQARF+BuZ/vie5JWkZ79tXZ3BKx5fv0=; b=ett25PXzBvdiHaQXHOEdl0o4jZV6eTdiTMHmYeKQXvXmvTWQ5ZZfkAhqx2pTHEdrRV heMVHoYCr1XpkpFC4rlo9470SFCoMfVYIMFnpR1X9cwTC/4qWwXN6JNt+iHBHp/xGReE VztsEAxoyPm/u86wMy1CtuX4Y6FoKBgxYqrkWPRjlWpusk3sNl100YswVMt+QSeaoVId h/dSWPgmMWnqBDnMzbyP0KVM3BH+i8jtEupD1smxBmNNKocvoxyqulIgP3B+FlJPPLt5 0zVR7QBNCpsUsIBq6LLfeq6JVeqc4bFLdrIPYAzHTgb1uqG5Cs9W+8OqTDIPOw0O2XMo io1w== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@infradead.org header.s=bombadil.20170209 header.b=Dy8v+6Hg; 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 y9si25112122pgh.55.2019.04.11.00.17.45; Thu, 11 Apr 2019 00:18:01 -0700 (PDT) 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; dkim=fail header.i=@infradead.org header.s=bombadil.20170209 header.b=Dy8v+6Hg; 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 S1726851AbfDKHQk (ORCPT + 99 others); Thu, 11 Apr 2019 03:16:40 -0400 Received: from bombadil.infradead.org ([198.137.202.133]:36434 "EHLO bombadil.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726104AbfDKHQk (ORCPT ); Thu, 11 Apr 2019 03:16:40 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.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:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=4mcNXJvlohQBdQARF+BuZ/vie5JWkZ79tXZ3BKx5fv0=; b=Dy8v+6Hgm3ADk2e57EDPOLFfj 07duP/Vzw0OKIKqfihsXrDyC5p/a1AK7diQ5/Ebjdt5SwchZNshEXtsrLDrOvt0sgwmcEQrlaj9bg OzdPkrkXKHzkjcUy2/y0gIgWHgD4KOGQVsUxT81FNLTq5h986YklcnSjhM61rwmcGNJdZ5H9ayiAA 39jS3ilCQzPk7DOBODvvE9DhVKF1gAgjEWCt+8PLV9w/2Ucx7NQmcFqfzZFYJV0t1Z+jfGzz85UpW +LKymqIzeRuu9qnllK7u6g8zpL5Zyp2f2lp0UQG6m/ih7JoChU5HkRTxlRKVOGXyTA+O0s+KZNphs JXHL1TPCQ==; Received: from j217100.upc-j.chello.nl ([24.132.217.100] helo=hirez.programming.kicks-ass.net) by bombadil.infradead.org with esmtpsa (Exim 4.90_1 #2 (Red Hat Linux)) id 1hETwo-0000zH-Ru; Thu, 11 Apr 2019 07:16:35 +0000 Received: by hirez.programming.kicks-ass.net (Postfix, from userid 1000) id 9B9B729AA8DC3; Thu, 11 Apr 2019 09:16:32 +0200 (CEST) Date: Thu, 11 Apr 2019 09:16:32 +0200 From: Peter Zijlstra To: Waiman Long Cc: Ingo Molnar , Will Deacon , Thomas Gleixner , linux-kernel@vger.kernel.org, x86@kernel.org, Davidlohr Bueso , Linus Torvalds , Tim Chen Subject: Re: [PATCH-tip v2 02/12] locking/rwsem: Implement lock handoff to prevent lock starvation Message-ID: <20190411071632.GZ4038@hirez.programming.kicks-ass.net> References: <20190405192115.17416-1-longman@redhat.com> <20190405192115.17416-3-longman@redhat.com> <20190410184429.GX4038@hirez.programming.kicks-ass.net> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.10.1 (2018-07-13) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Apr 10, 2019 at 10:25:16PM -0400, Waiman Long wrote: > On 04/10/2019 02:44 PM, Peter Zijlstra wrote: > > However there is another site that fiddles with the HANDOFF bit, namely > > __rwsem_down_write_failed_common(), and that does: > > > > + atomic_long_or(RWSEM_FLAG_HANDOFF, &sem->count); > > > > _OUTSIDE_ of ->wait_lock, which would yield: > > > > CPU0 CPU1 > > > > oldcount = atomic_long_fetch_add(adjustment, &sem->count) > > > > atomic_long_or(HANDOFF) > > > > if (!(oldcount & HANDOFF)) > > adjustment -= HANDOFF; > > > > atomic_long_sub(adjustment) > > > > *whoops*, incremented HANDOFF on HANDOFF. > > > > > > And there's not a comment in sight that would elucidate if this is > > possible or not. > > > > A writer can only set the handoff bit if it is the first waiter in the > queue. If it is the first waiter, a racing __rwsem_mark_wake() will see > that the first waiter is a writer and so won't go into the reader path. > I know I something don't spell out all the conditions that may look > obvious to me but not to others. I will elaborate more in comments. Aah, indeed.