Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754041AbcDAK3i (ORCPT ); Fri, 1 Apr 2016 06:29:38 -0400 Received: from bombadil.infradead.org ([198.137.202.9]:34579 "EHLO bombadil.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752143AbcDAK3h (ORCPT ); Fri, 1 Apr 2016 06:29:37 -0400 Date: Fri, 1 Apr 2016 12:29:30 +0200 From: Peter Zijlstra To: Waiman Long Cc: Ingo Molnar , linux-kernel@vger.kernel.org, Scott J Norton , Douglas Hatch , Will Deacon Subject: Re: [PATCH] locking/qrwlock: Allow multiple spinning readers Message-ID: <20160401102930.GI3448@twins.programming.kicks-ass.net> References: <1458444079-59601-1-git-send-email-Waiman.Long@hpe.com> <20160329202050.GN3408@twins.programming.kicks-ass.net> <56FDA0D6.4090904@hpe.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <56FDA0D6.4090904@hpe.com> User-Agent: Mutt/1.5.21 (2012-12-30) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1221 Lines: 30 On Thu, Mar 31, 2016 at 06:12:38PM -0400, Waiman Long wrote: > On 03/29/2016 04:20 PM, Peter Zijlstra wrote: > >> cnts = atomic_add_return_acquire(_QR_BIAS,&lock->cnts) - _QR_BIAS; > >>+ while ((cnts& _QW_WMASK) == _QW_LOCKED) { > >>+ if (locked&& ((cnts>> _QR_SHIFT)< MAX_SPINNING_READERS)) { > >>+ /* > >>+ * Unlock the wait queue so that more readers can > >>+ * come forward and waiting for the writer to exit > >>+ * as long as no more than MAX_SPINNING_READERS > >>+ * readers are present. > >>+ */ > >>+ arch_spin_unlock(&lock->wait_lock); > >>+ locked = false; > >Only 1 more can come forward with this logic. How can you ever get to 4? > > Yes, each reader in the unlock path will release one in the queue. If the > next one is also a reader, it will release one more and so on until the > reader count reach 4 where the process will stop. > > > > >Also, what says the next in queue is a reader? > > I did say in the changelog that the queue head could be a writer. In that > case, the process will stop and the writer will wait until all the readers > are gone. Clearly I could not read not think straight when I looked at this patch. You're right. I'll go have another look ..