ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
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.
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 ?
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.
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?
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.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.