您的位置:首页 > 其它

kthread

2016-04-05 22:22 218 查看
kernel/init/main.c
static noinline void __init_refok rest_init(void)
{
...
pid = kernel_thread(kthreadd, NULL, CLONE_FS | CLONE_FILES);
..
kthreadd_task = find_task_by_pid_ns(pid, &init_pid_ns);
...
}
kthreadd_task 实际对应 kthreadd

kernel/kthread.c
struct task_struct *kthread_create_on_node(int (*threadfn)(void *data),
void *data, int node,
const char namefmt[],
...)
{
...
wake_up_process(kthreadd_task);
...
}

唤醒 kthread_task,实际就是kthreadd函数执行:

#define kthread_create(threadfn, data, namefmt, arg...) \
kthread_create_on_node(threadfn, data, -1, namefmt, ##arg)

/**
* kthread_run - create and wake a thread.
* @threadfn: the function to run until signal_pending(current).
* @data: data ptr for @threadfn.
* @namefmt: printf-style name for the thread.
*
* Description: Convenient wrapper for kthread_create() followed by
* wake_up_process().  Returns the kthread or ERR_PTR(-ENOMEM).
*/
#define kthread_run(threadfn, data, namefmt, ...)              \
({                                     \
struct task_struct *__k                        \
= kthread_create(threadfn, data, namefmt, ## __VA_ARGS__); \
if (!IS_ERR(__k))                          \
wake_up_process(__k);                      \
__k;                                   \
})
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: