Solved

2ms sleep in linux

Posted on 2006-07-14
13
1,174 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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
 
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

More Than Just A Video Library

Train for your certification. Learn the latest DevOps tools. Grow your skillset to do better work.

At Linux Academy, we release new training modules every week so you'll always be up to date on the latest tech.

Question has a verified solution.

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

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…
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…
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

690 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