Realtime System Fundamentals : Scheduling and Priority-based scheduling B. Ramamurthy Amrita-UB-MSES-2013-7 5/11/2013.

Slides:



Advertisements
Similar presentations
Operating Systems Semaphores II
Advertisements

Real Time Scheduling.
Chapter 7 - Resource Access Protocols (Critical Sections) Protocols: No Preemptions During Critical Sections Once a job enters a critical section, it cannot.
Priority Inheritance and Priority Ceiling Protocols
1 EE5900 Advanced Embedded System For Smart Infrastructure RMS and EDF Scheduling.
B. RAMAMURTHY 4/13/2015 cse321-fall2014 Realtime System Fundamentals : Scheduling and Priority-based scheduling Pag e 1.
0 Synchronization Problem Resource sharing –Requires mutual exclusion –Critical section A code section that should be executed mutually exclusively by.
CS5270 Lecture 31 Uppaal, and Scheduling, and Resource Access Protocols CS 5270 Lecture 3.
CprE 458/558: Real-Time Systems (G. Manimaran)1 CprE 458/558: Real-Time Systems Resource Access Control Protocols.
Ch. 7 Process Synchronization (1/2) I Background F Producer - Consumer process :  Compiler, Assembler, Loader, · · · · · · F Bounded buffer.
Tasks Periodic The period is the amount of time between each iteration of a regularly repeated task Time driven The task is automatically activated by.
Semaphores and Mailboxes B. Ramamurthy 1. Page 2 Critical sections and Semaphores When multiples tasks are executing there may be sections where only.
By Group: Ghassan Abdo Rayyashi Anas to’meh Supervised by Dr. Lo’ai Tawalbeh.
Embedded Xinu Kernel Programming
Real-Time Kernel (Part 1)
PROCESSES TANNENBAUM, SECTION 2-1 OPERATING SYSTEMS.
Real-Time Scheduling CS4730 Fall 2010 Dr. José M. Garrido Department of Computer Science and Information Systems Kennesaw State University.
Midterm 1 – Wednesday, June 4  Chapters 1-3: understand material as it relates to concepts covered  Chapter 4 - Processes: 4.1 Process Concept 4.2 Process.
Real-Time Scheduling CS4730 Fall 2010 Dr. José M. Garrido Department of Computer Science and Information Systems Kennesaw State University.
Page 1 Task Control: Signals and Alarms Chapter 7 and 8 B. Ramamurthy.
Silberschatz, Galvin and Gagne ©2013 Operating System Concepts Essentials – 9 th Edition Chapter 5: Process Synchronization.
1 Interprocess Communication (IPC) - Outline Problem: Race condition Solution: Mutual exclusion –Disabling interrupts; –Lock variables; –Strict alternation.
Background Concurrent access to shared data may result in data inconsistency Maintaining data consistency requires mechanisms to ensure the orderly execution.
B. RAMAMURTHY 12/25/2015 Realtime System Fundamentals : Scheduling and Priority-based scheduling Pag e 1.
Silberschatz, Galvin and Gagne  2002 Modified for CSCI 399, Royden, Operating System Concepts Operating Systems Lecture 24 Critical Regions.
Introduction to Embedded Systems Rabie A. Ramadan 5.
Sandtids systemer 2.modul el. Henriks 1. forsøg m. Power Point.
3/1/2016Page 1 Realtime System Fundamentals : Scheduling B. Ramamurthy.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition Chapter 6: Process Synchronization.
Mutual Exclusion -- Addendum. Mutual Exclusion in Critical Sections.
Big Picture Lab 4 Operating Systems C Andras Moritz
Chapter 6 Synchronization Dr. Yingwu Zhu. The Problem with Concurrent Execution Concurrent processes (& threads) often access shared data and resources.
© Janice Regan, CMPT 300, May CMPT 300 Introduction to Operating Systems Mutual Exclusion Mutexes, Semaphores.
Real-Time Threads Time dependent, usually wrt deadline –Periodic –Aperiodic –Sporadic Priority scheduled Fault tolerant.
Real-Time Operating Systems RTOS For Embedded systems.
6.1 Silberschatz, Galvin and Gagne ©2005 Operating System Principles 6.5 Semaphore Less complicated than the hardware-based solutions Semaphore S – integer.
Deadlock and Starvation
REAL-TIME OPERATING SYSTEMS
CS703 – Advanced Operating Systems
Semaphore Synchronization tool that provides more sophisticated ways (than Mutex locks) for process to synchronize their activities. Semaphore S – integer.
COT 4600 Operating Systems Fall 2009
Chapter 5: Process Synchronization
Scheduling and Resource Access Protocols: Basic Aspects
PARALLEL PROGRAM CHALLENGES
Chapter 5: Process Synchronization – Part II
EEE 6494 Embedded Systems Design
Chapter 5: Process Synchronization
Xinu Semaphores.
Realtime System Fundamentals : Scheduling and Priority-based scheduling B. Ramamurthy cse321-fall2014 9/20/2018.
Chapter 5: Process Synchronization
Realtime System Fundamentals : Scheduling and Priority-based scheduling B. Ramamurthy 11/22/2018.
Xinu Semaphores.
Realtime System Fundamentals : Scheduling and Priority-based scheduling B. Ramamurthy cse321-fall /27/2018.
Topic 6 (Textbook - Chapter 5) Process Synchronization
Embedded Systems Introduction to Real-Time Systems
Semaphore Originally called P() and V() wait (S) { while S <= 0
Realtime System Fundamentals
Lecture 2 Part 2 Process Synchronization
Realtime System Fundamentals
Multiprocessor and Real-Time Scheduling
Xinu Semaphores.
CSCI1600: Embedded and Real Time Software
Realtime System Fundamentals
CHAPTER 8 Resources and Resource Access Control
CSE 153 Design of Operating Systems Winter 19
CSE 153 Design of Operating Systems Winter 2019
Real-Time Process Scheduling Concepts, Design and Implementations
Real-Time Process Scheduling Concepts, Design and Implementations
Lab #9 Semaphores Operating System Lab.
Presentation transcript:

Realtime System Fundamentals : Scheduling and Priority-based scheduling B. Ramamurthy Amrita-UB-MSES-2013-7 5/11/2013

Realtime scheduling We will realtime system scheduling as in: Earliest deadline scheduling (EDS) Starting deadline Completion deadline Dynamic priority scheduling Rate monotonic scheduling (RMS) Periodic tasks are prioritized by the frequency of repetition (high priority to tasks with shorter periods) Preemptive scheduling Fixed priority scheduling Schedulability according to RMS Σ(Ci/Ti) <= n(21/n-1) Cyclic executives (pre-scheduled) Concepts of cycle, slot and frame Repeated execution times Amrita-UB-MSES-2013-7 5/11/2013

Task State Diagram New Ready Blocked Run 5/11/2013 Task admitted Resources allocated Dispatched; cpu allocated Event occurred Task exit Blocked Run Waiting for event Amrita-UB-MSES-2013-7 5/11/2013

Deadline driven scheduling Parameters: ready time, starting deadline, completion deadline, processing time, resource requirement, priority, preemptive or non-preemptive Amrita-UB-MSES-2013-7 5/11/2013

Deadline Scheduling Process Arrival Time Execution Time Ending Deadline A(1) 0 10 20 A(2) 20 10 40 A(3) 40 10 60 A(4) 60 10 80 A(5) 80 10 100 • • • • B(1) 0 25 50 B(2) 50 25 100 Amrita-UB-MSES-2013-7 5/11/2013

Fixed-priority scheduling; A has priority B has priority deadline A1 B1 A2 B1 A3 B2 A4 B2 A5 B2 A1 A2 B1 A3 A4 A5, B2 (missed) A1 A2 A3 A4 A5, B2 B1 A2 A3 B2 A5 A1 B1 A2 B1 A3 B2 A4 B2 A5 Fixed-priority scheduling; A has priority B has priority Earliest-deadline scheduling using completion deadlines B1 Amrita-UB-MSES-2013-7 5/11/2013

Aperiodic Task set Arrival Time Execution Time Starting Deadline A 10 20 110 B 20 20 20 C 40 20 50 D 50 20 90 E 60 20 70 Use earliest deadline with unforced idle time Amrita-UB-MSES-2013-7 5/11/2013

Rate-monotonic scheduling First proposed by Liu. For RMS, the highest-priority task is the one with the shortest period, the second highest-priority task is the one with the second shortest period, and so on. Schedulability according to RMS Σ(Ci/Ti) <= n(21/n-1) Amrita-UB-MSES-2013-7 5/11/2013

Resources & Critical Resources Shared resources: need mutual exclusion Tasks cooperating to complete a job Tasks contending to access a resource Tasks synchronizing Critical resources and critical region A important synchronization and mutual exclusion primitive / resource is “semaphore” Amrita-UB-MSES-2013-7 5/11/2013

Critical sections and Semaphores When multiples tasks are executing there may be sections where only one task could execute at a given time: critical region or critical section There may be resources which can be accessed only be one of the processes: critical resource Semaphores can be used to ensure mutual exclusion to critical sections and critical resources Amrita-UB-MSES-2013-7 5/11/2013

Semaphores See semaphore.h of xinu Amrita-UB-MSES-2013-7 5/11/2013

Semaphore: wait() ppcb->sem = sem; /* record semaphore id in pcb */ enqueue(currpid, psem->queue); resched(); /* place in wait queue and reschedule */ } restore(ps); /* restore interrupts */ return OK; Amrita-UB-MSES-2013-7 5/11/2013

Semaphore: signal() /*signal - signal a semaphore, releasing one waiting process, and block * @param sem id of semaphore to signal * @return OK on success, SYSERR on failure */ syscall signal(semaphore sem) { irqmask ps; register struct sentry *psem; ps = disable(); /* disable interrupts */ if ( isbadsem(sem) ) /* safety check */ restore(ps); return SYSERR; } psem = &semtab[sem]; /* retrieve semaphore entry */ if ( (psem->count++) < 0 ) /* release one process from wait queue */ { ready(dequeue(psem->queue), RESCHED_YES); } restore(ps); /* restore interrupts */ return OK; Amrita-UB-MSES-2013-7 5/11/2013

Semaphore: usage Problem 1: Problem 2: Create 3 tasks that each sleep for a random time and update a counter. Counter is the critical resources shared among the processes. Only one task can update the counter at a time so that counter value is correct. Problem 2: Create 3 tasks; task 1 updates the counter by 1 and then signal task 2 that updates the counter by 2 and then signals task 3 to update the counter by 3. Amrita-UB-MSES-2013-7 5/11/2013

Problem 1 #include <..> //declare semaphore semaphore mutex1 = newsem(1); int counter = 0; //declare functions: proc1,proc1, proc3 ready(create((void *)proc1, INITSTK, INITPRIO, “PROC1",, 2, 0, NULL), RESCHED_NO); ready(create((void *)proc2, INITSTK, INITPRIO, “PROC2",, 2, 0, NULL), RESCHED_NO); ready(create((void *)proc3, INITSTK, INITPRIO, “PROC3",, 2, 0, NULL), RESCHED_NO); Amrita-UB-MSES-2013-7 5/11/2013

Problem 1: multi-tasks void proc1() { while (1) { sleep (rand()%10); wait(mutex1); counter++; signal(mutex1); } } void proc2() //similarly proc3 Amrita-UB-MSES-2013-7 5/11/2013

Problem 1 Task 1 Task 2 Counter1 Task 3 5/11/2013 Amrita-UB-MSES-2013-7 5/11/2013

Problem 2 semaphore synch12 = newsem(0); semaphore synch23 = newsem(0); semaphore synch31 = newsem(0); ready(create((void *)proc1, INITSTK, INITPRIO, “PROC1",, 2, 0, NULL), RESCHED_NO); ready(create((void *)proc2, INITSTK, INITPRIO, “PROC2",, 2, 0, NULL), RESCHED_NO); ready(create((void *)proc3, INITSTK, INITPRIO, “PROC3",, 2, 0, NULL), RESCHED_NO); signal(synch31); Amrita-UB-MSES-2013-7 5/11/2013

Task flow void proc1() void proc2() void proc3() 5/11/2013 { while (1) { sleep (rand()%10); wait(synch31); counter++; signal(synch12); } } void proc2() wait(synch12); signal(synch23); void proc3() sleep(rand()%10); wait(synch23); signal(synch31); } } Amrita-UB-MSES-2013-7 5/11/2013

Priority Inversion When we allow concurrent task to execute and with semaphore and mailboxes and other synchronization primitives, it is possible that a low priority task may come to block a high priority task. This situation is known as priority inversion. What happened on Mars? Amrita-UB-MSES-2013-7 5/11/2013

Priority inversion (Priority: t1>t2>t3) Critical section task1 time 0 1 2 3 4 5 6 7 8 9 10 blocked task2 task3 Amrita-UB-MSES-2013-7 5/11/2013

Problem: Priority inversion Solution1: Priority Inheritance task1 blocked Task 2 delayed task2 Priority of t1 inherited Critical section Priority reverted To t3 task3 0 1 2 3 4 5 6 7 8 9 10 time Amrita-UB-MSES-2013-7 5/11/2013

Solution2:Priority Ceiling Protocol CS Used by Priority Ceiling S1 t1,t2 P(t1) S2 t1,t2,t3 S3 t3 P(t3) Solution2:Priority Ceiling Protocol Acquire S1 Release S1 task1 Attempt to Acquire S1 Acquire S1 Acquire S2 No way task2 Acquire S2 Release S2 Critical section task3 0 1 2 3 4 5 6 7 8 9 10 time Amrita-UB-MSES-2013-7 5/11/2013