From db48465811a8d983a349d7b8a96c16f6adf942dc Mon Sep 17 00:00:00 2001 From: Boris Ostrovsky Date: Wed, 6 Jun 2012 16:34:53 +0100 Subject: xenpm, x86: Fix reporting of idle state average residency times If CPU stays in the same idle state for the full duration of xenpm sample then average residency may not be reported correctly since usage counter will not be incremented. In addition, in order to calculate averages correctly residence time and usage counter should be read and written atomically. Signed-off-by: Boris Ostrovsky Committed-by: Keir Fraser --- tools/misc/xenpm.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'tools/misc') diff --git a/tools/misc/xenpm.c b/tools/misc/xenpm.c index 65876fe370..e6fa942828 100644 --- a/tools/misc/xenpm.c +++ b/tools/misc/xenpm.c @@ -389,7 +389,14 @@ static void signal_int_handler(int signo) res = ( diff >= 0 ) ? diff : 0; triggers = cxstat_end[i].triggers[j] - cxstat_start[i].triggers[j]; - avg_res = (triggers==0) ? 0: (double)res/triggers/1000000.0; + /* + * triggers may be zero if the CPU has been in this state for + * the whole sample or if it never entered the state + */ + if ( triggers == 0 && cxstat_end[i].last == j ) + avg_res = (double)sum_cx[i]/1000000.0; + else + avg_res = (triggers==0) ? 0: (double)res/triggers/1000000.0; printf(" C%d\t%"PRIu64"\t(%5.2f%%)\t%.2f\n", j, res/1000000UL, 100 * res / (double)sum_cx[i], avg_res ); } -- cgit v1.2.3