Text archives Help
- From: boulos@sci.utah.edu
- To: manta@sci.utah.edu
- Subject: [MANTA] r1490 - trunk/Core/Util
- Date: Tue, 17 Jul 2007 18:47:30 -0600 (MDT)
Author: boulos
Date: Tue Jul 17 18:47:30 2007
New Revision: 1490
Modified:
trunk/Core/Util/CPUTime.cc
Log:
Bugfix for CPUTime on Apple systems (on recent
Intel chips the mach_timebase_info doesn't report
the scaling from ticks to seconds as mach_absolute_time
does that apparently).
Modified: trunk/Core/Util/CPUTime.cc
==============================================================================
--- trunk/Core/Util/CPUTime.cc (original)
+++ trunk/Core/Util/CPUTime.cc Tue Jul 17 18:47:30 2007
@@ -42,7 +42,7 @@
if (strstr(input,"cpu MHz")) {
char *p = strchr(input,':');
double MHz = 0.0;
- if (p)
+ if (p)
MHz = atof(p+1);
secondsPerTick_val = 1000. / MHz * 1e-9;
break;
@@ -55,7 +55,7 @@
//////////
// Return the current CPU time, in terms of clock ticks.
// Time zero is at some arbitrary point in the past.
-#if defined(__APPLE__) && defined(__POWERPC__)
+#if defined(__APPLE__)
/////////////////////////////
// Apple (PowerPC)
/////////////////////////////
@@ -63,15 +63,11 @@
{
if (!initialized) initialize();
- unsigned int tbl, tbu0, tbu1;
-
- do {
- __asm__ __volatile__ ("mftbu %0" : "=r"(tbu0));
- __asm__ __volatile__ ("mftb %0" : "=r"(tbl));
- __asm__ __volatile__ ("mftbu %0" : "=r"(tbu1));
- } while (tbu0 != tbu1);
-
- return ((static_cast<unsigned long long>(tbu0) << 32) | tbl);
+ // NOTE(boulos): On recent Apple systems using assembly won't give
+ // you the proper scaling factor, so we should be using
+ // mach_absolute_time. If this thing doesn't scale though, we
+ // should try to find some other solution.
+ return mach_absolute_time();
}
#elif defined (_WIN32)
/////////////////////////////
@@ -89,13 +85,14 @@
CPUTime::SysClock CPUTime::currentTicks()
{
if (!initialized) initialize();
+
unsigned int a, d;
asm volatile("rdtsc" : "=a" (a), "=d" (d));
- return static_cast<unsigned long long>(a) |
+ return static_cast<unsigned long long>(a) |
(static_cast<unsigned long long>(d) << 32);
}
#endif // defined(__APPLE__) && defined(__POWERPC__)
-
+
//////////
// Return the current CPU time, in terms of seconds.
// This is slower than currentTicks(). Time zero is at
@@ -104,14 +101,14 @@
{
return currentTicks()*secondsPerTick_val;
}
-
+
//////////
// Return the conversion from seconds to ticks.
double CPUTime::ticksPerSecond()
{
return 1.0/secondsPerTick_val;
}
-
+
//////////
// Return the conversion from ticks to seconds.
double CPUTime::secondsPerTick()
- [MANTA] r1490 - trunk/Core/Util, boulos, 07/17/2007
Archive powered by MHonArc 2.6.16.