summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSteve Huston <shuston@riverace.com>2000-09-20 17:08:40 +0000
committerSteve Huston <shuston@riverace.com>2000-09-20 17:08:40 +0000
commit39ce2f1f99caf8fbba71f7debfdfc13915fa1e64 (patch)
tree684b91c497cad3c9b2126ec02a9c462c3943de92
parent0243161fec028220fde77fba98298df3fdf7ace2 (diff)
downloadATCD-39ce2f1f99caf8fbba71f7debfdfc13915fa1e64.tar.gz
ChangeLogTag:Wed Sep 20 12:55:16 2000 Steve Huston <shuston@riverace.com>
-rw-r--r--ChangeLog10
-rw-r--r--ChangeLogs/ChangeLog-02a10
-rw-r--r--ChangeLogs/ChangeLog-03a10
-rw-r--r--ace/High_Res_Timer.cpp16
-rw-r--r--ace/High_Res_Timer.h11
-rw-r--r--ace/High_Res_Timer.i21
6 files changed, 75 insertions, 3 deletions
diff --git a/ChangeLog b/ChangeLog
index 9fd7a75b9cf..bd5923383ab 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,13 @@
+Wed Sep 20 12:55:16 2000 Steve Huston <shuston@riverace.com>
+
+ * ace/High_Res_Timer.(h cpp i): Win32's scale factor (from
+ QueryPerformanceFrequency) is very often too small a number to
+ convert to ticks/usec - it ends up losing about 20% of the elapsed
+ time in elapsed calculations. So, on Win32 only, the
+ global_scale_factor is now in ticks/msec, not ticks/usec. Adjusted
+ all of the conversions to ACE_Time_Value, nanoseconds, etc. to
+ account for this.
+
Wed Sep 20 08:24:34 2000 Ossama Othman <ossama@uci.edu>
* ace/Makefile.am (INLINE_FILES):
diff --git a/ChangeLogs/ChangeLog-02a b/ChangeLogs/ChangeLog-02a
index 9fd7a75b9cf..bd5923383ab 100644
--- a/ChangeLogs/ChangeLog-02a
+++ b/ChangeLogs/ChangeLog-02a
@@ -1,3 +1,13 @@
+Wed Sep 20 12:55:16 2000 Steve Huston <shuston@riverace.com>
+
+ * ace/High_Res_Timer.(h cpp i): Win32's scale factor (from
+ QueryPerformanceFrequency) is very often too small a number to
+ convert to ticks/usec - it ends up losing about 20% of the elapsed
+ time in elapsed calculations. So, on Win32 only, the
+ global_scale_factor is now in ticks/msec, not ticks/usec. Adjusted
+ all of the conversions to ACE_Time_Value, nanoseconds, etc. to
+ account for this.
+
Wed Sep 20 08:24:34 2000 Ossama Othman <ossama@uci.edu>
* ace/Makefile.am (INLINE_FILES):
diff --git a/ChangeLogs/ChangeLog-03a b/ChangeLogs/ChangeLog-03a
index 9fd7a75b9cf..bd5923383ab 100644
--- a/ChangeLogs/ChangeLog-03a
+++ b/ChangeLogs/ChangeLog-03a
@@ -1,3 +1,13 @@
+Wed Sep 20 12:55:16 2000 Steve Huston <shuston@riverace.com>
+
+ * ace/High_Res_Timer.(h cpp i): Win32's scale factor (from
+ QueryPerformanceFrequency) is very often too small a number to
+ convert to ticks/usec - it ends up losing about 20% of the elapsed
+ time in elapsed calculations. So, on Win32 only, the
+ global_scale_factor is now in ticks/msec, not ticks/usec. Adjusted
+ all of the conversions to ACE_Time_Value, nanoseconds, etc. to
+ account for this.
+
Wed Sep 20 08:24:34 2000 Ossama Othman <ossama@uci.edu>
* ace/Makefile.am (INLINE_FILES):
diff --git a/ace/High_Res_Timer.cpp b/ace/High_Res_Timer.cpp
index 8b60b3bcf79..3ed9c6e50cf 100644
--- a/ace/High_Res_Timer.cpp
+++ b/ace/High_Res_Timer.cpp
@@ -44,6 +44,7 @@ ACE_ALLOC_HOOK_DEFINE(ACE_High_Res_Timer)
/* static */
int ACE_High_Res_Timer::global_scale_factor_status_ = 0;
+
#if defined (linux)
// Determine the apparent CPU clock speed from /proc/cpuinfo
ACE_UINT32
@@ -174,7 +175,7 @@ ACE_High_Res_Timer::global_scale_factor (void)
// We have a high-res timer
ACE_High_Res_Timer::global_scale_factor
(ACE_static_cast (unsigned int,
- freq.QuadPart / ACE_ONE_SECOND_IN_USECS));
+ freq.QuadPart / ACE_HR_SCALE_CONVERSION));
}
else
// High-Res timers not supported
@@ -310,6 +311,9 @@ ACE_High_Res_Timer::elapsed_time (ACE_Time_Value &tv) const
}
#if defined (ACE_HAS_POSIX_TIME)
+// Note... Win32 does not have ACE_HAS_POSIX_TIME, so the scale factor
+// does not need to take into account the different units on Win32.
+
void
ACE_High_Res_Timer::elapsed_time (struct timespec &elapsed_time) const
{
@@ -353,16 +357,26 @@ ACE_High_Res_Timer::elapsed_time (ACE_hrtime_t &nanoseconds) const
// Please do _not_ rearrange this equation. It is carefully
// designed and tested to avoid overflow on machines that don't have
// native 64-bit ints.
+#if defined (ACE_WIN32)
+ nanoseconds = (this->end_ - this->start_)
+ * (1000000u / ACE_High_Res_Timer::global_scale_factor ());
+#else
nanoseconds = (this->end_ - this->start_)
* (1000u / ACE_High_Res_Timer::global_scale_factor ());
+#endif /* ACE_WIN32 */
}
void
ACE_High_Res_Timer::elapsed_time_incr (ACE_hrtime_t &nanoseconds) const
{
// Same as above.
+#if defined (ACE_WIN32)
+ nanoseconds = this->total_
+ / ACE_High_Res_Timer::global_scale_factor () * 1000000u;
+#else
nanoseconds = this->total_
/ ACE_High_Res_Timer::global_scale_factor () * 1000u;
+#endif
}
#if !defined (ACE_HAS_WINCE)
diff --git a/ace/High_Res_Timer.h b/ace/High_Res_Timer.h
index ae3d4793ec1..608ed3dea55 100644
--- a/ace/High_Res_Timer.h
+++ b/ace/High_Res_Timer.h
@@ -81,6 +81,17 @@ public:
static ACE_UINT32 global_scale_factor (void);
// Returns the global_scale_factor.
+ // On Win32, QueryPerformanceFrequency is used as a base for the global
+ // scale factor. The value this returns is often too small to be usefully
+ // converted to "ticks"/second - it loses unacceptably high levels of
+ // precision. So on Win32, global_scale_factor_ is in ticks/msec, not
+ // ticks/usec as on all others.
+#if defined (ACE_WIN32)
+# define ACE_HR_SCALE_CONVERSION (ACE_ONE_SECOND_IN_MSECS)
+#else
+# define ACE_HR_SCALE_CONVERSION (ACE_ONE_SECOND_IN_USECS)
+#endif /* ACE_WIN32 */
+
static int get_env_global_scale_factor (const ACE_TCHAR *env
= ACE_TEXT ("ACE_SCALE_FACTOR"));
// Sets the global_scale_factor to the value in the <env>
diff --git a/ace/High_Res_Timer.i b/ace/High_Res_Timer.i
index 568e34795b7..6fb562c6d80 100644
--- a/ace/High_Res_Timer.i
+++ b/ace/High_Res_Timer.i
@@ -8,7 +8,7 @@ ACE_High_Res_Timer::hrtime_to_tv (ACE_Time_Value &tv,
// The following are based on the units of global_scale_factor_
// being 1/microsecond. Therefore, dividing by it converts
// clock ticks to microseconds.
- tv.sec ((long) (hrt / (ACE_UINT32) ACE_ONE_SECOND_IN_USECS /
+ tv.sec ((long) (hrt / (ACE_UINT32) ACE_HR_SCALE_CONVERSION /
global_scale_factor ()));
// Calculate usec in a manner that's compatible with ACE_U_LongLong.
@@ -18,8 +18,18 @@ ACE_High_Res_Timer::hrtime_to_tv (ACE_Time_Value &tv,
// tv.usec = (hrt - tv.sec * ACE_ONE_SECOND_IN_USECS * global_scale_factor_)/
// global_scale_factor
ACE_hrtime_t tmp = tv.sec ();
- tmp *= ((ACE_UINT32) ACE_ONE_SECOND_IN_USECS * global_scale_factor ());
+ tmp *= ((ACE_UINT32) ACE_HR_SCALE_CONVERSION * global_scale_factor ());
+#if defined (ACE_WIN32)
+ // Win32's scale factor is in ticks/msec, so multiply up to usec.
+ ACE_hrtime_t subsec = hrt - tmp; // Remainder of ticks < 1sec
+ long msec = (long) (subsec / global_scale_factor ()); // #msec
+ long usec = (long) (subsec - (msec * global_scale_factor ()));
+ // (tick * usec/msec) / tick/msec = usec
+ usec = (usec * 1000) / (long) global_scale_factor ();
+ tv.usec ((msec * 1000) + usec);
+#else
tv.usec ((long) ((hrt - tmp) / global_scale_factor ()));
+#endif
}
@@ -115,6 +125,13 @@ ACE_High_Res_Timer::elapsed_microseconds (ACE_hrtime_t &usecs) const
{
usecs =
(ACE_hrtime_t) ((this->end_ - this->start_) / global_scale_factor ());
+#if defined (ACE_WIN32)
+ // Win32 scale factor is in msec, so multiply up to usecs and pick up
+ // the straggling usecs from the modulus.
+ usecs *= 1000u;
+ usecs +=
+ (ACE_hrtime_t) ((this->end_ - this->start_) % (global_scale_factor () * 1000u));
+#endif
}
ACE_INLINE void