Software Engineering Lecture 5 Multiprogramming and Scheduling ASPI8-4 Anders P. Ravn March 2004.

Slides:



Advertisements
Similar presentations
Chapter 7 - Resource Access Protocols (Critical Sections) Protocols: No Preemptions During Critical Sections Once a job enters a critical section, it cannot.
Advertisements

A very simple kernel Anders P. Ravn April A kernel specification /* kernel.h Interface to a lightweight kernel that implements concurrent processes.
1 EE5900 Advanced Embedded System For Smart Infrastructure RMS and EDF Scheduling.
Global Environment Model. MUTUAL EXCLUSION PROBLEM The operations used by processes to access to common resources (critical sections) must be mutually.
© Andy Wellings, 2004 Roadmap  Introduction  Concurrent Programming  Communication and Synchronization  Completing the Java Model  Overview of the.
Interprocess Communication
1 Concurrency: Mutual Exclusion and Synchronization Chapter 5.
Informationsteknologi Wednesday, September 26, 2007 Computer Systems/Operating Systems - Class 91 Today’s class Mutual exclusion and synchronization 
Scheduling Theory ITV Real-Time Systems Anders P. Ravn Aalborg University March 2007.
Big Picture Lab 4 Operating Systems Csaba Andras Moritz.
Programming R-T Abstractions TSW November 2009 Anders P. Ravn Aalborg University.
1 Concurrency: Mutual Exclusion and Synchronization Chapter 5.
1 CS318 Project #3 Preemptive Kernel. 2 Continuing from Project 2 Project 2 involved: Context Switch Stack Manipulation Saving State Moving between threads,
5.6 Semaphores Semaphores –Software construct that can be used to enforce mutual exclusion –Contains a protected variable Can be accessed only via wait.
Scheduling Theory ITV Multiprogramming and Real-Time Programs Anders P. Ravn Aalborg University May 2009.
© Andy Wellings, 2004 Roadmap  Introduction  Concurrent Programming  Communication and Synchronization  Completing the Java Model  Overview of the.
5.6.2 Thread Synchronization with Semaphores Semaphores can be used to notify other threads that events have occurred –Producer-consumer relationship Producer.
Monitors CSCI 444/544 Operating Systems Fall 2008.
Semaphores CSCI 444/544 Operating Systems Fall 2008.
Low-level Programming TSW November 2009 Anders P. Ravn Aalborg University.
The Implementation of Dynamic Priority Assignment on CVM Threading System Insik Shin Real-time Systems Group University of Pennsylvania.
A very simple kernel ITV Multiprogramming and Real-Time Programs Anders P. Ravn May 2009.
© 2004, D. J. Foreman 2-1 Concurrency, Processes and Threads.
Concurrency - 1 Tasking Concurrent Programming Declaration, creation, activation, termination Synchronization and communication Time and delays conditional.
The Real-Time Java Profile ITV Real-Time Systems Anders P. Ravn Aalborg University February 2006.
Real-Time Kernel (Part 1)
Object Oriented Programming Lecture 8: Introduction to laboratorial exercise – part II, Introduction to GUI frames in Netbeans, Introduction to threads.
Threads in Java. History  Process is a program in execution  Has stack/heap memory  Has a program counter  Multiuser operating systems since the sixties.
Quick overview of threads in Java Babak Esfandiari (extracted from Qusay Mahmoud’s slides)
Semaphores, Locks and Monitors By Samah Ibrahim And Dena Missak.
Concurrency Design Patterns
Concurrency: Mutual Exclusion and Synchronization Chapter 5.
Concurrency: Mutual Exclusion and Synchronization Chapter 5.
1 Concurrency: Mutual Exclusion and Synchronization Chapter 5.
1 Concurrency: Mutual Exclusion and Synchronization Chapter 5.
Chapter 6 – Process Synchronisation (Pgs 225 – 267)
Java Thread and Memory Model
Concurrency Control 1 Fall 2014 CS7020: Game Design and Development.
B. RAMAMURTHY 12/25/2015 Realtime System Fundamentals : Scheduling and Priority-based scheduling Pag e 1.
3/1/2016Page 1 Realtime System Fundamentals : Scheduling B. Ramamurthy.
Undergraduate course on Real-time Systems Linköping University TDDD07 Real-time Systems Lecture 2: Scheduling II Simin Nadjm-Tehrani Real-time Systems.
CSCI1600: Embedded and Real Time Software Lecture 17: Concurrent Programming Steven Reiss, Fall 2015.
Mutual Exclusion -- Addendum. Mutual Exclusion in Critical Sections.
Big Picture Lab 4 Operating Systems C Andras Moritz
Real-Time Threads Time dependent, usually wrt deadline –Periodic –Aperiodic –Sporadic Priority scheduled Fault tolerant.
CSE 120 Principles of Operating
CS703 – Advanced Operating Systems
Scheduling and Resource Access Protocols: Basic Aspects
Background on the need for Synchronization
G53SRP: Real Time Threads in RTSJ (part I)
EEE 6494 Embedded Systems Design
Process Synchronization and Communication
Realtime System Fundamentals : Scheduling and Priority-based scheduling B. Ramamurthy cse321-fall2014 9/20/2018.
Concurrency: Mutual Exclusion and Synchronization
Realtime System Fundamentals : Scheduling and Priority-based scheduling B. Ramamurthy 11/22/2018.
Realtime System Fundamentals : Scheduling and Priority-based scheduling B. Ramamurthy cse321-fall /27/2018.
Synchronization Issues
Midterm review: closed book multiple choice chapters 1 to 9
UNIVERSITY of WISCONSIN-MADISON Computer Sciences Department
Lecture 2 Part 2 Process Synchronization
Realtime System Fundamentals : Scheduling and Priority-based scheduling B. Ramamurthy Amrita-UB-MSES /11/2013.
CSCI1600: Embedded and Real Time Software
CSE 451: Operating Systems Autumn 2004 Module 6 Synchronization
CSE 451: Operating Systems Autumn 2003 Lecture 7 Synchronization
CSE 451: Operating Systems Autumn 2005 Lecture 7 Synchronization
CSE 451: Operating Systems Winter 2004 Module 6 Synchronization
CSE 451: Operating Systems Winter 2003 Lecture 7 Synchronization
CSE 153 Design of Operating Systems Winter 19
CSE 153 Design of Operating Systems Winter 2019
CSCI1600: Embedded and Real Time Software
Presentation transcript:

Software Engineering Lecture 5 Multiprogramming and Scheduling ASPI8-4 Anders P. Ravn March 2004

Overview 1.Concurrent processes - Java Threads 2.Mutual exclusion 3.Semaphores 4.Monitors - Java synchronized, wait, notify 5.Ada rendezvous

A kernel specification /* kernel.h Interface to a lightweight kernel that implements concurrent processes and a release primitive `pause'. Anders P. Ravn, DTU, Denmark 24 April 1998 typedef void (*Program)(void); /* A program text is a function without parameters*/ typedef void * Thread; /* identifier for a process */ extern Thread create(Program p,unsigned int stacksize); /* creates a process with a stack of the specified size and starts it executing the program. If there is insufficient memory, the result is NULL */ extern void pause(void); /* release the processor */

Multiprogramming #include ”kernel.h” void process() { /* do something */ pause(); /* do something */ } void main() { Thread p1, p2; p1 = create(&process,2000); /* p1 is started */ p2 = create(&process,1000); /* p2 is started */ /* the kernel will see to it that main is left when both p1 and p2 has exited */ }

A kernel implementation I typedef unsigned long Register; typedef struct x {struct x* next; Register esp;} Threaddescriptor; static Threaddesriptor* ready; /* queue of threads linked cyclically; ready points to last, the first is current */ #define current ready->next esp1esp2esp3 ready: current

A kernel implementation II void pause() { Register sp; __asm__(” pushal movl %esp,%sp"); /* sp -> |saved registers... | eip return from call */ DISABLE; /* scheduling */ current->esp = sp; ready = current; sp = current->esp; __asm__(" movl %sp,%esp popal" ); ENABLE; } esp1esp2esp3 ready: current stack1 stack2

A kernel implementation III pause:pushl %ebp movl %esp,%ebp pushal movl %esp,%ecx sp = esp movl ready,%eax movl (%eax),%edx current->esp movl %ecx,4(%edx) = sp movl %edx,ready ready = current movl (%edx),%edx movl 4(%edx),%ecx sp = current->esp movl %ecx,%esp popal leave ret

A kernel implementation IV pause: pushal movl ready,%eax movl (%eax),%edx current->esp movl %esp,4(%edx) = esp movl %edx,ready ready = current movl (%edx),%edx movl 4(%edx),%esp esp = current->esp popal ret

Java Threads import java.awt.*; class Process extends Thread { public Customer(...){...} public void run(){... // do something }... Process p1 = new Process(); p1.start();...

Shared Variables class Banking { /* shared variable balance and private withdrawals */ public int balance; public int[] wd; public Banking() { balance = 2000; wd = new int[2]; } // Invariant: // balance+wd[0]+wd[1] == 2000 }

Critical Section class Customer extends Thread { int id; Lock critical; Banking bank; public void run() { do { sleep( *id); critical.enter(id); int local = bank.balance; sleep(shortdelay); bank.balance = local-1; critical.leave(id); bank.wd[id]++; } while (true); } }

Semaphore public class Semaphore { int count; public Semaphore(int initial_value){ count= initial_value; } public synchronized void Wait(){ while(count == 0) wait(); --count; } public synchronized void signal(){ if (count++ == 0) notify(); }

Rendezvous

Scheduling 1.Periodic processes – cyclic executive 2.Fixed Priority Scheduling – Rate Monotonic 3.Response Time Analysis 4.Sporadic Processes 5.Blocking and priority inversion 6.Priority Ceiling protocols 7.Real-Time Java

Cyclic executive loop wait 25msinterrupt; a(); b(); c(); wait 25ms interrupt; a(); b(); d(); e(); wait 25ms interrupt; a(); b(); c(); wait 25ms interrupt; a(); b(); d(); end loop; ProcessT (period)C (wcet) a b 25 8 c 50 5 d 4 e 100 2

Utilization tests Utilization U = C/T Priority is rate (1/T) monotonic U U N  N( N  2 – 1)  (FPS) U U N  1 (Earliest Deadline First !?) Liu & Layland JACM, 1973

Response Time Analysis Response time R= C + I -- Interference I i =  R i /T N  C N  R i /T i+1  C i+1 (FPS) Joseph & Pandya Computer Journal 1986

Sporadic Processes Deadline D < T Priority is deadline (1/D) monotonic

Blocking Critical Regions V and Q locked by eg a semaphore. d(Q,V): EEEEBQ BQQVVEE c(V) : EEVV----VVEE b() : EEEE a(Q) : EEQQ QQQQQQ------EE Priority Inversion

Response Time Analysis Response time R= C + B + I K = (k1,..., km): resources used by a process of lower priority and by a process with a higher or equal prority B i = C k C km

Immediate Ceiling Protocol A resource uses the maximual priority of any process using it. K = (k1,..., km): resources used by a process of lower priority and by a process with a higher or equal prority B i = max C(k), k  K

Blocking ICPP d(Q,V): EEEEBQ BQQVVEE c(V) : EEVV----VVEE b() : EEEE a(Q) : EEQQ QQQQQQ------EE d(Q,V): BBEEEEQQVVEE c(V) : BBBBBB EEVVVVEE b() : BBBBBB EEEE a(Q) : EEQQQQQQQQ EE

Real-Time Java public class Periodic extends RealTimeThread{ public Periodic(PriorityParameters pp, PeriodicParameters p) {... } public void run(){ for (;;) {... waitForNextPeriod(); }

PeriodicParameters public class Periodicparameters... { public PeriodicParameters( HighResolutionTime start, RelativeTime period, RelativeTime cost, RelativeTime deadline, AsyncEventHandler overrunhandler, AsyncEventHandler misshandler){... }

And more