Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > linux.kernel > #1679017
| From | "Paul E. McKenney" <paulmck@linux.vnet.ibm.com> |
|---|---|
| Newsgroups | linux.kernel |
| Subject | Re: [PATCH RFC 02/26] task_work: Replace spin_unlock_wait() with lock/unlock pair |
| Date | 2017-06-30 19:30 +0200 |
| Message-ID | <tY7TY-8jY-13@gated-at.bofh.it> (permalink) |
| References | (1 earlier) <tXRPc-6s4-21@gated-at.bofh.it> <tY1Yd-4JJ-11@gated-at.bofh.it> <tY3GG-5AN-25@gated-at.bofh.it> <tY61Q-7aE-11@gated-at.bofh.it> <tY6Of-7ID-39@gated-at.bofh.it> |
| Organization | linux.* mail to news gateway |
On Fri, Jun 30, 2017 at 09:16:07AM -0700, Paul E. McKenney wrote:
> On Fri, Jun 30, 2017 at 05:20:10PM +0200, Oleg Nesterov wrote:
> > On 06/30, Paul E. McKenney wrote:
> > >
> > > > > + raw_spin_lock_irq(&task->pi_lock);
> > > > > + raw_spin_unlock_irq(&task->pi_lock);
> > >
> > > I agree that the spin_unlock_wait() implementations would avoid the
> > > deadlock with an acquisition from an interrupt handler, while also
> > > avoiding the need to momentarily disable interrupts. The ->pi_lock is
> > > a per-task lock, so I am assuming (perhaps naively) that contention is
> > > not a problem. So is the overhead of interrupt disabling likely to be
> > > noticeable here?
> >
> > I do not think the overhead will be noticeable in this particular case.
> >
> > But I am not sure I understand why do we want to unlock_wait. Yes I agree,
> > it has some problems, but still...
Well, I tried documenting exactly what it did and did not do, which got
an ack from Peter.
https://marc.info/?l=linux-kernel&m=149575078313105
However, my later pull request spawned a bit of discussion:
https://marc.info/?l=linux-kernel&m=149730349001044
This discussion led me to propose strengthening spin_unlock_wait()
to act as a lock/unlock pair. This can be implemented on x86 as
an smp_mb() followed by a read-only spinloop, as shown on branch
spin_unlock_wait.2017.06.23a on my -rcu tree.
Linus was not amused, and said that if we were going to make
spin_unlock_wait() have the semantics of lock+unlock, we should just
open-code that, especially given that there are way more definitions
of spin_unlock_wait() than there are uses. He also suggested making
spin_unlock_wait() have only acquire semantics (x86 spin loop with
no memory-barrier instructions) and add explicit barriers where
required.
https://marc.info/?l=linux-kernel&m=149860012913036
I did a series for this which may be found on branch
spin_unlock_wait.2017.06.27a on my -rcu tree.
This approach was not loved by others (see later on the above thread), and
Linus's reply (which reiterated his opposition to lock+unlock semantics)
suggested the possibility of removing spin_unlock_wait() entirely.
https://marc.info/?l=linux-kernel&m=149869476911620
So I figured, in for a penny, in for a pound, and therefore did the series
that includes this patch. The most recent update (which does not yet
include your improved version) is on branch spin_unlock_wait.2017.06.30b
of my -rcu tree.
Hey, you asked! ;-)
Thanx, Paul
> > The code above looks strange for me. If we are going to repeat this pattern
> > the perhaps we should add a helper for lock+unlock and name it unlock_wait2 ;)
> >
> > If not, we should probably change this code more:
>
> This looks -much- better than my patch! May I have your Signed-off-by?
>
> Thanx, Paul
>
> > --- a/kernel/task_work.c
> > +++ b/kernel/task_work.c
> > @@ -96,20 +96,16 @@ void task_work_run(void)
> > * work->func() can do task_work_add(), do not set
> > * work_exited unless the list is empty.
> > */
> > + raw_spin_lock_irq(&task->pi_lock);
> > do {
> > work = READ_ONCE(task->task_works);
> > head = !work && (task->flags & PF_EXITING) ?
> > &work_exited : NULL;
> > } while (cmpxchg(&task->task_works, work, head) != work);
> > + raw_spin_unlock_irq(&task->pi_lock);
> >
> > if (!work)
> > break;
> > - /*
> > - * Synchronize with task_work_cancel(). It can't remove
> > - * the first entry == work, cmpxchg(task_works) should
> > - * fail, but it can play with *work and other entries.
> > - */
> > - raw_spin_unlock_wait(&task->pi_lock);
> >
> > do {
> > next = work->next;
> >
> > performance-wise this is almost the same, and if we do not really care about
> > overhead we can simplify the code: this way it is obvious that we can't race
> > with task_work_cancel().
> >
> > Oleg.
> >
Back to linux.kernel | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
[PATCH RFC 0/26] Remove spin_unlock_wait() "Paul E. McKenney" <paulmck@linux.vnet.ibm.com> - 2017-06-30 02:00 +0200
[PATCH RFC 13/26] blackfin: Remove spin_unlock_wait() arch-specific definitions "Paul E. McKenney" <paulmck@linux.vnet.ibm.com> - 2017-06-30 02:10 +0200
[PATCH RFC 08/26] locking: Remove spin_unlock_wait() generic definitions "Paul E. McKenney" <paulmck@linux.vnet.ibm.com> - 2017-06-30 02:10 +0200
Re: [PATCH RFC 08/26] locking: Remove spin_unlock_wait() generic definitions Will Deacon <will.deacon@arm.com> - 2017-06-30 11:20 +0200
Re: [PATCH RFC 08/26] locking: Remove spin_unlock_wait() generic definitions "Paul E. McKenney" <paulmck@linux.vnet.ibm.com> - 2017-06-30 14:50 +0200
Re: [PATCH RFC 08/26] locking: Remove spin_unlock_wait() generic definitions Will Deacon <will.deacon@arm.com> - 2017-06-30 15:20 +0200
Re: [PATCH RFC 08/26] locking: Remove spin_unlock_wait() generic definitions "Paul E. McKenney" <paulmck@linux.vnet.ibm.com> - 2017-07-01 00:20 +0200
Re: [PATCH RFC 08/26] locking: Remove spin_unlock_wait() generic definitions Will Deacon <will.deacon@arm.com> - 2017-07-03 15:20 +0200
[PATCH RFC 23/26] sh: Remove spin_unlock_wait() arch-specific definitions "Paul E. McKenney" <paulmck@linux.vnet.ibm.com> - 2017-06-30 02:10 +0200
[PATCH RFC 16/26] m32r: Remove spin_unlock_wait() arch-specific definitions "Paul E. McKenney" <paulmck@linux.vnet.ibm.com> - 2017-06-30 02:10 +0200
[PATCH RFC 21/26] powerpc: Remove spin_unlock_wait() arch-specific definitions "Paul E. McKenney" <paulmck@linux.vnet.ibm.com> - 2017-06-30 02:10 +0200
Re: [PATCH RFC 21/26] powerpc: Remove spin_unlock_wait() arch-specific definitions Boqun Feng <boqun.feng@gmail.com> - 2017-07-02 06:00 +0200
[PATCH RFC 25/26] tile: Remove spin_unlock_wait() arch-specific definitions "Paul E. McKenney" <paulmck@linux.vnet.ibm.com> - 2017-06-30 02:10 +0200
Re: [PATCH RFC 25/26] tile: Remove spin_unlock_wait() arch-specific definitions Linus Torvalds <torvalds@linux-foundation.org> - 2017-06-30 02:10 +0200
Re: [PATCH RFC 25/26] tile: Remove spin_unlock_wait() arch-specific definitions Linus Torvalds <torvalds@linux-foundation.org> - 2017-06-30 02:20 +0200
Re: [PATCH RFC 25/26] tile: Remove spin_unlock_wait() arch-specific definitions "Paul E. McKenney" <paulmck@linux.vnet.ibm.com> - 2017-06-30 02:30 +0200
Re: [PATCH RFC 25/26] tile: Remove spin_unlock_wait() arch-specific definitions "Paul E. McKenney" <paulmck@linux.vnet.ibm.com> - 2017-06-30 02:20 +0200
Re: [PATCH RFC 25/26] tile: Remove spin_unlock_wait() arch-specific definitions "Paul E. McKenney" <paulmck@linux.vnet.ibm.com> - 2017-06-30 02:20 +0200
[PATCH RFC 18/26] mips: Remove spin_unlock_wait() arch-specific definitions "Paul E. McKenney" <paulmck@linux.vnet.ibm.com> - 2017-06-30 02:10 +0200
[PATCH RFC 19/26] mn10300: Remove spin_unlock_wait() arch-specific definitions "Paul E. McKenney" <paulmck@linux.vnet.ibm.com> - 2017-06-30 02:10 +0200
[PATCH RFC 20/26] parisc: Remove spin_unlock_wait() arch-specific definitions "Paul E. McKenney" <paulmck@linux.vnet.ibm.com> - 2017-06-30 02:10 +0200
[PATCH RFC 15/26] ia64: Remove spin_unlock_wait() arch-specific definitions "Paul E. McKenney" <paulmck@linux.vnet.ibm.com> - 2017-06-30 02:10 +0200
[PATCH RFC 11/26] arm: Remove spin_unlock_wait() arch-specific definitions "Paul E. McKenney" <paulmck@linux.vnet.ibm.com> - 2017-06-30 02:10 +0200
[PATCH RFC 22/26] s390: Remove spin_unlock_wait() arch-specific definitions "Paul E. McKenney" <paulmck@linux.vnet.ibm.com> - 2017-06-30 02:10 +0200
[PATCH RFC 01/26] netfilter: Replace spin_unlock_wait() with lock/unlock pair "Paul E. McKenney" <paulmck@linux.vnet.ibm.com> - 2017-06-30 02:10 +0200
Re: [PATCH RFC 01/26] netfilter: Replace spin_unlock_wait() with lock/unlock pair "Paul E. McKenney" <paulmck@linux.vnet.ibm.com> - 2017-07-02 04:10 +0200
[PATCH RFC 04/26] completion: Replace spin_unlock_wait() with lock/unlock pair "Paul E. McKenney" <paulmck@linux.vnet.ibm.com> - 2017-06-30 02:10 +0200
[PATCH RFC 07/26] drivers/ata: Replace spin_unlock_wait() with lock/unlock pair "Paul E. McKenney" <paulmck@linux.vnet.ibm.com> - 2017-06-30 02:10 +0200
[PATCH RFC 14/26] hexagon: Remove spin_unlock_wait() arch-specific definitions "Paul E. McKenney" <paulmck@linux.vnet.ibm.com> - 2017-06-30 02:10 +0200
[PATCH RFC 09/26] alpha: Remove spin_unlock_wait() arch-specific definitions "Paul E. McKenney" <paulmck@linux.vnet.ibm.com> - 2017-06-30 02:10 +0200
[PATCH RFC 24/26] sparc: Remove spin_unlock_wait() arch-specific definitions "Paul E. McKenney" <paulmck@linux.vnet.ibm.com> - 2017-06-30 02:10 +0200
[PATCH RFC 26/26] xtensa: Remove spin_unlock_wait() arch-specific definitions "Paul E. McKenney" <paulmck@linux.vnet.ibm.com> - 2017-06-30 02:10 +0200
[PATCH RFC 03/26] sched: Replace spin_unlock_wait() with lock/unlock pair "Paul E. McKenney" <paulmck@linux.vnet.ibm.com> - 2017-06-30 02:20 +0200
Re: [PATCH RFC 03/26] sched: Replace spin_unlock_wait() with lock/unlock pair Arnd Bergmann <arnd@arndb.de> - 2017-06-30 12:40 +0200
Re: [PATCH RFC 03/26] sched: Replace spin_unlock_wait() with lock/unlock pair "Paul E. McKenney" <paulmck@linux.vnet.ibm.com> - 2017-06-30 14:40 +0200
[PATCH RFC 05/26] exit: Replace spin_unlock_wait() with lock/unlock pair "Paul E. McKenney" <paulmck@linux.vnet.ibm.com> - 2017-06-30 02:20 +0200
[PATCH RFC 12/26] arm64: Remove spin_unlock_wait() arch-specific definitions "Paul E. McKenney" <paulmck@linux.vnet.ibm.com> - 2017-06-30 02:20 +0200
Re: [PATCH RFC 12/26] arm64: Remove spin_unlock_wait() arch-specific definitions Will Deacon <will.deacon@arm.com> - 2017-06-30 11:30 +0200
Re: [PATCH RFC 12/26] arm64: Remove spin_unlock_wait() arch-specific definitions "Paul E. McKenney" <paulmck@linux.vnet.ibm.com> - 2017-06-30 19:40 +0200
[PATCH RFC 10/26] arc: Remove spin_unlock_wait() arch-specific definitions "Paul E. McKenney" <paulmck@linux.vnet.ibm.com> - 2017-06-30 02:20 +0200
[PATCH RFC 02/26] task_work: Replace spin_unlock_wait() with lock/unlock pair "Paul E. McKenney" <paulmck@linux.vnet.ibm.com> - 2017-06-30 02:20 +0200
Re: [PATCH RFC 02/26] task_work: Replace spin_unlock_wait() with lock/unlock pair Oleg Nesterov <oleg@redhat.com> - 2017-06-30 13:10 +0200
Re: [PATCH RFC 02/26] task_work: Replace spin_unlock_wait() with lock/unlock pair "Paul E. McKenney" <paulmck@linux.vnet.ibm.com> - 2017-06-30 15:00 +0200
Re: [PATCH RFC 02/26] task_work: Replace spin_unlock_wait() with lock/unlock pair Oleg Nesterov <oleg@redhat.com> - 2017-06-30 17:30 +0200
Re: [PATCH RFC 02/26] task_work: Replace spin_unlock_wait() with lock/unlock pair "Paul E. McKenney" <paulmck@linux.vnet.ibm.com> - 2017-06-30 18:20 +0200
Re: [PATCH RFC 02/26] task_work: Replace spin_unlock_wait() with lock/unlock pair "Paul E. McKenney" <paulmck@linux.vnet.ibm.com> - 2017-06-30 19:30 +0200
Re: [PATCH RFC 02/26] task_work: Replace spin_unlock_wait() with lock/unlock pair Oleg Nesterov <oleg@redhat.com> - 2017-06-30 21:30 +0200
Re: [PATCH RFC 02/26] task_work: Replace spin_unlock_wait() with lock/unlock pair Alan Stern <stern@rowland.harvard.edu> - 2017-06-30 22:00 +0200
Re: [PATCH RFC 02/26] task_work: Replace spin_unlock_wait() with lock/unlock pair "Paul E. McKenney" <paulmck@linux.vnet.ibm.com> - 2017-06-30 22:10 +0200
Re: [PATCH RFC 02/26] task_work: Replace spin_unlock_wait() with lock/unlock pair "Paul E. McKenney" <paulmck@linux.vnet.ibm.com> - 2017-06-30 22:10 +0200
Re: [PATCH RFC 02/26] task_work: Replace spin_unlock_wait() with lock/unlock pair "Paul E. McKenney" <paulmck@linux.vnet.ibm.com> - 2017-06-30 22:20 +0200
Re: [PATCH RFC 06/26] ipc: Replace spin_unlock_wait() with lock/unlock pair Manfred Spraul <manfred@colorfullife.com> - 2017-07-01 21:30 +0200
Re: [PATCH RFC 06/26] ipc: Replace spin_unlock_wait() with lock/unlock pair "Paul E. McKenney" <paulmck@linux.vnet.ibm.com> - 2017-07-02 05:20 +0200
csiph-web