这里应该注意,sched_domain的父子关系,高层级的sched_domain是低层级的sched_domain的parent,低层级的sched_domain是高层级的child 。sched_domain的span为自己该层级的兄弟CPU以及下面几个层级的兄弟CPU的并集 。
创建完sched_domain之后,开始从CPU开始由低到高依次建立sched_group,这就是第3个核心函数,build_sched_groups 。
static int
build_sched_groups(struct sched_domain *sd, int cpu)
{
struct sched_group *first = NULL, *last = NULL;
struct sd_data *sdd = sd->private;
const struct cpumask *span = sched_domain_span(sd);
struct cpumask *covered;
int i;
lockdep_assert_held(&sched_domains_mutex);
covered = sched_domains_tmpmask;
cpumask_clear(covered);
for_each_cpu_wrap(i, span, cpu) {
struct sched_group *sg;
if (cpumask_test_cpu(i, covered))
continue;
sg = get_group(i, sdd);
cpumask_or(covered, covered, sched_group_span(sg));
if (!first)
first = sg;
if (last)
last->next = sg;
last = sg;
}
last->next = first;
sd->groups = first;
return 0;
}
build_sched_groups函数的核心是get_group函数 。
static struct sched_group *get_group(int cpu, struct sd_data *sdd)
{
struct sched_domain *sd = *per_cpu_ptr(sdd->sd, cpu);
struct sched_domain *child = sd->child;
struct sched_group *sg;
bool already_visited;
if (child)
cpu = cpumask_first(sched_domain_span(child));
sg = *per_cpu_ptr(sdd->sg, cpu);
sg->sgc = *per_cpu_ptr(sdd->sgc, cpu);
/* Increase refcounts for claim_allocations: */
already_visited = atomic_inc_return(&sg->ref) > 1;
/* sgc visits should follow a similar trend as sg */
WARN_ON(already_visited != (atomic_inc_return(&sg->sgc->ref) > 1));
/* If we have already visited that group, it's already initialized. */
if (already_visited)
return sg;
if (child) {
cpumask_copy(sched_group_span(sg), sched_domain_span(child));
cpumask_copy(group_balance_mask(sg), sched_group_span(sg));
} else {
cpumask_set_cpu(cpu, sched_group_span(sg));
cpumask_set_cpu(cpu, group_balance_mask(sg));
}
sg->sgc->capacity = SCHED_CAPACITY_SCALE * cpumask_weight(sched_group_span(sg));
sg->sgc->min_capacity = SCHED_CAPACITY_SCALE;
sg->sgc->max_capacity = SCHED_CAPACITY_SCALE;
return sg;
}
可以从get_group函数看出来,如果是最底层的sched_domain,即不存在child,那么get_group中建立的sched_group是该CPU独有的 。而如果是非最底层的sched_domain,那么get_group中建立的sched_group是其child的span成员共享的 。这里注意,sched_group_capacity和sched_group两位一体,表示该调度组的计算能力 。
到这里,调度域和调度组的关系基本可以理清楚 。在CPU层次结构上,CPU在每个层次都有一个调度域,该CPU在高层次的调度域与该CPU在低层次的调度域互成父子关系 。
而调度域下皆有一个调度组,调度组是呈链表组织的 。一个调度域将其调度域中所有CPU按照兄弟关系分成不同的调度组,然后以链表形式组织起来,一个调度域中的所有CPU在该CPU层次上是共享这个调度组的 。
更新完成sched_group_capacity之后,最后一部分cpu_attach_domain –> rq_attach_root 。
【cpu核数和内存大小怎么搭配 cpu核数】rq_attach_root中有这样的一行代码:rq->rd = rd; 。至此,从rq –> root_domain –> sched_domain的关系已经建立完成 。
- 卡力特黑啤和教士哪个好 卡力特黑啤
- cpu单核性能天梯图2021 cpu单核性能天梯图
- 冬天喝鸡汤还是鸭汤 鸡汤和鸭汤各有优点
- 绿鸡蛋和普通鸡蛋的区别
- 白云岩和石灰岩区别
- 和相亲女亲嘴了算确定关系吗-相亲认识的接吻了是否女的就接受了
- 苹果落果怎么办 苹果采前落果的原因和预防
- 小两寸和两寸能混用吗
- 桌斗和桌兜哪个正确
- 梁山好汉中,武松和鲁智深到底谁厉害
