linux内核中的两个hrtimer回调能否同时运行?
如linux内核中的两个hrtimer回调能否同时运行?,linux,timer,kernel,locking,interrupt,Linux,Timer,Kernel,Locking,Interrupt,如hr中所述,计时器回调在禁用IRQ的硬中断上下文中运行。 但是SMP呢? 另一个hrtimer的第二次回调能否在另一个内核上运行, 当第一个回调正在allready运行时,或者它们是否在所有内核上相互排除,以便它们之间不需要锁定? 编辑: 当一个“常规”硬件IRQ(我们称之为X)的处理程序在一个内核上运行时,所有IRQ仅在该内核上被禁用,但IRQ X在整个系统上被禁用,因此X的两个处理程序永远不会同时运行。 hrtimer中断在这方面的表现如何? 它们是否都共享相同的准IRQ,或者每个HRQ
hr中所述,计时器回调在禁用IRQ的硬中断上下文中运行。
但是SMP呢?
另一个hrtimer的第二次回调能否在另一个内核上运行, 当第一个回调正在allready运行时,或者它们是否在所有内核上相互排除,以便它们之间不需要锁定?
编辑:
当一个“常规”硬件IRQ(我们称之为X)的处理程序在一个内核上运行时,所有IRQ仅在该内核上被禁用,但IRQ X在整个系统上被禁用,因此X的两个处理程序永远不会同时运行。
hrtimer中断在这方面的表现如何?
它们是否都共享相同的准IRQ,或者每个HRQ计时器是否有一个IRQ?
编辑:
使用两个计时器A和B进行了一些实验:
// starting timer A to fire as fast as possible...
A_ktime = ktime_set(0, 1); // 1 NS
hrtimer_start( &A, A_ktime, HRTIMER_MODE_REL );
// starting timer B to fire 10 us later
B_ktime = ktime_set(0, 10000); // 10 us
hrtimer_start( &B, B_ktime, HRTIMER_MODE_REL );
在回调中放入一些printk,在回调中放入一个巨大的延迟,用于计时器
// fired after 1 NS
enum hrtimer_restart A(struct hrtimer *timer)
{
printk("timer A: %lu\n",jiffies);
int i;
for(i=0;i<10000;i++){ // delay 10 seconds (1000 jiffies with HZ 100)
udelay(1000);
}
printk("end timer A: %lu\n",jiffies);
return HRTIMER_NORESTART;
}
// fired after 10 us
enum hrtimer_restart B(struct hrtimer *timer)
{
printk("timer B: %lu\n",jiffies);
return HRTIMER_NORESTART;
}
计时器A启动后1000个jiffies,
当定时器B设置为在它之后不到一个时点后触发时。当进一步行驶并将延迟增加到70秒时, 在计时器A回调和计时器B回调的开始之间,我得到了7000个jiffies
[ 6.218258] timer A: 4294937914
[ 76.220058] end timer A: 4294944914
[ 76.224192] timer B: 4294944915
编辑:可能需要锁定,因为hr计时器 只要在任何CPU上排队就可以了。如果其中两个在同一个队列中排队,它们可能会互相延迟,但无法保证 从hrtimer.h:
* On SMP it is possible to have a "callback function running and enqueued" * status. It happens for example when a posix timer expired and the callback * queued a signal. Between dropping the lock which protects the posix timer * and reacquiring the base lock of the hrtimer, another CPU can deliver the * signal and rearm the timer. *在SMP上,可以让“回调函数运行并排队” *地位。例如,当posix计时器过期且回调 *排队等待信号。在放下保护posix定时器的锁之间 *并且重新获得hrtimer的基本锁,另一个CPU可以提供 *发出信号并重新启动计时器。
我不确定这里是否需要锁定,但可能需要。IRQ通常仅在给定的CPU上被禁用,但可能同时在其他CPU上发生。如果两个hrtimer回调访问相同的数据,我将使用自旋锁或类似的东西来保护这些数据。 * On SMP it is possible to have a "callback function running and enqueued" * status. It happens for example when a posix timer expired and the callback * queued a signal. Between dropping the lock which protects the posix timer * and reacquiring the base lock of the hrtimer, another CPU can deliver the * signal and rearm the timer.