linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Yongji Xie <elohimes@gmail.com>
To: peterz@infradead.org
Cc: dave@stgolabs.net, mingo@redhat.com, will.deacon@arm.com,
	linux-kernel@vger.kernel.org, Xie Yongji <xieyongji@baidu.com>,
	zhangyu31@baidu.com, liuqi16@baidu.com, yuanlinsi01@baidu.com,
	nixun@baidu.com, lilin24@baidu.com, longman@redhat.com,
	andrea.parri@amarulasolutions.com
Subject: Re: [RFC] locking/rwsem: Avoid issuing wakeup before setting the reader waiter to nil
Date: Mon, 10 Dec 2018 23:12:52 +0800	[thread overview]
Message-ID: <CAONzpcZ_kQ0cwit+d5uL=v2SqwP=Fo0WSihdCr23uKCAFAhTbQ@mail.gmail.com> (raw)
In-Reply-To: <20181129221714.GF11632@hirez.programming.kicks-ass.net>

On Fri, 30 Nov 2018 at 06:17, Peter Zijlstra <peterz@infradead.org> wrote:
>
> On Thu, Nov 29, 2018 at 01:34:21PM -0800, Davidlohr Bueso wrote:
> > I messed up something such that waiman was not in the thread. Ccing.
> >
> > > On Thu, 29 Nov 2018, Waiman Long wrote:
> > >
> > > > That can be costly for x86 which will now have 2 locked instructions.
> > >
> > > Yeah, and when used as an actual queue we should really start to notice.
> > > Some users just have a single task in the wake_q because avoiding the cost
> > > of wake_up_process() with locks held is significant.
> > >
> > > How about instead of adding the barrier before the cmpxchg, we do it
> > > in the failed branch, right before we return. This is the uncommon
> > > path.
> > >
> > > Thanks,
> > > Davidlohr
> > >
> > > diff --git a/kernel/sched/core.c b/kernel/sched/core.c
> > > index 091e089063be..0d844a18a9dc 100644
> > > --- a/kernel/sched/core.c
> > > +++ b/kernel/sched/core.c
> > > @@ -408,8 +408,14 @@ void wake_q_add(struct wake_q_head *head, struct task_struct *task)
> > >      * This cmpxchg() executes a full barrier, which pairs with the full
> > >      * barrier executed by the wakeup in wake_up_q().
> > >      */
> > > -   if (cmpxchg(&node->next, NULL, WAKE_Q_TAIL))
> > > +   if (cmpxchg(&node->next, NULL, WAKE_Q_TAIL)) {
> > > +           /*
> > > +            * Ensure, that when the cmpxchg() fails, the corresponding
> > > +            * wake_up_q() will observe our prior state.
> > > +            */
> > > +           smp_mb__after_atomic();
> > >             return;
> > > +   }
>
> So wake_up_q() does:
>
>   wake_up_q():
>         node->next = NULL;
>         /* implied smp_mb */
>         wake_up_process();
>
> So per the cross your variables 'rule', this side then should do:
>
>   wake_q_add():
>         /* wake_cond = true */
>         smp_mb()
>         cmpxchg_relaxed(&node->next, ...);
>
> So that the ordering pivots around node->next.
>
> Either we see NULL and win the cmpxchg (in which case we'll do the
> wakeup later) or, when we fail the cmpxchg, we must observe what came
> before the failure.
>
> If it wasn't so damn late, I'd try and write a litmus test for this,
> because now I'm starting to get confused -- also probably because it's
> late.
>

Hi Peter,

Please let me know If there is any progress on this issue. Thank you!

Thanks,
Yongji

  parent reply	other threads:[~2018-12-10 15:13 UTC|newest]

