调度器9—调度相关trace汇总—Qcom

1. sched_find_best_target

打印:

cat-32758 [001] d..4  5235.529561: sched_find_best_target: pid=18090 comm=kworker/u16:25 start_cpu=0 best_idle=-1 most_spare_cap=-1 target=0 order_index=0 end_index=0 skip=-1 running=0

形参:

TP_PROTO(struct task_struct *tsk, unsigned long min_util, int start_cpu, int best_idle, int most_spare_cap, int target, int order_index, int end_index, int skip, bool running),

打印解析:

pid: 取参数 tsk->pid
comm: 取参数 tsk->comm
tart_cpu: 取参数 start_cpu
best_idle: 取参数 best_idle
most_spare_cap: 取参数 most_spare_cap
target: 取参数 target
order_index: 取参数 order_index
end_index: 取参数 end_index
skip: 取参数 skip
running: 取参数 running
注:min_util 传参了,但是没有打印它。

调用路径:

check_for_migration
select_task_rq_fair
    find_energy_efficient_cpu //fair.c
        walt_find_best_target //fair.c
            trace_sched_find_best_target

说明:
是对任务p选核路径中的trace,Qcom的WALT算法带入的函数。

调用传参: 

trace_sched_find_best_target(p, min_util, start_cpu, best_idle_cpu, most_spare_cap_cpu, target_cpu, order_index, end_index, fbt_env->skip_cpu, p->state == TASK_RUNNING);

实参解析:

p: 
    为p选核
min_util:
    返回的是被钳位在 uclamp_max 和 uclamp_min 之间的 p->wts.demand_scaled 值,就是被钳位后p的util值。但是 trace 没有打印它。
start_cpu:
    表示从哪个cluster中开始选核,walt_get_indicies()中做逻辑判断,若是有BOOST就按BOOST类型选核,若没有,则找一个算力大于任务demand的CPU核开始选。从这里的执行逻辑看,start_cpu一
    定是某个cluster的首个CPU.
best_idle_cpu:
    初始化为-1,首先从start_cpu开始遍历所有cpu,找到一个idle深度最浅的cpu,但是若选核任务是rtg标记的任务,就又把best_idle_cpu清成-1了。
most_spare_cap_cpu:
    初始化为-1,从start_cpu开始遍历所有cpu,表示找到的空闲算力最大的cpu。空闲算力指的是此CPU的算力减去任务p在此CPU上的贡献,若任务p是新    建或刚唤醒或之前不是运行在这个CPU上,直接返
    回task_util(cpu),也就是WALT下的 cpu_rq(cpu)->wrq.walt_stats.cumulative_runnable_avg_scaled。
target_cpu: 
    (1)快速路径:任务p之前运行的cpu的算力和start_cpu相同(不多不少)或两者是兄弟cpu,并且之前运行的cpu是onlline的,并且没有isolate,并且是idle状态,并且idle深度小于或等于1,然后走快速路径,
    直接选prev_cpu为target_cpu,设置为候选者。
    (2)慢速路径:若快速路径没有选到CPU,则会从start_cpu开始遍历所有CPU进行选核。依次为:Android留了hook接口vendor厂商可以自己制定策略剔除一部分CPU。剔除非active的CPU。    剔除isolated的CPU。
    剔除尚未完成的迁移的目标CPU。剔除irq负载高的CPU。若是当前CPU唤醒比较多剔除当前CPU。若某个CPU上的当前任务正在per-task的boost就剔除这个CPU。    CPU原来的利用率加上任务p的利用率后超过其算
    力了也剔除。若是idle cpu,但不是idle最浅的cpu也剔除,若dile深度一致但之前有发现idle的cpu是任务之前运行的cpu时 或 这个CPU虽然idle深度和之前选出的一样,但是不是任务p之前运行的CPU并且其
    利用率也比之前选的idle CPU的高,也剔除。若P->state=RUNNING的主动迁移的任务剔除非idle的CPU。若p是rtg组    里的任务并且优先级数值低于99,若此CPU上有比之前记录的CPU的rtg高优先级任务多,也
    剔除,若数量相同,非空余算力最大的也剔除。若以上都没剔除,就将此CPU作为best_target,然后遍历下一个CPU。
    最终将 target_cpu 和 best_idle_cpu 都作为选出的best target cpu 设置进候选CPU中去了。
order_index:
    walt_get_indicies() 中修改的,应该是根据算力和BOOST情况选出来的从哪个cluster开始选核
end_index:
    walt_get_indicies() 中有修改,若是有BOOST可能大于0,应该表示结束选核的cluster.
fbt_env->skip_cpu:
    若当前CPU上有超过1000个任务待唤醒时,将当前CPU设置到skip的,为p选核时不选它。
p->state == TASK_RUNNING:
    表示为任务选核时任务的状态是不是正在running,若是就表示是active迁移的任务,只会为其选择idle核。

2. sched_task_util

打印:

kworker/u16:1-23809 [001] d..3 280354.250435: sched_task_util: pid=23645 comm=kworker/u16:4 util=156 prev_cpu=3 candidates=0x8 best_energy_cpu=3 sync=0 need_idle=0
fastpath=2 placement_boost=0 latency=2343 stune_boosted=0 is_rtg=0 rtg_skip_min=0 start_cpu=0 unfilter=20000000 affinity=ff task_boost=0 low_latency=0

形参:

TP_PROTO(struct task_struct *p, unsigned long candidates, int best_energy_cpu, bool sync, int need_idle, int fastpath, bool placement_boost, u64 start_t,
        bool uclamp_boosted, bool is_rtg, bool rtg_skip_min, int start_cpu),

打印解析:

pid: 取自 p->pid
comm: 取自 p->comm
util: 取自参数p的 task_util(p),WALT算法下是 p->wts.demand_scaled,PELT算法下是 p->se.avg.util_avg
prev_cpu: 取自参数p的 task_cpu(p),即 p->cpu
candidates: 取自参数 candidates
best_energy_cpu: 取自参数 best_energy_cpu
sync: 取自参数 sync
need_idle: 取自参数 need_idle
fastpath: 取自参数 fastpath
placement_boost: 取自参数 placement_boost
latency: 取自 sched_clock() - 参数 start_t
stune_boosted: 取自参数 uclamp_boosted
is_rtg: 取自参数 is_rtg
rtg_skip_min: 取自参数 rtg_skip_min
start_cpu: 取自参数 start_cpu
unfilter: 取自 p->wts.unfilter
affinity: 取自 cpumask_bits(&p->cpus_mask)[0],即 ((&p->cpus_mask)->bits)[0]
task_boost: 取自 per_task_boost(p),即 p->wts.boost
low_latency: 取自 walt_low_latency_task(p),即 p->wts.low_latency && (task_util(p) < sysctl_walt_low_latency_task_threshold),目前Qcom还没enable此功能,因此一直是0.

调用路径:

check_for_migration //qc_vas.c
select_task_rq_fair //fair.c
    find_energy_efficient_cpu //fair.c 函数结束位置调用
        trace_sched_task_util

说明:
在为任务的选核路径中,对任务的信息进行trace.

调用传参: 

trace_sched_task_util(p, cpumask_bits(candidates)[0], best_energy_cpu, sync, fbt_env.need_idle, fbt_env.fastpath,
        task_boost_policy(p), start_t, boosted, is_rtg, walt_get_rtg_status(p), start_cpu);

实参解析:

p:
    为任务p选核
cpumask_bits(candidates)[0]:
    walt_find_best_target()中为任务p选出来的候选cpu,位掩码,是怎么选的可参考 trace_sched_find_best_target,如0x8就是CPU3
best_energy_cpu:
    初始化为prev_cpu,然后根据条件进行更新,是 find_energy_efficient_cpu() 的最终返回结果。
sync:
    是 find_energy_efficient_cpu() 传入的参数,如果想sync唤醒,又是时间敏感,或任务和当前任务都是rtg组中的任务,就清除掉sync标志。sync标志会导致更倾向于唤醒后运行在在当前cpu上,
    只要条件满足:cpu在任务p允许运行的cpu里面,并且是active的,并且cpu的算力要大于start_cpu的算力。
fbt_env.need_idle:
    任务p通过 /proc/<PID>/sched_wake_up_idle 设置过,或其所在的任务组通过 /dev/cpuctl/<xx_group>/cpu.uclamp.latency_sensitive 赋值过,任务就有 wakeup_idle 属性了。有此属性后,就会
    将sync标志清0,也更倾向于选择 walt_find_best_target 选出来的cpu,降低通过EAS选核的概率。
fbt_env.fastpath:
    满足sync的同步唤醒的话,赋值为 SYNC_WAKEUP=1,若在 walt_find_best_target 中满足快速路径选核心,会被设置为 PREV_CPU_FASTPATH=2
task_boost_policy(p):
    返回全局变量 boost_policy 的值,来自 /proc/sys/kernel/sched_boost,只能取 SCHED_BOOST_NONE=0 或 SCHED_BOOST_ON_BIG=1
start_t:
    是个事件点,选核流程开始前 sched_clock() 获取的时间,trace中打印的 latency 值大概可以表示选核花费的时间,大概 1-6us
