Chapter 3 RTOS Concepts And Definitions Department of

  • Slides: 16
Download presentation
Chapter 3 RTOS Concepts And Definitions Department of Computer Science Hsu Hao Chen Professor

Chapter 3 RTOS Concepts And Definitions Department of Computer Science Hsu Hao Chen Professor Hsung-Pin Chang

Outline(1/2) n n n Priorities Ready threads and suspended threads Preemptive, priority-based scheduling Round-Robin

Outline(1/2) n n n Priorities Ready threads and suspended threads Preemptive, priority-based scheduling Round-Robin scheduling Kernel、 RTOS Context Switch

Outline(2/2) n n Interrupt handling、Thread starvation Priority inversion Priority inheritance Preemption-threshold

Outline(2/2) n n Interrupt handling、Thread starvation Priority inversion Priority inheritance Preemption-threshold

Priorities(1/2) n n Most real-time systems use a priority system as a means of

Priorities(1/2) n n Most real-time systems use a priority system as a means of establishing the relative importance of threads. Priorities include two classes n n n Static priority Dynamic priority Thread. X provides priority values from 0 to 31, the value 0 represents the highest priority

Priorities(2/2)

Priorities(2/2)

Ready threads and suspended threads(1/3) n Thread. X maintains to manage threads two classes

Ready threads and suspended threads(1/3) n Thread. X maintains to manage threads two classes n Suspended Threads List n Occur n n Wait for an unavailable resource Removed n n It is placed on the Ready Thread List It is terminated

Ready threads and suspended threads(2/3)

Ready threads and suspended threads(2/3)

Ready threads and suspended threads(3/3) n Ready Threads List n Occur n n Remove

Ready threads and suspended threads(3/3) n Ready Threads List n Occur n n Remove n n Thread is ready for execution When Thread. X schedules a thread for execution If all the threads on the list have equal priority, Thread. X selects the thread that has been waiting the longest.

Preemptive, priority-based scheduling n A higher priority thread can interrupt and suspend a currently

Preemptive, priority-based scheduling n A higher priority thread can interrupt and suspend a currently executing thread that has a lower priority

Round-Robin scheduling n n Provide processor sharing in the case in which multiple threads

Round-Robin scheduling n n Provide processor sharing in the case in which multiple threads have the same priority Two primary ways are supported by Thread. X : Round-robin processing and cooperative multithreading

Round-Robin scheduling

Round-Robin scheduling

Kernel、 RTOS n n A kernel is minimal implementation of an RTOS Consists of

Kernel、 RTOS n n A kernel is minimal implementation of an RTOS Consists of at least a scheduler and a context switch handler Full-blown operating systems RTOS is dedicated to the control of hardware and must operate within specified time contraints

Context Switch n n Context is the current execution state of a thread Consists

Context Switch n n Context is the current execution state of a thread Consists of such items as the program counter , register and stack pointer Context switch refers to the saving or restoring a different thread’s When a thread’s context is restored then the thread resumes execution at the stopping point

Interrupt handling、Thread starvation n Interrupt handling n n n Interrupt vector Interrupt service routine

Interrupt handling、Thread starvation n Interrupt handling n n n Interrupt vector Interrupt service routine (ISR) Thread starvation n n Priority-based scheduling Solution would be to gradually raise the priority of starved

Priority inversion

Priority inversion

Preemption-threshold n n n Disabling preemption Threads with priorities higher than 15 will be

Preemption-threshold n n n Disabling preemption Threads with priorities higher than 15 will be permitted Even though priorities 15 through 19 are higher than thread’s priority of 20, threads with those priorities will not be allowed to preempt this thread