linux del_timer_sync

 Note: You must not hold locks that are held in interrupt context
 *   while calling this function. Even if the lock has nothing to do
 *   with the timer in question.  Here's why:
 *
 *    CPU0                             CPU1
 *    ----                             ----
 *                                  
 *                                   call_timer_fn();
 *                                     base->running_timer = mytimer;
 *  spin_lock_irq(somelock);
 *                                    
 *                                        spin_lock(somelock);
 *  del_timer_sync(mytimer);
 *   while (base->running_timer == mytimer);
 *
 * Now del_timer_sync() will never return and never release somelock.
 * The interrupt on the other CPU is waiting to grab somelock but
 * it has interrupted the softirq that CPU0 is waiting to finish.

 *

在调用del_timer_sync这个函数时, 不能获取在中断上下文可能要占用的锁,不然会导致死锁问题。 比如CPU0上已经获取了somelock, 然后等待定时器的完成,此时CPU1进入软中断上下文时,会首先获取somelock锁,但由于该锁已经被CPU0上的跑的代码占用了,会在CPU1上一直忙等待, 因此CPU0和CPU1的代码都不会继续跑下去了。

你可能感兴趣的:(linux)