kthread

来源:互联网 发布:淘宝网充话费怎么查询 编辑:程序博客网 时间:2024/05/31 13:16
kernel/init/main.cstatic 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 实际对应 kthreaddkernel/kthread.cstruct 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;                                   \})
0 0