Skip to content

Commit

Permalink
Fix some cfs notes.
Browse files Browse the repository at this point in the history
  • Loading branch information
zhaogezhang committed Jun 12, 2020
1 parent e99fef7 commit bbb23dd
Show file tree
Hide file tree
Showing 4 changed files with 126 additions and 79 deletions.
22 changes: 16 additions & 6 deletions include/linux/sched.h
Original file line number Diff line number Diff line change
Expand Up @@ -1512,10 +1512,20 @@ struct sched_avg {
详情见 __update_entity_runnable_avg 函数 */
u32 runnable_avg_sum, runnable_avg_period;

/* 表示上一次更新当前调度实例处于可运行状态时间的负载贡献值时的调度系统时间,单位是 ns */
/* 表示上一次更新当前调度实例处于可运行状态时间的负载贡献值时的调度系统时间,用来计算运行时间间隔,单位是 ns */
u64 last_runnable_update;

/* 表示当前调度实例需要对其负载贡献指定的衰减阶数 */
/*
* We track migrations using entity decay_count <= 0, on a wake-up
* migration we use a negative decay count to track the remote decays
* accumulated while sleeping.
*
* Newly forked tasks are enqueued with se->avg.decay_count == 0, they
* are seen by enqueue_entity_load_avg() as a migration with an already
* constructed load_avg_contrib.
*/
/* 记录上次该调度实体离开 cfs 队列时 cfs 运行队列累计运行时间周期数,每个周期是 1ms
如果为 0 表示当前调度实例的负载已经同步衰减到和其所属运行队列相同的阶数 */
s64 decay_count;

/* [<- 1024us ->|<- 1024us ->|<- 1024us ->| ...
Expand All @@ -1527,7 +1537,7 @@ struct sched_avg {
load_avg_contrib = u_0` + y*(u_0 + u_1*y + u_2*y^2 + ... )
= u_0 + u_1*y + u_2*y^2 + ... [re-labeling u_i --> u_{i+1}] */
/* 表示当前调度实例过去“时间段”内经过衰减后的负载贡献值 */
/* 表示当前调度实例过去“时间段”内乘以了权重信息(se->load.weight)并经过衰减后的负载贡献值 */
unsigned long load_avg_contrib;
};

Expand Down Expand Up @@ -1611,13 +1621,13 @@ struct sched_entity {
struct sched_entity *parent;

/* rq on which this entity is (to be) queued: */
/* 指向当前调度任务组实例所在的 cfs 运行队列指针,当前任务组相当于这个 cfs 运行队列上的一个
/* 指向当前调度任务组实例所在的 cfs 运行队列指针,当前任务组实例相当于这个 cfs 运行队列上的一个
调度实例,即当前任务组相当于这个 cfs 运行队列红黑树上的一个节点 */
struct cfs_rq *cfs_rq;

/* rq "owned" by this entity/group: */
/* 如果当前调度实例代表的是一个任务组,则指向当前任务组拥有的 cfs 运行队列,这个 cfs 运行队
列上包含了当前任务组拥有的所有调度实例,如果当前调度实例代表的是一个线程,则指向 NULL */
/* 如果当前调度实例代表的是一个任务组实例(每个 cpu 上一个),则指向当前任务组拥有的 cfs 运行队列,这个 cfs
运行队列上包含了当前任务组拥有的所有调度实例,如果当前调度实例代表的是一个线程,则指向 NULL */
struct cfs_rq *my_q;
#endif

Expand Down
14 changes: 13 additions & 1 deletion kernel/sched/core.c
Original file line number Diff line number Diff line change
Expand Up @@ -834,12 +834,14 @@ void resched_curr(struct rq *rq)

cpu = cpu_of(rq);

/* 如果指定的 cpu 运行队列是当前正在执行的 cpu 的运行队列,则设置 TIF_NEED_RESCHED 标志并返回 */
if (cpu == smp_processor_id()) {
set_tsk_need_resched(curr);
set_preempt_need_resched();
return;
}

/* 如果指定的 cpu 运行队列是其他 cpu 上的运行队列,则设置 TIF_NEED_RESCHED 标志并发送 IPI_RESCHEDULE 核间中断 */
if (set_nr_and_not_polling(curr))
smp_send_reschedule(cpu);
else
Expand Down Expand Up @@ -3555,7 +3557,17 @@ unsigned long long task_sched_runtime(struct task_struct *p)
*/
/*********************************************************************************************************
** 函数名称: scheduler_tick
** 功能描述: 当前调度子系统的 tick 函数,在关中断的状态下由定时器处理函数调用
** 功能描述: 当前调度子系统的 tick 函数,在关中断的状态下由定时器处理函数调用,具体操作如下:
** : 1. 更新当前调度子系统的调度时钟信息
** : 2. 更新当前运行队列的任务运行时间信息
** : 3. 执行当前正在运行任务所属调度类的 task_tick 函数(以下以 CFS 调度类为例)
** : a. 对当前正在运行的调度实例执行周期性操作,用来更新调度实例运行时统计信息
** : b. 检查指定的任务的 numa 扫描周期时间是否已经到达,如果已经到达了则执行相关的扫描操作
** : c. 更新指定的 cpu 运行队列的 runnable_avg 贡献值信息,包括任务和任务组的
** : 4. 更新当前 cpu 运行队列的 cpu 负载贡献值
** : 5. perf_event_task_tick
** : 6. 尝试在当前 cpu 上触发一次负载均衡操作
** : 7. 更新当前 cpu 运行队列的 last_sched_tick 字段值
** 注 释: 如果是多核,那么每个核上都会有自己的定时器,所以这个函数会按照 HZ 周期在每一个核上执行
** 输 入:
** 输 出:
Expand Down
Loading

0 comments on commit bbb23dd

Please sign in to comment.