← Back to the chapter · Previous detail · Next detail →
Technical detail · Measure-First Optimization
Race-to-sleep arithmetic
Model the active current as I_active = k x f + I_fixed, a frequency-proportional dynamic part plus a fixed overhead that is on whenever the core is awake. For a fixed workload of N cycles, run time is N / f, so the dynamic energy is constant with frequency while the fixed-overhead energy shrinks as the clock rises.
Worked example: an 8 million cycle task.
Take k = 0.15 mA/MHz and a fixed overhead of 2 mA while awake, at a constant core voltage. The voltage comparisons below use a 1.0 V baseline. Calculate with unrounded run times and round the final results.
- At 16 MHz: run time 0.5 s; current 0.15 x 16 + 2 = 4.4 mA; charge 4.4 x 0.5 = 2.20 mA-s.
- At 48 MHz: run time 0.167 s; current 0.15 x 48 + 2 = 9.2 mA; charge 9.2 x (8 / 48) = 1.53 mA-s.
- Why: the dynamic charge is 1.2 mA-s at either clock (frequency cancels), but the fixed 2 mA overhead costs 1.0 mA-s at 16 MHz and only 0.33 mA-s at 48 MHz. Racing pays that overhead for a third of the time.
So the faster clock uses about 30% less energy despite drawing about twice the current, entirely because the fixed active overhead was paid for less time - and only if the core actually sleeps once the task ends.
Do the same arithmetic with the costs around the task. If both choices pay a 0.25 mA-s wake transition, the totals become 2.45 and 1.78 mA-s, so the fast case still wins. If the fast case alone instead pays a 0.70 mA-s voltage-switch or PLL-lock cost, its total rises to 2.23 mA-s, roughly equal to the 2.20 mA-s slow baseline before the shared wake cost. Including both costs gives 2.48 mA-s versus 2.45 mA-s. That is why the ledger must include wake, clock, sensor, and regulator overheads, not just instruction time.