rcu_sched_clock_irq源码
时间: 2023-08-05 20:09:19 浏览: 181
rcu_sched_clock_irq 是 Linux 内核中用于实现抢占式调度的一个重要函数。下面是该函数的源码:
```c
/*
* RCU scheduler clock interrupt.
*
* This function is called from the timer interrupt. It increments
* the jiffies variable and then does a bunch of work.
*
* The math in this function is designed to be done with interrupts disabled
* to prevent races between this and the timer interrupt. We use the
* low-level clock interrupt to do this.
*/
static void rcu_sched_clock_irq(struct clock_event_device *dev)
{
ktime_t now;
/*
* Update jiffies before doing anything else.
*/
now = ktime_get();
if (time_after(now, dev->next_event))
rcu_tick_update(jiffies - dev->next_jiffies);
dev->next_event = now + dev->delta;
dev->next_jiffies = jiffies + 1;
/*
* Preempt idle tasks if needed.
*/
if (need_resched())
preempt_schedule_irq();
/*
* Check for RCU grace period completion.
*/
if (rcu_scheduler_active && !rcu_is_watching())
rcu_check_callbacks(1);
/*
* Update jiffies after doing everything else.
*/
rcu_tick_update(jiffies - dev->next_jiffies);
dev->next_jiffies = jiffies + 1;
}
```
这个函数会在定时器中断中被调用。它会先更新 jiffies 变量,然后执行一些工作。在这个函数中,使用低级别的时钟中断来禁止中断,以防止与定时器中断之间的竞争。函数的具体逻辑如下:
1. 更新 jiffies 变量,确保 jiffies 的值正确。
2. 如果当前需要进行抢占调度,则调用 preempt_schedule_irq() 函数进行抢占。
3. 检查 RCU grace period 是否已完成,如果是,则调用 rcu_check_callbacks() 函数。
4. 最后再次更新 jiffies 变量。
这段代码的作用是实现抢占式调度,并在特定条件下执行 RCU grace period 检查。
阅读全文