Big Picture Lab 4 Operating Systems C Andras Moritz

Slides:



Advertisements
Similar presentations
Operating Systems Part III: Process Management (Process Synchronization)
Advertisements

CAS3SH3 Midterm Review. The midterm 50 min, Friday, Feb 27 th Materials through CPU scheduling closed book, closed note Types of questions: True & False,
Ch. 7 Process Synchronization (1/2) I Background F Producer - Consumer process :  Compiler, Assembler, Loader, · · · · · · F Bounded buffer.
Chapter 6: Process Synchronization
Background Concurrent access to shared data can lead to inconsistencies Maintaining data consistency among cooperating processes is critical What is wrong.
5.1 Silberschatz, Galvin and Gagne ©2009 Operating System Concepts with Java – 8 th Edition Chapter 5: CPU Scheduling.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition, Chapter 6: Process Synchronization.
Process Synchronization. Module 6: Process Synchronization Background The Critical-Section Problem Peterson’s Solution Synchronization Hardware Semaphores.
Review: Chapters 1 – Chapter 1: OS is a layer between user and hardware to make life easier for user and use hardware efficiently Control program.
Big Picture Lab 4 Operating Systems Csaba Andras Moritz.
Page 1 Processes and Threads Chapter Processes 2.2 Threads 2.3 Interprocess communication 2.4 Classical IPC problems 2.5 Scheduling.
1/27/2010CSCI 315 Operating Systems Design1 Processes Notice: The slides for this lecture have been largely based on those accompanying an earlier version.
1/28/2004CSCI 315 Operating Systems Design1 Operating System Structures & Processes Notice: The slides for this lecture have been largely based on those.
Ceng Operating Systems Chapter 2.1 : Processes Process concept Process scheduling Interprocess communication Deadlocks Threads.
Chapter 11 Operating Systems
1/23/2008CSCI 315 Operating Systems Design1 Processes Notice: The slides for this lecture have been largely based on those accompanying the textbook Operating.
CSE451 Processes Spring 2001 Gary Kimura Lecture #4 April 2, 2001.
Processes April 5, 2000 Instructor: Gary Kimura Slides courtesy of Hank Levy.
Race Conditions CS550 Operating Systems. Review So far, we have discussed Processes and Threads and talked about multithreading and MPI processes by example.
Synchronization Solutions
Operating Systems CSE 411 CPU Management Oct Lecture 13 Instructor: Bhuvan Urgaonkar.
Process Management. Processes Process Concept Process Scheduling Operations on Processes Interprocess Communication Examples of IPC Systems Communication.
Object Oriented Analysis & Design SDL Threads. Contents 2  Processes  Thread Concepts  Creating threads  Critical sections  Synchronizing threads.
Implementing Processes and Process Management Brian Bershad.
Chapter 3: Processes. 3.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts - 7 th Edition, Feb 7, 2006 Process Concept Process – a program.
Lecture 3 Process Concepts. What is a Process? A process is the dynamic execution context of an executing program. Several processes may run concurrently,
Hardware process When the computer is powered up, it begins to execute fetch-execute cycle for the program that is stored in memory at the boot strap entry.
1 Chapter 2.1 : Processes Process concept Process concept Process scheduling Process scheduling Interprocess communication Interprocess communication Threads.
Process by Dr. Amin Danial Asham. References Operating System Concepts ABRAHAM SILBERSCHATZ, PETER BAER GALVIN, and GREG GAGNE.
ITEC 502 컴퓨터 시스템 및 실습 Chapter 2-1: Process Mi-Jung Choi DPNM Lab. Dept. of CSE, POSTECH.
Silberschatz, Galvin and Gagne  Operating System Concepts Chapter 3: Processes Process Concept Process Scheduling Operations on Processes Cooperating.
© 2000 Morgan Kaufman Overheads for Computers as Components Processes and operating systems  Operating systems.
© 2000 Morgan Kaufman Overheads for Computers as Components Processes and operating systems Operating systems. 1.
Silberschatz, Galvin and Gagne  Operating System Concepts Chapter 7: Process Synchronization Background The Critical-Section Problem Synchronization.
Silberschatz, Galvin and Gagne ©2013 Operating System Concepts Essentials – 9 th Edition Chapter 5: Process Synchronization.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition, Chapter 3: Process-Concept.
Java Thread and Memory Model
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition, Chapter 3: Process-Concept.
1 OS Review Processes and Threads Chi Zhang
Hardware process When the computer is powered up, it begins to execute fetch-execute cycle for the program that is stored in memory at the boot strap entry.
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.
Operating Systems CMPSC 473 Signals, Introduction to mutual exclusion September 28, Lecture 9 Instructor: Bhuvan Urgaonkar.
Slides created by: Professor Ian G. Harris Operating Systems  Allow the processor to perform several tasks at virtually the same time Ex. Web Controlled.
Chapter 3: Processes. 3.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts Chapter 3: Processes Process Concept Process Scheduling Operations.
Silberschatz, Galvin and Gagne  Operating System Concepts Chapter 4: Processes Process Concept Process Scheduling Types of shedulars Process.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition Chapter 6: Process Synchronization.
Mutual Exclusion -- Addendum. Mutual Exclusion in Critical Sections.
CSCI/CMPE 4334 Operating Systems Review: Exam 1 1.
1 Module 3: Processes Reading: Chapter Next Module: –Inter-process Communication –Process Scheduling –Reading: Chapter 4.5, 6.1 – 6.3.
Background on the need for Synchronization
Operating Systems (CS 340 D)
Lecture Topics: 11/1 Processes Process Management
Intro to Processes CSSE 332 Operating Systems
Chapter 5: Process Synchronization
Operating Systems (CS 340 D)
Lecture Topics: 11/1 General Operating System Concepts Processes
Processes Hank Levy 1.
Processes and operating systems
Concurrency: Mutual Exclusion and Process Synchronization
Chapter 6: Process Synchronization
Chapter 6: Synchronization Tools
Outline Chapter 2 (cont) Chapter 3: Processes Virtual machines
Processes Hank Levy 1.
Chapter 3: Processes Process Concept Process Scheduling
Chapter 3: Process Concept
Process/Thread Synchronization (Part 2)
Chapter 3: Process Management
Presentation transcript:

