linux-api.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Petr Mladek <pmladek@suse.com>
To: Andrew Morton <akpm@linux-foundation.org>,
	Oleg Nesterov <oleg@redhat.com>, Tejun Heo <tj@kernel.org>,
	Ingo Molnar <mingo@redhat.com>,
	Peter Zijlstra <peterz@infradead.org>
Cc: Steven Rostedt <rostedt@goodmis.org>,
	"Paul E. McKenney" <paulmck@linux.vnet.ibm.com>,
	Josh Triplett <josh@joshtriplett.org>,
	Thomas Gleixner <tglx@linutronix.de>,
	Linus Torvalds <torvalds@linux-foundation.org>,
	Jiri Kosina <jkosina@suse.cz>, Borislav Petkov <bp@suse.de>,
	Michal Hocko <mhocko@suse.cz>,
	linux-mm@kvack.org, Vlastimil Babka <vbabka@suse.cz>,
	linux-api@vger.kernel.org, linux-kernel@vger.kernel.org,
	Petr Mladek <pmladek@suse.com>
Subject: [PATCH v5 02/20] kthread: Allow to call __kthread_create_on_node() with va_list args
Date: Mon, 22 Feb 2016 15:56:52 +0100	[thread overview]
Message-ID: <1456153030-12400-3-git-send-email-pmladek@suse.com> (raw)
In-Reply-To: <1456153030-12400-1-git-send-email-pmladek@suse.com>

kthread_create_on_node() implements a bunch of logic to create
the kthread. It is already called by kthread_create_on_cpu().

We are going to extend the kthread worker API and will
need to call kthread_create_on_node() with va_list args there.

This patch does only a refactoring and does not modify the existing
behavior.

Signed-off-by: Petr Mladek <pmladek@suse.com>
---
 kernel/kthread.c | 72 +++++++++++++++++++++++++++++++++-----------------------
 1 file changed, 42 insertions(+), 30 deletions(-)

diff --git a/kernel/kthread.c b/kernel/kthread.c
index 1ffc11ec5546..bfe8742c4217 100644
--- a/kernel/kthread.c
+++ b/kernel/kthread.c
@@ -244,33 +244,10 @@ static void create_kthread(struct kthread_create_info *create)
 	}
 }
 
