Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > linux.kernel > #1345033
| From | Peter Zijlstra <peterz@infradead.org> |
|---|---|
| Newsgroups | linux.kernel |
| Subject | Re: [PATCH v5 08/20] kthread: Allow to cancel kthread work |
| Date | 2016-02-27 16:20 +0100 |
| Message-ID | <r6OP0-4TV-21@gated-at.bofh.it> (permalink) |
| References | (2 earlier) <r5Kkq-72Y-17@gated-at.bofh.it> <r63Gr-3TO-13@gated-at.bofh.it> <r6sEN-5li-15@gated-at.bofh.it> <r6trb-5Z1-1@gated-at.bofh.it> <r6u3V-6vT-35@gated-at.bofh.it> |
| Organization | linux.* mail to news gateway |
On Fri, Feb 26, 2016 at 06:00:56PM +0100, Petr Mladek wrote:
> On Fri 2016-02-26 17:25:52, Peter Zijlstra wrote:
> > On Fri, Feb 26, 2016 at 04:38:18PM +0100, Petr Mladek wrote:
> > > On Thu 2016-02-25 13:59:32, Peter Zijlstra wrote:
> > > > On Wed, Feb 24, 2016 at 05:18:05PM +0100, Petr Mladek wrote:
> > > > > @@ -770,7 +782,22 @@ void delayed_kthread_work_timer_fn(unsigned long __data)
> > > > > if (WARN_ON_ONCE(!worker))
> > > > > return;
> > > > >
> > > > > - spin_lock(&worker->lock);
> > > > > + /*
> > > > > + * We might be unable to take the lock if someone is trying to
> > > > > + * cancel this work and calls del_timer_sync() when this callback
> > > > > + * has already been removed from the timer list.
> > > > > + */
> > > > > + while (!spin_trylock(&worker->lock)) {
> > > > > + /*
> > > > > + * Busy wait with spin_is_locked() to avoid cache bouncing.
> > > > > + * Break when canceling is set to avoid a deadlock.
> > > > > + */
> > > > > + do {
> > > > > + if (work->canceling)
> > > > > + return;
> > > > > + cpu_relax();
> > > > > + } while (spin_is_locked(&worker->lock));
> > > > > + }
> > > > > /* Work must not be used with more workers, see queue_kthread_work(). */
> > > > > WARN_ON_ONCE(work->worker != worker);
> > And since you do add_timer() while holding the spinlock, this should all
> > work out, no?
>
> Interesting idea. Yes, it should work. But is this really easier? The
> try_again/relock/recheck code is not trivial either.
The trylock loop has very bad worst case behaviour, it really is best to
avoid such patterns if at all possible.
Back to linux.kernel | Previous | Next — Previous in thread | Find similar | Unroll thread
Re: [PATCH v5 08/20] kthread: Allow to cancel kthread work Petr Mladek <pmladek@suse.com> - 2016-02-24 17:20 +0100
Re: [PATCH v5 08/20] kthread: Allow to cancel kthread work Peter Zijlstra <peterz@infradead.org> - 2016-02-25 14:00 +0100
Re: [PATCH v5 08/20] kthread: Allow to cancel kthread work Petr Mladek <pmladek@suse.com> - 2016-02-26 16:40 +0100
Re: [PATCH v5 08/20] kthread: Allow to cancel kthread work Peter Zijlstra <peterz@infradead.org> - 2016-02-26 17:30 +0100
Re: [PATCH v5 08/20] kthread: Allow to cancel kthread work Petr Mladek <pmladek@suse.com> - 2016-02-26 18:10 +0100
Re: [PATCH v5 08/20] kthread: Allow to cancel kthread work Peter Zijlstra <peterz@infradead.org> - 2016-02-27 16:20 +0100
csiph-web