Operating System - HP-UX
1836361 Members
2079 Online
110100 Solutions
New Discussion

about using "select()" and "poll()" as timer

 
tang zhibo
Occasional Advisor

about using "select()" and "poll()" as timer

Hi,
Does anyone has experience on using select() or poll() calls as timer on 11i? When I do it, I find that select() actually sleeps 30 milli seconds even passed the parameter 20 milliseconds. "
timeout.tv_sec = 0;
timeout.tv_usec = 20000;
select(1,NULL,NULL,NULL, &timeout);

When use poll(), the same problem exists. How to solve it? Does anyone have other method for timer which precision is better than 10 millisecond which is for select() or poll()?
Thanks!
bo
4 REPLIES 4
Klaus Crusius
Trusted Contributor

Re: about using "select()" and "poll()" as timer

Hi,

the time resolution of the system clock is documented by the constant HZ in /ust/include/sys/time.h. It is typically set to 100 (cycles per second) corresponding to 10 ms. So your expectations are very hard at the limit of what is possible.
To find out, why the delay was 30 ms, and not 20 ms, it is necessary to ask, how did you measure the time. Besides the time for the system call you have to consider the latency times needed for the process management of HPUX.

Klaus
There is a live before death!
Olav Baadsvik
Esteemed Contributor

Re: about using "select()" and "poll()" as timer


Hi,

using select() and poll() as a timer
is an abuse of these calls.
You should use nanosleep()

Regards
Olav
tang zhibo
Occasional Advisor

Re: about using "select()" and "poll()" as timer

Klaus,
I use gettimeofday() to measure the time spent on the select() or poll() calls.
Olav,
Just tested nanosleep, I can't control the precise time, passing the 10000000 ns parameter in, the result varies as 19 ms, 13 ms, 12ms ...
Very thankful for your attentions!!
bo
Kiran N. Mehta
Advisor

Re: about using "select()" and "poll()" as timer


=== Tang Zhibo wrote:

> I use gettimeofday() to measure the time
> spent on the select() or poll() calls.

gettimeofday(2) is known to be rather slow... You might want to measure with gethrtime(2) which comes with PHCO_23092. See also:

http://h21007.www2.hp.com/hpux-devtools/CXX/hpux-devtools.0201/0091.html

Kiran