Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1178783

Re: [PATCH 2/4] locking/qrwlock: Reduce reader/writer to reader lock transfer latency

From Will Deacon <will.deacon@arm.com>
Newsgroups linux.kernel
Subject Re: [PATCH 2/4] locking/qrwlock: Reduce reader/writer to reader lock transfer latency
Date 2015-07-07 19:30 +0200
Message-ID <pJEQW-8vd-15@gated-at.bofh.it> (permalink)
References (3 earlier) <pJkyR-45h-19@gated-at.bofh.it> <pJxcK-3O3-37@gated-at.bofh.it> <pJz4S-4Y0-35@gated-at.bofh.it> <pJzxU-586-15@gated-at.bofh.it> <pJCcq-6MJ-5@gated-at.bofh.it>
Organization linux.* mail to news gateway

Show all headers | View raw


On Tue, Jul 07, 2015 at 03:30:22PM +0100, Waiman Long wrote:
> On 07/07/2015 07:49 AM, Will Deacon wrote:
> > On Tue, Jul 07, 2015 at 12:17:31PM +0100, Peter Zijlstra wrote:
> >> On Tue, Jul 07, 2015 at 10:17:11AM +0100, Will Deacon wrote:
> >>>>> Thinking about it, can we kill _QW_WAITING altogether and set (cmpxchg
> >>>>> from 0) wmode to _QW_LOCKED in the write_lock slowpath, polling (acquire)
> >>>>> rmode until it hits zero?
> >>>> No, this is how we make the lock fair so that an incoming streams of
> >>>> later readers won't block a writer from getting the lock.
> >>> But won't those readers effectively see that the lock is held for write
> >>> (because we set wmode to _QW_LOCKED before the existing reader had drained)
> >>> and therefore fall down the slow-path and get held up on the spinlock?
> >> Yes, that's the entire point. Once there's a writer pending, new readers
> >> should queue too.
> > Agreed. My point was that we can achieve the same result without
> > a separate _QW_WAITING flag afaict.
> 
> _QW_WAITING and _QW_LOCKED has different semantics and are necessary for 
> the proper handshake between readers and writer. We set _QW_WAITING when 
> readers own the lock and the writer is waiting for the readers to go 
> away. The _QW_WAITING flag will force new readers to go to queuing while 
> the writer is waiting. We set _QW_LOCKED when a writer own the lock and 
> it can only be set atomically when no reader is present. Without the 
> intermediate _QW_WAITING step, a continuous stream of incoming readers 
> (which make the reader count never 0) could deny a writer from getting 
> the lock indefinitely.

It's probably best if I try to implement something and we can either pick
holes in the patch or I'll realise why I'm wrong in the process :)

Will
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Back to linux.kernel | Previous | Next — Previous in thread | Find similar | Unroll thread


Thread

Re: [PATCH 2/4] locking/qrwlock: Reduce reader/writer to reader lock  transfer latency Peter Zijlstra <peterz@infradead.org> - 2015-07-07 13:20 +0200
  Re: [PATCH 2/4] locking/qrwlock: Reduce reader/writer to reader lock  transfer latency Will Deacon <will.deacon@arm.com> - 2015-07-07 19:30 +0200

csiph-web