2.6.3.4 组调度 - 任务组权重
/* file: kernel/sched/sched.h */
struct task_group {
#ifdef CONFIG_FAIR_GROUP_SCHED
unsigned long shares;
#endif
};
Last updated
/* file: kernel/sched/sched.h */
struct task_group {
#ifdef CONFIG_FAIR_GROUP_SCHED
unsigned long shares;
#endif
};
Last updated
/* file: kernsl/sched/fair.c */
static long calc_group_shares(struct cfs_rq *cfs_rq) {
long tg_weight, tg_shares, load, shares;
struct task_group *tg = cfs_rq->tg;
tg_shares = READ_ONCE(tg->shares);
load = max(scale_load_down(cfs_rq->load.weight), cfs_rq->avg.load_avg);
tg_weight = atomic_long_read(&tg->load_avg);
/* Ensure tg_weight >= load */
tg_weight -= cfs_rq->tg_load_avg_contrib;
tg_weight += load;
shares = (tg_shares * load);
if (tg_weight)
shares /= tg_weight;
return clamp_t(long, shares, MIN_SHARES, tg_shares);
}/* file: kernel/sched/fair.c */
int sched_group_set_shares(struct task_group *tg, unsigned long shares) {
int i;
/* 设置任务组的 shares */
tg->shares = shares;
/* 设置好任务组的总体 shares 之后,更新任务组在每个CPU上的se的权重信息 */
for_each_possible_cpu(i) {
struct rq *rq = cpu_rq(i);
struct sched_entity *se = tg->se[i];
/* 从当前se开始,沿着parent路径一路更新所有上层任务组的权重信息 */
for_each_sched_entity(se) {
update_load_avg(cfs_rq_of(se), se, UPDATE_TG);
update_cfs_group(se);
}
}
}