Re: [PATCH 2/2] [PATCH] sched: Add smp_rmb() in task rq locking cycles

2015-04-30 Thread Paul E. McKenney
On Tue, Apr 28, 2015 at 04:32:35PM +0200, Peter Zijlstra wrote: > On Sat, Apr 25, 2015 at 12:56:03PM -0700, Paul E. McKenney wrote: > > smp: Make control dependencies work on Alpha, improve documentation > > > > The current formulation of control dependencies fails on DEC Alpha, > > w

Re: [PATCH 2/2] [PATCH] sched: Add smp_rmb() in task rq locking cycles

2015-04-28 Thread Chris Metcalf
On 04/28/2015 02:24 PM, Peter Zijlstra wrote: A few questions: On Tue, Apr 28, 2015 at 02:00:48PM -0400, Chris Metcalf wrote: static inline void arch_spin_lock(arch_spinlock_t *lock) { unsigned short head, tail; ___tns_lock(&lock->lock); /* XXX does the TNS imply a ___sync? */

Re: [PATCH 2/2] [PATCH] sched: Add smp_rmb() in task rq locking cycles

2015-04-28 Thread Peter Zijlstra
On Tue, Apr 28, 2015 at 02:00:48PM -0400, Chris Metcalf wrote: > Yes, tilepro can do 16-bit atomic load/stores. The reason we didn't use > your approach (basically having tns provide locking for the head/tail) > is just a perceived efficiency gain from rolling the tns lock into the head. > > The

Re: [PATCH 2/2] [PATCH] sched: Add smp_rmb() in task rq locking cycles

2015-04-28 Thread Chris Metcalf
On 04/28/2015 01:43 PM, Peter Zijlstra wrote: On Tue, Apr 28, 2015 at 12:58:55PM -0400, Chris Metcalf wrote: On 04/28/2015 12:40 PM, Peter Zijlstra wrote: On Tue, Apr 28, 2015 at 11:53:21AM -0400, Chris Metcalf wrote: The reason we use two 32-bit fields on tilepro is that the only available a

Re: [PATCH 2/2] [PATCH] sched: Add smp_rmb() in task rq locking cycles

2015-04-28 Thread Peter Zijlstra
On Tue, Apr 28, 2015 at 12:58:55PM -0400, Chris Metcalf wrote: > On 04/28/2015 12:40 PM, Peter Zijlstra wrote: > >On Tue, Apr 28, 2015 at 11:53:21AM -0400, Chris Metcalf wrote: > > > >>The reason we use two 32-bit fields on tilepro is that the only available > >>atomic instruction is tns (test and

Re: [PATCH 2/2] [PATCH] sched: Add smp_rmb() in task rq locking cycles

2015-04-28 Thread Chris Metcalf
On 04/28/2015 12:40 PM, Peter Zijlstra wrote: On Tue, Apr 28, 2015 at 11:53:21AM -0400, Chris Metcalf wrote: The reason we use two 32-bit fields on tilepro is that the only available atomic instruction is tns (test and set), which sets a 32-bit "1" value into the target memory and returns the o

Re: [PATCH 2/2] [PATCH] sched: Add smp_rmb() in task rq locking cycles

2015-04-28 Thread Peter Zijlstra
On Tue, Apr 28, 2015 at 11:53:21AM -0400, Chris Metcalf wrote: > The reason we use two 32-bit fields on tilepro is that the only available > atomic instruction is tns (test and set), which sets a 32-bit "1" value > into the target memory and returns the old 32-bit value. And you want a ticket loc

Re: [PATCH 2/2] [PATCH] sched: Add smp_rmb() in task rq locking cycles

2015-04-28 Thread Peter Zijlstra
On Tue, Apr 28, 2015 at 11:53:21AM -0400, Chris Metcalf wrote: > As you surmise, tilepro doesn't have 64-bit loads. So we are stuck with > 32-bit loads on these two fields. It's true that spin_unlock_wait() can > therefore falsely claim that the lock is unlocked, but it should be only a > hint an

Re: [PATCH 2/2] [PATCH] sched: Add smp_rmb() in task rq locking cycles

2015-04-28 Thread Chris Metcalf
On 04/28/2015 10:33 AM, Peter Zijlstra wrote: On Sun, Apr 26, 2015 at 03:52:13AM -0700, Paul E. McKenney wrote: And then an smp_read_barrier_depends() would be needed either here or embedded in apin_unlock_wait(). But we also need to check the spin_unlock_wait() implementations to see if any a

Re: [PATCH 2/2] [PATCH] sched: Add smp_rmb() in task rq locking cycles

2015-04-28 Thread Peter Zijlstra
On Sun, Apr 26, 2015 at 03:52:13AM -0700, Paul E. McKenney wrote: > And then an smp_read_barrier_depends() would be needed either here > or embedded in apin_unlock_wait(). But we also need to check the > spin_unlock_wait() implementations to see if any are potentially > vulnerable to compiler mis

Re: [PATCH 2/2] [PATCH] sched: Add smp_rmb() in task rq locking cycles

2015-04-28 Thread Peter Zijlstra
On Sat, Apr 25, 2015 at 12:56:03PM -0700, Paul E. McKenney wrote: > smp: Make control dependencies work on Alpha, improve documentation > > The current formulation of control dependencies fails on DEC Alpha, which > does not respect dependencies of any kind unless an explicit memor

Re: [PATCH 2/2] [PATCH] sched: Add smp_rmb() in task rq locking cycles

2015-04-26 Thread Paul E. McKenney
On Fri, Feb 20, 2015 at 07:45:51PM +0100, Peter Zijlstra wrote: > On Fri, Feb 20, 2015 at 07:28:16PM +0100, Manfred Spraul wrote: > > > >We need the full barrier to serialize STORE's as well, but probably we can > > >rely on control dependancy and thus we only need rmb(). > > Do we need a full bar

Re: [PATCH 2/2] [PATCH] sched: Add smp_rmb() in task rq locking cycles

2015-04-26 Thread Paul E. McKenney
On Sat, Apr 25, 2015 at 12:56:02PM -0700, Paul E. McKenney wrote: > On Fri, Feb 20, 2015 at 07:45:51PM +0100, Peter Zijlstra wrote: > > On Fri, Feb 20, 2015 at 07:28:16PM +0100, Manfred Spraul wrote: > > > > > >We need the full barrier to serialize STORE's as well, but probably we > > > >can > >

Re: [PATCH 2/2] [PATCH] sched: Add smp_rmb() in task rq locking cycles

2015-02-23 Thread Paul E. McKenney
On Fri, Feb 20, 2015 at 07:26:21PM -0800, Paul E. McKenney wrote: > On Fri, Feb 20, 2015 at 07:28:16PM +0100, Manfred Spraul wrote: > > Hi Oleg, > > > > my example was bad, let's continue with your example. > > > > And: If sem_lock() needs another smp_xmb(), then we must add it: > > Some apps do

Re: [PATCH 2/2] [PATCH] sched: Add smp_rmb() in task rq locking cycles

2015-02-21 Thread Peter Zijlstra
On Fri, Feb 20, 2015 at 09:23:19PM +0100, Oleg Nesterov wrote: > On 02/20, Peter Zijlstra wrote: > > > > I think I agree with Oleg in that we only need the smp_rmb(); of course > > that wants a somewhat elaborate comment to go along with it. How about > > something like so: > > > > spin_unlock_

Re: [PATCH 2/2] [PATCH] sched: Add smp_rmb() in task rq locking cycles

2015-02-20 Thread Paul E. McKenney
On Fri, Feb 20, 2015 at 07:28:16PM +0100, Manfred Spraul wrote: > Hi Oleg, > > my example was bad, let's continue with your example. > > And: If sem_lock() needs another smp_xmb(), then we must add it: > Some apps do not have a user space hot path, i.e. it seems that on > some setups, we have mil

Re: [PATCH 2/2] [PATCH] sched: Add smp_rmb() in task rq locking cycles

2015-02-20 Thread Oleg Nesterov
On 02/20, Peter Zijlstra wrote: > > I think I agree with Oleg in that we only need the smp_rmb(); of course > that wants a somewhat elaborate comment to go along with it. How about > something like so: > > spin_unlock_wait(&local); > /* >* The above spin_unlock_wait() forms a co

Re: [PATCH 2/2] [PATCH] sched: Add smp_rmb() in task rq locking cycles

2015-02-20 Thread Peter Zijlstra
On Fri, Feb 20, 2015 at 07:28:16PM +0100, Manfred Spraul wrote: > >We need the full barrier to serialize STORE's as well, but probably we can > >rely on control dependancy and thus we only need rmb(). > Do we need a full barrier or not? > > I don't manage to create a proper line of reasoning. I

Re: [PATCH 2/2] [PATCH] sched: Add smp_rmb() in task rq locking cycles

2015-02-20 Thread Manfred Spraul
Hi Oleg, my example was bad, let's continue with your example. And: If sem_lock() needs another smp_xmb(), then we must add it: Some apps do not have a user space hot path, i.e. it seems that on some setups, we have millions of calls per second. If there is a race, then it will happen. I've t

Re: [PATCH 2/2] [PATCH] sched: Add smp_rmb() in task rq locking cycles

2015-02-19 Thread Oleg Nesterov
On 02/18, Peter Zijlstra wrote: > > On Wed, Feb 18, 2015 at 08:14:01PM +0100, Manfred Spraul wrote: > > > >spinlock_t local, global; > > >bool force_global; Yes, force_global (sma->complex_count) adds more complications, but I think we can ignoire it in this discussion. > > >bool my_lock(bool try

Re: [PATCH 2/2] [PATCH] sched: Add smp_rmb() in task rq locking cycles

2015-02-18 Thread Peter Zijlstra
On Wed, Feb 18, 2015 at 08:14:01PM +0100, Manfred Spraul wrote: > >spinlock_t local, global; > >bool force_global; > >bool my_lock(bool try_local) > >{ > > if (try_local) { > > spin_lock(&local); > > if (!spin_is_locked(&global)) { > > if (!force_glo

Re: [PATCH 2/2] [PATCH] sched: Add smp_rmb() in task rq locking cycles

2015-02-18 Thread Paul E. McKenney
On Wed, Feb 18, 2015 at 05:32:56PM +0100, Oleg Nesterov wrote: > On 02/18, Peter Zijlstra wrote: > > > > On Wed, Feb 18, 2015 at 04:53:34PM +0100, Oleg Nesterov wrote: > > > On 02/17, Paul E. McKenney wrote: > > > > > > > > | mb | wmb | rmb | rbd | acq | rel | ctl | > > > > --

Re: [PATCH 2/2] [PATCH] sched: Add smp_rmb() in task rq locking cycles

2015-02-18 Thread Manfred Spraul
Hi Oleg, On 02/18/2015 04:59 PM, Oleg Nesterov wrote: Let's look at sem_lock(). I never looked at this code before, I can be easily wrong. Manfred will correct me. But at first glance we can write the oversimplified pseudo-code: spinlock_t local, global; bool my_lock(bool try_l

Re: [PATCH 2/2] [PATCH] sched: Add smp_rmb() in task rq locking cycles

2015-02-18 Thread Paul E. McKenney
On Wed, Feb 18, 2015 at 02:47:06PM +0100, Peter Zijlstra wrote: > On Tue, Feb 17, 2015 at 01:52:31PM -0800, Paul E. McKenney wrote: > > I could do a table per communication style. For example, message > > passing looks like this (give or take likely errors in the table): > > > > Side CPU

Re: [PATCH 2/2] [PATCH] sched: Add smp_rmb() in task rq locking cycles

2015-02-18 Thread Oleg Nesterov
On 02/18, Peter Zijlstra wrote: > > On Wed, Feb 18, 2015 at 04:53:34PM +0100, Oleg Nesterov wrote: > > On 02/17, Paul E. McKenney wrote: > > > > > > | mb | wmb | rmb | rbd | acq | rel | ctl | > > > -+---+---+---+---+---+---+---+ > > >mb |

Re: [PATCH 2/2] [PATCH] sched: Add smp_rmb() in task rq locking cycles

2015-02-18 Thread Peter Zijlstra
On Wed, Feb 18, 2015 at 04:53:34PM +0100, Oleg Nesterov wrote: > On 02/17, Paul E. McKenney wrote: > > > > | mb | wmb | rmb | rbd | acq | rel | ctl | > > -+---+---+---+---+---+---+---+ > >mb | Y | | Y | y | Y | |

Re: [PATCH 2/2] [PATCH] sched: Add smp_rmb() in task rq locking cycles

2015-02-18 Thread Oleg Nesterov
(Forgot to add Manfred, resending) Thanks Paul and Peter, this was the interesting reading ;) This is almost off-topic (but see below), but perhaps memory-barriers.txt could also mention spin_unlock_wait() to explain that _most probably_ it is pointless without the memory barrier(s), and the barr

Re: [PATCH 2/2] [PATCH] sched: Add smp_rmb() in task rq locking cycles

2015-02-18 Thread Oleg Nesterov
Thanks Paul and Peter, this was the interesting reading ;) This is almost off-topic (but see below), but perhaps memory-barriers.txt could also mention spin_unlock_wait() to explain that _most probably_ it is pointless without the memory barrier(s), and the barrer before-or-after unlock_wait() pai

Re: [PATCH 2/2] [PATCH] sched: Add smp_rmb() in task rq locking cycles

2015-02-18 Thread Peter Zijlstra
On Tue, Feb 17, 2015 at 01:52:31PM -0800, Paul E. McKenney wrote: > I could do a table per communication style. For example, message > passing looks like this (give or take likely errors in the table): > > Side CPUTop CPU > --- > X = 1; r1 =

Re: [PATCH 2/2] [PATCH] sched: Add smp_rmb() in task rq locking cycles

2015-02-18 Thread Peter Zijlstra
On Tue, Feb 17, 2015 at 01:45:22PM -0800, Paul E. McKenney wrote: > > documentation: Clarify control-dependency pairing > > This commit explicitly states that control dependencies pair normally > with other barriers, and gives an example of such pairing. > > Reported-by: Peter Zijlstra > Signed

Re: [PATCH 2/2] [PATCH] sched: Add smp_rmb() in task rq locking cycles

2015-02-17 Thread Paul E. McKenney
On Tue, Feb 17, 2015 at 07:36:36PM +0100, Peter Zijlstra wrote: > On Tue, Feb 17, 2015 at 08:05:32AM -0800, Paul E. McKenney wrote: > > > FWIW, we should probably update that table to include control > > > dependencies too; we didn't (formally) have those back then I think. > > > > > > The blob un

Re: [PATCH 2/2] [PATCH] sched: Add smp_rmb() in task rq locking cycles

2015-02-17 Thread Paul E. McKenney
On Tue, Feb 17, 2015 at 07:23:35PM +0100, Peter Zijlstra wrote: > On Tue, Feb 17, 2015 at 10:01:54AM -0800, Paul E. McKenney wrote: > > > > The blob under SMP BARRIER PAIRING does not mention pairing with control > > > > dependencies; and I'm rather sure I've done so. > > > > And here is a patch f

Re: [PATCH 2/2] [PATCH] sched: Add smp_rmb() in task rq locking cycles

2015-02-17 Thread Peter Zijlstra
On Tue, Feb 17, 2015 at 08:05:32AM -0800, Paul E. McKenney wrote: > > FWIW, we should probably update that table to include control > > dependencies too; we didn't (formally) have those back then I think. > > > > The blob under SMP BARRIER PAIRING does not mention pairing with control > > dependen

Re: [PATCH 2/2] [PATCH] sched: Add smp_rmb() in task rq locking cycles

2015-02-17 Thread Peter Zijlstra
On Tue, Feb 17, 2015 at 10:01:54AM -0800, Paul E. McKenney wrote: > > > The blob under SMP BARRIER PAIRING does not mention pairing with control > > > dependencies; and I'm rather sure I've done so. > > And here is a patch for the control-dependency pairing. Thoughts? The proposed patch does not

Re: [PATCH 2/2] [PATCH] sched: Add smp_rmb() in task rq locking cycles

2015-02-17 Thread Paul E. McKenney
On Tue, Feb 17, 2015 at 08:05:32AM -0800, Paul E. McKenney wrote: > On Tue, Feb 17, 2015 at 02:05:23PM +0100, Peter Zijlstra wrote: > > On Tue, Feb 17, 2015 at 01:12:58PM +0100, Peter Zijlstra wrote: > > > --- a/kernel/sched/core.c > > > +++ b/kernel/sched/core.c > > > @@ -341,6 +341,22 @@ static s

Re: [PATCH 2/2] [PATCH] sched: Add smp_rmb() in task rq locking cycles

2015-02-17 Thread Paul E. McKenney
On Tue, Feb 17, 2015 at 02:05:23PM +0100, Peter Zijlstra wrote: > On Tue, Feb 17, 2015 at 01:12:58PM +0100, Peter Zijlstra wrote: > > --- a/kernel/sched/core.c > > +++ b/kernel/sched/core.c > > @@ -341,6 +341,22 @@ static struct rq *task_rq_lock(struct ta > > raw_spin_lock_irqsave(&p->p

Re: [PATCH 2/2] [PATCH] sched: Add smp_rmb() in task rq locking cycles

2015-02-17 Thread Peter Zijlstra
On Tue, Feb 17, 2015 at 01:12:58PM +0100, Peter Zijlstra wrote: > --- a/kernel/sched/core.c > +++ b/kernel/sched/core.c > @@ -341,6 +341,22 @@ static struct rq *task_rq_lock(struct ta > raw_spin_lock_irqsave(&p->pi_lock, *flags); > rq = task_rq(p); > raw_sp

Re: [PATCH 2/2] [PATCH] sched: Add smp_rmb() in task rq locking cycles

2015-02-17 Thread Peter Zijlstra
On Tue, Feb 17, 2015 at 03:36:50PM +0300, Kirill Tkhai wrote: > > If we observe the new cpu value, we've acquired the new rq->lock and its > > ACQUIRE will pair with the WMB to ensure we see the migrate value. > > Yes, I warried about new_cpu case. > > So, spin_lock() implies smp_rmb(). I used t

Re: [PATCH 2/2] [PATCH] sched: Add smp_rmb() in task rq locking cycles

2015-02-17 Thread Kirill Tkhai
В Вт, 17/02/2015 в 13:12 +0100, Peter Zijlstra пишет: > On Tue, Feb 17, 2015 at 01:47:01PM +0300, Kirill Tkhai wrote: > > > > We migrate a task using TASK_ON_RQ_MIGRATING state of on_rq: > > > > raw_spin_lock(&old_rq->lock); > > deactivate_task(old_rq, p, 0); > > p->on_rq = TASK_ON_RQ

Re: [PATCH 2/2] [PATCH] sched: Add smp_rmb() in task rq locking cycles

2015-02-17 Thread Peter Zijlstra
On Tue, Feb 17, 2015 at 01:47:01PM +0300, Kirill Tkhai wrote: > > We migrate a task using TASK_ON_RQ_MIGRATING state of on_rq: > > raw_spin_lock(&old_rq->lock); > deactivate_task(old_rq, p, 0); > p->on_rq = TASK_ON_RQ_MIGRATING; > set_task_cpu(p, new_cpu); > raw_spin

[PATCH 2/2] [PATCH] sched: Add smp_rmb() in task rq locking cycles

2015-02-17 Thread Kirill Tkhai
We migrate a task using TASK_ON_RQ_MIGRATING state of on_rq: raw_spin_lock(&old_rq->lock); deactivate_task(old_rq, p, 0); p->on_rq = TASK_ON_RQ_MIGRATING; set_task_cpu(p, new_cpu); raw_spin_unlock(&rq->lock); I.e.: write TASK_ON_RQ_MIGRATING