linuk kthread

来源:互联网 发布:ubuntu怎么运行exe 编辑:程序博客网 时间:2024/06/05 06:01

有问题的线程函数:( BUD: scheduling while atomic: )

//static int fsp_kthread(void * ptr){    int ret = 0;    char* buff = (char*)kmalloc(F_LEN, GFP_KERNEL);    if(IS_ERR(buff))    {        printk("<2>""fsp_kthread kmalloc failed\n");        return -1;    }    memset(buff, '\0', F_LEN);    while(1)    {        set_current_state(TASK_UNINTERRUPTIBLE);        //msleep(10);        if(kthread_should_stop())        {            break;        }        if(kfifo_get(fsp_kfifo, buff, F_LEN) > 0)        {            send_msg_(buff); // 此函数内使用了read_lock_bh导致Bug        }else{            //schedule_timeout(HZ);            schedule();        }    }    kfree(buff);    return ret;}

kthread

kernel/kthread.c

int kthreadd(void *unused){    struct task_struct *tsk = current;    /* Setup a clean context for our children to inherit. */    set_task_comm(tsk, "kthreadd");    ignore_signals(tsk);    set_cpus_allowed_ptr(tsk, cpu_all_mask);    set_mems_allowed(node_possible_map);    current->flags |= PF_NOFREEZE | PF_FREEZER_NOSIG;    for (;;) {        set_current_state(TASK_INTERRUPTIBLE);        if (list_empty(&kthread_create_list))            schedule();        __set_current_state(TASK_RUNNING);        spin_lock(&kthread_create_lock);        while (!list_empty(&kthread_create_list)) {            struct kthread_create_info *create;            create = list_entry(kthread_create_list.next,                        struct kthread_create_info, list);            list_del_init(&create->list);            spin_unlock(&kthread_create_lock);            create_kthread(create);            spin_lock(&kthread_create_lock);        }        spin_unlock(&kthread_create_lock);    }    return 0;}


参考:

http://www.cnblogs.com/zhuyp1015/archive/2012/06/11/2545624.html

原创粉丝点击