cpu性能统计
cpu负载
top中avg,/proc/loadavg, 包括cpu密集型任务+io型任务
统计流程
每cpu
scheduler_tick
----calc_global_load_tick : 当前瞬时 cpu::this_rq:: nr_running+nr_inunterrupt->calc_load_tasks(全局变量)
全局
do_timer
----calc_global_load:瞬时calc_load_tasks 分别加权做移动平均->avenrun[3](分别为5分、10分、15分)
cpu利用率
top中 us,sy,ni,id,wa,hi,si,st ; /proc/stat , /proc/$pid/stat
用户空间: us+ni(user+nice)
内核空间: sy+hi+si(sys+irq+softirq)
idle: id+wa(idle+iowait)
统计流程
per_cpu变量 kernel_cpustat: cpustat[]
update_process_timers(每cpu tick, 常见1ms采样,1ms时间统一归入cpustat[所选统计项])
----accuount_process_tick
--------account_user_time(用户态 统计项=user或nice)
------------task_group_account_field (该采样时间计入cpustat[统计项])
--------account_system_time (中断或者kernel,统计项=irq或softirq或system)
------------account_system_index_time
----------------task_group_account_field (该采样时间计入cpustat[统计项])
--------account_ider_time(idle,统计项=idle或iowait,该采样时间计入cpustat[统计项])
perf统计
内建perf命令
硬事件:
周期数、指令数、cache-miss、分支预测失败等 ->cpu性能计数器(硬件寄存器)
软事件:
软件统计缺页中断、上下文切换、cpu迁移->kernel变量
关键指标CPI/IPC, 周期数每指令(求低)/指令数每周期(求高),彼此互为倒数,本质如一
低CPI优化:
1. 高频cpu、内存
2. 大cpu cache
3. 局部性代码,提高cache命中
4. cpu绑定限制,缓解cpu迁移导致cache失效