【发布时间】:2013-12-08 05:09:12
【问题描述】:
我正在查看实时调度程序/kernel/sched/rt.c 中update_curr_rt 函数的代码。有人可以解释一下它是如何工作的吗?
static void update_curr_rt(struct rq *rq)
{
struct task_struct *curr = rq->curr;
struct sched_rt_entity *rt_se = &curr->rt;
struct rt_rq *rt_rq = rt_rq_of_se(rt_se);
u64 delta_exec; // Time difference (???)
if (curr->sched_class != &rt_sched_class)
return;
// check if sched class is Real-Time sched class
delta_exec = rq->clock_task - curr->se.exec_start;
if (unlikely((s64)delta_exec <= 0))
return;
// ???
schedstat_set(curr->se.statistics.exec_max,
max(curr->se.statistics.exec_max, delta_exec));
// I am assuming that se.sum_exec_runtime is total time task ran
// and we add time difference to
curr->se.sum_exec_runtime += delta_exec;
// can be skipped, has to do with threads
account_group_exec_runtime(curr, delta_exec);
// reset start time
curr->se.exec_start = rq->clock_task;
cpuacct_charge(curr, delta_exec);
// I guess it calculates average ran time of the task
sched_rt_avg_update(rq, delta_exec);
// can be skipped
if (!rt_bandwidth_enabled())
return;
// ??? Nothing makes sense for code below
for_each_sched_rt_entity(rt_se) {
rt_rq = rt_rq_of_se(rt_se);
if (sched_rt_runtime(rt_rq) != RUNTIME_INF) {
raw_spin_lock(&rt_rq->rt_runtime_lock);
rt_rq->rt_time += delta_exec;
if (sched_rt_runtime_exceeded(rt_rq))
resched_task(curr);
raw_spin_unlock(&rt_rq->rt_runtime_lock);
}
}
}
【问题讨论】:
-
您已将二十个问题合并为一个问题;这太宽泛了。
标签: c linux linux-kernel scheduling scheduler