Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1379011

[PATCH v6 05/20] kthread: Add destroy_kthread_worker()

From Petr Mladek <pmladek@suse.com>
Newsgroups linux.kernel
Subject [PATCH v6 05/20] kthread: Add destroy_kthread_worker()
Date 2016-04-14 17:20 +0200
Message-ID <rnRdO-3Ro-75@gated-at.bofh.it> (permalink)
References <rnRdL-3Ro-3@gated-at.bofh.it>
Organization linux.* mail to news gateway

Show all headers | View raw


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 create_kthread_worker*() that
allocates struct kthread_worker.

Also note that drain() correctly handles self-queuing works in compare
with flush().

Signed-off-by: Petr Mladek <pmladek@suse.com>
---
 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 468011efa68d..a36604fa8aa2 100644
--- a/include/linux/kthread.h
+++ b/include/linux/kthread.h
@@ -136,4 +136,6 @@ bool queue_kthread_work(struct kthread_worker *worker,
 void flush_kthread_work(struct kthread_work *work);
 void flush_kthread_worker(struct kthread_worker *worker);
 
+void destroy_kthread_worker(struct kthread_worker *worker);
+
 #endif /* _LINUX_KTHREAD_H */
diff --git a/kernel/kthread.c b/kernel/kthread.c
index 6051aa9d93c6..441651765f08 100644
--- a/kernel/kthread.c
+++ b/kernel/kthread.c
@@ -852,3 +852,24 @@ void drain_kthread_worker(struct kthread_worker *worker)
 	spin_unlock_irq(&worker->lock);
 }
 EXPORT_SYMBOL(drain_kthread_worker);
+
+/**
+ * destroy_kthread_worker - destroy a kthread worker
+ * @worker: worker to be destroyed
+ *
+ * Drain and destroy @worker.  It has the same conditions
+ * for use as drain_kthread_worker(), see above.
+ */
+void destroy_kthread_worker(struct kthread_worker *worker)
+{
+	struct task_struct *task;
+
+	task = worker->task;
+	if (WARN_ON(!task))
+		return;
+
+	drain_kthread_worker(worker);
+	kthread_stop(task);
+	kfree(worker);
+}
+EXPORT_SYMBOL(destroy_kthread_worker);
-- 
1.8.5.6

Back to linux.kernel | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

[PATCH v6 00/20] kthread: Use kthread worker API more widely Petr Mladek <pmladek@suse.com> - 2016-04-14 17:20 +0200
  [PATCH v6 18/20] memstick/r592: convert r592_io kthread into kthread worker API Petr Mladek <pmladek@suse.com> - 2016-04-14 17:20 +0200
  [PATCH v6 15/20] ipmi: Convert kipmi kthread into kthread worker API Petr Mladek <pmladek@suse.com> - 2016-04-14 17:20 +0200
  [PATCH v6 07/20] kthread: Initial support for delayed kthread work Petr Mladek <pmladek@suse.com> - 2016-04-14 17:20 +0200
  [PATCH v6 19/20] thermal/intel_powerclamp: Remove duplicated code that starts the kthread Petr Mladek <pmladek@suse.com> - 2016-04-14 17:20 +0200
  [PATCH v6 16/20] IB/fmr_pool: Convert the cleanup thread into kthread worker API Petr Mladek <pmladek@suse.com> - 2016-04-14 17:20 +0200
  [PATCH v6 12/20] ring_buffer: Convert benchmark kthreads into kthread worker API Petr Mladek <pmladek@suse.com> - 2016-04-14 17:20 +0200
  [PATCH v6 20/20] thermal/intel_powerclamp: Convert the kthread to kthread worker API Petr Mladek <pmladek@suse.com> - 2016-04-14 17:20 +0200
  [PATCH v6 02/20] kthread: Allow to call __kthread_create_on_node() with va_list args Petr Mladek <pmladek@suse.com> - 2016-04-14 17:20 +0200
  [PATCH v6 03/20] kthread: Add create_kthread_worker*() Petr Mladek <pmladek@suse.com> - 2016-04-14 17:20 +0200
  [PATCH v6 11/20] mm/huge_page: Convert khugepaged() into kthread worker API Petr Mladek <pmladek@suse.com> - 2016-04-14 17:20 +0200
  [PATCH v6 17/20] memstick/r592: Better synchronize debug messages in r592_io kthread Petr Mladek <pmladek@suse.com> - 2016-04-14 17:20 +0200
  [PATCH v6 05/20] kthread: Add destroy_kthread_worker() Petr Mladek <pmladek@suse.com> - 2016-04-14 17:20 +0200
  [PATCH v6 13/20] hung_task: Convert hungtaskd into kthread worker API Petr Mladek <pmladek@suse.com> - 2016-04-14 17:20 +0200
  [PATCH v6 01/20] kthread/smpboot: Do not park in kthread_create_on_cpu() Petr Mladek <pmladek@suse.com> - 2016-04-14 17:30 +0200
  [PATCH v6 06/20] kthread: Detect when a kthread work is used by more workers Petr Mladek <pmladek@suse.com> - 2016-04-14 17:30 +0200
  [PATCH v6 08/20] kthread: Allow to cancel kthread work Petr Mladek <pmladek@suse.com> - 2016-04-14 17:30 +0200
  [PATCH v6 04/20] kthread: Add drain_kthread_worker() Petr Mladek <pmladek@suse.com> - 2016-04-14 17:30 +0200

csiph-web