Skip to content

Commit 255451e

Browse files
pmladektorvalds
authored andcommitted
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. Link: http://lkml.kernel.org/r/1470754545-17632-5-git-send-email-pmladek@suse.com Signed-off-by: Petr Mladek <pmladek@suse.com> Acked-by: Tejun Heo <tj@kernel.org> Cc: Oleg Nesterov <oleg@redhat.com> Cc: Ingo Molnar <mingo@redhat.com> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Steven Rostedt <rostedt@goodmis.org> Cc: "Paul E. McKenney" <paulmck@linux.vnet.ibm.com> Cc: Josh Triplett <josh@joshtriplett.org> Cc: Thomas Gleixner <tglx@linutronix.de> Cc: Jiri Kosina <jkosina@suse.cz> Cc: Borislav Petkov <bp@suse.de> Cc: Michal Hocko <mhocko@suse.cz> Cc: Vlastimil Babka <vbabka@suse.cz> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent a65d409 commit 255451e

1 file changed

Lines changed: 42 additions & 30 deletions

File tree

‎kernel/kthread.c‎

Lines changed: 42 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -244,33 +244,10 @@ static void create_kthread(struct kthread_create_info *create)
244244
}
245245
}
246246

247-
/**
248-
* kthread_create_on_node - create a kthread.
249-
* @threadfn: the function to run until signal_pending(current).
250-
* @data: data ptr for @threadfn.
251-
* @node: task and thread structures for the thread are allocated on this node
252-
* @namefmt: printf-style name for the thread.
253-
*
254-
* Description: This helper function creates and names a kernel
255-
* thread. The thread will be stopped: use wake_up_process() to start
256-
* it. See also kthread_run(). The new thread has SCHED_NORMAL policy and
257-
* is affine to all CPUs.
258-
*
259-
* If thread is going to be bound on a particular cpu, give its node
260-
* in @node, to get NUMA affinity for kthread stack, or else give NUMA_NO_NODE.
261-
* When woken, the thread will run @threadfn() with @data as its
262-
* argument. @threadfn() can either call do_exit() directly if it is a
263-
* standalone thread for which no one will call kthread_stop(), or
264-
* return when 'kthread_should_stop()' is true (which means
265-
* kthread_stop() has been called). The return value should be zero
266-
* or a negative error number; it will be passed to kthread_stop().
267-
*
268-
* Returns a task_struct or ERR_PTR(-ENOMEM) or ERR_PTR(-EINTR).
269-
*/
270-
struct task_struct *kthread_create_on_node(int (*threadfn)(void *data),
271-
void *data, int node,
272-
const char namefmt[],
273-
...)
247+
static struct task_struct *__kthread_create_on_node(int (*threadfn)(void *data),
248+
void *data, int node,
249+
const char namefmt[],
250+
va_list args)
274251
{
275252
DECLARE_COMPLETION_ONSTACK(done);
276253
struct task_struct *task;
@@ -311,11 +288,8 @@ struct task_struct *kthread_create_on_node(int (*threadfn)(void *data),
311288
task = create->result;
312289
if (!IS_ERR(task)) {
313290
static const struct sched_param param = { .sched_priority = 0 };
314-
va_list args;
315291

316-
va_start(args, namefmt);
317292
vsnprintf(task->comm, sizeof(task->comm), namefmt, args);
318-
va_end(args);
319293
/*
320294
* root may have changed our (kthreadd's) priority or CPU mask.
321295
* The kernel thread should not inherit these properties.
@@ -326,6 +300,44 @@ struct task_struct *kthread_create_on_node(int (*threadfn)(void *data),
326300
kfree(create);
327301
return task;
328302
}
303+
304+
/**
305+
* kthread_create_on_node - create a kthread.
306+
* @threadfn: the function to run until signal_pending(current).
307+
* @data: data ptr for @threadfn.
308+
* @node: task and thread structures for the thread are allocated on this node
309+
* @namefmt: printf-style name for the thread.
310+
*
311+
* Description: This helper function creates and names a kernel
312+
* thread. The thread will be stopped: use wake_up_process() to start
313+
* it. See also kthread_run(). The new thread has SCHED_NORMAL policy and
314+
* is affine to all CPUs.
315+
*
316+
* If thread is going to be bound on a particular cpu, give its node
317+
* in @node, to get NUMA affinity for kthread stack, or else give NUMA_NO_NODE.
318+
* When woken, the thread will run @threadfn() with @data as its
319+
* argument. @threadfn() can either call do_exit() directly if it is a
320+
* standalone thread for which no one will call kthread_stop(), or
321+
* return when 'kthread_should_stop()' is true (which means
322+
* kthread_stop() has been called). The return value should be zero
323+
* or a negative error number; it will be passed to kthread_stop().
324+
*
325+
* Returns a task_struct or ERR_PTR(-ENOMEM) or ERR_PTR(-EINTR).
326+
*/
327+
struct task_struct *kthread_create_on_node(int (*threadfn)(void *data),
328+
void *data, int node,
329+
const char namefmt[],
330+
...)
331+
{
332+
struct task_struct *task;
333+
va_list args;
334+
335+
va_start(args, namefmt);
336+
task = __kthread_create_on_node(threadfn, data, node, namefmt, args);
337+
va_end(args);
338+
339+
return task;
340+
}
329341
EXPORT_SYMBOL(kthread_create_on_node);
330342

331343
static void __kthread_bind_mask(struct task_struct *p, const struct cpumask *mask, long state)

0 commit comments

Comments
 (0)