From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933896AbcAYTFB (ORCPT ); Mon, 25 Jan 2016 14:05:01 -0500 Received: from mail-pf0-f196.google.com ([209.85.192.196]:34385 "EHLO mail-pf0-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1757063AbcAYTE5 (ORCPT ); Mon, 25 Jan 2016 14:04:57 -0500 Date: Mon, 25 Jan 2016 14:04:54 -0500 From: Tejun Heo To: Petr Mladek Cc: Andrew Morton , Oleg Nesterov , Ingo Molnar , Peter Zijlstra , Steven Rostedt , "Paul E. McKenney" , Josh Triplett , Thomas Gleixner , Linus Torvalds , Jiri Kosina , Borislav Petkov , Michal Hocko , linux-mm@kvack.org, Vlastimil Babka , linux-api@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH v4 08/22] kthread: Initial support for delayed kthread work Message-ID: <20160125190454.GD3628@mtj.duckdns.org> References: <1453736711-6703-1-git-send-email-pmladek@suse.com> <1453736711-6703-9-git-send-email-pmladek@suse.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1453736711-6703-9-git-send-email-pmladek@suse.com> User-Agent: Mutt/1.5.24 (2015-08-30) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.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