Solved

2ms sleep in linux

Posted on 2006-07-14
13
1,160 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Centos Boot Error 42 115
Building an initscript with start stop and restart 3 58
specifying dependencies for an rpm 2 44
centOS 7 GUI is now showing. 20 1,178
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 demonstrate how we can upgrade Python from version 2.7.6 to Python 2.7.10 on the Linux Mint operating system. I am using an Oracle Virtual Box where I have installed Linux Mint operating system version 17.2. Once yo…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, just open a new email message. In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…

911 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

19 Experts available now in Live!

Get 1:1 Help Now