我在uni处理器机器上面临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失败并且没有阻止竞争条件,我真的很感激?