Micro seconds delay inclusion

We have developped a C++ program which communicates to the server in udp socket. In certain cases we want to include a 100 microseconds delay between our write operation on udp socket, this we have tried using the select system call which accepts the timeval structure.

But this doesnot include exact 100 microseconds but adds 10 milliseconds(this i can see from the snoop trace). Also in the below url it has been specified that timeval cannot include microseconds delay.

http://rabbit.eng.miami.edu/info/functions/time.html

Could you please suggest me what i can use?

[595 byte] By [saravananma] at [2007-11-26 17:04:30]
# 1
nanosleepPaul
Paul_Floyda at 2007-7-8 23:32:16 > top of Java-index,Development Tools,Solaris and Linux Development Tools...
# 2
Thank you very much Paul,Can you please tell me, how this can be acheived .
saravananma at 2007-7-8 23:32:16 > top of Java-index,Development Tools,Solaris and Linux Development Tools...
# 3

As I understand it, unless things have changed recently, you are not going to get anything below a 10 millisecond sleep with nanosleep unless you change the kernel system clock granularity by setting hires_tick in /etc/system. Even if you set hires_tick you are still only at 1 ms granularity.

http://docs.sun.com/app/docs/doc/817-0404/6mg74vsa3?q=hires_tick&a=view

Your other option is to use the real time clock facility with CLOCK_HIRES (man timer_create) and use something like the ports facility for completion (don't use signals if you can avoid it); this requires either root or a least privlege assignment.

amorrowcrcga at 2007-7-8 23:32:16 > top of Java-index,Development Tools,Solaris and Linux Development Tools...
# 4
Thank you very much amorrowcrcg.
saravananma at 2007-7-8 23:32:16 > top of Java-index,Development Tools,Solaris and Linux Development Tools...
# 5

Nice article is here:

http://www.sun.com/software/whitepapers/wp-realtime/wp-realtime.pdf

I think real time scheduling class and high-res timer can be used.

Edit:

Another article:

http://www.opengroup.org/rtforum/oct2000/slides/litchfield.pdf

Edit:

And here how to use timers and port:

http://developers.sun.com/solaris/articles/event_completion.html

Message was edited by:

Olda79

Olda79a at 2007-7-8 23:32:16 > top of Java-index,Development Tools,Solaris and Linux Development Tools...
# 6
Thanks a lot Olda79. Can you please tell me the maximum value for hires_hz?
saravananma at 2007-7-8 23:32:16 > top of Java-index,Development Tools,Solaris and Linux Development Tools...
# 7
I dont know, but i found this: http://src.opensolaris.org/source/xref/onnv/onnv-gate/usr/src/uts/common/conf/p aram.c#128If i understand then teoretical maximum can be 1000000, but what is real maximum today i dont know.
Olda79a at 2007-7-8 23:32:16 > top of Java-index,Development Tools,Solaris and Linux Development Tools...
# 8

Set the clock rate to a very high value and you may find that your CPUs are spending a significant amount of time servicing clock interrupts rather than doing "real" work.

Also, what happens when you discover that your delay needs to be 75 microseconds, but you have set the system clock rate to 10KHz to provide a floor of 100 microseconds? You would have to edit /etc/system, double the clock interrupt rate, and reboot the machine, all just to handle what should be a trivial configuration change in your software.

Can anyone more familiar with the user space RT facilities comment on the viability of sub 100 microsecond timer_create timers?

amorrowcrcga at 2007-7-8 23:32:16 > top of Java-index,Development Tools,Solaris and Linux Development Tools...