Article directory
In this blog, start to analyze the function source code pointed to by each function pointer in the struct sched_class rt_sched_class
structure variable;
rt_sched_class
The structure is defined in the linux-5.6.18\kernel\sched\rt.c
source , and the core real-time scheduling are also defined in the source code;
1. The dequeue_task_rt function (remove the process from the execution queue)
Introduction to the dequeue_task_rt function:
dequeue_task_rt
The function is used to update the "scheduling information" ,
remove the "real-time scheduling entity" sched_rt_entity
from the "execution queue" (red-black tree) ,
Then add the deleted "real-time scheduling entity" to the end of the "execution queue" (red-black tree) ;
Analysis of dequeue_task_rt function:
update_curr_rt(rq);
The function is to update the "scheduling information" ,
dequeue_rt_entity(rt_se, flags);
The function is to delete the "real- time scheduling entity" rt_se
from the "execution queue" (red-black tree) , and add the deleted "real-time scheduling entity" to the end of the "execution queue" (red-black tree) ;
dequeue_pushable_task(rq, p);
The role is to remove the process from the hash table ;
dequeue_task_rt function source code:
static void dequeue_task_rt(struct rq *rq, struct task_struct *p, int flags)
{
struct sched_rt_entity *rt_se = &p->rt;
update_curr_rt(rq);
dequeue_rt_entity(rt_se, flags);
dequeue_pushable_task(rq, p);
}
Source code path: linux-5.6.18\kernel\sched\rt.c#1381
Two, update_curr_rt function (update scheduling information)
update_curr_rt(rq);
The role is to update the "scheduling information" ;
update_curr_rt function source code:
/*
* Update the current task's runtime statistics. Skip current tasks that
* are not in our scheduling class.
*/
static void update_curr_rt(struct rq *rq)
{
struct task_struct *curr = rq->curr;
struct sched_rt_entity *rt_se = &curr->rt;
u64 delta_exec;
u64 now;
if (curr->sched_class != &rt_sched_class)
return;
now = rq_clock_task(rq);
delta_exec = now - 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));
curr->se.sum_exec_runtime += delta_exec;
account_group_exec_runtime(curr, delta_exec);
curr->se.exec_start = now;
cgroup_account_cputime(curr, delta_exec);
if (!rt_bandwidth_enabled())
return;
for_each_sched_rt_entity(rt_se) {
struct rt_rq *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_curr(rq);
raw_spin_unlock(&rt_rq->rt_runtime_lock);
}
}
}
Source code path: linux-5.6.18\kernel\sched\rt.c#994