diff options
-rw-r--r-- | ChangeLog-97a | 9 | ||||
-rw-r--r-- | ace/High_Res_Timer.cpp | 26 | ||||
-rw-r--r-- | ace/High_Res_Timer.h | 84 | ||||
-rw-r--r-- | ace/High_Res_Timer.i | 42 |
4 files changed, 74 insertions, 87 deletions
diff --git a/ChangeLog-97a b/ChangeLog-97a index fdec92e860d..62677a13c0c 100644 --- a/ChangeLog-97a +++ b/ChangeLog-97a @@ -1,10 +1,9 @@ Sun Mar 23 13:25:39 1997 Tim H. Harrison <harrison@lambada.cs.wustl.edu> - * ace/High_Res_Timer.h: Set the constructor <scale_factor> back to - 1 by default. Changed the non Win32 global_scale_factor_ to - 1000. For <scale_factor> == 1, the constructor takes the - global_scale_factor_. This will still allow construction with - no parameters on Solaris. + * ace/High_Res_Timer.h: Removed <scale_factor> from the + constructor of High_Res_Timer. All High_Res_Timers now use + global_scale_factor_ directly. Hopefully, this will not break + any existing code! Sat Mar 22 12:06:22 1997 Douglas C. Schmidt <schmidt@flamenco.cs.wustl.edu> diff --git a/ace/High_Res_Timer.cpp b/ace/High_Res_Timer.cpp index ed8c483faa2..1fff0bf7db8 100644 --- a/ace/High_Res_Timer.cpp +++ b/ace/High_Res_Timer.cpp @@ -11,14 +11,10 @@ ACE_ALLOC_HOOK_DEFINE(ACE_High_Res_Timer) // For Intel platforms, a scale factor is required for -// ACE_OS::gethrtime. Thus, initialize the global_scale_factor to -// zero. This will prevent use unless someone explicitly sets it. -// All this is necessary since we use the RDTSC instruction in -// ACE_OS::gethrtime where the value of each tick varies per processor -// speed. For instance, on a 200MHz Pentium use a scale factor of -// 200. That is, it takes 200 ticks to equal one microsecond. +// ACE_OS::gethrtime. We'll still set this to one to prevent division +// by zero errors. #if defined (ACE_WIN32) -u_long ACE_High_Res_Timer::global_scale_factor_ = 0; +u_long ACE_High_Res_Timer::global_scale_factor_ = 1; #else // A scale_factor of 1000 converts nanosecond ticks to microseconds. // That is, on these platforms, 1 tick == 1 nanosecond. @@ -48,24 +44,24 @@ ACE_High_Res_Timer::reset (void) void ACE_High_Res_Timer::elapsed_time (ACE_Time_Value &tv) { - tv.sec ((long) ((this->end_ - this->start_) / scale_factor_) / 1000000); - tv.usec ((long) ((this->end_ - this->start_) / scale_factor_) % 1000000); + tv.sec ((long) ((this->end_ - this->start_) / global_scale_factor_) / 1000000); + tv.usec ((long) ((this->end_ - this->start_) / global_scale_factor_) % 1000000); } #if defined (ACE_HAS_POSIX_TIME) void ACE_High_Res_Timer::elapsed_time (struct timespec &elapsed_time) { - elapsed_time.tv_sec = (time_t) ((this->end_ - this->start_) / scale_factor_) / 1000000; - elapsed_time.tv_nsec = (long) ((this->end_ - this->start_) / scale_factor_) % 1000000; + elapsed_time.tv_sec = (time_t) ((this->end_ - this->start_) / global_scale_factor_) / 1000000; + elapsed_time.tv_nsec = (long) ((this->end_ - this->start_) / global_scale_factor_) % 1000000; } #endif /* ACE_HAS_POSIX_TIME */ void ACE_High_Res_Timer::elapsed_time_incr (ACE_Time_Value &tv) { - tv.sec ((long) (this->total_ / scale_factor_) / 1000000); - tv.usec ((long) (this->total_ / scale_factor_) % 1000000); + tv.sec ((long) (this->total_ / global_scale_factor_) / 1000000); + tv.usec ((long) (this->total_ / global_scale_factor_) % 1000000); } void @@ -73,7 +69,7 @@ ACE_High_Res_Timer::print_ave (const char *str, const int count, ACE_HANDLE hand { ACE_TRACE ("ACE_High_Res_Timer::print_ave"); ACE_hrtime_t total; - total = (ACE_hrtime_t) ((this->end_ - this->start_) / scale_factor_ * 1000); + total = (ACE_hrtime_t) ((this->end_ - this->start_) / global_scale_factor_ * 1000); ACE_hrtime_t total_secs = total / 1000000000; u_long extra_nsecs = (u_long) (total % 1000000000); @@ -98,7 +94,7 @@ ACE_High_Res_Timer::print_total (const char *str, const int count, ACE_HANDLE ha { ACE_TRACE ("ACE_High_Res_Timer::print_total"); ACE_hrtime_t total_secs; - total_secs = (ACE_hrtime_t) (this->total_ / scale_factor_ / 1000000); + total_secs = (ACE_hrtime_t) (this->total_ / global_scale_factor_ / 1000000); u_long extra_nsecs = (u_long) (this->total_ % 1000000000); char buf[100]; diff --git a/ace/High_Res_Timer.h b/ace/High_Res_Timer.h index b12fb0bb974..02b825571ef 100644 --- a/ace/High_Res_Timer.h +++ b/ace/High_Res_Timer.h @@ -20,10 +20,9 @@ #include "ace/ACE.h" class ACE_Export ACE_High_Res_Timer - // = TITLE - // A high resolution timer class wrapper that encapsulates - // OS-specific high-resolution timers, such as those found on - // Solaris, AIX, Win32/Pentium, and VxWorks. + // = TITLE A high resolution timer class wrapper that encapsulates + // OS-specific high-resolution timers, such as those found on + // Solaris, AIX, Win32/Pentium, and VxWorks. // // = DESCRIPTION // Most of the member functions don't return values. The only @@ -33,14 +32,21 @@ class ACE_Export ACE_High_Res_Timer // added. It returns 1 if high-resolution time (ACE_OS::gethrtime ()) // is supported on the platform, and 0 if not. // - // The scale factor is required for platforms that have + // The global scale factor is required for platforms that have // high-resolution timers that return units other than - // microseconds, such as clock ticks. The member functions that - // return or print times use this scale factor. They divide the - // "time" that they get from ACE_OS::gethrtime () by it to - // obtain the time in microseconds. Its units are therefore - // 1/microsecond. On Solaris, a scale factor of 1000 should be used - // because its high-resolution timer returns nanoseconds. + // microseconds, such as clock ticks. It is represented as a + // static u_long, can only be accessed through static methods, + // and is used by all instances of High Res Timer. The member + // functions that return or print times use the global scale + // factor. They divide the "time" that they get from + // ACE_OS::gethrtime () by global_scale_factor_ to obtain the + // time in microseconds. Its units are therefore 1/microsecond. + // On Solaris, a scale factor of 1000 should be used because its + // high-resolution timer returns nanoseconds. However, on Intel + // platforms, we use RDTSC which returns the number of clock + // ticks since system boot. For a 200MHz cpu, each clock tick + // is 1/200 of a microsecond; the global_scale_factor_ should + // therefore be 200. // // NOTE: the elapsed time calculations in the print methods use // ACE_hrtime_t values. If ACE_hrtime_t is not a 64-bit type @@ -53,38 +59,35 @@ public: static int supported (); // Returns 1 if high-resolution time is supported on the platform, 0 if not. - static int get_env_global_scale_factor (const char *env = "ACE_SCALE_FACTOR"); - // Sets the global_scale_factor to the value in the <env> - // environment variable. Returns 0 on success, -1 on failure. Note - // if <env> points to string "0" (value zero), this call will fail. - static void global_scale_factor (u_long gsf); - // <gsf> is used as a global scale factor. Any High_Res_Timers - // constructed with scale_factor == 0 will check and use <gsf> if - // set. This allows applications to set the scale factor just once - // for all High_Res_Timers. The scale factors passed to - // constructors take precedence to global_scale_factor_. - - static ACE_Time_Value gettimeofday (void); - // Calls ACE_High_Res_Timer::hrtime_to_tv passing ACE_OS::gethrtime - // and global_scale_factor_. This function can be used to - // parameterize objects such as ACE_Timer_Queue::gettimeofday. If - // global_scale_factor_ is not set, and we're on a platform that - // requires global_scale_factor_ (e.g., Win32), ACE_OS::gettimeofday - // will be used instead of ACE_OS::gethrtime. This allows the - // scale_factor of 1 to still result in correct values. - - ACE_High_Res_Timer (u_long scale_factor = 1); - // Initialize the timer. The <scale_factor> != 1 takes precedence - // to global_scale_factor_. That is, to use the - // global_scale_factor_, leave <scale_factor> == 1; to override the - // global_scale_factor, set <scale_factor> appropriately. Check + // global_scale_factor_ is set to <gsf>. All High_Res_Timers use + // global_scale_factor_. This allows applications to set the scale + // factor just once for all High_Res_Timers. Check // High_Res_Timer.cpp for the default global_scale_factors for // several platforms. For many platforms (e.g., Solaris), the // global_scale_factor_ is set to 1000 so that <scale_factor> need // not be set. Careful, a <scale_factor> of 0 will cause division // by zero exceptions. + static int get_env_global_scale_factor (const char *env = "ACE_SCALE_FACTOR"); + // Sets the global_scale_factor to the value in the <env> + // environment variable. Returns 0 on success, -1 on failure. Note + // if <env> points to string "0" (value zero), this call will fail. + + static ACE_Time_Value gettimeofday (void); + // Calls ACE_High_Res_Timer::hrtime_to_tv passing ACE_OS::gethrtime. + // This function can be used to parameterize objects such as + // ACE_Timer_Queue::gettimeofday. If global_scale_factor_ is not + // set, and we're on a platform that requires global_scale_factor_ + // (e.g., Win32), ACE_OS::gettimeofday will be used instead of + // ACE_OS::gethrtime. This allows applications on Intel to use + // High_Res_Timer even when global_scale_factor is not set. + // However, setting the global_scale_factor_ appropriately will + // result in the finest resolution possible. + + ACE_High_Res_Timer (void); + // Initialize the timer. + void reset (void); // Reinitialize the timer. @@ -134,9 +137,8 @@ public: private: static void hrtime_to_tv (ACE_Time_Value &tv, - ACE_hrtime_t hrt, - u_long scale_factor); - // Converts an <hrt> to <tv> using the <scale_factor>. + ACE_hrtime_t hrt); + // Converts an <hrt> to <tv> using global_scale_factor_. ACE_hrtime_t start_; // Starting time. @@ -150,9 +152,9 @@ private: ACE_hrtime_t start_incr_; // Start time of incremental timing. - u_long scale_factor_; - static u_long global_scale_factor_; + // Converts ticks to microseconds. That is, ticks / + // global_scale_factor_ == microseconds. }; #if defined (__ACE_INLINE__) diff --git a/ace/High_Res_Timer.i b/ace/High_Res_Timer.i index 913c982fdb9..acd82ea4e14 100644 --- a/ace/High_Res_Timer.i +++ b/ace/High_Res_Timer.i @@ -10,18 +10,10 @@ ACE_High_Res_Timer::supported () } ACE_INLINE -ACE_High_Res_Timer::ACE_High_Res_Timer (u_long scale_factor) - : scale_factor_ (scale_factor) +ACE_High_Res_Timer::ACE_High_Res_Timer (void) { ACE_TRACE ("ACE_High_Res_Timer::ACE_High_Res_Timer"); - // <scale_factor> takes precendence over the global_scale_factor_. - // If scale_factor_ is not set (== 1) and a global_scale_factor is - // set (!= 0), use the global_scale_factor_. - if (scale_factor_ == 1 && - ACE_High_Res_Timer::global_scale_factor_ != 0) - scale_factor_ = ACE_High_Res_Timer::global_scale_factor_; - this->reset (); } @@ -56,7 +48,7 @@ ACE_High_Res_Timer::stop_incr (void) ACE_INLINE void ACE_High_Res_Timer::elapsed_microseconds (ACE_hrtime_t &usecs) const { - usecs = (ACE_hrtime_t) ((this->end_ - this->start_) / scale_factor_); + usecs = (ACE_hrtime_t) ((this->end_ - this->start_) / global_scale_factor_); } ACE_INLINE void @@ -67,27 +59,25 @@ ACE_High_Res_Timer::global_scale_factor (u_long gsf) ACE_INLINE void ACE_High_Res_Timer::hrtime_to_tv (ACE_Time_Value &tv, - ACE_hrtime_t hrt, - u_long scale_factor) + ACE_hrtime_t hrt) { - tv.sec ((long) (hrt / scale_factor) / 1000000); - tv.usec ((long) (hrt / scale_factor) % 1000000); + tv.sec ((long) (hrt / global_scale_factor_) / 1000000); + tv.usec ((long) (hrt / global_scale_factor_) % 1000000); } ACE_INLINE ACE_Time_Value ACE_High_Res_Timer::gettimeofday (void) { - // If the global_scale_factor_ == 0, then a scale factor is needed - // by the platform gethrtime, but a scale factor has not been set. - // Hence, just return ACE_OS::gettimeofday. - if (ACE_High_Res_Timer::global_scale_factor_ == 0) +#if defined (ACE_WIN32) + // If the global_scale_factor_ == 1 and we're on an Intel platform, + // then a scale factor is needed by the platform gethrtime. Since + // one has not been set, just return ACE_OS::gettimeofday. + if (ACE_High_Res_Timer::global_scale_factor_ == 1) return ACE_OS::gettimeofday (); - else - { - ACE_Time_Value tv; - ACE_High_Res_Timer::hrtime_to_tv (tv, - ACE_OS::gethrtime (), - ACE_High_Res_Timer::global_scale_factor_); - return tv; - } +#endif /* ACE_WIN32 */ + + ACE_Time_Value tv; + ACE_High_Res_Timer::hrtime_to_tv (tv, + ACE_OS::gethrtime ()); + return tv; } |