LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 12-07-2009, 06:48 AM   #1
mircan
LQ Newbie
 
Registered: Dec 2009
Posts: 16

Rep: Reputation: 0
Real time processes


Hi,

I've got the following problem:
1. I start two bash windows
2. In one of them I start a script test1:
Code:
#!/bin/sh

counter=0;
while true; do
	counter=`expr $counter + 1`;
	sleep 0.2;
	echo "$counter";
done
This script puts a natural number 5 times a second.
3. Then in the second bash window I type (as root):
Code:
chrt -rr 99 ./test2
The script test2 looks as follows:
Code:
#!/bin/sh

(sleep 15; kill -9 $$) &

while true; do
	true;
done
During the following 15 seconds test2 is the process with the highest real-time priority. As far as I know the script doesn't perform any system calls so it shouldn't be suspended even for a minimal timeslice. My question is: why the process test1 manages to put a few numbers on the screen before test2 stops. I thought that test2 would exclusivly own the processor for 15 seconds. Am I wrong?
 
Old 12-07-2009, 08:47 AM   #2
estabroo
Senior Member
 
Registered: Jun 2008
Distribution: debian, ubuntu, sidux
Posts: 1,126
Blog Entries: 2

Rep: Reputation: 124Reputation: 124
sleep and kill are both system calls
 
Old 12-07-2009, 01:26 PM   #3
mircan
LQ Newbie
 
Registered: Dec 2009
Posts: 16

Original Poster
Rep: Reputation: 0
Quote:
sleep and kill are both system calls
Indeed, but i meant there are no system calls after calling sleep and before kill, during the 15-second execution of the loop. The script test1 puts some numbers on the screen during those 15 seconds.
 
Old 12-07-2009, 04:33 PM   #4
estabroo
Senior Member
 
Registered: Jun 2008
Distribution: debian, ubuntu, sidux
Posts: 1,126
Blog Entries: 2

Rep: Reputation: 124Reputation: 124
ah, I see what you mean, well script2 is asleep for those 15 seconds, so its not taking any cpu time regardless of its priority
 
Old 12-07-2009, 04:52 PM   #5
mircan
LQ Newbie
 
Registered: Dec 2009
Posts: 16

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by estabroo View Post
ah, I see what you mean, well script2 is asleep for those 15 seconds, so its not taking any cpu time regardless of its priority
Maybe I'm not writing clearly.
The sleep and kill commands are started in the background, only to stop the script after 15 seconds. During this 15 seconds the script is executing an endless loop, so it really is taking cpu time. As test2 is a real-time process, I think the scheduler shouldn't preempt it, but in fact test1 manages to put some numbers on the screen (but not 5 times a second as if test2 was not running). And my question is how this happens. I thought that test2 shouldn't be preempted during this 15 seconds.
 
Old 12-07-2009, 11:02 PM   #6
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,359

Rep: Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751
sleep doesn't run in the cpu, or nobody would ever get any work done. It sets an interrupt, so the kernel/cpu can deal with other stuff while its waiting.

Last edited by chrism01; 12-08-2009 at 06:54 PM.
 
Old 12-08-2009, 12:55 PM   #7
estabroo
Senior Member
 
Registered: Jun 2008
Distribution: debian, ubuntu, sidux
Posts: 1,126
Blog Entries: 2

Rep: Reputation: 124Reputation: 124
mircan, I see what you mean now, I guess the question is can userspace have hard realtime processes, I'd guess at best it gets a minimum latency between time slices but isn't guaranteed all the time slices.
 
Old 12-08-2009, 02:46 PM   #8
mircan
LQ Newbie
 
Registered: Dec 2009
Posts: 16

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by estabroo View Post
mircan, I see what you mean now, I guess the question is can userspace have hard realtime processes, I'd guess at best it gets a minimum latency between time slices but isn't guaranteed all the time slices.
Yeah, that is my question. Perhaps you're right. Thanks for the answer.
 
Old 02-12-2010, 07:29 AM   #9
mircan
LQ Newbie
 
Registered: Dec 2009
Posts: 16

Original Poster
Rep: Reputation: 0
I've found out what is the problem. I'm writing here in case anyone is interested. As I experienced my problem occurs only in kernels with Completely Fair Scheduler. The solution is simple. In CFS there are two new options sched_rt_runtime_us and sched_rt_period_us. The first is the period of time after which all real time process will be preempted and the second is the period after which any of real time processes can run again. By default they are 0.95 s and 1 s. And this is the reason of my problem. The options values can be dynamically changed.
Code:
sysctl -w kernel/sched_rt_runtime_us=-1
This makes preempting of a real time process in order to run a normal process not possible.

Last edited by mircan; 02-12-2010 at 07:44 AM.
 
  


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 On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
real time kernel not real time, still xruns in Jackd browny_amiga Linux - General 0 09-20-2009 02:47 PM
Need some detail information on Hard Real-Time Systems and Soft real-Time Systems. LinuxInfo General 3 09-22-2008 03:25 AM
Real Time Clock & Real Time Timer jiramak Linux - Newbie 1 09-05-2007 06:43 PM
LXer: Real-time garbage collection with Real-time Java LXer Syndicated Linux News 0 05-05-2007 12:16 PM
LXer: Real-time Linux gains real-time JVM LXer Syndicated Linux News 0 10-12-2006 10:54 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 01:18 PM.

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