linuk kthread

有问题的线程函数:( 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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值