boosted: 
    来自 is_uclamp_boosted || (task_boost > 0),前者来自 /dev/cpuctl/<xx_group>/cpu.uclamp.min 的赋值,后者是来自 p->wts.boost,由 /proc/<pid>/sched_boost 设置,它是per-task的boot,并且
    可以指定boost的时间段的长短,若是boost了,就更倾向于不经过EAS选核流程。
is_rtg: 
    p->wts.grp != NULL 表示被选核的任务p不是rtg组中的任务。为真的话就会将sync标志清0,也更倾向于选择 walt_find_best_target 选出来的cpu,降低通过EAS选核的概率。
walt_get_rtg_status(p): 
    主要是返回 grp->skip_min 的值,应该是表示是否跳过小核,但是在选核路径中还没发现他起什么作用。
start_cpu: 
    从 start_cpu 开始选核,start_cpu 是根据算力需求得来的。

3. sched_migrate_task

打印:

adbd-1290  [003] d..3 260655.930040: sched_migrate_task: comm=UsbFfs-worker pid=17754 prio=120 orig_cpu=3 dest_cpu=1 running=0

形参:

TP_PROTO(struct task_struct *p, int dest_cpu)

打印解析:

comm: 取自 p->comm
pid: 取自 p->pid
prio: 取自 p->prio
orig_cpu: 取自task_cpu(p),表示迁移前任务的cpu
dest_cpu: 取自参数 dest_cpu
running:  bool值,取自 p->state == TASK_RUNNING,walt_find_best_target 中描述:为true表示是active迁移,dest_cpu只选idle核。

调用路径:

move_queued_task //core.c
__migrate_swap_task //core.c
try_to_wake_up //发现任务p的prev_cpu和选核选出来的cpu不是同一个cpu时调用
dl_task_offline_migration
push_dl_task //deadline.c
pull_dl_task //deadline.c
detach_task //fair.c
push_rt_task //rt.c
pull_rt_task //rt.c
    set_task_cpu //core.c
        trace_sched_migrate_task(p, new_cpu);

说明:
在任务的迁移路径中trace

调用传参: 

trace_sched_migrate_task(p, new_cpu);

实参解析:

p: 
    被迁移的任务
dest_cpu: 
    迁移的目的CPU

4. sched_isolate

打印:

core_ctl/0-434   [002] .... 304625.209544: sched_isolate: iso cpu=5 cpus=0x30 time=1595 us isolated=1
core_ctl/0-434   [001] .... 304628.095985: sched_isolate: iso cpu=4 cpus=0x20 time=460 us isolated=0

形参:

TP_PROTO(unsigned int requested_cpu, unsigned int isolated_cpus, u64 start_time, unsigned char isolate),

打印解析:

iso cpu: 取自参数 requested_cpu
cpus: 取自参数 isolated_cpus
time: 取自 div64_u64(sched_clock() - start_time, 1000),时间差值转换为us,表示隔离CPU操作和去掉隔离CPU操作各花费多少时间
isolated: 取自参数 isolate

调用路径:

try_to_isolate //core_ctl.c
cpu_isolate_pm_notify //drivers	hermalqcomcpu_isolate.c
cpu_isolate_set_cur_state //drivers	hermalqcomcpu_isolate.c
hyp_core_ctl_do_reservation //driverssocqcomhyp_core_ctl.c
    sched_isolate_cpu
        trace_sched_isolate(cpu, cpumask_bits(cpu_isolated_mask)[0], start_time, 1) //隔离


    isolation_cpuhp_state //core_ctl.c
    cpu_isolate_hp_offline //core_ctl.c
    hyp_core_ctl_hp_offline //driverssocqcomhyp_core_ctl.c
__try_to_unisolate //core_ctl.c
cpu_isolate_set_cur_state //cpu_isolate.c
hyp_core_ctl_undo_reservation //hyp_core_ctl.c
hyp_core_ctl_do_reservation //hyp_core_ctl.c
hyp_core_ctl_cpu_cooling_cb //hyp_core_ctl.c
    sched_unisolate_cpu //kernel/sched/qc_vas.c
        sched_unisolate_cpu_unlocked
            trace_sched_isolate(cpu, cpumask_bits(cpu_isolated_mask)[0], start_time, 0); //取消隔离

说明:

trace要隔离/取消隔离的cpu、时间、cpu核的隔离状态。

调用传参:

见调用路径

实参解析:

cpu: 
    要被隔离和取消隔离的cpu
cpumask_bits(cpu_isolated_mask)[0]: 
    已经被isolate的cpus的mask,不算正在被操作的这个
start_time: 
    开始进行隔离/取消隔离的时间点
1/0: 
    1是隔离cpu,0是取消隔离cpu.
原文地址:https://www.cnblogs.com/hellokitty2/p/15435642.html