I want to calculate idle CPU cycles. I have tried to find out answer of this question on the internet. But the answers were not satisfactory. I queried for calculating idle CPU cycles but answers were for CPU utilization/CPU usage.
Please tell me how to calculate idle CPU cycles for a given time interval in c language? I am working on speed setting algorithm Scheduling for Reduced CPU Energy
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;
In this algorithm I came across the term idle_cycles which I want to calculate using c.