【WALT】update_task_cpu_cycles()代码猜测
代码版本:Linux4.9 android-msm-crosshatch-4.9-android12
代码展示
static void update_task_cpu_cycles(struct task_struct *p, int cpu,
u64 wallclock)
{
if (use_cycle_counter)
p->cpu_cycles = read_cycle_counter(cpu, wallclock);
}
代码逻辑
还没有详细看,先挖个坑
1. use_cycle_counter 来源
猜想:cpu_cycles 寄存器注册之后就将 use_cycle_counter 置为 true。
int register_cpu_cycle_counter_cb(struct cpu_cycle_counter_cb *cb)
{
mutex_lock(&cluster_lock);
if (!cb->get_cpu_cycle_counter) {
mutex_unlock(&cluster_lock);
return -EINVAL;
}
cpu_cycle_counter_cb = *cb;
use_cycle_counter = true;
mutex_unlock(&cluster_lock);
return 0;
}
2. read_cycle_counter
猜想:通过函数 read_cycle_counter() 读寄存器,将 cycles 赋进 p->cpu_cycles。
/*
* Assumes rq_lock is held and wallclock was recorded in the same critical
* section as this function's invocation.
*/
static inline u64 read_cycle_counter(int cpu, u64 wallclock)
{
struct rq *rq = cpu_rq(cpu);
if (rq->last_cc_update != wallclock) {
rq->cycles = cpu_cycle_counter_cb.get_cpu_cycle_counter(cpu);
rq->last_cc_update = wallclock;
}
return rq->cycles;
}