Big Picture Lab 4 Operating Systems C Andras Moritz

2 ECE 354 © Moritz 2008, Burleson 2010, Kundu 2011, Moritz 2013, some slides Wolf, Computers as Components, Morgan Kaufman, 2005 Readings Wolf, Computers as Components, Chapter 6 pp Multiple Tasks and Multiple Processes Pre-emptive Real-time Operating Systems Priority-Based Scheduling Interprocess Communication Mechanisms Evaluating OS Performance Power Management and Optimization for Processes Design Example Telephone Answering Machine

3 ECE 354 © Moritz 2008, Burleson 2010, Kundu 2011, Moritz 2013, some slides Wolf, Computers as Components, Morgan Kaufman, 2005 Operating system is just another program.. a big one  The operating system controls resources: who gets the CPU; when I/O takes place; how much memory is allocated.  The most important resource is the CPU itself. CPU access controlled by the scheduler of processes.  OS needs to keep track of: process priorities; scheduling state; process activation record.

4 ECE 354 © Moritz 2008, Burleson 2010, Kundu 2011, Moritz 2013, some slides Wolf, Computers as Components, Morgan Kaufman, 2005 Where is the OS?

5 ECE 354 © Moritz 2008, Burleson 2010, Kundu 2011, Moritz 2013, some slides Wolf, Computers as Components, Morgan Kaufman, 2005 Process Concept  Process = a program in execution (main thing to manage) process execution must progress in sequential fashion.  Processes may be created: statically before system starts; dynamically during execution.

6 ECE 354 © Moritz 2008, Burleson 2010, Kundu 2011, Moritz 2013, some slides Wolf, Computers as Components, Morgan Kaufman, 2005 Process State  As a process executes, it changes state  Each process may be in one of the following states (names vary across various OS): new: The process is being created. running: Instructions are being executed. waiting: The process is waiting for some event to occur. ready: The process is waiting to be assigned to a processor. terminated: The process has finished execution.

7 ECE 354 © Moritz 2008, Burleson 2010, Kundu 2011, Moritz 2013, some slides Wolf, Computers as Components, Morgan Kaufman, 2005 Diagram of Process State in the OS

8 ECE 354 © Moritz 2008, Burleson 2010, Kundu 2011, Moritz 2013, some slides Wolf, Computers as Components, Morgan Kaufman, 2005 Process Control Block (PCB)  Information associated with each process in the OS, i.e., the process related data structure.  The PCB contains: Process state (running, waiting, …) Program counter (value of PC) Stack pointer, General purpose CPU registers CPU scheduling information (e.g., priority) Memory-management information Username of owner I/O status information Pointer to state queues,..

9 ECE 354 © Moritz 2008, Burleson 2010, Kundu 2011, Moritz 2013, some slides Wolf, Computers as Components, Morgan Kaufman, 2005 Process Control Block (PCB)

10 ECE 354 © Moritz 2008, Burleson 2010, Kundu 2011, Moritz 2013, some slides Wolf, Computers as Components, Morgan Kaufman, 2005 Example Process State in Memory What you wrote: void X(int b){ If (b==1).. } main(){ int a = 2; X(a); } In memory: PC->

11 ECE 354 © Moritz 2008, Burleson 2010, Kundu 2011, Moritz 2013, some slides Wolf, Computers as Components, Morgan Kaufman, 2005 Single and Multithreaded Processes  A thread = stream of execution  Benefits?

12 ECE 354 © Moritz 2008, Burleson 2010, Kundu 2011, Moritz 2013, some slides Wolf, Computers as Components, Morgan Kaufman, 2005 Example of Memory Layout with Threads main() { …… fork_thread(producer); fork_thread(consumer); …… } producer() { …… } consumer(){ ……. }

