LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Kernel (https://www.linuxquestions.org/questions/linux-kernel-70/)
-   -   What's the differences between CFS and real-time scheduling (https://www.linuxquestions.org/questions/linux-kernel-70/whats-the-differences-between-cfs-and-real-time-scheduling-4175478729/)

songcaidao 09-27-2013 04:50 AM

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!

sundialsvcs 09-27-2013 02:51 PM

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.

crosstalk 09-28-2013 04:56 PM

Quote:

Originally Posted by songcaidao (Post 5035824)
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.

songcaidao 09-29-2013 09:56 AM

Quote:

Originally Posted by crosstalk (Post 5036548)
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!

songcaidao 09-29-2013 09:57 AM

Quote:

Originally Posted by crosstalk (Post 5036548)
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!

sundialsvcs 09-30-2013 08:12 PM

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.")

trukna 10-04-2013 12:52 AM

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.

songcaidao 10-04-2013 10:01 AM

Quote:

Originally Posted by trukna (Post 5039787)
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?

trukna 10-04-2013 11:47 PM

Quote:

Originally Posted by songcaidao (Post 5040048)
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.


All times are GMT -5. The time now is 06:17 AM.