我在单处理器机器上遇到了 spin_lock_irqsave 的奇怪问题。我有一段以 rx_process 命名的关键代码/函数,它由两个函数 rx_timeout 和 rx_callback 共享。它位于 Linux 内核驱动程序 omap-serial.c 下
rx_process ( uartNum)
{
//critical section
}
rx_timeout (uartNum)//this is called from softIrq context upon timer expiry
{
rx_process (uartNum);
}
rx_callback(uartNum)//this is called when interrupt handler registers upon interrupt and when 4k buf is full in rx_process function which invokes start_rx_dma which results in this call back function.
{
rx_process (uartNum);
}
我发现这两个函数之间发生了竞态条件,因此我决定在函数开始和函数结束时在 rx_process 中引入 spin_lock_irqsave,但它仍然会导致竞态条件,并且不时,我观察数据丢失和内核恐慌。
rx_process ( uartNum)
{ spin_lock_irqsave(&lock, flags);
//critical section
spin_unlock_irqrestore(&lock, flags);
}
rx_timeout (uartNum)//this is called from softIrq context upon timer expiry
{
rx_process (uartNum);
}
rx_callback(uartNum)//this is called when interrupt handler registers upon interrupt and when 4k buf is full in rx_process function which invokes start_rx_dma which results in this call back function
{
rx_process (uartNum);
}
现在,我将 spin_lock_irqsave 移动到 rx_timeout 以及 rx_callback 函数,我没有看到竞争条件。
rx_process ( uartNum)
{
//critical section
spin_unlock_irqrestore(&lock, flags);
}
rx_timeout (uartNum)//this is called from softIrq context upon timer expiry
{
spin_lock_irqsave(&lock, flags);
rx_process (uartNum);
spin_unlock_irqrestore(&lock, flags);
}
rx_callback(uartNum)//this is called when interrupt handler registers upon interrupt and when 4k buf is full in rx_process function which invokes start_rx_dma which results in this call back function
{
spin_lock_irqsave(&lock, flags);
rx_process (uartNum);
spin_unlock_irqrestore(&lock, flags);
}
如果有人能解释为什么在 rx_process 中使用的 spin_lock_irqsave 失败并且没有防止竞争条件,我将非常感激?