ECE291 Computer Engineering II Lecture 15 Dr. Zbigniew Kalbarczyk University of Illinois at Urbana- Champaign.

Slides:



Advertisements
Similar presentations
Concurrency: Mutual Exclusion and Synchronization Chapter 5.
Advertisements

Ch. 7 Process Synchronization (1/2) I Background F Producer - Consumer process :  Compiler, Assembler, Loader, · · · · · · F Bounded buffer.
Chapter 6 Process Synchronization Bernard Chen Spring 2007.
Chapter 6: Process Synchronization
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition, Chapter 6: Process Synchronization.
CH7 discussion-review Mahmoud Alhabbash. Q1 What is a Race Condition? How could we prevent that? – Race condition is the situation where several processes.
1 Friday, June 16, 2006 "In order to maintain secrecy, this posting will self-destruct in five seconds. Memorize it, then eat your computer." - Anonymous.
CSC 501 Lecture 2: Processes. Von Neumann Model Both program and data reside in memory Execution stages in CPU: Fetch instruction Decode instruction Execute.
OS2-1 Chapter 2 Computer System Structures. OS2-2 Outlines Computer System Operation I/O Structure Storage Structure Storage Hierarchy Hardware Protection.
Review: Operating System Manages all system resources ALU Memory I/O Files Objectives: Security Efficiency Convenience.
3.5 Interprocess Communication
Chapter 11 Operating Systems
Real-Time Kernels and Operating Systems. Operating System: Software that coordinates multiple tasks in processor, including peripheral interfacing Types.
CSSE Operating Systems
1 Process Description and Control Chapter 3 = Why process? = What is a process? = How to represent processes? = How to control processes?
A. Frank - P. Weisberg Operating Systems Introduction to Cooperating Processes.
Operating Systems (CSCI2413) Lecture 3 Processes phones off (please)
1/26/2007CSCI 315 Operating Systems Design1 Processes Notice: The slides for this lecture have been largely based on those accompanying the textbook Operating.
Process Description and Control A process is sometimes called a task, it is a program in execution.
Introduction to Embedded Systems
CE Operating Systems Lecture 5 Processes. Overview of lecture In this lecture we will be looking at What is a process? Structure of a process Process.
1 Previous lecture review n Out of basic scheduling techniques none is a clear winner: u FCFS - simple but unfair u RR - more overhead than FCFS may not.
CSC 501 Lecture 2: Processes. Process Process is a running program a program in execution an “instantiation” of a program Program is a bunch of instructions.
Object Oriented Analysis & Design SDL Threads. Contents 2  Processes  Thread Concepts  Creating threads  Critical sections  Synchronizing threads.
Chapter 3: Processes. 3.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts - 7 th Edition, Feb 7, 2006 Process Concept Process – a program.
Recall: Three I/O Methods Synchronous: Wait for I/O operation to complete. Asynchronous: Post I/O request and switch to other work. DMA (Direct Memory.
Computer Architecture and Operating Systems CS 3230: Operating System Section Lecture OS-1 Process Concepts Department of Computer Science and Software.
Lecture 3 Process Concepts. What is a Process? A process is the dynamic execution context of an executing program. Several processes may run concurrently,
8-Sep Operating Systems Yasir Kiani. 8-Sep Agenda for Today Review of previous lecture Process scheduling concepts Process creation and termination.
Silberschatz, Galvin and Gagne  Operating System Concepts Chapter 3: Processes Process Concept Process Scheduling Operations on Processes Cooperating.
Processes. Chapter 3: Processes Process Concept Process Scheduling Operations on Processes Cooperating Processes Interprocess Communication Communication.
Computer Studies (AL) Operating System Process Management - Process.
Processes – Part I Processes – Part I. 3.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts Review on OSs Upon brief introduction of OSs,
11/13/20151 Processes ICS 240: Operating Systems –William Albritton Information and Computer Sciences Department at Leeward Community College –Original.
Concurrency: Mutual Exclusion and Synchronization Chapter 5.
Chapter 7 -1 CHAPTER 7 PROCESS SYNCHRONIZATION CGS Operating System Concepts UCF, Spring 2004.
Silberschatz, Galvin and Gagne  Operating System Concepts Chapter 4: Processes Process Concept Process Scheduling Operations on Processes Cooperating.
Concurrency & Context Switching Process Control Block What's in it and why? How is it used? Who sees it? 5 State Process Model State Labels. Causes of.
CE Operating Systems Lecture 2 Low level hardware support for operating systems.
1 Computer Systems II Introduction to Processes. 2 First Two Major Computer System Evolution Steps Led to the idea of multiprogramming (multiple concurrent.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition, Chapter 3: Process-Concept.
1 VxWorks 5.4 Group A3: Wafa’ Jaffal Kathryn Bean.
CE Operating Systems Lecture 2 Low level hardware support for operating systems.
© Janice Regan, CMPT 300, May CMPT 300 Introduction to Operating Systems Operating Systems Processes and Threads.
13-1 Chapter 13 Concurrency Topics Introduction Introduction to Subprogram-Level Concurrency Semaphores Monitors Message Passing Java Threads C# Threads.
Chapter 2 Process Management. 2 Objectives After finish this chapter, you will understand: the concept of a process. the process life cycle. process states.
Operating Systems (CS 340 D) Dr. Abeer Mahmoud Princess Nora University Faculty of Computer & Information Systems Computer science Department.
Processes. Process Concept Process Scheduling Operations on Processes Interprocess Communication Communication in Client-Server Systems.
Lecture Topics: 11/15 CPU scheduling: –Scheduling goals and algorithms.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition, Chapter 3: Processes.
Silberschatz, Galvin and Gagne ©2011 Operating System Concepts Essentials – 8 th Edition Chapter 2: The Linux System Part 3.
Embedded Computer - Definition When a microcomputer is part of a larger product, it is said to be an embedded computer. The embedded computer retrieves.
Chapter 3: Processes. 3.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts Chapter 3: Processes Process Concept Process Scheduling Operations.
Assembly Language Co-Routines
1 5-High-Performance Embedded Systems using Concurrent Process (cont.)
CE Operating Systems Lecture 8 Process Scheduling continued and an introduction to process synchronisation.
Copyright © Curt Hill More on Operating Systems Continuation of Introduction.
Introduction to operating systems What is an operating system? An operating system is a program that, from a programmer’s perspective, adds a variety of.
Lecturer 5: Process Scheduling Process Scheduling  Criteria & Objectives Types of Scheduling  Long term  Medium term  Short term CPU Scheduling Algorithms.
1 Module 3: Processes Reading: Chapter Next Module: –Inter-process Communication –Process Scheduling –Reading: Chapter 4.5, 6.1 – 6.3.
Processes and threads.
Topic 3 (Textbook - Chapter 3) Processes
Background on the need for Synchronization
Chapter 3: Process Concept
Operating Systems (CS 340 D)
CS 143A Quiz 1 Solution.
Operating Systems Lecture 6.
Process & its States Lecture 5.
Lecture 2 Part 2 Process Synchronization
Computer Science & Engineering Electrical Engineering
Presentation transcript:

ECE291 Computer Engineering II Lecture 15 Dr. Zbigniew Kalbarczyk University of Illinois at Urbana- Champaign

Z. KalbarczykECE291 Outline Multitasking, concurrency, real-time –DOS processes –Multitasking –Interrupt driven multitasking

Z. KalbarczykECE291 Multitasking, Concurrency, Real-Time Depending on how the timesharing is administered by the operating system, it can appears as though the programs are executing simultaneously Multitasking is difficult to achieve when running DOS Multitasking is not trivial, but it is not that difficult when you write an application with multitasking specifically in mind –you can, however, write programs that multitasks under DOS if you take some precautions

Z. KalbarczykECE291 Issues How do we schedule tasks so that they meet their deadlines? How do we coordinate operations perform by different tasks? How do we control access to shared resources? How do we ensure consistency of shared data?

Z. KalbarczykECE291 DOS Processes Under DOS several programs can be loaded into memory at one time DOS provides ability to run one program at the time When a DOS application is running, it can load and execute some other program using the DOS EXEC function When an application (the parent) runs a second program (the child) the child process executes to completion and then returns to the parent DOS provides several functions (members of INT 21) to –load and execute program code (function 4Bh) –terminate processes (function 4Ch) –obtain the exit status for the process (function 4Dh)

Z. KalbarczykECE291 Shared Memory Problem with running different DOS programs as part of single application is inter-process communication How do all these programs talk to one another? The ideal solution would be to keep a copy of various variables in shared memory (memory that appears in the address space of two or more processes) Most modern multitasking operating systems provide for shared memory MS-DOS does not support shared memory –solution is to write a resident program that provides this capability

Z. KalbarczykECE291 Coroutines A primary drawback of DOS processes, even when using shared memory, is that each program executes to completion before returning control to the parent process A common paradigm is for two programs to swap control of the CPU back and forth while executing The mechanism used is often called co-routine The 80x86 CPUs do not provide a cocall instruction –a cocall is effectively a call and a return instruction all as one operation

Z. KalbarczykECE291 Call Sequence Between Two Processes Using cocalls control transfers between the two processes When the second process calls the first, control resumes not at the beginning of the first process but immediately after the cocall operation To preserve consistency of processes we need to maintain the current state of a process (process control block) CoCall Process 1 Process 2

Z. KalbarczykECE291 Multitasking Co-routines provide reasonable mechanism for switching between processes that must take turns In reality not always all processes need to take turns The basic idea behind multitasking is that one process runs for a period of time (the time quantum or time slice) and the timer interrupts the process The timer ISR saves the state of the process and then switches control to another process We need a timer ISR that cocall the various processes, one per timer interrupt A timer interrupt that switches between processes is a dispatcher

Z. KalbarczykECE291 Multitasking Designing a dispatcher we need to decide on a policy for the process scheduling algorithm –Round-robin place all processes on the queue and then rotate them tradeoff between a time quantum and overhead in switching between different processes –Preemptive scheduling higher priority process can interrupt lower priority process –Non-Preemptive scheduling processes run until they finish.

Z. KalbarczykECE291 Multitasking Synchronization Cooperative concurrently executing processes must be synchronize The producer-consumer problem (famous problem from operating system theory) –one or more processes that produce data and write the data to a shared buffer –one or more consumers that read data from this buffer –system must ensure that the producers do not produce more data than the buffer can hold –consumers do not remove data from an empty buffer –preserve integrity of the buffer data structure by allowing access to only one process at a time

Z. KalbarczykECE291 Multitasking Synchronization (example problem) Consider the following fragment of a consumer code (after fetching a byte of data from a circular buffer) DECMyBuffer.Count INCMyBuffer.OutPtr CMP MyBuffer.OutPtr, MaxBufSize JBNoWrap MOV MyBuffer.OutPtr, 0 NoWrap: If after the interrupt (as it is marked) the control is transfers to another consumer which reenters this portion of code, the second consumer will malfunction The end result is that two consumers processes fetch the same data and then skip a byte in the circular buffer An interrupt occurs here

Z. KalbarczykECE291 Multitasking Synchronization Critical Section The previous problem is easy to solve by recognizing the fact that the code that manipulates the buffer data is a critical region (section) Restrict the execution of the critical region to one process at the time Reentrancy can be prevented by turning the interrupts off while in the critical region CLI: CLear Interrupt enable –Retain full control of CPU STI: SeT Interrupt enable –Allow other routines to be serviced

Z. KalbarczykECE291 Multitasking Synchronization Critical Section Turning the Interrupts off does not always work –critical regions may take considerable amount of time (seconds, minutes) and you cannot leave the interrupts off for that amount of time) –critical region can call a procedure that turns the interrupts back on and you have no control over this (e.g., procedures that calls DOS) Synchronization objects known as semaphores provides an efficient, general purpose mechanism for protecting critical regions –when a process wants to use a given resource, it waits on the semaphore –if no other process is currently using the resource, then the wait call sets the semaphore to in-us and returns to the process

Z. KalbarczykECE291 Real-Time ISR Scheduling Artificial Heart Example

Z. KalbarczykECE291 Assumptions Assume that all requests are buffered If multiple tasks occur while the CPU is busy, they will be sequentially processed when the task is scheduled until –the CPU is interrupted with the higher priority interrupt or –there are no more tasks to execute Interrupts with lower-numbered priorities are always serviced before higher-numbered priorities The time to switch between interrupts is negligible Tasks are independent of each other

Z. KalbarczykECE291 Real-Time ISR Scheduling (cont.) Consider ISRs for the Jarvic 2000 artificial heart Task Pri. Run Time Deadline Event Freq. Event Period CPU Load BP 1 1 ms 3 ms 100 Hz 10 ms 10% OX 2 5 ms 20 ms 50 Hz 20 ms 25% PH 2 10 ms 20 ms 10 Hz 100 ms 10% VAG 3 1 ms 25 ms 200 Hz 5 ms 20%

Z. KalbarczykECE291 Real-Time Characteristics of the Jarvic-Heart Base on the data in the table determine the worst-case completion time for each of the tasks for two cases: –preemptive scheduling –non-preemptive scheduling