LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 12-25-2006, 08:49 AM   #1
stz
LQ Newbie
 
Registered: Nov 2006
Posts: 11

Rep: Reputation: 0
calibrate sleep


Hello,

Somehow in my embedded system the sleep/usleep aren’t paused for the correct time.
(the actual sleep time is X10)
How can I calibrate the linux sleep?

Thanks,
Stz
 
Old 12-26-2006, 03:43 AM   #2
kshkid
Member
 
Registered: Dec 2005
Distribution: RHEL3, FC3
Posts: 383

Rep: Reputation: 30
Quote:
Originally Posted by stz
Somehow in my embedded system the sleep/usleep aren’t paused for the correct time.

This could ( i think, necessarily it would include) involve, mode switch over duration also !
 
Old 12-26-2006, 09:47 AM   #3
sundialsvcs
LQ Guru
 
Registered: Feb 2004
Location: SE Tennessee, USA
Distribution: Gentoo, LFS
Posts: 10,642
Blog Entries: 4

Rep: Reputation: 3933Reputation: 3933Reputation: 3933Reputation: 3933Reputation: 3933Reputation: 3933Reputation: 3933Reputation: 3933Reputation: 3933Reputation: 3933Reputation: 3933
You can't.

The intention of sleep/usleep-type calls in any non-real-time operating system (such as Linux) is that the process will be delayed for not less than the stipulated amount of time. It will not be delayed for (precisely) that time.

The timer interrupt that puts the process back onto the runlist is guaranteed not to occur in less time, but it could be as much as one "jiffy" later than that. Then, although the process is now in the runlist, it must still attain enough priority to be selected by the dispatcher of one of the CPUs, and once selected it must then actually make the transition to running-state.

Linux is not a "real time operating system."
 
Old 12-26-2006, 12:21 PM   #4
stz
LQ Newbie
 
Registered: Nov 2006
Posts: 11

Original Poster
Rep: Reputation: 0
Hello sundialsvcs,

I don’t need a real time,
For instance assume that we have ONLY the following process in our system:

while(1)
{
setGPIO(‘1’)
sleep(1)
setGPIO(‘0’)
sleep(1)
}
"

It’s not make sense that the actual time of the sleep is X10.(10 instead of 1 )
I’m not familiar with the Linux timing, but maybe it is because of something in the linux setting/definition isn’t corrected for instance : system tick / hardware clock ?

Appreciate any advice
Regards,
Stz
 
Old 12-26-2006, 07:05 PM   #5
Denes
Member
 
Registered: Mar 2004
Distribution: CentOS 4.3/4.5
Posts: 72

Rep: Reputation: 15
I believe in 2.4 kernels where jiffy was set to 10ms that would cause you to sleep at least 10ms even if you set the sleep value below that. With the newer kernels, I believe that jiffy is set to 1ms so that it should not sleep that long in the general case. Are you using a newer 2.6 kernel? As pointed out before, Linux is not a RTOS so if the system decides to go away for 30ms and then come back, don't be surprised.
 
Old 12-27-2006, 02:55 AM   #6
kshkid
Member
 
Registered: Dec 2005
Distribution: RHEL3, FC3
Posts: 383

Rep: Reputation: 30
Quote:
Originally Posted by sundialsvcs
You can't.

The intention of sleep/usleep-type calls in any non-real-time operating system (such as Linux) is that the process will be delayed for not less than the stipulated amount of time. It will not be delayed for (precisely) that time.

The timer interrupt that puts the process back onto the runlist is guaranteed not to occur in less time, but it could be as much as one "jiffy" later than that. Then, although the process is now in the runlist, it must still attain enough priority to be selected by the dispatcher of one of the CPUs, and once selected it must then actually make the transition to running-state.

Linux is not a "real time operating system."
Interesting! I really had a different notion about this.
Say, if the process is to be delayed by 'x' units of time there is no way it would be made to wait/delay only 'y' units of time (where x > y ).

In such case, what if the processor is not busy and is able to reschedule the swapped process between the time slice of 'x-y' units of time itself?
 
Old 11-08-2007, 10:41 PM   #7
bricedebrignaisplage
Member
 
Registered: Apr 2006
Location: singapore
Distribution: debian
Posts: 51

Rep: Reputation: 16
I made an experiment some time ago: simply flip a bit on a DIO and usleep. Using ubuntu dapper, kernel 2.6.15. When asking to sleep for a few micro (less than 1ms) it would alway sleep 1ms +/- a small jitter. If asking to sleep some ms then it would sleep that amount plus one ms +/- a small jitter. Can somebody explain that?

My guess is that it takes 1 ms on that machine to resume a process after usleep. I think the timer resolution option in kernel conf is set to 1ms (what is this option for anyway?).

man page of usleep gives:
Quote:
Implementations may place limitations on the granularity of timer values. For each interval timer, if the requested timer value requires a finer granularity than the implementation supports, the actual timer value will be rounded up to the next supported value.
What timer? Is it the same one as the one in previous paragraph?

Last edited by bricedebrignaisplage; 11-08-2007 at 10:43 PM.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Calibrate your mouse HERE. /bin/bash General 26 11-06-2006 05:48 AM
Howto calibrate a canon U650??? Sören Schneider SUSE / openSUSE 0 07-24-2006 01:06 PM
Searching for Server (BOOTP/DHCP) <sleep> <sleep> .. .. Eileen Linux - Networking 12 10-21-2005 01:14 AM
calibrate processor thermometer? frieza Linux - Laptop and Netbook 2 11-09-2003 08:41 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 05:12 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration