powerd calculates CPU usage incorrectly. First, it calculates usage as a sum of usage % of all cores, which, for example, for 4 core CPU gives a value in range [0; 400]. At the same time, powerd limits usage percent input by user (-i option) with 100. This is confusing and doesn't allow to set usage correctnly. So at the very least, *load = *load / ncpus is needed in read_usage_times().
However, it seems to me that the whole thing with summing core usage is incorrect. Imagine two cases:
- 4 core system, each core is 25% loaded.
- 4 core system, one core is 100% loaded.
In the first case, frequency can be safely lowered 4x without causing CPU hunger for processes. In the second, lowering freq will lead to performance degradation.
The sum of CPU usages is the same in both cases, so powerd will not distinguish these cases. Logic based on maximal core load seems more correct though.
This patch was not really tested.