免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 1539 | 回复: 5
打印 上一主题 下一主题

[内核模块] tasklet的链表问题 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2014-02-26 14:04 |只看该作者 |倒序浏览
今天无意中看了下tasklet的原代码
void __tasklet_schedule(struct tasklet_struct *t)
{
        unsigned long flags;

        local_irq_save(flags);
        t->next = NULL;
        *__this_cpu_read(tasklet_vec.tail) = t;
        __this_cpu_write(tasklet_vec.tail, &(t->next));
        raise_softirq_irqoff(TASKLET_SOFTIRQ);
        local_irq_restore(flags);
}

这里的tasklet_vec是一个单向的链表,head用来遍历,tail用来添加元素。
但是
         t->next = NULL;
        *__this_cpu_read(tasklet_vec.tail) = t;
        __this_cpu_write(tasklet_vec.tail, &(t->next));
这怎么能实现添加新成员的功能,
还有t应该是和&(t->next)相等的,
那上面两句是一样的功能。
我觉得要这样写才能实现
        t->next = NULL;
        (*__this_cpu_read(tasklet_vec.tail) ).next= t;
        __this_cpu_write(tasklet_vec.tail, t);
希望哪位大牛能解释下。

论坛徽章:
1
15-16赛季CBA联赛之北控
日期:2016-03-15 22:53:29
2 [报告]
发表于 2014-02-26 14:27 |只看该作者

我看的是linux-2.6.31版本,在软中断初始化函数中,有:
                per_cpu(tasklet_vec, cpu).tail =
                        &per_cpu(tasklet_vec, cpu).head;

因此,在队列空时,tail成员指向head成员。


添加一个tasklet_struct结构的代码如函数__tasklet_schedule下面代码:
        *__get_cpu_var(tasklet_vec).tail = t;
        __get_cpu_var(tasklet_vec).tail = &(t->next);

所以当添加第一个tasklet_struct结构后,tail指向该task的next成员,而head指向task。
当继续添加一些tasklet_struct结构后,tail指向最后一个task的next成员,而head指向第一个task。

不知道对不对?

论坛徽章:
0
3 [报告]
发表于 2014-02-26 15:56 |只看该作者
这个地方我也看过,但是per_cpu(tasklet_vec, cpu).tail =&per_cpu(tasklet_vec, cpu).head
相当于tasklet_vec.tail =&tasklet_vec.head,
但*__get_cpu_var(tasklet_vec).tail = t;后
相当于*(tasklet_vec.tail ) = t会把前面的值重新赋值,这也是我不解的地方,难倒这其中还有什么悬妙的地方。
请哪位大牛解释下。

论坛徽章:
1
15-16赛季CBA联赛之北控
日期:2016-03-15 22:53:29
4 [报告]
发表于 2014-02-26 16:10 |只看该作者
在队列为空,*__get_cpu_var(tasklet_vec).tail 作为左值时就是head成员变量本身,把t赋值给head成员不是很正常吗,没什么悬妙的

论坛徽章:
0
5 [报告]
发表于 2014-02-26 17:29 |只看该作者
h = 0
t = &h

*t = h = n1
t = &n1->n

*t = n1->n = n2
t = &n2->n

.
.
.

论坛徽章:
0
6 [报告]
发表于 2014-02-26 17:30 |只看该作者
恩,我上机试了下,是你说的那样的,这里面有个指针赋值我理解错了,多谢。
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP