[Ace-users] [ace-users] the ACE_OS::gettimeofday() vs Solaris gettimeofday()

Douglas C. Schmidt schmidt at dre.vanderbilt.edu
Wed Nov 7 16:17:27 CST 2007


Hi Brigitte,

Thanks very much for your email!  Please make sure to send all
questions related to TAO or ACE to the ACE mailing list or ACE+TAO
newsgroup, rather than to me directly since I travel frequently and
often don't have ready access to email.  See

http://www.cs.wustl.edu/~schmidt/ACE-mail.html

for more info on how to access these resources.

> I am currently working on a part of our code that uses the ACE
> Reactor. One of the things we are trying to do is to make our ITC
> component more "timer" flexible.

In addition, to ensure that we have proper version/platform/compiler
information, please make sure you fill out the appropriate problem
report form (PRF), which is in

$ACE_ROOT/PROBLEM-REPORT-FORM
$TAO_ROOT/PROBLEM-REPORT-FORM

or in

$ACE_ROOT/BUG-REPORT-FORM
$TAO_ROOT/BUG-REPORT-FORM

in older versions of ACE+TAO.  Make sure to include this information
when asking any questions about ACE+TAO since otherwise we have to
"guess" what version/platform/compiler/options you've using, which is
very error-prone and slows down our responsiveness.  If you don't use
the PRF, therefore, it is less likely that someone from the core
ACE+TAO developer team will be able to answer your question.
Naturally, we encourage and appreciate other members of the ACE+TAO
user community who can respond to questions that they have the answers
to.
  
> While debugging some of the code I noticed that the output for the ACE_OS::gettimeofday() call was quite different than the
> output from the system level call.
>  
> The system level call yielded the following output:
>  
> gettimeofday: sec = 1194469777, usec = 945257
> clock_gettime: sec = 1194469777, usec = 945275
> while the output from the ACE_OS:call was:
>  
> *** 11/07/2007 21:09:25.015 32(IF) KeyMech_KeyMechSelectReactor.cpp(350) task:30 pid: 6909 tid: 1 current time of day =
> 695826 secs, 670425 usecs
> *** 11/07/2007 21:09:33.020 32(IF) KeyMech_KeyMechSelectReactor.cpp(350) task:30 pid: 6909 tid: 1 current time of day =
> 695834 secs, 675425 usecs
>  
> What I would like to know is does ACE somehow compact the 1/1/1970 to present seconds? Or is there something wrong with the
> way I am using ACE_Time_Value operators? I am trying to use the cast operator for ACE_Time_Value to timeval.
>  
> Here is a sample of the code:
>  
>         ACE_Time_Value curr_time = this->timer_queue_->gettimeofday();
>         TIMEVAL tmr = curr_time;   // TIMEVAL typedef of struct timeval - this should use the cast operator to timeval
>  
>         sz_err_msg(INFORMATIONAL,
>                    NULL,
>                    __FILE__,
>                    __LINE__,
>                    "current time of day = %d secs, %d usecs",
>                    tmr.tv_sec,
>                    tmr.tv_usec);
> And here is the code for the direct system call
>  
> int main(void)
> {
>     typedef struct doh {
>         long duh[32];
>     } DOH;
>    
>     DOH x;
>     struct timeval tp;
>    
>     int y = sizeof(x)/sizeof(long);
>    
>     printf("\nsizeof doh = %d\n", sizeof(x));
>     printf("sizeof duh = %d\n", sizeof(x.duh));
>     printf("y = %d\n", y);
>    
>     gettimeofday(&tp, 0);
>    
>     printf("gettimeofday: sec = %u, usec = %u\n", tp.tv_sec, tp.tv_usec);
>  
>     struct timespec ts;
>  
>     int brig = clock_gettime(CLOCK_REALTIME, &ts);
> 
>     printf("clock_gettime: sec = %u, usec = %u\n", ts.tv_sec, ts.tv_nsec/1000);
>  
> }
> I know that the ACE timers work fine because we have been using them for years. I am just curious since I expected
> ACE_OS::gettimeofday() to be the wrapper for the system gettimeofday(). From what I see in the ACE code this would be the
> case for our Solaris OS, but this is not what I am seeing.

There may be various things going on here.  The first thing I recommend
you do is to try calling

ACE_OS::gettimeofday() 

rather than

this->timer_queue_->gettimeofday();

to see how that affects the results.  For example, your reactor may be
configured to use the ACE high-resolution timer.  Likewise, the reactor
uses "relative" time, whereas gettimeofday() uses "absolute" time.  I
recommend you use the debugger to see precisely what ACE is doing.

Please also note that when you use ACE_Time_Value it's "normalizing" the
time so you can use its comparison operators correctly.  Please see the
discussion about ACE_Time_Value in Chapter 3 of C++NPv2
<www.cs.wustl.edu/~schmidt/ACE/book2/>.  In contrast, the gettimeofday()
system call doesn't normalize the time.

Thanks,

        Doug



More information about the Ace-users mailing list