首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >不执行tasklet_kill时内核挂起

不执行tasklet_kill时内核挂起
EN

Stack Overflow用户
提问于 2015-10-11 19:50:11
回答 1查看 253关注 0票数 0

我写了一些简单的代码来测试微线程的功能。

当我不执行tasklet_kill时,内核将在使用insmod命令后挂起。由于没有日志,我不知道会发生什么。

以下是我的代码。

代码语言:javascript
复制
void work_fcn(unsigned long a)
{
    printk("this is tasklet work function\n");
}

void tasklet_test(void)
{
    struct tasklet_struct task;
    tasklet_init(&task, work_fcn, 0);
    tasklet_schedule(&task);
    //if I don't do the following line, then kernel hang
    tasklet_kill(&task); 
}

static int __init hello_init(void)
{
     tasklet_test();
     return 0;
}

module_init(hello_init);

谢谢。

EN

回答 1

Stack Overflow用户

发布于 2021-02-22 20:27:04

代码语言:javascript
复制
static void tasklet_action_common(struct softirq_action *a,
                  struct tasklet_head *tl_head,
                  unsigned int softirq_nr)
{
...

    while (list) {
        struct tasklet_struct *t = list;

        list = list->next;

        if (tasklet_trylock(t)) {
            if (!atomic_read(&t->count)) {
                if (!test_and_clear_bit(TASKLET_STATE_SCHED,
                            &t->state)) //<===========(1)
                    BUG();
                t->func(t->data);
                tasklet_unlock(t);
                continue;
            }
            tasklet_unlock(t);
        }

...
    }
}

在注释(1)中,它检查微线程状态是否为TASKLET_STATE_SCHED,,如果是,它将死机。

代码语言:javascript
复制
void tasklet_kill(struct tasklet_struct *t)
{
    if (in_interrupt())
        pr_notice("Attempt to kill tasklet from interrupt\n");

    while (test_and_set_bit(TASKLET_STATE_SCHED, &t->state)) {
        do {
            yield();
        } while (test_bit(TASKLET_STATE_SCHED, &t->state));
    }
    tasklet_unlock_wait(t);
    clear_bit(TASKLET_STATE_SCHED, &t->state); //<=========(2)
}
EXPORT_SYMBOL(tasklet_kill);

在注释(2)中将清除TASKLET_STATE_SCHED位,这不会引起恐慌。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/33064623

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档