LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software > Linux - Kernel
User Name
Password
Linux - Kernel This forum is for all discussion relating to the Linux kernel.

Notices


Reply
  Search this Thread
Old 09-27-2013, 04:50 AM   #1
songcaidao
LQ Newbie
 
Registered: Sep 2013
Posts: 9

Rep: Reputation: Disabled
Question What's the differences between CFS and real-time scheduling


Hi,I'm learning about Linux Scheduler.After I read the introduction and discussion about CFS,the topic turns to the Real-Time Scheduling Policies.
But I don't know what's the differences between them?
Does the kernel schedule the non real-time process by CFS,and real-time process by Real-Time Scheduling policies?
What is real-time process?How to identify the real-time process?
Every apply is appreciate!

Last edited by songcaidao; 10-04-2013 at 09:48 AM.
 
Old 09-27-2013, 02:51 PM   #2
sundialsvcs
LQ Guru
 
Registered: Feb 2004
Location: SE Tennessee, USA
Distribution: Gentoo, LFS
Posts: 9,078
Blog Entries: 4

Rep: Reputation: 3180Reputation: 3180Reputation: 3180Reputation: 3180Reputation: 3180Reputation: 3180Reputation: 3180Reputation: 3180Reputation: 3180Reputation: 3180Reputation: 3180
A "real-time process" is one that has hard-and-fast requirements concerning how rapidly it will be dispatched after an interrupt occurs, how long its time-slices must be and how frequently it receives them. Linux is not designed to be a "real-time operating system (RTOS)," although it does possess scheduling-controls that allows it to come fairly close. (However: "fairly close," in terms of true real-time programming, is not good enough.) Linux is a general-purpose operating system, and it really can't be both at once.

I've encountered a few "true real-time" systems which employed two CPUs ... effectively two machines in one box ... one of them running an RTOS and the other one running Linux. The Linux software was used to "feed" the RTOS (which was not Linux ...) and to act as its controller, because one necessary side-effect of real-time operation is that it is quite inflexible. The RTOS was a slave to its interrupts and could never afford to do anything else.

Last edited by sundialsvcs; 09-27-2013 at 02:52 PM.
 
1 members found this post helpful.
Old 09-28-2013, 04:56 PM   #3
crosstalk
Member
 
Registered: Jul 2010
Distribution: Gentoo, Debian, Mint, Xubuntu
Posts: 150

Rep: Reputation: 35
Quote:
Originally Posted by songcaidao View Post
Is the kernel schedule the non real-time process by CFS,and real-time process by Real-Time Scheduling policies?
What is real-time process?How to identify the real-time process?
sundialsvcs is correct in defining what a real-time task is. However, as far as the kernel itself is concerned, a real-time process or thread is simply one with a priority (not nice value) greater than 0.

If processes A and B both want to run, there is only one processor, and A has a higher priority, A is guaranteed to run before B.

If processes A and B both want to run, there is only one processor, and both have the same priority, then their scheduling policy determines which actually gets to run. If their priorities are 0 (non-realtime), then the CFS scheduler determines which runs; otherwise, a real-time scheduling policy determines which gets to run.

To identify real-time processes, you can run the "top" program. Note that top shows a combined priority (priority and nice value), so any process with a priority of 0 to 39 in top has an actual priority of 0 and is not realtime; all processes with a priority of 40 or higher are real-time.

Quote:
Originally Posted by sundialsvcs
Linux is not designed to be a "real-time operating system (RTOS)," although it does possess scheduling-controls that allows it to come fairly close. (However: "fairly close," in terms of true real-time programming, is not good enough.) Linux is a general-purpose operating system, and it really can't be both at once.
Not entirely true. Vanilla Linux is not an RTOS, but it can be patched via the PREEMPT_RT patchset to become hard-realtime capable (if properly configured and setup). With this patchset, Linux has both hard real-time and general-purpose capabilities. However, for safety-critical applications, Linux will probably never be trustworthy enough to use.

There are also RTOSs that run alongside Linux via a realtime hypervisor. An excellent example of this type of RTOS is Xenomai. The advantage of using such an RTOS over Linux with PREEMPT_RT is that it can perform better -- PREEMPT_RT typically only satisfies requirements in the couple-hundred-microsecond range; Xenomai satisfies requirements as small as tens of microseconds. Again, Xenomai + Linux is a complex system, and as a result, will probably never be trustworthy enough to use in life-critical applications.

Last edited by crosstalk; 09-28-2013 at 04:57 PM. Reason: clarification
 
1 members found this post helpful.
Old 09-29-2013, 09:56 AM   #4
songcaidao
LQ Newbie
 
