Transcript Chapter 3
Chapter 3 RTOS Concepts And Definitions Department of Computer Science Hsu Hao Chen Professor Hsung-Pin Chang Outline(1/2) Priorities Ready threads and suspended threads Preemptive, priority-based scheduling Round-Robin scheduling Kernel、 RTOS Context Switch Outline(2/2) Interrupt handling、Thread starvation Priority inversion Priority inheritance Preemption-threshold Priorities(1/2) Most real-time systems use a priority system as a means of establishing the relative importance of threads. Priorities include two classes Static priority Dynamic priority ThreadX provides priority values from 0 to 31,the value 0 represents the highest priority Priorities(2/2) Ready threads and suspended threads(1/3) ThreadX maintains to manage threads two classes Suspended Threads List Occur Wait for an unavailable resource Removed It is placed on the Ready Thread List It is terminated Ready threads and suspended threads(2/3) Ready threads and suspended threads(3/3) Ready Threads List Occur Remove Thread is ready for execution When ThreadX schedules a thread for execution If all the threads on the list have equal priority,ThreadX selects the thread that has been waiting the longest. Preemptive, priority-based scheduling A higher priority thread can interrupt and suspend a currently executing thread that has a lower priority Round-Robin scheduling Provide processor sharing in the case in which multiple threads have the same priority Two primary ways are supported by ThreadX : Round-robin processing and cooperative multithreading Round-Robin scheduling Kernel、 RTOS 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 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 Interrupt handling Interrupt vector Interrupt service routine (ISR) Thread starvation Priority-based scheduling Solution would be to gradually raise the priority of starved Priority inversion Preemption-threshold 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