我想计算空闲的 CPU 周期。我试图在互联网上找到这个问题的答案。但答案并不令人满意。我询问计算空闲 CPU 周期,但答案是 CPU 利用率/CPU 使用率。
请告诉我如何用c语言计算给定时间间隔的空闲CPU周期?我正在研究减少 CPU 能量的速度设置算法调度
idle_cycles = hard_idle + soft_idle;
run_cycles += excess_cycles;
run_percent = run_cycles /
(idle_cycles + run_cycles);
next_excess = run_cycles -
speed * (run_cycles + soft_idle)
IF excess_cycles < 0. THEN
excess_cycles = 0.
energy = (run_cycles - excess_cycles) *
speed * speed;
IF excess_cycles > idle_cycles THEN
newspeed = 1.0;
ELSEIF run_percent > 0.7 THEN
newspeed = speed + 0.2;
ELSEIF run_percent < 0.5 THEN
newspeed = speed -
(0.6 - run_percent);
IF newspeed > 1.0 THEN
newspeed = 1.0;
IF newspeed < min_speed THEN
newspeed = min_speed;
speed = newspeed;
excess_cycles = next_excess;
在这个算法中,我遇到了我想用 c 计算的术语 idle_cycles。