Registered: Sep 2013
Posts: 9

Original Poster
Rep: Reputation: Disabled
Thumbs up

Quote:
Originally Posted by crosstalk View Post
sundialsvcs is correct in defining what a real-time task is. However, as far as the kernel itself is concerned, a real-time process or thread is simply one with a priority (not nice value) greater than 0.

If processes A and B both want to run, there is only one processor, and A has a higher priority, A is guaranteed to run before B.

If processes A and B both want to run, there is only one processor, and both have the same priority, then their scheduling policy determines which actually gets to run. If their priorities are 0 (non-realtime), then the CFS scheduler determines which runs; otherwise, a real-time scheduling policy determines which gets to run.

To identify real-time processes, you can run the "top" program. Note that top shows a combined priority (priority and nice value), so any process with a priority of 0 to 39 in top has an actual priority of 0 and is not realtime; all processes with a priority of 40 or higher are real-time.



Not entirely true. Vanilla Linux is not an RTOS, but it can be patched via the PREEMPT_RT patchset to become hard-realtime capable (if properly configured and setup). With this patchset, Linux has both hard real-time and general-purpose capabilities. However, for safety-critical applications, Linux will probably never be trustworthy enough to use.

There are also RTOSs that run alongside Linux via a realtime hypervisor. An excellent example of this type of RTOS is Xenomai. The advantage of using such an RTOS over Linux with PREEMPT_RT is that it can perform better -- PREEMPT_RT typically only satisfies requirements in the couple-hundred-microsecond range; Xenomai satisfies requirements as small as tens of microseconds. Again, Xenomai + Linux is a complex system, and as a result, will probably never be trustworthy enough to use in life-critical applications.
Thank you!I'm so glad to get something useful.Thank you again!
 
Old 09-29-2013, 09:57 AM   #5
songcaidao
LQ Newbie
 
Registered: Sep 2013
Posts: 9

Original Poster
Rep: Reputation: Disabled
Thumbs up

Quote:
Originally Posted by crosstalk View Post
sundialsvcs is correct in defining what a real-time task is. However, as far as the kernel itself is concerned, a real-time process or thread is simply one with a priority (not nice value) greater than 0.

If processes A and B both want to run, there is only one processor, and A has a higher priority, A is guaranteed to run before B.

If processes A and B both want to run, there is only one processor, and both have the same priority, then their scheduling policy determines which actually gets to run. If their priorities are 0 (non-realtime), then the CFS scheduler determines which runs; otherwise, a real-time scheduling policy determines which gets to run.

To identify real-time processes, you can run the "top" program. Note that top shows a combined priority (priority and nice value), so any process with a priority of 0 to 39 in top has an actual priority of 0 and is not realtime; all processes with a priority of 40 or higher are real-time.



Not entirely true. Vanilla Linux is not an RTOS, but it can be patched via the PREEMPT_RT patchset to become hard-realtime capable (if properly configured and setup). With this patchset, Linux has both hard real-time and general-purpose capabilities. However, for safety-critical applications, Linux will probably never be trustworthy enough to use.

There are also RTOSs that run alongside Linux via a realtime hypervisor. An excellent example of this type of RTOS is Xenomai. The advantage of using such an RTOS over Linux with PREEMPT_RT is that it can perform better -- PREEMPT_RT typically only satisfies requirements in the couple-hundred-microsecond range; Xenomai satisfies requirements as small as tens of microseconds. Again, Xenomai + Linux is a complex system, and as a result, will probably never be trustworthy enough to use in life-critical applications.
Thanks!
 
Old 09-30-2013, 08:12 PM   #6
sundialsvcs
LQ Guru
 
Registered: Feb 2004
Location: SE Tennessee, USA
Distribution: Gentoo, LFS
Posts: 9,078
Blog Entries: 4

Rep: Reputation: 3180Reputation: 3180Reputation: 3180Reputation: 3180Reputation: 3180Reputation: 3180Reputation: 3180Reputation: 3180Reputation: 3180Reputation: 3180Reputation: 3180
That was exactly my point: if you want "a true RTOS," then you can certainly have one ... and run it under a hypervisor that's also built for real-time ... but it just won't be a very good "general-purpose operating system." (It will be, instead, "a very good RTOS.")

The two sets of requirements really are "mutually exclusive." Attempts to accommodate both-at-once unfortunately tend to turn out to be neither-at-once. But, having two parallel implementations, either on two separate boards or (maybe ...) one board with a hypervisor, works quite well. The RTOS does its highly-specialized task, and the GPOS (e.g. Linux) feeds it. (The "sort-of real-time scheduling" features of Linux might be important for those "feeder processes.")
 
