Skip to content

Commit

Permalink
kthread: Add the helper macro kthread_run_on_cpu()
Browse files Browse the repository at this point in the history
the helper macro kthread_run_on_cpu() inculdes
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.

Signed-off-by: Cai Huoqing <caihuoqing@baidu.com>
  • Loading branch information
caihuoqing1990 authored and intel-lab-lkp committed Oct 21, 2021
1 parent 26da4ab commit 48bdddb
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions include/linux/kthread.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,27 @@ bool kthread_is_per_cpu(struct task_struct *k);
__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).
*/
#define kthread_run_on_cpu(threadfn, data, cpu, namefmt) \
({ \
struct task_struct *__k \
= kthread_create_on_cpu(threadfn, data, cpu, namefmt); \
if (!IS_ERR(__k)) \
wake_up_process(__k); \
__k; \
})

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);
Expand Down

0 comments on commit 48bdddb

Please sign in to comment.