Lecture 8 Outline in MS Word format Linux and VxWorks Scheduling

advertisement

Page 1
Scheduling for Linux and VxWorks
 Linux kernels 2.4 and 2.6 have dramatically different scheduling
algorithms
 Most Linux kernel 2.4 distributions have the 2.4 scheduler
 In kernel 2.5 the scheduler was re-written to improve the algorithm’s
performance when used for real-time processes
 Some later releases of the 2.4 kernel were built with the 2.5 kernel
scheduler
 Linux kernel 2.6 was built on the kernel 2.5 scheduler
 Although the 2.4 scheduler performs in O(n), the 2.6 kernel
scheduler has performance of O(1) substantially improving the
scheduler performance when the number of processes to be
scheduled are increased in the system
Page 2

Linux conventional scheduling
 Based on Unix time-sharing scheme
 Several processes will run in time multiplexing
 CPU time is divided into slices or quantum one for each ready
process
 Every running process will be switched out if it does not terminate
before it’s time slice or quantum expires
 Time sharing relies on timer interrupts transparent to the processes
 Processes also have priorities
 Process priorities are dynamic
Page 3
 Processes that have been denied the use of the CPU for a long time
get a higher priority so that they can be scheduled
 This policy introduces non-deterministic delays which prevent
conventional Linux scheduling policy to be of use for real-time
processing
 Linux supports three types of processes
 Interactive processes
 Batch processes
 Real-time processes
Page 4
 Linux 2.4 kernel is non-preemptive as oppose to that later kernels
that are preemptive
 Linux processes can be preemptive
 Real time OS support a preemptive kernel
 If a process is running in the kernel mode, it can be
interrupted just as if it was running in user mode
 A process is preempted if it’s time slice is expired or a process of
higher priority is ready in the system
Page 5
 User can change the quantum of a process by using the nice() and
setpriority() system calls
 Real-Time processes utilize Static Priorities that range from 1 to 99
 Static priority of a real-time process is always higher than the
dynamic priority of a conventional process
 Scheduling policies in Linux
 SCHED_FIFO
 Real-time FIFO process
 SCHED_RR
 Real-time Round Robin process
 SCHED_OTHER
 Conventional time-shared process
Page 6
 Linux did not support priority inversion avoidance: priority inheritance
until recently
o Priority inversion occurs when a high priority task is prevented
from executing because a low priority task holds a lock it
requires.
 POSIX pthreads provide two mechanisms for bounding priority
inversion (not preventing it): priority ceiling and priority inheritance
mutexes.
 Linux kernel 2.6.24.4 explicitly supports the use of priority inheritance
by SCHED_OTHER threads
 In current versions of Linux Priority Ceiling protocol is also supported
 Priority ceiling mutexes (PTHREAD_PRIO_PROTECT protocol)
have an internal priority set which is used to boost the priority of
every thread that takes the lock to this priority "ceiling".
 Priority inheritance mutexes (PTHREAD_PRIO_INHERIT protocol)
will boost the priority of a lower priority task to match that of the
highest priority task blocked on it.
Page 7
Scheduling system calls in Linux
 nice() Changes the priority of a conventional process from -20 to
+19, negative numbers correspond to high priority, positive, low
priority
 getpriority(), setpriority() gets the maximum priority of a group of
conventional processes, sets the priority of a group of conventional
processes
 sched_getscheduler(), sched_setscheduler() gets and sets the
scheduling policy of a process
 sched_getparam(), sched_setparam() gets and sets the priority of a
process
Page 8
Scheduling in VxWorks 5.1 and 5.4-5.5
 Supports priority based preemptive scheduling by default as well as
round robin scheduling
 Wind kernel has 256 priority levels, 0 to 255, 0 is the highest priority
 Scheduler system calls




kernelTimeSlice()
taskPrioritySet()
taskLock() disables task rescheduling
taskUnlock
 VxWroks 5.4 and higher also support POSIX Scheduling interface
Page 9
 VxWorks uses the term preemptive priority scheduling, while POSIX
standard uses the term FIFO, both describe the same priority-based
policy
 POSIX and Linux scheduling is based on processes, Wind
scheduling is based on tasks
 A task can address memory directly while process inherits
only specific attributes from its parent process and can only
address within the process context
 POSIX scheduling algorithms are applied on a process-by-process
basis, Wind scheduling algorithm is on a system-wide basis, either
all tasks use a round-robin scheme, or all use a preemptive priority
scheme
 POSIX priority numbering scheme is the inverse of the Wind scheme
Page 10
 Linux 2.6 FIFO and RR scheduling interfaces and policies are POSIX
compliant
Page 11
Download