13 ECE 354 © Moritz 2008, Burleson 2010, Kundu 2011, Moritz 2013, some slides Wolf, Computers as Components, Morgan Kaufman, 2005 Embedded vs. general-purpose scheduling  Workstations try to avoid starving processes of CPU access. Fairness = access to CPU.  Embedded systems must meet deadlines. Low-priority processes may not run for a long time.  Priority Driven scheduling Each process has a priority. CPU goes to highest-priority process that is ready.

14 ECE 354 © Moritz 2008, Burleson 2010, Kundu 2011, Moritz 2013, some slides Wolf, Computers as Components, Morgan Kaufman, 2005 CPU Switch From Process to Process

15 ECE 354 © Moritz 2008, Burleson 2010, Kundu 2011, Moritz 2013, some slides Wolf, Computers as Components, Morgan Kaufman, 2005 Interprocess Communication  Interprocess communication (IPC): OS provides mechanisms so that processes can pass data.

16 ECE 354 © Moritz 2008, Burleson 2010, Kundu 2011, Moritz 2013, some slides Wolf, Computers as Components, Morgan Kaufman, 2005 IPC Styles  Shared memory: processes have some memory in common; must cooperate to avoid destroying/missing messages.  Message passing: processes send messages along a communication channel---no common address space.

17 ECE 354 © Moritz 2008, Burleson 2010, Kundu 2011, Moritz 2013, some slides Wolf, Computers as Components, Morgan Kaufman, 2005 Critical Regions  Critical region: section of code that cannot be interrupted by another process.  Examples: writing shared memory; accessing I/O device.

18 ECE 354 © Moritz 2008, Burleson 2010, Kundu 2011, Moritz 2013, some slides Wolf, Computers as Components, Morgan Kaufman, 2005 Shared Memory  Shared memory on a bus: CPU 1CPU 2 memory

19 ECE 354 © Moritz 2008, Burleson 2010, Kundu 2011, Moritz 2013, some slides Wolf, Computers as Components, Morgan Kaufman, 2005 Race Condition in Shared Memory  Problem when two CPUs try to write the same location: CPU 1 reads flag and sees 0. CPU 2 reads flag and sees 0. CPU 1 sets flag to one and writes location with 123. CPU 2 sets flag to one and overwrites location with 456. CPU 1 thinks value is 123 since it checked flag but it is 456!

20 ECE 354 © Moritz 2008, Burleson 2010, Kundu 2011, Moritz 2013, some slides Wolf, Computers as Components, Morgan Kaufman, 2005 Synchronization Hardware – ISA Support  E.g.,: Test and modify the content of a word atomically  Below pseudo-code for the hardware would implement in ISA. boolean TestAndSet(boolean &target) { boolean rv = target; target = true; return rv; }

21 ECE 354 © Moritz 2008, Burleson 2010, Kundu 2011, Moritz 2013, some slides Wolf, Computers as Components, Morgan Kaufman, 2005 Mutual Exclusion Lock with Test-and-Set Can be used to implement a simple lock Shared data: boolean lock = false; Process P i do { while (TestAndSet(lock)) ; critical section lock = false; remainder section } Wait here/test until/if Lock is TRUE, If it is not, set it and continue

22 ECE 354 © Moritz 2008, Burleson 2010, Kundu 2011, Moritz 2013, some slides Wolf, Computers as Components, Morgan Kaufman, 2005 Semaphores  Semaphore: OS primitive for controlling access to critical regions. Based on test-and-set or swap at implementation level Binary semaphors similar to mutex locks shown earlier conceptually Counting semaphors allow some # of players access to critical section  Protocol: Get access to semaphore. Perform critical region operations. Release semaphore.

23 ECE 354 © Moritz 2008, Burleson 2010, Kundu 2011, Moritz 2013, some slides Wolf, Computers as Components, Morgan Kaufman, 2005 Backup

24 ECE 354 © Moritz 2008, Burleson 2010, Kundu 2011, Moritz 2013, some slides Wolf, Computers as Components, Morgan Kaufman, 2005 What do you need to design a real embedded system?  You know how to interface to simple switches and lights  You know how to use memory of different types (SRAM, DRAM, EEPROM, Flash)  You know how to interface to serial I/O (UART, USB, SPI, GPIO)  You know how to interface to Ethernet/Internet  You know how to write programs and process data in C  What’s next?  Running multiple programs  Real-time?  Reliability? Security? Upgradeability?  You need an Operating System!

25 ECE 354 © Moritz 2008, Burleson 2010, Kundu 2011, Moritz 2013, some slides Wolf, Computers as Components, Morgan Kaufman, 2005 Atomic test-and-set in ARM ISA  ARM test-and-set provided by SWP: single bus operation reads memory location, tests it, writes it.  Example mutex lock implementation