From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753460AbbG1RS1 (ORCPT ); Tue, 28 Jul 2015 13:18:27 -0400 Received: from mail-yk0-f196.google.com ([209.85.160.196]:36694 "EHLO mail-yk0-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752180AbbG1RSZ (ORCPT ); Tue, 28 Jul 2015 13:18:25 -0400 Date: Tue, 28 Jul 2015 13:18:22 -0400 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 , live-patching@vger.kernel.org, linux-api@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [RFC PATCH 03/14] kthread: Add drain_kthread_worker() Message-ID: <20150728171822.GA5322@mtj.duckdns.org> References: <1438094371-8326-1-git-send-email-pmladek@suse.com> <1438094371-8326-4-git-send-email-pmladek@suse.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1438094371-8326-4-git-send-email-pmladek@suse.com> User-Agent: Mutt/1.5.23 (2014-03-12) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 From mboxrd@z Thu Jan 1 00:00:00 1970 From: Tejun Heo Subject: Re: [RFC PATCH 03/14] kthread: Add drain_kthread_worker() Date: Tue, 28 Jul 2015 13:18:22 -0400 Message-ID: <20150728171822.GA5322@mtj.duckdns.org> References: <1438094371-8326-1-git-send-email-pmladek@suse.com> <1438094371-8326-4-git-send-email-pmladek@suse.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Return-path: Content-Disposition: inline In-Reply-To: <1438094371-8326-4-git-send-email-pmladek-IBi9RG/b67k@public.gmane.org> Sender: linux-api-owner-u79uwXL29TY76Z2rM5mHXA@public.gmane.org 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-Bw31MaZKKs3YtjvyW6yDsg@public.gmane.org, Vlastimil Babka , live-patching-u79uwXL29TY76Z2rM5mHXA@public.gmane.org, linux-api-u79uwXL29TY76Z2rM5mHXA@public.gmane.org, linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org List-Id: linux-api@vger.kernel.org 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 From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-yk0-f176.google.com (mail-yk0-f176.google.com [209.85.160.176]) by kanga.kvack.org (Postfix) with ESMTP id C146E6B0038 for ; Tue, 28 Jul 2015 13:18:26 -0400 (EDT) Received: by ykay190 with SMTP id y190so101182551yka.3 for ; Tue, 28 Jul 2015 10:18:26 -0700 (PDT) Received: from mail-yk0-x242.google.com (mail-yk0-x242.google.com. [2607:f8b0:4002:c07::242]) by mx.google.com with ESMTPS id x188si15971690ywd.77.2015.07.28.10.18.25 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 28 Jul 2015 10:18:25 -0700 (PDT) Received: by ykek23 with SMTP id k23so6277342yke.0 for ; Tue, 28 Jul 2015 10:18:25 -0700 (PDT) Date: Tue, 28 Jul 2015 13:18:22 -0400 From: Tejun Heo Subject: Re: [RFC PATCH 03/14] kthread: Add drain_kthread_worker() Message-ID: <20150728171822.GA5322@mtj.duckdns.org> References: <1438094371-8326-1-git-send-email-pmladek@suse.com> <1438094371-8326-4-git-send-email-pmladek@suse.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1438094371-8326-4-git-send-email-pmladek@suse.com> Sender: owner-linux-mm@kvack.org List-ID: 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 , live-patching@vger.kernel.org, linux-api@vger.kernel.org, linux-kernel@vger.kernel.org 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 -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to majordomo@kvack.org. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: email@kvack.org