From: Tejun Heo <tj-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>
To: Petr Mladek <pmladek-IBi9RG/b67k@public.gmane.org>
Cc: Andrew Morton
<akpm-de/tnXTf+JLsfHDXvbKv3WD2FQJk+8+b@public.gmane.org>,
Oleg Nesterov <oleg-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>,
Ingo Molnar <mingo-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>,
Peter Zijlstra <peterz-wEGCiKHe2LqWVfeAwA7xHQ@public.gmane.org>,
Steven Rostedt <rostedt-nx8X9YLhiw1AfugRpC6u6w@public.gmane.org>,
"Paul E. McKenney"
<paulmck-23VcF4HTsmIX0ybBhKVfKdBPR1lH4CV8@public.gmane.org>,
Josh Triplett <josh-iaAMLnmF4UmaiuxdJuQwMA@public.gmane.org>,
Thomas Gleixner <tglx-hfZtesqFncYOwBW4kG4KsQ@public.gmane.org>,
Linus Torvalds
<torvalds-de/tnXTf+JLsfHDXvbKv3WD2FQJk+8+b@public.gmane.org>,
Jiri Kosina <jkosina-AlSwsSmVLrQ@public.gmane.org>,
Borislav Petkov <bp-l3A5Bk7waGM@public.gmane.org>,
Michal Hocko <mhocko-AlSwsSmVLrQ@public.gmane.org>,
linux-mm-Bw31MaZKKs3YtjvyW6yDsg@public.gmane.org,
Vlastimil Babka <vbabka-AlSwsSmVLrQ@public.gmane.org>,
linux-api-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
Subject: Re: [PATCH v4 08/22] kthread: Initial support for delayed kthread work
Date: Mon, 25 Jan 2016 14:04:54 -0500 [thread overview]
Message-ID: <20160125190454.GD3628@mtj.duckdns.org> (raw)
In-Reply-To: <1453736711-6703-9-git-send-email-pmladek-IBi9RG/b67k@public.gmane.org>
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
next prev parent reply other threads:[~2016-01-25 19:04 UTC|newest]
Thread overview: 37+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-01-25 15:44 [PATCH v4 00/22] kthread: Use kthread worker API more widely Petr Mladek
2016-01-25 15:44 ` [PATCH v4 01/22] timer: Allow to check when the timer callback has not finished yet Petr Mladek
2016-01-25 18:44 ` Tejun Heo
2016-01-25 15:44 ` [PATCH v4 02/22] kthread/smpboot: Do not park in kthread_create_on_cpu() Petr Mladek
2016-01-25 15:44 ` [PATCH v4 03/22] kthread: Allow to call __kthread_create_on_node() with va_list args Petr Mladek
2016-01-25 15:44 ` [PATCH v4 04/22] kthread: Add create_kthread_worker*() Petr Mladek
2016-01-25 18:53 ` Tejun Heo
2016-02-16 15:44 ` Petr Mladek
[not found] ` <20160216154443.GW12548-KsEp0d+Q8qECVLCxKZUutA@public.gmane.org>
2016-02-16 16:08 ` Tejun Heo
2016-02-16 16:10 ` Petr Mladek
2016-01-25 15:44 ` [PATCH v4 05/22] kthread: Add drain_kthread_worker() Petr Mladek
2016-01-25 15:44 ` [PATCH v4 06/22] kthread: Add destroy_kthread_worker() Petr Mladek
2016-01-25 15:44 ` [PATCH v4 07/22] kthread: Detect when a kthread work is used by more workers Petr Mladek
[not found] ` <1453736711-6703-8-git-send-email-pmladek-IBi9RG/b67k@public.gmane.org>
2016-01-25 18:57 ` Tejun Heo
[not found] ` <20160125185747.GC3628-qYNAdHglDFBN0TnZuCh8vA@public.gmane.org>
2016-02-16 16:38 ` Petr Mladek
2016-01-25 15:44 ` [PATCH v4 08/22] kthread: Initial support for delayed kthread work Petr Mladek
[not found] ` <1453736711-6703-9-git-send-email-pmladek-IBi9RG/b67k@public.gmane.org>
2016-01-25 19:04 ` Tejun Heo [this message]
2016-01-25 15:44 ` [PATCH v4 09/22] kthread: Allow to cancel " Petr Mladek
2016-01-25 19:17 ` Tejun Heo
2016-02-19 16:22 ` Petr Mladek
2016-01-25 15:44 ` [PATCH v4 10/22] kthread: Allow to modify delayed " Petr Mladek
2016-01-25 19:19 ` Tejun Heo
2016-01-25 15:45 ` [PATCH v4 11/22] kthread: Better support freezable kthread workers Petr Mladek
2016-01-25 19:21 ` Tejun Heo
2016-01-25 15:45 ` [PATCH v4 12/22] kthread: Use try_lock_kthread_work() in flush_kthread_work() Petr Mladek
2016-01-25 15:45 ` [PATCH v4 14/22] ring_buffer: Convert benchmark kthreads into kthread worker API Petr Mladek
2016-01-25 15:45 ` [PATCH v4 15/22] hung_task: Convert hungtaskd " Petr Mladek
2016-01-25 15:45 ` [PATCH v4 16/22] kmemleak: Convert kmemleak kthread " Petr Mladek
2016-01-25 15:45 ` [PATCH v4 17/22] ipmi: Convert kipmi " Petr Mladek
2016-01-25 15:45 ` [PATCH v4 18/22] IB/fmr_pool: Convert the cleanup thread " Petr Mladek
[not found] ` <1453736711-6703-1-git-send-email-pmladek-IBi9RG/b67k@public.gmane.org>
2016-01-25 15:45 ` [PATCH v4 13/22] mm/huge_page: Convert khugepaged() " Petr Mladek
2016-01-25 15:45 ` [PATCH v4 19/22] memstick/r592: Better synchronize debug messages in r592_io kthread Petr Mladek
2016-01-25 15:45 ` [PATCH v4 20/22] memstick/r592: convert r592_io kthread into kthread worker API Petr Mladek
2016-01-25 15:45 ` [PATCH v4 21/22] thermal/intel_powerclamp: Remove duplicated code that starts the kthread Petr Mladek
2016-01-25 16:23 ` Jacob Pan
2016-01-25 15:45 ` [PATCH v4 22/22] thermal/intel_powerclamp: Convert the kthread to kthread worker API Petr Mladek
2016-01-25 16:28 ` Jacob Pan
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20160125190454.GD3628@mtj.duckdns.org \
--to=tj-dgejt+ai2ygdnm+yrofe0a@public.gmane.org \
--cc=akpm-de/tnXTf+JLsfHDXvbKv3WD2FQJk+8+b@public.gmane.org \
--cc=bp-l3A5Bk7waGM@public.gmane.org \
--cc=jkosina-AlSwsSmVLrQ@public.gmane.org \
--cc=josh-iaAMLnmF4UmaiuxdJuQwMA@public.gmane.org \
--cc=linux-api-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
--cc=linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
--cc=linux-mm-Bw31MaZKKs3YtjvyW6yDsg@public.gmane.org \
--cc=mhocko-AlSwsSmVLrQ@public.gmane.org \
--cc=mingo-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org \
--cc=oleg-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org \
--cc=paulmck-23VcF4HTsmIX0ybBhKVfKdBPR1lH4CV8@public.gmane.org \
--cc=peterz-wEGCiKHe2LqWVfeAwA7xHQ@public.gmane.org \
--cc=pmladek-IBi9RG/b67k@public.gmane.org \
--cc=rostedt-nx8X9YLhiw1AfugRpC6u6w@public.gmane.org \
--cc=tglx-hfZtesqFncYOwBW4kG4KsQ@public.gmane.org \
--cc=torvalds-de/tnXTf+JLsfHDXvbKv3WD2FQJk+8+b@public.gmane.org \
--cc=vbabka-AlSwsSmVLrQ@public.gmane.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).