From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752625AbcFINwf (ORCPT ); Thu, 9 Jun 2016 09:52:35 -0400 Received: from mx2.suse.de ([195.135.220.15]:55100 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752590AbcFINwc (ORCPT ); Thu, 9 Jun 2016 09:52:32 -0400 From: Petr Mladek To: Andrew Morton , Oleg Nesterov , Tejun Heo , Ingo Molnar , Peter Zijlstra Cc: 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, Petr Mladek Subject: [PATCH v8 07/12] kthread: Add kthread_destroy_worker() Date: Thu, 9 Jun 2016 15:52:01 +0200 Message-Id: <1465480326-31606-8-git-send-email-pmladek@suse.com> X-Mailer: git-send-email 1.8.5.6 In-Reply-To: <1465480326-31606-1-git-send-email-pmladek@suse.com> References: <1465480326-31606-1-git-send-email-pmladek@suse.com> Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The current kthread worker users call flush() and stop() explicitly. This function drains the worker, stops it, and frees the kthread_worker struct in one call. It is supposed to be used together with kthread_create_worker*() that allocates struct kthread_worker. Also note that drain() correctly handles self-queuing works in compare with flush(). Signed-off-by: Petr Mladek --- include/linux/kthread.h | 2 ++ kernel/kthread.c | 21 +++++++++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/include/linux/kthread.h b/include/linux/kthread.h index 6fc0940b9657..c0a527581d95 100644 --- a/include/linux/kthread.h +++ b/include/linux/kthread.h @@ -137,4 +137,6 @@ void kthread_flush_work(struct kthread_work *work); void kthread_flush_worker(struct kthread_worker *worker); void kthread_drain_worker(struct kthread_worker *worker); +void kthread_destroy_worker(struct kthread_worker *worker); + #endif /* _LINUX_KTHREAD_H */ diff --git a/kernel/kthread.c b/kernel/kthread.c index fa3c327be889..d9f59fdcf466 100644 --- a/kernel/kthread.c +++ b/kernel/kthread.c @@ -853,3 +853,24 @@ void kthread_drain_worker(struct kthread_worker *worker) spin_unlock_irq(&worker->lock); } EXPORT_SYMBOL(kthread_drain_worker); + +/** + * kthread_destroy_worker - destroy a kthread worker + * @worker: worker to be destroyed + * + * Drain and destroy @worker. It has the same conditions + * for use as kthread_drain_worker(), see above. + */ +void kthread_destroy_worker(struct kthread_worker *worker) +{ + struct task_struct *task; + + task = worker->task; + if (WARN_ON(!task)) + return; + + kthread_drain_worker(worker); + kthread_stop(task); + kfree(worker); +} +EXPORT_SYMBOL(kthread_destroy_worker); -- 1.8.5.6 From mboxrd@z Thu Jan 1 00:00:00 1970 From: Petr Mladek Subject: [PATCH v8 07/12] kthread: Add kthread_destroy_worker() Date: Thu, 9 Jun 2016 15:52:01 +0200 Message-ID: <1465480326-31606-8-git-send-email-pmladek@suse.com> References: <1465480326-31606-1-git-send-email-pmladek@suse.com> Return-path: In-Reply-To: <1465480326-31606-1-git-send-email-pmladek@suse.com> Sender: owner-linux-mm@kvack.org To: Andrew Morton , Oleg Nesterov , Tejun Heo , Ingo Molnar , Peter Zijlstra Cc: 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, Petr Mladek List-Id: linux-api@vger.kernel.org The current kthread worker users call flush() and stop() explicitly. This function drains the worker, stops it, and frees the kthread_worker struct in one call. It is supposed to be used together with kthread_create_worker*() that allocates struct kthread_worker. Also note that drain() correctly handles self-queuing works in compare with flush(). Signed-off-by: Petr Mladek --- include/linux/kthread.h | 2 ++ kernel/kthread.c | 21 +++++++++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/include/linux/kthread.h b/include/linux/kthread.h index 6fc0940b9657..c0a527581d95 100644 --- a/include/linux/kthread.h +++ b/include/linux/kthread.h @@ -137,4 +137,6 @@ void kthread_flush_work(struct kthread_work *work); void kthread_flush_worker(struct kthread_worker *worker); void kthread_drain_worker(struct kthread_worker *worker); +void kthread_destroy_worker(struct kthread_worker *worker); + #endif /* _LINUX_KTHREAD_H */ diff --git a/kernel/kthread.c b/kernel/kthread.c index fa3c327be889..d9f59fdcf466 100644 --- a/kernel/kthread.c +++ b/kernel/kthread.c @@ -853,3 +853,24 @@ void kthread_drain_worker(struct kthread_worker *worker) spin_unlock_irq(&worker->lock); } EXPORT_SYMBOL(kthread_drain_worker); + +/** + * kthread_destroy_worker - destroy a kthread worker + * @worker: worker to be destroyed + * + * Drain and destroy @worker. It has the same conditions + * for use as kthread_drain_worker(), see above. + */ +void kthread_destroy_worker(struct kthread_worker *worker) +{ + struct task_struct *task; + + task = worker->task; + if (WARN_ON(!task)) + return; + + kthread_drain_worker(worker); + kthread_stop(task); + kfree(worker); +} +EXPORT_SYMBOL(kthread_destroy_worker); -- 1.8.5.6 -- 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