lkml.org 
[lkml]   [2015]   [Jul]   [28]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: [RFC PATCH 03/14] kthread: Add drain_kthread_worker()
Hello,

On Tue, Jul 28, 2015 at 04:39:20PM +0200, Petr Mladek wrote:
> +/*
> + * Test whether @work is being queued from another work
> + * executing on the same kthread.
> + */
> +static bool is_chained_work(struct kthread_worker *worker)
> +{
> + struct kthread_worker *current_worker;
> +
> + current_worker = current_kthread_worker();
> + /*
> + * Return %true if I'm a kthread worker executing a work item on
> + * the given @worker.
> + */
> + return current_worker && current_worker == worker;
> +}

I'm not sure full-on chained work detection is necessary here.
kthread worker's usages tend to be significantly simpler and draining
is only gonna be used for destruction.

> +void drain_kthread_worker(struct kthread_worker *worker)
> +{
> + int flush_cnt = 0;
> +
> + spin_lock_irq(&worker->lock);
> + worker->nr_drainers++;
> +
> + while (!list_empty(&worker->work_list)) {
> + /*
> + * Unlock, so we could move forward. Note that queuing
> + * is limited by @nr_drainers > 0.
> + */
> + spin_unlock_irq(&worker->lock);
> +
> + flush_kthread_worker(worker);
> +
> + if (++flush_cnt == 10 ||
> + (flush_cnt % 100 == 0 && flush_cnt <= 1000))
> + pr_warn("kthread worker %s: drain_kthread_worker() isn't complete after %u tries\n",
> + worker->task->comm, flush_cnt);
> +
> + spin_lock_irq(&worker->lock);
> + }

I'd just do something like WARN_ONCE(flush_cnt++ > 10, "kthread worker: ...").

Thanks.

--
tejun


\
 
 \ /
  Last update: 2015-07-28 19:41    [W:0.232 / U:0.192 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site