-/**
- * kthread_create_on_node - create a kthread.
- * @threadfn: the function to run until signal_pending(current).
- * @data: data ptr for @threadfn.
- * @node: task and thread structures for the thread are allocated on this node
- * @namefmt: printf-style name for the thread.
- *
- * Description: This helper function creates and names a kernel
- * thread.  The thread will be stopped: use wake_up_process() to start
- * it.  See also kthread_run().  The new thread has SCHED_NORMAL policy and
- * is affine to all CPUs.
- *
- * If thread is going to be bound on a particular cpu, give its node
- * in @node, to get NUMA affinity for kthread stack, or else give NUMA_NO_NODE.
- * When woken, the thread will run @threadfn() with @data as its
- * argument. @threadfn() can either call do_exit() directly if it is a
- * standalone thread for which no one will call kthread_stop(), or
- * return when 'kthread_should_stop()' is true (which means
- * kthread_stop() has been called).  The return value should be zero
- * or a negative error number; it will be passed to kthread_stop().
- *
- * Returns a task_struct or ERR_PTR(-ENOMEM) or ERR_PTR(-EINTR).
- */
-struct task_struct *kthread_create_on_node(int (*threadfn)(void *data),
-					   void *data, int node,
-					   const char namefmt[],
-					   ...)
+static struct task_struct *__kthread_create_on_node(int (*threadfn)(void *data),
+						    void *data, int node,
+						    const char namefmt[],
+						    va_list args)
 {
 	DECLARE_COMPLETION_ONSTACK(done);
 	struct task_struct *task;
@@ -311,11 +288,8 @@ struct task_struct *kthread_create_on_node(int (*threadfn)(void *data),
 	task = create->result;
 	if (!IS_ERR(task)) {
 		static const struct sched_param param = { .sched_priority = 0 };
-		va_list args;
 
-		va_start(args, namefmt);
 		vsnprintf(task->comm, sizeof(task->comm), namefmt, args);
-		va_end(args);
 		/*
 		 * root may have changed our (kthreadd's) priority or CPU mask.
 		 * The kernel thread should not inherit these properties.
@@ -326,6 +300,44 @@ struct task_struct *kthread_create_on_node(int (*threadfn)(void *data),
 	kfree(create);
 	return task;
 }
+
+/**
+ * kthread_create_on_node - create a kthread.
+ * @threadfn: the function to run until signal_pending(current).
+ * @data: data ptr for @threadfn.
+ * @node: task and thread structures for the thread are allocated on this node
+ * @namefmt: printf-style name for the thread.
+ *
+ * Description: This helper function creates and names a kernel
+ * thread.  The thread will be stopped: use wake_up_process() to start
+ * it.  See also kthread_run().  The new thread has SCHED_NORMAL policy and
+ * is affine to all CPUs.
+ *
+ * If thread is going to be bound on a particular cpu, give its node
+ * in @node, to get NUMA affinity for kthread stack, or else give NUMA_NO_NODE.
+ * When woken, the thread will run @threadfn() with @data as its
+ * argument. @threadfn() can either call do_exit() directly if it is a
+ * standalone thread for which no one will call kthread_stop(), or
+ * return when 'kthread_should_stop()' is true (which means
+ * kthread_stop() has been called).  The return value should be zero
+ * or a negative error number; it will be passed to kthread_stop().
+ *
+ * Returns a task_struct or ERR_PTR(-ENOMEM) or ERR_PTR(-EINTR).
+ */
+struct task_struct *kthread_create_on_node(int (*threadfn)(void *data),
+					   void *data, int node,
+					   const char namefmt[],
+					   ...)
+{
+	struct task_struct *task;
+	va_list args;
+
+	va_start(args, namefmt);
+	task = __kthread_create_on_node(threadfn, data, node, namefmt, args);
+	va_end(args);
+
+	return task;
+}
 EXPORT_SYMBOL(kthread_create_on_node);
 
 static void __kthread_bind_mask(struct task_struct *p, const struct cpumask *mask, long state)
-- 
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: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>

  parent reply	other threads:[~2016-02-22 14:56 UTC|newest]

Thread overview: 41+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-02-22 14:56 [PATCH v5 00/20] kthread: Use kthread worker API more widely Petr Mladek
     [not found] ` <1456153030-12400-1-git-send-email-pmladek-IBi9RG/b67k@public.gmane.org>
2016-02-22 14:56   ` [PATCH v5 01/20] kthread/smpboot: Do not park in kthread_create_on_cpu() Petr Mladek
2016-02-22 14:56   ` [PATCH v5 03/20] kthread: Add create_kthread_worker*() Petr Mladek
2016-02-22 15:48     ` kbuild test robot
2016-02-24 15:56       ` Petr Mladek
2016-02-22 14:56 ` Petr Mladek [this message]
2016-02-22 14:56 ` [PATCH v5 04/20] kthread: Add drain_kthread_worker() Petr Mladek
2016-02-25 12:35   ` Peter Zijlstra
     [not found]     ` <20160225123551.GG6357-ndre7Fmf5hadTX5a5knrm8zTDFooKrT+cvkQGrU6aU0@public.gmane.org>
2016-02-26 15:23       ` Petr Mladek
     [not found]         ` <20160226152309.GH3305-KsEp0d+Q8qECVLCxKZUutA@public.gmane.org>
2016-02-27 15:18           ` Peter Zijlstra
2016-02-22 14:56 ` [PATCH v5 05/20] kthread: Add destroy_kthread_worker() Petr Mladek
     [not found]   ` <1456153030-12400-6-git-send-email-pmladek-IBi9RG/b67k@public.gmane.org>
2016-02-25 12:36     ` Peter Zijlstra
     [not found]       ` <20160225123641.GH6357-ndre7Fmf5hadTX5a5knrm8zTDFooKrT+cvkQGrU6aU0@public.gmane.org>
2016-02-26 15:15         ` Petr Mladek
2016-02-22 14:56 ` [PATCH v5 06/20] kthread: Detect when a kthread work is used by more workers Petr Mladek
2016-02-22 14:56 ` [PATCH v5 07/20] kthread: Initial support for delayed kthread work Petr Mladek
2016-02-22 16:06   ` kbuild test robot
2016-02-24 16:09     ` Petr Mladek
2016-02-22 14:56 ` [PATCH v5 08/20] kthread: Allow to cancel " Petr Mladek
     [not found]   ` <1456153030-12400-9-git-send-email-pmladek-IBi9RG/b67k@public.gmane.org>
2016-02-22 16:50     ` kbuild test robot
2016-02-24 16:18       ` Petr Mladek
2016-02-25 12:59         ` Peter Zijlstra
     [not found]           ` <20160225125932.GI6357-ndre7Fmf5hadTX5a5knrm8zTDFooKrT+cvkQGrU6aU0@public.gmane.org>
2016-02-26 15:38             ` Petr Mladek
2016-02-26 16:25               ` Peter Zijlstra
     [not found]                 ` <20160226162552.GB6356-ndre7Fmf5hadTX5a5knrm8zTDFooKrT+cvkQGrU6aU0@public.gmane.org>
2016-02-26 17:00                   ` Petr Mladek
     [not found]                     ` <20160226170056.GA12548-KsEp0d+Q8qECVLCxKZUutA@public.gmane.org>
2016-02-27 15:16                       ` Peter Zijlstra
2016-02-22 14:56 ` [PATCH v5 09/20] kthread: Allow to modify delayed " Petr Mladek
2016-02-22 14:57 ` [PATCH v5 10/20] kthread: Better support freezable kthread workers Petr Mladek
2016-02-22 17:33   ` kbuild test robot
2016-02-24 16:25     ` Petr Mladek
     [not found]   ` <1456153030-12400-11-git-send-email-pmladek-IBi9RG/b67k@public.gmane.org>
2016-02-25 13:01     ` Peter Zijlstra
     [not found]       ` <20160225130115.GJ6357-ndre7Fmf5hadTX5a5knrm8zTDFooKrT+cvkQGrU6aU0@public.gmane.org>
2016-02-26 15:43         ` Petr Mladek
2016-02-22 14:57 ` [PATCH v5 11/20] mm/huge_page: Convert khugepaged() into kthread worker API Petr Mladek
2016-02-22 14:57 ` [PATCH v5 12/20] ring_buffer: Convert benchmark kthreads " Petr Mladek
2016-02-22 14:57 ` [PATCH v5 13/20] hung_task: Convert hungtaskd " Petr Mladek
2016-02-22 14:57 ` [PATCH v5 14/20] kmemleak: Convert kmemleak kthread " Petr Mladek
2016-02-22 14:57 ` [PATCH v5 15/20] ipmi: Convert kipmi " Petr Mladek
2016-02-22 14:57 ` [PATCH v5 16/20] IB/fmr_pool: Convert the cleanup thread " Petr Mladek
2016-02-22 14:57 ` [PATCH v5 17/20] memstick/r592: Better synchronize debug messages in r592_io kthread Petr Mladek
2016-02-22 14:57 ` [PATCH v5 18/20] memstick/r592: convert r592_io kthread into kthread worker API Petr Mladek
2016-02-22 14:57 ` [PATCH v5 19/20] thermal/intel_powerclamp: Remove duplicated code that starts the kthread Petr Mladek
2016-02-22 14:57 ` [PATCH v5 20/20] thermal/intel_powerclamp: Convert the kthread to kthread worker API Petr Mladek

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=1456153030-12400-3-git-send-email-pmladek@suse.com \
    --to=pmladek@suse.com \
    --cc=akpm@linux-foundation.org \
    --cc=bp@suse.de \
    --cc=jkosina@suse.cz \
    --cc=josh@joshtriplett.org \
    --cc=linux-api@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=mhocko@suse.cz \
    --cc=mingo@redhat.com \
    --cc=oleg@redhat.com \
    --cc=paulmck@linux.vnet.ibm.com \
    --cc=peterz@infradead.org \
    --cc=rostedt@goodmis.org \
    --cc=tglx@linutronix.de \
    --cc=tj@kernel.org \
    --cc=torvalds@linux-foundation.org \
    --cc=vbabka@suse.cz \
    /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).