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


Groups > linux.kernel > #1220428

Re: wake_up_process implied memory barrier clarification

From Boqun Feng <boqun.feng@gmail.com>
Newsgroups linux.kernel
Subject Re: wake_up_process implied memory barrier clarification
Date 2015-09-08 02:30 +0200
Message-ID <q6eXn-4Q0-1@gated-at.bofh.it> (permalink)
References (5 earlier) <q3QFR-3qt-53@gated-at.bofh.it> <q3Vcv-1fz-47@gated-at.bofh.it> <q3WUW-3KU-5@gated-at.bofh.it> <q44Su-6P9-1@gated-at.bofh.it> <q685A-3mv-13@gated-at.bofh.it>
Organization linux.* mail to news gateway

Show all headers | View raw


[Multipart message — attachments visible in raw view] - view raw

Hi Oleg,

On Mon, Sep 07, 2015 at 07:06:52PM +0200, Oleg Nesterov wrote:
> Sorry for delay,
> 
> On 09/02, Boqun Feng wrote:
> >
> > On Tue, Sep 01, 2015 at 06:39:23PM +0200, Oleg Nesterov wrote:
> > > On 09/01, Boqun Feng wrote:
> > > >
> > > > On Tue, Sep 01, 2015 at 11:59:23AM +0200, Oleg Nesterov wrote:
> > > > >
> > > > > And just in case, wake_up() differs in a sense that it doesn't even need
> > > > > that STORE-LOAD barrier in try_to_wake_up(), we can rely on
> > > > > wait_queue_head_t->lock. Assuming that wake_up() pairs with the "normal"
> > > > > wait_event()-like code.
> > >
> > > Looks like, you have missed this part of my previous email. See below.
> >
> > I guess I need to think through this, though I haven't found any problem
> > in wake_up() if we remove the STORE-LOAD barrier in try_to_wake_up().
> > And I know that in wake_up(), try_to_wake_up() will be called with
> > holding wait_queue_head_t->lock, however, only part of wait_event()
> > holds the same lock, I can't figure out why the barrier is not needed
> > because of the lock..
> 
> This is very simple. __wait_event() does
> 
> 	for (;;) {
> 		prepare_to_wait_event(WQ, ...);	// takes WQ->lock
> 
> 		if (CONDITION)
> 			break;
> 
> 		schedule();
> 	}
> 
> and we have
> 
> 	CONDITION = 1;
> 	wake_up(WQ);				// takes WQ->lock
> 
> on another side.
> 
> Suppose that __wait_event() wins and takes WQ->lock first. It can block
> then. In this case wake_up() must see the result of set_current_state()
> and list_add() when it takes the same lock, otherwise spin_lock() would
> be simply buggy. So it will wake the waiter up.
> 
> At the same time, if __wait_event() takes this lock after wake_up(), it
> can not miss CONDITION = 1. It must see it after it takes the lock, and
> of course after it drops the lock too.
> 

Yes, you're right! I wasn't aware that in prepare_to_wait_event(),
set_current_state() is called with the WQ->lock.

> So I am not sure I understand your concerns in this case...
> 

It's my mistake. Thank you for your explanation ;-)

Regards,
Boqun

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


Thread

wake_up_process implied memory barrier clarification Michal Hocko <mhocko@kernel.org> - 2015-08-27 14:30 +0200
  Re: wake_up_process implied memory barrier clarification Peter Zijlstra <peterz@infradead.org> - 2015-08-27 14:50 +0200
    Re: wake_up_process implied memory barrier clarification Michal Hocko <mhocko@kernel.org> - 2015-08-27 15:20 +0200
      Re: wake_up_process implied memory barrier clarification Oleg Nesterov <oleg@redhat.com> - 2015-08-27 20:30 +0200
        Re: wake_up_process implied memory barrier clarification Michal Hocko <mhocko@kernel.org> - 2015-08-28 17:00 +0200
          Re: wake_up_process implied memory barrier clarification Oleg Nesterov <oleg@redhat.com> - 2015-08-28 18:10 +0200
            Re: wake_up_process implied memory barrier clarification Boqun Feng <boqun.feng@gmail.com> - 2015-08-29 11:30 +0200
              Re: wake_up_process implied memory barrier clarification Oleg Nesterov <oleg@redhat.com> - 2015-08-29 16:40 +0200
                Re: wake_up_process implied memory barrier clarification Boqun Feng <boqun.feng@gmail.com> - 2015-08-31 02:40 +0200
                Re: wake_up_process implied memory barrier clarification Oleg Nesterov <oleg@redhat.com> - 2015-08-31 20:40 +0200
                Re: wake_up_process implied memory barrier clarification "Paul E. McKenney" <paulmck@linux.vnet.ibm.com> - 2015-08-31 22:50 +0200
                Re: wake_up_process implied memory barrier clarification Boqun Feng <boqun.feng@gmail.com> - 2015-09-01 05:50 +0200
                Re: wake_up_process implied memory barrier clarification "Paul E. McKenney" <paulmck@linux.vnet.ibm.com> - 2015-09-01 06:10 +0200
                Re: wake_up_process implied memory barrier clarification Oleg Nesterov <oleg@redhat.com> - 2015-09-01 12:10 +0200
                Re: wake_up_process implied memory barrier clarification Boqun Feng <boqun.feng@gmail.com> - 2015-09-01 17:00 +0200
                Re: wake_up_process implied memory barrier clarification Oleg Nesterov <oleg@redhat.com> - 2015-09-01 18:50 +0200
                Re: wake_up_process implied memory barrier clarification Boqun Feng <boqun.feng@gmail.com> - 2015-09-02 03:20 +0200
                Re: wake_up_process implied memory barrier clarification Oleg Nesterov <oleg@redhat.com> - 2015-09-07 19:10 +0200
                Re: wake_up_process implied memory barrier clarification Boqun Feng <boqun.feng@gmail.com> - 2015-09-08 02:30 +0200
                Re: wake_up_process implied memory barrier clarification Oleg Nesterov <oleg@redhat.com> - 2015-09-01 11:50 +0200

csiph-web