kthread: allow to call __kthread_create_on_node() with va_list args
PATCH 90/102 kthread: allow to call __kthread_create_on_node() with va_list args
From: Petr Mladek <[email protected]>
Subject: kthread: allow to call __kthread_create_on_node() with va_list args
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 <[email protected]>
Acked-by Tejun Heo <[email protected]>
Cc Oleg Nesterov <[email protected]>
Cc Ingo Molnar <[email protected]>
Cc Peter Zijlstra <[email protected]>
Cc Steven Rostedt <[email protected]>
Cc "Paul E. McKenney" <[email protected]>
Cc Josh Triplett <[email protected]>
Cc Thomas Gleixner <[email protected]>
Cc Jiri Kosina <[email protected]>
Cc Borislav Petkov <[email protected]>
Cc Michal Hocko <[email protected]>
Cc Vlastimil Babka <[email protected]>
Signed-off-by Andrew Morton <[email protected]>
---
kernel/kthread.c | 72 ++++++++++++++++++++++++++------------------- 1 file changed, 42 insertions(+), 30 deletions(-)
kernel/kthread.c renamed from kernel/kthread.c~kthread-allow-to-call-__kthread_create_on_node-with-va_list-args +42 -30
@@ -244,33 +244,10 @@ static void create_kthread(struct kthrea } } -/** -* 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_no 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_nokfree (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)
_