Thread overview: 50+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-11-29 12:50 [RFC] locking/rwsem: Avoid issuing wakeup before setting the reader waiter to nil Yongji Xie
2018-11-29 13:12 ` Peter Zijlstra
2018-11-29 13:44   ` Peter Zijlstra
2018-11-29 14:02     ` Yongji Xie
2018-11-29 18:43     ` Davidlohr Bueso
2018-11-29 18:49       ` Waiman Long
2018-11-29 15:21   ` Waiman Long
2018-11-29 15:29     ` Waiman Long
2018-11-29 16:06     ` Peter Zijlstra
2018-11-29 17:02       ` Waiman Long
2018-11-29 17:27         ` Peter Zijlstra
2018-11-29 17:58           ` Waiman Long
2018-11-29 18:13             ` Peter Zijlstra
2018-11-29 18:17               ` Davidlohr Bueso
2018-11-29 18:08           ` Peter Zijlstra
2018-11-29 18:26             ` Waiman Long
2018-11-29 18:31               ` Will Deacon
2018-11-29 18:34                 ` Waiman Long
2018-11-29 22:05                   ` Peter Zijlstra
2018-11-30  9:34                     ` 答复: " Liu,Qi(ACU-T1)
2018-11-30 14:15                       ` Peter Zijlstra
2018-11-29 21:30               ` Davidlohr Bueso
2018-11-29 21:34                 ` Davidlohr Bueso
2018-11-29 22:17                   ` Peter Zijlstra
2018-11-30  9:30                     ` Andrea Parri
2018-12-03  5:31                     ` [PATCH -tip] kernel/sched,wake_q: Branch predict wake_q_add() cmpxchg Davidlohr Bueso
2018-12-03 16:10                       ` Waiman Long
2019-01-21 11:28                       ` [tip:locking/core] sched/wake_q: Add branch prediction hint to " tip-bot for Davidlohr Bueso
2018-12-10 15:12                     ` Yongji Xie [this message]
2018-12-17 11:37                       ` [RFC] locking/rwsem: Avoid issuing wakeup before setting the reader waiter to nil Peter Zijlstra
2018-12-17 13:12                         ` Yongji Xie
2019-01-07 14:35                           ` Waiman Long
2019-01-07 15:31                             ` Peter Zijlstra
2019-01-07 15:35                               ` Waiman Long
2018-12-17 20:53                         ` Davidlohr Bueso
2018-12-18 13:10                           ` Peter Zijlstra
2018-12-18 13:14                             ` Peter Zijlstra
2018-12-18 17:27                               ` Davidlohr Bueso
2018-12-18 18:54                               ` [PATCH v2] sched/wake_q: Reduce reference counting for special users Davidlohr Bueso
2018-12-18 19:17                                 ` Waiman Long
2018-12-18 19:30                                   ` Davidlohr Bueso
2018-12-18 19:39                                     ` Davidlohr Bueso
2018-12-18 19:53                                       ` [PATCH v4] " Davidlohr Bueso
2018-12-18 20:35                                         ` Waiman Long
2019-01-21 16:02                                           ` Davidlohr Bueso
2019-01-22  8:55                                             ` Peter Zijlstra
2019-02-04  8:57                                         ` [tip:locking/core] " tip-bot for Davidlohr Bueso
2019-02-07 19:30                                           ` Davidlohr Bueso
2019-02-12 14:14                                           ` Daniel Vacek
2019-01-21 11:28 ` [tip:locking/core] locking/rwsem: Fix (possible) missed wakeup tip-bot for Xie Yongji

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CAONzpcZ_kQ0cwit+d5uL=v2SqwP=Fo0WSihdCr23uKCAFAhTbQ@mail.gmail.com' \
    --to=elohimes@gmail.com \
    --cc=andrea.parri@amarulasolutions.com \
    --cc=dave@stgolabs.net \
    --cc=lilin24@baidu.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=liuqi16@baidu.com \
    --cc=longman@redhat.com \
    --cc=mingo@redhat.com \
    --cc=nixun@baidu.com \
    --cc=peterz@infradead.org \
    --cc=will.deacon@arm.com \
    --cc=xieyongji@baidu.com \
    --cc=yuanlinsi01@baidu.com \
    --cc=zhangyu31@baidu.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).