Operating System - HP-UX
1825766 Members
2089 Online
109687 Solutions
New Discussion

getting reliable ellapsed time

 
Laurent Laperrousaz
Regular Advisor

getting reliable ellapsed time

Hi everyone
I have some trouble to get reliable information on ellapsed time measurement.
I use gettimeofday call fot that purpose but sometimes the ellapsed time I get is negative.
Here is the algorithm I use:
long m8_curBegPro;
long m8_endProcess;
long l8_durTrt;

gettimeofday(&lc_timeval, NULL);
m8_curBegPro = byte8(lc_timeval.tv_sec) * 1000LL +
byte8(lc_timeval.tv_usec) / 1000LL;

{
// some code ... (switch to an other thread)
}

gettimeofday(&lc_timeval, NULL);

lc_sReqTimes.m8_endProcess = byte8(lc_timeval.tv_sec) * 1000LL +
byte8(lc_timeval.tv_usec) / 1000LL;

// do the calculation

l8_durTrt = m8_endProcess - m8_curBegPro;
// l8_durTrt is sometimes < 0;

What is going wrong?
4 REPLIES 4
Dietmar Konermann
Honored Contributor

Re: getting reliable ellapsed time

Laurent,

if you are running 11.11 take care to have PHKL_27727 installed.

Best regards...
Dietmar.
"Logic is the beginning of wisdom; not the end." -- Spock (Star Trek VI: The Undiscovered Country)
Laurent Laperrousaz
Regular Advisor

Re: getting reliable ellapsed time

Hi Dietmar,
I am running on HP 11.0 on Stratus bi-processor boxes.
When I run on HP boxes I don't seem to have the problem.
Is there a patch on PA equivalent to the 11.11 one?

By the way, The code I mentionned above is not the good one: I used to initialise a tz structure as the second parameter. I just changed it now to NULL. COuld it be the reason why I'm getting these incorrect values?
Dietmar Konermann
Honored Contributor

Re: getting reliable ellapsed time

Laurent,

the problem I had in mind was never present on 11.00. A correspondung 11.00 patch _would_ be PHKL_28766... but this patch covers a lot more modules.

The algorithms to guarantee consistant and well performing gettimeofday() results on MP systems are not that trivial and tightly bound to the underlying hardware design. Since you don't see the symptom on genuine HP systems, I would suggest to 1) try the above patch and then 2) call Stratus to see if this is a known issue for them.

Best regards...
Dietmar.
"Logic is the beginning of wisdom; not the end." -- Spock (Star Trek VI: The Undiscovered Country)
Brian Bergstrand
Honored Contributor

Re: getting reliable ellapsed time

Three things:

1.) From gettimeofday man page:
If tzp is not a null pointer, the behaviour is unspecified.

You are using NULL, so the behaviour is unspecified which means the call could fail.

2.) You aren't checking the return value of gettimeofday to see if the call failed for some reason (!0).

3.) Finally, I noticed you are assigning the second time to lc_sReqTimes.m8_endProcess, but then when calculating the duration, you are using m8_endProcess which hasn't been initialized, so it could be 0, a negative, or anything else. 0 - positve = negative.

I think you need to change the assignment to:
m8_endProcess = byte8(lc_timeval.tv_sec) * 1000LL + byte8(lc_timeval.tv_usec) / 1000LL;

HTH.