我的内核线程崩溃了

时间:2015-12-29 07:02:17

标签: c linux linux-kernel kernel

首先,查看我的代码(非常简单,只是为了测试)

struct task_struct *test_task;  

int test_func(void *arg)
{
    uint64_t cur = 0;   //current time 
    uint64_t last = 0;  //last time

    while(!kthread_should_stop())
    {
        cur = get_cycle();
        if (cur - last > 2410000000)
        {
            printk(KERN_INFO "this time: %llu\n", cur);
            last = cur;
        }
    }
    return 0;
}    

void run_thread(void)
{
    struct sched_param param;
    param.sched_priority = 1;

    test_task = kthread_create(&test_func, NULL, "MY_test");
    kthread_bind(test_task, 2); //just use cpu 2
    sched_setscheduler(test_task, SCHED_RR, &param);
    wake_up_process(test_task);
    printk(KERN_INFO"OK, Kernel Thread : %s, Running\n", test_task->comm);
}

static int __init test_init(void)
{
    run_thread();
    return 0;
}

static void __exit test_exit(void)
{
    kthread_stop(test_task);
}

module_init(test_init);
module_exit(test_exit);

这些都是代码,当我删除此模块时会出现问题,系统会崩溃 我认为这对我对核心流程的理解应该是一个问题,请帮助获取建议,谢谢! 请原谅我这个中国英语....

0 个答案:

没有答案