Old 10-04-2013, 12:52 AM   #7
trukna
LQ Newbie
 
Registered: Sep 2013
Posts: 8

Rep: Reputation: 0
There are two priority ranges in Linux.

1) The first is the nice value, a number from –20 to +19 with a default of 0. Larger nice values correspond to a lower priority
You can list all of the processes on your system and their respective nice values (under the column marked NI) with the command ps -el.

2) The second range is the real-time priority. The values are configurable, but by default range from 0 to 99, inclusive. Opposite from nice values, higher real-time priority values correspond to a greater priority. All real-time processes are at a higher priority than normal processes.
You can see a list of the processes on your system and their respective real-time priority (under the column marked RTPRIO) with the command ps -eo state,uid,pid,ppid,rtprio,time,comm.
A value of “-” means the process is not real-time.


The Linux scheduler is modular and have scheduler classes i.e enabling different algorithms to schedule different types of processes. Each scheduler class has a priority.
The base scheduler code iterates over each scheduler class in order of priority. The highest priority scheduler class that has a runnable process wins, selecting who runs next.

Linux provides two real-time scheduling policies, SCHED_FIFO and SCHED_RR. The normal, not real-time scheduling policy is SCHED_NORMAL

The Completely Fair Scheduler (CFS) is the registered scheduler class for normal processes (SCHED_NORMAL).

The real-time policies (SCHED_FIFO and SCHED_RR) are managed not by the Completely Fair Scheduler, but by a special real-time scheduler.
 
Old 10-04-2013, 10:01 AM   #8
songcaidao
LQ Newbie
 
Registered: Sep 2013
Posts: 9

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by trukna View Post
There are two priority ranges in Linux.

1) The first is the nice value, a number from 20 to +19 with a default of 0. Larger nice values correspond to a lower priority
You can list all of the processes on your system and their respective nice values (under the column marked NI) with the command ps -el.

2) The second range is the real-time priority. The values are configurable, but by default range from 0 to 99, inclusive. Opposite from nice values, higher real-time priority values correspond to a greater priority. All real-time processes are at a higher priority than normal processes.
You can see a list of the processes on your system and their respective real-time priority (under the column marked RTPRIO) with the command ps -eo state,uid,pid,ppid,rtprio,time,comm.
A value of - means the process is not real-time.


The Linux scheduler is modular and have scheduler classes i.e enabling different algorithms to schedule different types of processes. Each scheduler class has a priority.
The base scheduler code iterates over each scheduler class in order of priority. The highest priority scheduler class that has a runnable process wins, selecting who runs next.

Linux provides two real-time scheduling policies, SCHED_FIFO and SCHED_RR. The normal, not real-time scheduling policy is SCHED_NORMAL

The Completely Fair Scheduler (CFS) is the registered scheduler class for normal processes (SCHED_NORMAL).

The real-time policies (SCHED_FIFO and SCHED_RR) are managed not by the Completely Fair Scheduler, but by a special real-time scheduler.
Thank you!
Can I say that the kernel choose the scheduling policy by the type of process?Is that when a real-time(or not real-time) process use out it's timeslice,the kernel will use the real-time(or normal) scheduling policies to select next process?
 
Old 10-04-2013, 11:47 PM   #9
trukna
LQ Newbie
 
Registered: Sep 2013
Posts: 8

Rep: Reputation: 0
Quote:
Originally Posted by songcaidao View Post
Thank you!
Can I say that the kernel choose the scheduling policy by the type of process?Is that when a real-time(or not real-time) process use out it's timeslice,the kernel will use the real-time(or normal) scheduling policies to select next process?
Yes, based upon policy (real-time or normal) process is managed by corresponding scheduler class.
And as mentioned earlier, base scheduler iterates over each scheduler class in order of priority. The highest priority scheduler class that has a runnable process wins, selecting who runs next.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
Scheduling with CFS: what happens at the end of a period? bharathravi1 Linux - Kernel 3 01-27-2012 08:33 AM
problem in assigning real time scheduling to pthread in linux jasdeep_js Linux - Kernel 1 09-07-2008 01:44 AM
LXer: Linux: CFS Scheduler v19, Group Scheduling LXer Syndicated Linux News 0 07-07-2007 06:16 PM
Differences between RTOS and non real time operating system like LINU ramkumarv Linux - General 2 03-20-2006 07:10 AM
Real-time Round-Robin Scheduling cttran Programming 2 05-06-2005 04:41 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software > Linux - Kernel

All times are GMT -5. The time now is 04:11 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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration