RTOS Scheduling 2 0 Problems Solutions Excellent Book
RTOS Scheduling 2. 0 Problems - Solutions Excellent Book – PDF avail. Georgio Butazzo, “Predictable scheduling Algorithms and applications”, 3 rd edition 4/16 RTOS scheduling prob. 1
RTOS Scheduling Problems Cause: : Mutual exclusion & deadlocks Priority inversion 2 Solutions Priority inheritance Priority ceiling ¢ 4/16 RTOS scheduling prob. 2
Synchronization Eg: - review 4/16 conveyer belt object recognition two cameras used Tasks Acquisition: image_1 and image_2 image_1 image_2 Edge detect: edge 1 and edge 2 edge_1 Edge_2 Task object height, shape height shape recognition Recog. RTOS scheduling prob. 3
Mutual Exclusion – mutex ; review locks affect scheduling. • shared data structure across threads data access is atomic. Enforced by mutexes. critical section : : code executed while holding lock • • • 4/16 RTOS scheduling prob. 4
Missed Deadlines ? Preemption: waiting for higher priority tasks Execution: execution time Blocking (priority inversion) delayed by lower priority tasks [major source of missing deadlines] 4/16 Task schedulable if preemption + execution + blocking < deadline. RTOS scheduling prob. 5
Priority Inversion eg. With - lock priorities highest lowest Task 3 acquires lock, critical section; preempted by task 1, tries to acquire lock blocks, waiitng for lock. Task 2 preempts task 3 at time 4, higher priority task 1 blocked. effect, priorities of tasks 1 and 2 get inverted, task 2 keeps task 1 waiting. 4/16 RTOS scheduling prob. 6
Priority Inversion (same example) Task 1 tries to acquire lock from Task 3 Task 2 (unrelated) preempts Task 3 before it releases lock, keeping Task 1 waiting Task 1 blocked Task 1 (highest priority) blocked by task 3 Attempts to lock data resource (blocked) B Task 1 Task 2 Task 3 4/16 Task 3 acquires lock Task 3 releases lock RTOS scheduling prob. 7
• Mars Rover Pathfinder Landed July 1997 airbags deployed at 350 m worked till Sep 97 few days into mission Started missing deadlines 4/16 RTOS scheduling prob. 8
Pathfinder: deadlines missed priority inversion Vx. Works RTOS, preemptive scheduling few days into mission, Pathfinder sporadically missing deadlines Watchdog timer generated system resets loss of data. T 1 information bus manager -shared Blocked T 2 communication task T 3 meteorological data collection Mutex controlled shared information bus PIP used but disabled for performance; more on PIP later Sol PIP re-enabled from ground 4/16 RTOS scheduling prob. 9
Pathfinder problem bc_sched detects bc_dist incomplete, generates system reset http: //research. microsoft. com/~mbj/Mars_Pathfinde/Authoritative_Account. html 4/16 RTOS scheduling prob. 10
Priority Inheritance Protocol (PIP) solution I to priority inversion Priority Task 1 > Task 2 > Task 3 acquires lock , enters critical section. Task 1 preempts task 3, tries to acquire the lock & blocks. Task 3 inherits task 1 priority, - but only after Task 1 blocks – prevents preemption by task 2. 4/16 RTOS scheduling prob. 11
Pathfinder after S/W update 4/16 RTOS scheduling prob. 12
Deadlocks happen with priority inheritance -2 locks 4/16 task 2 acquires lock a task 1 preempts task 2, acquires lock b blocks trying to acquire lock a. Task 2 blocks trying to acquire lock b. Deadlock no further progress possible. #include <pthread. h> pthread_mutex_t lock_a, lock_b; void* thread_1_function(void* arg) { pthread_mutex_lock(&lock_b) ; . . . pthread_mutex_lock(&lock_a ); . . . pthread_mutex_unlock(&lock _a); . . . pthread_mutex_unlock(&lock _b); . . . } void* thread_2_function(void* arg) { pthread_mutex_lock(&lock_a ); . . . pthread_mutex_lock(&lock_b RTOS scheduling prob. 13
PIP Problems – high OH 4/16 Managing priority inheritance mechanism updating task priority Managing data structure for inherited task priorities ( task & mutex lists) Dynamic priority management implies dynamic reordering of task lists Does not prevent deadlocks RTOS scheduling prob. 14
Priority Ceiling Protocol (PCP) prevents deadlock ¢ Lock priority = highest-priority task that can lock it. priority ceiling ¢ task can acquire lock only if ¢ task’s priority > priority ceilings of all locks currently held by other tasks Locks not held by any task don’t affect the task ¢ Prevents deadlocks Protocol extensions can support dynamic priority scheduling ¢ 4/16 RTOS scheduling prob. 15
Priority Ceiling Protocol eg RTOS solution II to priority inversion: Example 4/16 locks a and b have priority ceilings equal to task 1 priority task 1 preempts task 2 task 1 attempts to lock b, but cannot. task 2 currently holds lock a, with priority ceiling = task 1 priority Task 1 priority must be higher to lock b RTOS scheduling prob. 16
- Slides: 16