日期:2014-05-16  浏览次数:20578 次

请教高手,如何理解Tasklet的序列化?
LKD中讲Tasklet机制可以保证相同tasklet的序列化,是因为在对tasklet处理的时候通过设置相应的state和count实现的。但如果是SMP时,如果有多个cpu同时读取某个tasklet(假如该tasklet当前状态不是RUN),那么这时岂不会有多个cpu对同一个tasklet进行处理?

------解决方案--------------------
Nod see ulk Chapter 4

Sftirqs are statically allocated (i.e., defined at compile time), while tasklets can also be allocated and initialized at runtime (for instance, when loading a kernel module). Softirqs can run concurrently on several CPUs, even if they are of the same type. Thus, softirqs are reentrant functions and must explicitly protect their data structures with spin locks. Tasklets do not have to worry about this, because their execution is controlled more strictly by the kernel. Tasklets of the same type are always serialized: in other words, the same type of tasklet cannot be executed by two CPUs at the same time. However, tasklets of different types can be executed concurrently on several CPUs. Serializing the tasklet simplifies the life of device driver developers, because the tasklet function needs not be reentrant.


especially "the same type of tasklet cannot be executed by two CPUs at the same time "


-------------------------------

i_noname(晚九朝五) ( ) 信誉:100 Blog 加为好友 2007-6-14 20:08:29 得分: 0



看书不仔细,一个tasklet永远只会在同一个CPU上执行




------解决方案--------------------

tasklet要通过__tasklet_schedule()或者__tasklet_hi_schedule()调度才能投入使用。只在一个cpu上运行就是靠注释部分实现的。


void fastcall __tasklet_schedule(struct tasklet_struct *t)
{
unsigned long flags;

local_irq_save(flags);
/*tasklet在调用tasklet_schedule标记其需要被调度时已经把该tasklet绑定到当前CPU。*/
t-> next = __get_cpu_var(tasklet_vec).list;
__get_cpu_var(tasklet_vec).list = t;
raise_softirq_irqoff(TASKLET_SOFTIRQ);
local_irq_restore(flags);
}


---------------------------

jianchaolv() ( ) 信誉:100 Blog 加为好友 2007-06-15 09:35:09 得分: 0


我知道 "一个tasklet永远只会在同一个CPU上执行 ", 但我想知道它是如何实现的。是不是在处理tasklet中的state和count时,采用原子操作?



------解决方案--------------------
__get_cpu_var(tasklet_vec).list;