tools/power: turbostat: fix large c1% issue

Under some conditions, c1% was displayed as very large number,
much higher than 100%.

c1% is not measured, it is derived as "that, which is left over"
from other counters.  However, the other counters are not collected
atomically, and so it is possible for c1% to be calaculagted as
a small negative number -- displayed as very large positive.

There was a check for mperf vs tsc for this already,
but it needed to also include the other counters
that are used to calculate c1.

Signed-off-by: Len Brown <len.brown@intel.com>
This commit is contained in:
Len Brown 2012-06-13 21:31:46 -04:00
parent c98d5d9444
commit c3ae331d1c
1 changed files with 8 additions and 4 deletions

View File

@ -444,6 +444,9 @@ delta_core(struct core_data *new, struct core_data *old)
old->c7 = new->c7 - old->c7; old->c7 = new->c7 - old->c7;
} }
/*
* old = new - old
*/
void void
delta_thread(struct thread_data *new, struct thread_data *old, delta_thread(struct thread_data *new, struct thread_data *old,
struct core_data *core_delta) struct core_data *core_delta)
@ -482,19 +485,20 @@ delta_thread(struct thread_data *new, struct thread_data *old,
/* /*
* As mperf and tsc collection are not atomic, * As counter collection is not atomic,
* it is possible for mperf's non-halted cycles * it is possible for mperf's non-halted cycles + idle states
* to exceed TSC's all cycles: show c1 = 0% in that case. * to exceed TSC's all cycles: show c1 = 0% in that case.
*/ */
if (old->mperf > old->tsc) if ((old->mperf + core_delta->c3 + core_delta->c6 + core_delta->c7) > old->tsc)
old->c1 = 0; old->c1 = 0;
else { else {
/* normal case, derive c1 */ /* normal case, derive c1 */
old->c1 = old->tsc - old->mperf - core_delta->c3 old->c1 = old->tsc - old->mperf - core_delta->c3
- core_delta->c6 - core_delta->c7; - core_delta->c6 - core_delta->c7;
} }
if (old->mperf == 0) { if (old->mperf == 0) {
if (verbose) fprintf(stderr, "cpu%d MPERF 0!\n", old->cpu_id); if (verbose > 1) fprintf(stderr, "cpu%d MPERF 0!\n", old->cpu_id);
old->mperf = 1; /* divide by 0 protection */ old->mperf = 1; /* divide by 0 protection */
} }