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


Groups > linux.kernel > #1526625

Re: [PATCH 3/3] locking/percpu-rwsem: Avoid unnecessary writer wakeups

From Peter Zijlstra <peterz@infradead.org>
Newsgroups linux.kernel
Subject Re: [PATCH 3/3] locking/percpu-rwsem: Avoid unnecessary writer wakeups
Date 2016-11-21 13:30 +0100
Message-ID <sFVTr-18L-5@gated-at.bofh.it> (permalink)
References <sEWye-2tW-9@gated-at.bofh.it> <sEWyf-2tW-55@gated-at.bofh.it> <sFVTr-18L-7@gated-at.bofh.it>
Organization linux.* mail to news gateway

Show all headers | View raw


On Mon, Nov 21, 2016 at 01:23:44PM +0100, Oleg Nesterov wrote:
> On 11/18, Davidlohr Bueso wrote:
> >
> > +static bool __readers_active_check(struct percpu_rw_semaphore *sem)
> > +{
> > +	return !(per_cpu_sum(*sem->read_count) !=0);
> > +}
> 
> Hmm,
> 
> 	return per_cpu_sum(*sem->read_count) == 0;
> 
> looks more clear, but this is minor,

Very much so; that must be one of the most convoluted statements
possible :-).

> 
> >  int __percpu_init_rwsem(struct percpu_rw_semaphore *sem,
> >  			const char *name, struct lock_class_key *rwsem_key)
> >  {
> > @@ -103,41 +141,11 @@ void __percpu_up_read(struct percpu_rw_semaphore *sem)
> >  	__this_cpu_dec(*sem->read_count);
> >  
> >  	/* Prod writer to recheck readers_active */
> > -	swake_up(&sem->writer);
> > +	if (__readers_active_check(sem))
> > +		swake_up(&sem->writer);
> 
> Suppose we have 2 active readers which call __percpu_up_read() at the same
> time and the pending writer sleeps.
> 
> What guarantees that one of these readers will observe per_cpu_sum() == 0 ?
> They both can read the old value of the remote per-cpu counter, no?

In particular, you're thinking of what provides the guarantee that the
woken CPU observes the same state the wakee saw? Isn't this one of the
Program-Order guarantees the scheduler _should_ provide?

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


Thread

[PATCH -tip 0/3] locking/percpu-rwsem: writer-side optimizations Davidlohr Bueso <dave@stgolabs.net> - 2016-11-18 20:00 +0100
  [PATCH 1/3] locking/percpu-rwsem: Move text file into Documentation/locking/ Davidlohr Bueso <dave@stgolabs.net> - 2016-11-18 20:00 +0100
  [PATCH 2/3] locking/percpu-rwsem: Replace bulky wait-queues with swait Davidlohr Bueso <dave@stgolabs.net> - 2016-11-18 20:00 +0100
    Re: [PATCH 2/3] locking/percpu-rwsem: Replace bulky wait-queues         with swait Oleg Nesterov <oleg@redhat.com> - 2016-11-21 14:00 +0100
      Re: [PATCH 2/3] locking/percpu-rwsem: Replace bulky wait-queues with  swait Davidlohr Bueso <dave@stgolabs.net> - 2016-11-21 18:30 +0100
  [PATCH 3/3] locking/percpu-rwsem: Avoid unnecessary writer wakeups Davidlohr Bueso <dave@stgolabs.net> - 2016-11-18 20:00 +0100
    Re: [PATCH 3/3] locking/percpu-rwsem: Avoid unnecessary writer  wakeups Peter Zijlstra <peterz@infradead.org> - 2016-11-21 13:30 +0100
      Re: [PATCH 3/3] locking/percpu-rwsem: Avoid unnecessary writer         wakeups Oleg Nesterov <oleg@redhat.com> - 2016-11-21 13:50 +0100
        Re: [PATCH 3/3] locking/percpu-rwsem: Avoid unnecessary writer         wakeups Oleg Nesterov <oleg@redhat.com> - 2016-11-21 16:10 +0100
          Re: [PATCH 3/3] locking/percpu-rwsem: Avoid unnecessary writer  wakeups Davidlohr Bueso <dave@stgolabs.net> - 2016-11-22 05:00 +0100
            Re: [PATCH 3/3] locking/percpu-rwsem: Avoid unnecessary writer         wakeups Oleg Nesterov <oleg@redhat.com> - 2016-11-23 15:50 +0100
    Re: [PATCH 3/3] locking/percpu-rwsem: Avoid unnecessary writer         wakeups Oleg Nesterov <oleg@redhat.com> - 2016-11-21 13:30 +0100

csiph-web