Improve company productivity with a Business Account.Sign Up

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1205
  • Last Modified:

2ms sleep in linux

Hi Experts,

I am in desperate need of a 2ms sleep in on an ARM linux board.  I have tried usleep and now even nanosleep.  Using the gettimeof day call I see that it is about 19ms of time....how can I get this lower?
0
DanRaposo
Asked:
DanRaposo
  • 3
  • 2
  • 2
  • +2
3 Solutions
 
DanRaposoAuthor Commented:
to clarify some this is a c++ app cross compied
0
 
ravenplCommented:
You can't. Linux assures You only, that You will not sleep less than specified.
But if You use kernel 2.4.*, try 2.6.* - it has finer time resolution than 2.4.
Or try RTLinux...
0
 
DanRaposoAuthor Commented:
i am using 2.6.11.11

i just don't know how to take advantage of this finer resolution and how much finer can I go?
0
Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
ravenplCommented:
Hmm, You run on ARM - on i386 clock is set to 1/1000 sec (by default - may be changed to 1/250 or 1/100).
Not sure what is the default for ARM.

But even that the clock is set to 1ms - You can't expect usleep(2000) would sleep exectly 2ms - under heavy load it can extend it even to 1s.
0
 
manish_regmiCommented:
The resolution depends in the HZ value in the kernel. If it is set to 1000 you get 1ms granuality. Please see what is the HZ value is set in your arch. 1000 HZ means the schedular code runs once in 1 MS.

AFAIK: in arm it is 500. see kernel source to be sure.

If you really want exact resolution, you can move your code to kernel and use mdelay(). But i can unserstand this is not always possibe.

As you can see general Linux kernel cannot meet such constraints, the best way is to use RTLinux as Realtime applications run below kernel.

regards
Manish Regmi
0
 
Duncan RoeSoftware DeveloperCommented:
You may be able to use /dev/rtc. I have used it on i386 but not arm. i386 has an ioctl to set frequency - up to 8KHz IIRC.
See /usr/src/linux/Documentation/rtc.txt on your system.
0
 
leisnerCommented:
2 msec is a very small time -- sleeps will cause AT least 2 msec.
I suppose if your running as root you can play with priorities (i.e run SCHED_FIFO for 2 msec)
so nothing else is scheduled.

and then busy wait...not sure how the sleep calls with interact...

You'll get scheduled if there's nothing else "more important" -- if you're root and you own the system, you can
set this up...
0
 
ravenplCommented:
Split to me manish_regmi  duncan_roe
Aside the /dev/rtc there is /dev/hpet
0
 
leisnerCommented:
actually, my answer was reasonable (and key)...elevate your priority so nothing else runs and spin on a timebase...if the kernel
runs any user processes, you'll run...

You can do this if you're root...

Its not fair, but ti works...
0
 
Duncan RoeSoftware DeveloperCommented:
Of course we all think our solutions are best. Just split it (I'm being generous;)
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 3
  • 2
  • 2
  • +2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now