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
 *    ----                             ----
 *                                   <SOFTIRQ>
 *                                   call_timer_fn();
 *                                     base->running_timer = mytimer;
 *  spin_lock_irq(somelock);
 *                                     <IRQ>
 *                                        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的代碼都不會繼續跑下去了。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章