Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > linux.kernel > #1317215
| From | Tejun Heo <tj@kernel.org> |
|---|---|
| Newsgroups | linux.kernel |
| Subject | Re: [PATCH v4 08/22] kthread: Initial support for delayed kthread work |
| Date | 2016-01-25 20:10 +0100 |
| Message-ID | <qUUGu-8W-15@gated-at.bofh.it> (permalink) |
| References | <qURyW-64A-19@gated-at.bofh.it> <qURyZ-64A-81@gated-at.bofh.it> |
| Organization | linux.* mail to news gateway |
Hello,
On Mon, Jan 25, 2016 at 04:44:57PM +0100, Petr Mladek wrote:
> +/*
> + * Returns true when there is a pending operation for this work.
> + * In particular, it checks if the work is:
> + * - queued
> + * - a timer is running to queue this delayed work
> + *
> + * This function must be called with locked work.
> + */
> +static inline bool kthread_work_pending(const struct kthread_work *work)
> +{
> + return !list_empty(&work->node) ||
> + (work->timer && timer_active(work->timer));
> +}
Why not just put the work item on a separate list so that
lits_empty(&work->node) is always enough? IOW, put delayed work items
on timers on worker->delayed or sth.
> +/*
> + * Queue @work right into the worker queue.
> + */
> +static void __queue_kthread_work(struct kthread_worker *worker,
> + struct kthread_work *work)
> +{
> + insert_kthread_work(worker, work, &worker->work_list);
> +}
Does this really need to be an inline function? This sort of one
liner helpers tend to be obfuscating more than anything else.
> @@ -756,6 +779,121 @@ bool queue_kthread_work(struct kthread_worker *worker,
> }
> EXPORT_SYMBOL_GPL(queue_kthread_work);
>
> +static bool try_lock_kthread_work(struct kthread_work *work)
> +{
> + struct kthread_worker *worker;
> + int ret = false;
> +
> +try_again:
> + worker = work->worker;
> +
> + if (!worker)
> + goto out;
return false;
> +
> + spin_lock(&worker->lock);
> + if (worker != work->worker) {
> + spin_unlock(&worker->lock);
> + goto try_again;
> + }
return true;
> + ret = true;
> +
> +out:
> + return ret;
> +}
Stop building unnecessary structures. Keep it simple.
> +static inline void unlock_kthread_work(struct kthread_work *work)
> +{
> + spin_unlock(&work->worker->lock);
> +}
Ditto. Just open code it. It doesn't add anything.
> +/**
> + * delayed_kthread_work_timer_fn - callback that queues the associated delayed
> + * kthread work when the timer expires.
> + * @__data: pointer to the data associated with the timer
> + *
> + * The format of the function is defined by struct timer_list.
> + * It should have been called from irqsafe timer with irq already off.
> + */
> +void delayed_kthread_work_timer_fn(unsigned long __data)
> +{
> + struct delayed_kthread_work *dwork =
> + (struct delayed_kthread_work *)__data;
> + struct kthread_work *work = &dwork->work;
> +
> + if (!try_lock_kthread_work(work))
Can you please explain why try_lock is necessary here? That's the
most important and non-obvious thing going on here and there's no
explanation of that at all.
Thanks.
--
tejun
Back to linux.kernel | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
[PATCH v4 00/22] kthread: Use kthread worker API more widely Petr Mladek <pmladek@suse.com> - 2016-01-25 16:50 +0100
[PATCH v4 21/22] thermal/intel_powerclamp: Remove duplicated code that starts the kthread Petr Mladek <pmladek@suse.com> - 2016-01-25 16:50 +0100
Re: [PATCH v4 21/22] thermal/intel_powerclamp: Remove duplicated code that starts the kthread Jacob Pan <jacob.jun.pan@linux.intel.com> - 2016-01-25 17:30 +0100
[PATCH v4 18/22] IB/fmr_pool: Convert the cleanup thread into kthread worker API Petr Mladek <pmladek@suse.com> - 2016-01-25 16:50 +0100
[PATCH v4 03/22] kthread: Allow to call __kthread_create_on_node() with va_list args Petr Mladek <pmladek@suse.com> - 2016-01-25 16:50 +0100
[PATCH v4 19/22] memstick/r592: Better synchronize debug messages in r592_io kthread Petr Mladek <pmladek@suse.com> - 2016-01-25 16:50 +0100
[PATCH v4 12/22] kthread: Use try_lock_kthread_work() in flush_kthread_work() Petr Mladek <pmladek@suse.com> - 2016-01-25 16:50 +0100
[PATCH v4 17/22] ipmi: Convert kipmi kthread into kthread worker API Petr Mladek <pmladek@suse.com> - 2016-01-25 16:50 +0100
[PATCH v4 08/22] kthread: Initial support for delayed kthread work Petr Mladek <pmladek@suse.com> - 2016-01-25 16:50 +0100
Re: [PATCH v4 08/22] kthread: Initial support for delayed kthread work Tejun Heo <tj@kernel.org> - 2016-01-25 20:10 +0100
[PATCH v4 01/22] timer: Allow to check when the timer callback has not finished yet Petr Mladek <pmladek@suse.com> - 2016-01-25 16:50 +0100
Re: [PATCH v4 01/22] timer: Allow to check when the timer callback has not finished yet Tejun Heo <tj@kernel.org> - 2016-01-25 19:50 +0100
[PATCH v4 06/22] kthread: Add destroy_kthread_worker() Petr Mladek <pmladek@suse.com> - 2016-01-25 16:50 +0100
[PATCH v4 22/22] thermal/intel_powerclamp: Convert the kthread to kthread worker API Petr Mladek <pmladek@suse.com> - 2016-01-25 16:50 +0100
Re: [PATCH v4 22/22] thermal/intel_powerclamp: Convert the kthread to kthread worker API Jacob Pan <jacob.jun.pan@linux.intel.com> - 2016-01-25 17:40 +0100
[PATCH v4 20/22] memstick/r592: convert r592_io kthread into kthread worker API Petr Mladek <pmladek@suse.com> - 2016-01-25 17:00 +0100
[PATCH v4 15/22] hung_task: Convert hungtaskd into kthread worker API Petr Mladek <pmladek@suse.com> - 2016-01-25 17:00 +0100
[PATCH v4 16/22] kmemleak: Convert kmemleak kthread into kthread worker API Petr Mladek <pmladek@suse.com> - 2016-01-25 17:00 +0100
[PATCH v4 13/22] mm/huge_page: Convert khugepaged() into kthread worker API Petr Mladek <pmladek@suse.com> - 2016-01-25 17:00 +0100
[PATCH v4 14/22] ring_buffer: Convert benchmark kthreads into kthread worker API Petr Mladek <pmladek@suse.com> - 2016-01-25 17:00 +0100
[PATCH v4 11/22] kthread: Better support freezable kthread workers Petr Mladek <pmladek@suse.com> - 2016-01-25 17:10 +0100
Re: [PATCH v4 11/22] kthread: Better support freezable kthread workers Tejun Heo <tj@kernel.org> - 2016-01-25 20:30 +0100
[PATCH v4 09/22] kthread: Allow to cancel kthread work Petr Mladek <pmladek@suse.com> - 2016-01-25 17:20 +0100
Re: [PATCH v4 09/22] kthread: Allow to cancel kthread work Tejun Heo <tj@kernel.org> - 2016-01-25 20:20 +0100
[PATCH v4 02/22] kthread/smpboot: Do not park in kthread_create_on_cpu() Petr Mladek <pmladek@suse.com> - 2016-01-25 17:20 +0100
[PATCH v4 07/22] kthread: Detect when a kthread work is used by more workers Petr Mladek <pmladek@suse.com> - 2016-01-25 17:20 +0100
Re: [PATCH v4 07/22] kthread: Detect when a kthread work is used by more workers Tejun Heo <tj@kernel.org> - 2016-01-25 20:00 +0100
[PATCH v4 04/22] kthread: Add create_kthread_worker*() Petr Mladek <pmladek@suse.com> - 2016-01-25 17:20 +0100
Re: [PATCH v4 04/22] kthread: Add create_kthread_worker*() Tejun Heo <tj@kernel.org> - 2016-01-25 20:00 +0100
csiph-web