Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > linux.kernel > #1343144 > unrolled thread
| Started by | Peter Zijlstra <peterz@infradead.org> |
|---|---|
| First post | 2016-02-25 13:40 +0100 |
| Last post | 2016-02-27 16:20 +0100 |
| Articles | 3 — 2 participants |
Back to article view | Back to linux.kernel
This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by
below is the oldest one visible, not the original post.
Re: [PATCH v5 04/20] kthread: Add drain_kthread_worker() Peter Zijlstra <peterz@infradead.org> - 2016-02-25 13:40 +0100
Re: [PATCH v5 04/20] kthread: Add drain_kthread_worker() Petr Mladek <pmladek@suse.com> - 2016-02-26 16:30 +0100
Re: [PATCH v5 04/20] kthread: Add drain_kthread_worker() Peter Zijlstra <peterz@infradead.org> - 2016-02-27 16:20 +0100
| From | Peter Zijlstra <peterz@infradead.org> |
|---|---|
| Date | 2016-02-25 13:40 +0100 |
| Subject | Re: [PATCH v5 04/20] kthread: Add drain_kthread_worker() |
| Message-ID | <r63n3-3MM-3@gated-at.bofh.it> |
On Mon, Feb 22, 2016 at 03:56:54PM +0100, Petr Mladek wrote:
> +/**
> + * drain_kthread_worker - drain a kthread worker
> + * @worker: worker to be drained
> + *
> + * Wait until there is no work queued for the given kthread worker.
> + * @worker is flushed repeatedly until it becomes empty. The number
> + * of flushing is determined by the depth of chaining and should
> + * be relatively short. Whine if it takes too long.
> + *
> + * The caller is responsible for blocking all users of this kthread
> + * worker from queuing new works. Also it is responsible for blocking
> + * the already queued works from an infinite re-queuing!
> + */
> +void drain_kthread_worker(struct kthread_worker *worker)
> +{
> + int flush_cnt = 0;
> +
> + spin_lock_irq(&worker->lock);
Would it not make sense to set a flag here that inhibits (or warns)
queueing new work?
Otherwise this can, as you point out, last forever.
And I think its a logic fail if you both want to drain it and keeping
adding new work.
> + while (!list_empty(&worker->work_list)) {
> + spin_unlock_irq(&worker->lock);
> +
> + flush_kthread_worker(worker);
> + WARN_ONCE(flush_cnt++ > 10,
> + "kthread worker %s: drain_kthread_worker() isn't complete after %u tries\n",
> + worker->task->comm, flush_cnt);
> +
> + spin_lock_irq(&worker->lock);
> + }
> +
> + spin_unlock_irq(&worker->lock);
> +}
> +EXPORT_SYMBOL(drain_kthread_worker);
> --
> 1.8.5.6
>
[toc] | [next] | [standalone]
| From | Petr Mladek <pmladek@suse.com> |
|---|---|
| Date | 2016-02-26 16:30 +0100 |
| Message-ID | <r6sv8-5gy-7@gated-at.bofh.it> |
| In reply to | #1343144 |
On Thu 2016-02-25 13:35:51, Peter Zijlstra wrote:
> On Mon, Feb 22, 2016 at 03:56:54PM +0100, Petr Mladek wrote:
> > +/**
> > + * drain_kthread_worker - drain a kthread worker
> > + * @worker: worker to be drained
> > + *
> > + * Wait until there is no work queued for the given kthread worker.
> > + * @worker is flushed repeatedly until it becomes empty. The number
> > + * of flushing is determined by the depth of chaining and should
> > + * be relatively short. Whine if it takes too long.
> > + *
> > + * The caller is responsible for blocking all users of this kthread
> > + * worker from queuing new works. Also it is responsible for blocking
> > + * the already queued works from an infinite re-queuing!
> > + */
> > +void drain_kthread_worker(struct kthread_worker *worker)
> > +{
> > + int flush_cnt = 0;
> > +
> > + spin_lock_irq(&worker->lock);
>
> Would it not make sense to set a flag here that inhibits (or warns)
> queueing new work?
>
> Otherwise this can, as you point out, last forever.
>
> And I think its a logic fail if you both want to drain it and keeping
> adding new work.
We must allow self-queuing because it might be needed to finish
the processing. We would need to detect it. Tejun suggested
to avoid this and make the code simple.
I do not have a strong opinion here. On one hand, such a check might
help with debugging. On the other hand, workqueues have happily lived
without it for years.
Thanks a lot for review,
Petr
[toc] | [prev] | [next] | [standalone]
| From | Peter Zijlstra <peterz@infradead.org> |
|---|---|
| Date | 2016-02-27 16:20 +0100 |
| Message-ID | <r6OOZ-4TV-5@gated-at.bofh.it> |
| In reply to | #1344334 |
On Fri, Feb 26, 2016 at 04:23:09PM +0100, Petr Mladek wrote: > I do not have a strong opinion here. On one hand, such a check might > help with debugging. On the other hand, workqueues have happily lived > without it for years. TJ and me have a different view on these things. I'm always for the strictest possible semantics with strong validation. TJ always worries a lot about existing users. Luckily, you don't have users yet :-)
[toc] | [prev] | [standalone]
Back to top | Article view | linux.kernel
csiph-web