全部博文(160)
分类: LINUX
2014-01-21 14:55:50
原文地址:local_irq_disable()分析 作者:lsaism
local_irq_disable()用来禁止本地cpu的中断;
local_irq_disable()
函数主要干了两件事情:
#define local_irq_disable() \
do { raw_local_irq_disable(); trace_hardirqs_off(); } while (0)
static void (void)
{
unsigned long = ();
(( & ~) | );
}
保存cpu flags的值;当中断处理程序返回是再恢复到寄存器中;
2) trace_hardirqs_off();
void (void)
{
struct *curr = current;
if ((! || current->lockdep_recursion))
return;
if ((!()))
return;
if (curr->) {
/*
* We have done an ON -> OFF transition:
*/
curr-> = 0;
curr-> = ;
curr-> = ++curr->;
(&);
} else
(&);
}
:
可以看到经过系列的判断,最终的操作还是集中在 : if (curr->):
如果硬件断是打开的,则对struct *curr = current;执行后面的一系列操作:
= 0;,硬件中断关标志,
= 此项记录的应该是引起中断的进程;
= ++curr->;则是记录的引起中断发生的事件;
以上操作将硬件中断关掉.
* @v: pointer of type atomic_t
*
* Atomically adds @i to @v.
*/
static void (int , *)
{
(
"addl %1,%0"
:"+m" (->)
:"ir" ());
}
其中lock是一个指令前缀,Intel的手册上对其的解释是:
Causes the processor's LOCK# signal to be asserted during execution of the accompanying instruction (turns the instruction into an atomic instruction). In a multiprocessor environment, the LOCK# signal insures that the processor has exclusive use of any shared memory while the signal is asserted.
也就是说lock会使紧跟在其后面的指令变成 atomic instruction。在执行该指令是暂时的锁一下总线,
指令执行完了,总线就解锁了! 相同的如static void (int , *)等对
整型原子数的操作都是通过 lock 前缀来实现的;