diff options
| author | Petr Mladek <pmladek@suse.com> | 2016-10-11 16:55:27 -0400 |
|---|---|---|
| committer | Linus Torvalds <torvalds@linux-foundation.org> | 2016-10-11 18:06:33 -0400 |
| commit | 255451e45345bcd19e79f25e9afc0b9e14ccb104 (patch) | |
| tree | 0fc2011e9b9099529713da76aa89943eddb62d6a /kernel | |
| parent | a65d40961dc70d15dec046c2ee88c556f57940b2 (diff) | |
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>
Diffstat (limited to 'kernel')
| -rw-r--r-- | kernel/kthread.c | 72 |
1 files changed, 42 insertions, 30 deletions
diff --git a/kernel/kthread.c b/kernel/kthread.c index f5dc0b151d61..36fd751a769f 100644 --- a/kernel/kthread.c +++ b/kernel/kthread.c | |||
| @@ -244,33 +244,10 @@ static void create_kthread(struct kthread_create_info *create) | |||
| 244 | } | 244 | } |
| 245 | } | 245 | } |
| 246 | 246 | ||
| 247 | /** | 247 | static struct task_struct *__kthread_create_on_node(int (*threadfn)(void *data), |
| 248 | * kthread_create_on_node - create a kthread. | 248 | void *data, int node, |
| 249 | * @threadfn: the function to run until signal_pending(current). | 249 | const char namefmt[], |
| 250 | * @data: data ptr for @threadfn. | 250 | va_list args) |
| 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 | ...) | ||
| 274 | { | 251 | { |
| 275 | DECLARE_COMPLETION_ONSTACK(done); | 252 | DECLARE_COMPLETION_ONSTACK(done); |
| 276 | struct task_struct *task; | 253 | struct task_struct *task; |
| @@ -311,11 +288,8 @@ struct task_struct *kthread_create_on_node(int (*threadfn)(void *data), | |||
| 311 | task = create->result; | 288 | task = create->result; |
| 312 | if (!IS_ERR(task)) { | 289 | if (!IS_ERR(task)) { |
| 313 | static const struct sched_param param = { .sched_priority = 0 }; | 290 | static const struct sched_param param = { .sched_priority = 0 }; |
| 314 | va_list args; | ||
| 315 | 291 | ||
| 316 | va_start(args, namefmt); | ||
| 317 | vsnprintf(task->comm, sizeof(task->comm), namefmt, args); | 292 | vsnprintf(task->comm, sizeof(task->comm), namefmt, args); |
| 318 | va_end(args); | ||
| 319 | /* | 293 | /* |
| 320 | * root may have changed our (kthreadd's) priority or CPU mask. | 294 | * root may have changed our (kthreadd's) priority or CPU mask. |
| 321 | * The kernel thread should not inherit these properties. | 295 | * The kernel thread should not inherit these properties. |
| @@ -326,6 +300,44 @@ struct task_struct *kthread_create_on_node(int (*threadfn)(void *data), | |||
| 326 | kfree(create); | 300 | kfree(create); |
| 327 | return task; | 301 | return task; |
| 328 | } | 302 | } |
| 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 | } | ||
| 329 | EXPORT_SYMBOL(kthread_create_on_node); | 341 | EXPORT_SYMBOL(kthread_create_on_node); |
| 330 | 342 | ||
| 331 | static void __kthread_bind_mask(struct task_struct *p, const struct cpumask *mask, long state) | 343 | static void __kthread_bind_mask(struct task_struct *p, const struct cpumask *mask, long state) |
