The patch titled Subject: kthread: add the helper function kthread_run_on_cpu() has been added to the -mm tree. Its filename is kthread-add-the-helper-function-kthread_run_on_cpu.patch This patch should soon appear at https://ozlabs.org/~akpm/mmots/broken-out/kthread-add-the-helper-function-kthread_run_on_cpu.patch and later at https://ozlabs.org/~akpm/mmotm/broken-out/kthread-add-the-helper-function-kthread_run_on_cpu.patch Before you just go and hit "reply", please: a) Consider who else should be cc'ed b) Prefer to cc a suitable mailing list as well c) Ideally: find the original patch on the mailing list and do a reply-to-all to that, adding suitable additional cc's *** Remember to use Documentation/process/submit-checklist.rst when testing your code *** The -mm tree is included into linux-next and is updated there every 3-4 working days ------------------------------------------------------ From: Cai Huoqing <caihuoqing@xxxxxxxxx> Subject: kthread: add the helper function kthread_run_on_cpu() the helper function kthread_run_on_cpu() includes kthread_create_on_cpu/wake_up_process(). In some cases, use kthread_run_on_cpu() directly instead of kthread_create_on_node/kthread_bind/wake_up_process() or kthread_create_on_cpu/wake_up_process() or kthreadd_create/kthread_bind/wake_up_process() to simplify the code. Link: https://lkml.kernel.org/r/20211022025711.3673-2-caihuoqing@xxxxxxxxx Signed-off-by: Cai Huoqing <caihuoqing@xxxxxxxxx> Cc: Bernard Metzler <bmt@xxxxxxxxxxxxxx> Cc: Cai Huoqing <caihuoqing@xxxxxxxxx> Cc: Daniel Bristot de Oliveira <bristot@xxxxxxxxxx> Cc: Davidlohr Bueso <dave@xxxxxxxxxxxx> Cc: Doug Ledford <dledford@xxxxxxxxxx> Cc: Ingo Molnar <mingo@xxxxxxxxxx> Cc: Jason Gunthorpe <jgg@xxxxxxxx> Cc: Joel Fernandes (Google) <joel@xxxxxxxxxxxxxxxxx> Cc: Josh Triplett <josh@xxxxxxxxxxxxxxxx> Cc: Lai Jiangshan <jiangshanlai@xxxxxxxxx> Cc: Mathieu Desnoyers <mathieu.desnoyers@xxxxxxxxxxxx> Cc: "Paul E . McKenney" <paulmck@xxxxxxxxxx> Cc: Steven Rostedt <rostedt@xxxxxxxxxxx> Signed-off-by: Andrew Morton <akpm@xxxxxxxxxxxxxxxxxxxx> --- include/linux/kthread.h | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) --- a/include/linux/kthread.h~kthread-add-the-helper-function-kthread_run_on_cpu +++ a/include/linux/kthread.h @@ -56,6 +56,31 @@ bool kthread_is_per_cpu(struct task_stru __k; \ }) +/** + * kthread_run_on_cpu - create and wake a cpu bound thread. + * @threadfn: the function to run until signal_pending(current). + * @data: data ptr for @threadfn. + * @cpu: The cpu on which the thread should be bound, + * @namefmt: printf-style name for the thread. Format is restricted + * to "name.*%u". Code fills in cpu number. + * + * Description: Convenient wrapper for kthread_create_on_cpu() + * followed by wake_up_process(). Returns the kthread or + * ERR_PTR(-ENOMEM). + */ +static inline struct task_struct * +kthread_run_on_cpu(int (*threadfn)(void *data), void *data, + unsigned int cpu, const char *namefmt) +{ + struct task_struct *p; + + p = kthread_create_on_cpu(threadfn, data, cpu, namefmt); + if (!IS_ERR(p)) + wake_up_process(p); + + return p; +} + void free_kthread_struct(struct task_struct *k); void kthread_bind(struct task_struct *k, unsigned int cpu); void kthread_bind_mask(struct task_struct *k, const struct cpumask *mask); _ Patches currently in -mm which might be from caihuoqing@xxxxxxxxx are kthread-add-the-helper-function-kthread_run_on_cpu.patch rdma-siw-make-use-of-the-helper-function-kthread_run_on_cpu.patch ring-buffer-make-use-of-the-helper-function-kthread_run_on_cpu.patch rcutorture-make-use-of-the-helper-function-kthread_run_on_cpu.patch trace-osnoise-make-use-of-the-helper-function-kthread_run_on_cpu.patch trace-hwlat-make-use-of-the-helper-function-kthread_run_on_cpu.patch