From 5e58066bba0e390c0dc60bdf1e242554b6f93826 Mon Sep 17 00:00:00 2001 From: Dave Jones Date: Mon, 26 Oct 2009 17:21:55 -0400 Subject: handle rdtsc wrapping. --- bench/MHz.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'bench') diff --git a/bench/MHz.c b/bench/MHz.c index 34cac39..874658c 100644 --- a/bench/MHz.c +++ b/bench/MHz.c @@ -51,7 +51,12 @@ void estimate_MHz(struct cpudata *cpu) cycles[1] = rdtsc(); - cpu->MHz = (cycles[1] - cycles[0]) / 1000000; + /* Check to see if rdtsc wrapped */ + if (cycles[1] < cycles[0]) + /* yes we did. */ + cpu->MHz = ((-1ULL - cycles[0]) + cycles[1]) / 1000000; + else + cpu->MHz = (cycles[1] - cycles[0]) / 1000000; if ((cpu->MHz % 50) > 15) cpu->MHz = ((cpu->MHz / 50) * 50) + 50; -- cgit v1.2.3