Solved

2ms sleep in linux

Posted on 2006-07-14
13
1,159 Views
Last Modified: 2008-02-01
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
Comment
Question by:DanRaposo
  • 3
  • 2
  • 2
  • +2
13 Comments
 

Author Comment

by:DanRaposo
ID: 17108477
to clarify some this is a c++ app cross compied
0
 
LVL 43

Accepted Solution

by:
ravenpl earned 84 total points
ID: 17108711
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
 

Author Comment

by:DanRaposo
ID: 17108829
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
 
LVL 43

Expert Comment

by:ravenpl
ID: 17109055
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
 
LVL 8

Assisted Solution

by:manish_regmi
manish_regmi earned 83 total points
ID: 17109109
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
Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

 
LVL 34

Assisted Solution

by:Duncan Roe
Duncan Roe earned 83 total points
ID: 17112817
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
 
LVL 3

Expert Comment

by:leisner
ID: 17227092
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
 
LVL 43

Expert Comment

by:ravenpl
ID: 17379515
Split to me manish_regmi  duncan_roe
Aside the /dev/rtc there is /dev/hpet
0
 
LVL 3

Expert Comment

by:leisner
ID: 17440358
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
 
LVL 34

Expert Comment

by:Duncan Roe
ID: 17440579
Of course we all think our solutions are best. Just split it (I'm being generous;)
0

Featured Post

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Have you ever been frustrated by having to click seven times in order to retrieve a small bit of information from the web, always the same seven clicks, scrolling down and down until you reach your target? When you know the benefits of the command l…
The purpose of this article is to fix the unknown display problem in Linux Mint operating system. After installing the OS if you see Display monitor is not recognized then we can install "MESA" utilities to fix this problem or we can install additio…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

757 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now