引入CPU算力(capacity)的概念来测量每个CPU能达到的性能,它的值相对系统中性能最强的CPU做过归一化处理。异构系统也被称为非对称CPU算力系统,因为它们由不同算力的CPU组成。
调度域中的负载均衡发生在调度组中。
# cpu_capacity 的设置
(gdb) b topology_parse_cpu_capacity
Breakpoint 1 at 0xffff80001150db70: file drivers/base/arch_topology.c, line 147.
#topology_normalize_cpu_scale 函数,它负责对CPU算力进行归一化到1024
(gdb) b init_cpu_topology
Breakpoint 5 at 0xffff80001150e100: file drivers/base/arch_topology.c, line 568.
#每个cpufreq策略初始化OK后进行通知更新,只是在 cpufreq_online 中 notifier 通知一次
(gdb) b cpuhp_cpufreq_online
Breakpoint 8 at 0xffff800010ae0bc8: file drivers/cpufreq/cpufreq.c, line 2654.
# 更新函数
(gdb) b update_cpu_capacity
Breakpoint 11 at 0xffff8000100ac610: file kernel/sched/fair.c, line 8110.
# per_cpu 的 max_freq_scale 的设置:
(gdb) b cpufreq_set_policy
Breakpoint 12 at 0xffff800010adfe98: file drivers/cpufreq/cpufreq.c, line 2414.
(gdb) b try_to_wake_up
Breakpoint 13 at 0xffff80001009e270: file kernel/sched/core.c, line 2602.
(gdb) b check_misfit_status
Breakpoint 15 at 0xffff8000100aede0: file kernel/sched/fair.c, line 10134.
(gdb) b sd_init
Breakpoint 16 at 0xffff8000100b8dc4: file kernel/sched/topology.c, line 1990.
(gdb) b check_misfit_status
Note: breakpoint 15 also set at pc 0xffff8000100aede0.
Breakpoint 18 at 0xffff8000100aede0: file kernel/sched/fair.c, line 10134.
#对于每一个最低级别的cpu(比如超线程cpu)依次执行
(gdb) b build_sched_domains
Breakpoint 1 at 0xffffffff810a7300: file kernel/sched/topology.c, line 1971.
# 该函数比较复杂,它在同一个调度域的各个调度组之间进行负载均衡,总的来讲分为三块 1 .找出最busy的组 2.在最busy的组中找出最busy的cpu 3.迁移最busy的cpu上的进程到本cpu,并返回实际迁移的进程的数目
(gdb) b load_balance
Breakpoint 2 at 0xffffffff8109dfc0: file kernel/sched/fair.c, line 9488.
# find_busiest_group函数 该函数实现很复杂,然而逻辑很简单,基本策略祥见第一部分的“负载均衡算法分析”。对于代码,实际上就是一个两层的循环加上数据的更新
(gdb) b find_busiest_group
Breakpoint 3 at 0xffffffff8109d4a0: file kernel/sched/fair.c, line 9138.
# 在最busy的组中寻找最busy的cpu,很简单,就是一次冒泡算法。
(gdb) b find_busiest_queue
Breakpoint 4 at 0xffffffff8109e127: file kernel/sched/fair.c, line 9519.
# cache的热度是通过进程离开运行态到现在的时间差来决定的,而这个差的阀值到底是多少,则由调度域的一个cache_hot_time字段决定。
(gdb) b can_migrate_task
Breakpoint 5 at 0xffffffff810989c0: file ./arch/x86/include/asm/bitops.h, line 214.
# 调度域的构建函数
(gdb) b build_sched_domains
Note: breakpoint 1 also set at pc 0xffffffff810a7300.
Breakpoint 6 at 0xffffffff810a7300: file kernel/sched/topology.c, line 1971.
#更新函数
(gdb) b update_top_cache_domain
Breakpoint 7 at 0xffffffff810a7117: file kernel/sched/sched.h, line 1399.
# 当前运行队列下一个定期调度再平衡事件到达后,它引发一个软中断。
(gdb) b trigger_load_balance
Breakpoint 1 at 0xffffffff8109f8c0: file kernel/sched/fair.c, line 10603.
(gdb) b scheduler_tick
Breakpoint 8 at 0xffffffff81095a20: file kernel/sched/core.c, line 3764.
(gdb) b run_rebalance_domains
Breakpoint 9 at 0xffffffff8109f110: file kernel/sched/fair.c, line 10577.
(gdb) b rebalance_domains
Breakpoint 10 at 0xffffffff8109ebc0: file kernel/sched/fair.c, line 9895
(gdb) b load_balance
Breakpoint 11 at 0xffffffff8109dfc0: file kernel/sched/fair.c, line 9488.
# 体系结构可以把指定的拓扑层级的通用调度域构建器和默认的SD标志位覆盖掉
(gdb) b set_sched_topology
Breakpoint 12 at 0xffffffff810a8210: file kernel/sched/topology.c, line 1439.
本篇文章只对算力和调度域的相关函数进行了打断点。 为后面进一步理解cpu算力和调度域做好准备。
进入linux大门可以看这个视屏:https://ke.qq.com/course/4032547?flowToken=1042701
学习还是得靠自己。❤️
参考链接1: https://www.cnblogs.com/hellokitty2/p/15429760.html
参考链接2:https://blog.csdn.net/wh8_2011/article/details/52061574
参考链接3:https://www.cnblogs.com/hellokitty2/p/15487560.html