Processes and Non-Preemptive Scheduling

Slides:



Advertisements
Similar presentations
Processes and Threads Chapter 3 and 4 Operating Systems: Internals and Design Principles, 6/E William Stallings Patricia Roy Manatee Community College,
Advertisements

More on Processes Chapter 3. Process image _the physical representation of a process in the OS _an address space consisting of code, data and stack segments.
Chapter 3 Process Description and Control
CSC 501 Lecture 2: Processes. Von Neumann Model Both program and data reside in memory Execution stages in CPU: Fetch instruction Decode instruction Execute.
Thursday, June 08, 2006 The number of UNIX installations has grown to 10, with more expected. The UNIX Programmer's Manual, 2nd Edition, June, 1972.
Page 1 Processes and Threads Chapter Processes 2.2 Threads 2.3 Interprocess communication 2.4 Classical IPC problems 2.5 Scheduling.
Forking & Process Scheduling Vivek Pai / Kai Li Princeton University.
1 Process Description and Control Chapter 3. 2 Process Management—Fundamental task of an OS The OS is responsible for: Allocation of resources to processes.
CSCE 351: Operating System Kernels
Advanced OS Chapter 3p2 Sections 3.4 / 3.5. Interrupts These enable software to respond to signals from hardware. The set of instructions to be executed.
CSSE Operating Systems
1 Process Description and Control Chapter 3 = Why process? = What is a process? = How to represent processes? = How to control processes?
Threads CS 416: Operating Systems Design, Spring 2001 Department of Computer Science Rutgers University
Operating Systems (CSCI2413) Lecture 3 Processes phones off (please)
Process Description and Control A process is sometimes called a task, it is a program in execution.
Chapter 51 Threads Chapter 5. 2 Process Characteristics  Concept of Process has two facets.  A Process is: A Unit of resource ownership:  a virtual.
Process Description and Control Chapter 3. Major Requirements of an OS Interleave the execution of several processes to maximize processor utilization.
Chapter 3 Process Description and Control
Lecture 3 Process Concepts. What is a Process? A process is the dynamic execution context of an executing program. Several processes may run concurrently,
1 Chapter 2.1 : Processes Process concept Process concept Process scheduling Process scheduling Interprocess communication Interprocess communication Threads.
8-Sep Operating Systems Yasir Kiani. 8-Sep Agenda for Today Review of previous lecture Process scheduling concepts Process creation and termination.
Processes – Part I Processes – Part I. 3.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts Review on OSs Upon brief introduction of OSs,
Processes and Process Control 1. Processes and Process Control 2. Definitions of a Process 3. Systems state vs. Process State 4. A 2 State Process Model.
Processes CS 6560: Operating Systems Design. 2 Von Neuman Model Both text (program) and data reside in memory Execution cycle Fetch instruction Decode.
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.
1 Computer Systems II Introduction to Processes. 2 First Two Major Computer System Evolution Steps Led to the idea of multiprogramming (multiple concurrent.
Processes, Threads, and Process States. Programs and Processes  Program: an executable file (before/after compilation)  Process: an instance of a program.
Chapter 2 Process Management. 2 Objectives After finish this chapter, you will understand: the concept of a process. the process life cycle. process states.
1 Process Description and Control Chapter 3. 2 Process A program in execution An instance of a program running on a computer The entity that can be assigned.
Threads prepared and instructed by Shmuel Wimer Eng. Faculty, Bar-Ilan University 1July 2016Processes.
Processes and Threads Chapter 3 and 4 Operating Systems: Internals and Design Principles, 6/E William Stallings Patricia Roy Manatee Community College,
Processes and threads.
Process concept.
Process Management Process Concept Why only the global variables?
CS 6560: Operating Systems Design
Chapter 2 Processes and Threads Today 2.1 Processes 2.2 Threads
Process Management Presented By Aditya Gupta Assistant Professor
Operating Systems: A Modern Perspective, Chapter 6
Intro to Processes CSSE 332 Operating Systems
System Structure and Process Model
System Structure and Process Model
Structure of Processes
Lecture 2: Processes Part 1
System Structure B. Ramamurthy.
More examples How many processes does this piece of code create?
System Structure and Process Model
Operating Systems Lecture 6.
Process & its States Lecture 5.
Chapter 3: Processes.
Process Description and Control
Process Description and Control
Threads Chapter 4.
Operating Systems Processes (Ch 4.1).
Chapter 2 Processes and Threads 2.1 Processes 2.2 Threads
Process Description and Control
Process Control B.Ramamurthy 2/22/2019 B.Ramamurthy.
Process Description and Control
Process Description and Control
Process Description and Control
Process Description and Control
Lecture 6: Multiprogramming and Context Switching
Chapter 3: Processes.
Unix Process Control B.Ramamurthy 4/11/2019 B.Ramamurthy.
Implementing Processes, Threads, and Resources
Processes in Unix and Windows
Chapter 2 Processes and Threads 2.1 Processes 2.2 Threads
CS510 Operating System Foundations
Process Description and Control
Process Description and Control in Unix
Process Description and Control in Unix
Presentation transcript:

Processes and Non-Preemptive Scheduling Lars Ailo Bongo, Tore Larsen University of Tromsø Otto J. Anshus University of Tromsø, University of Oslo Kai Li Princeton University

An aside on concurrency Timing and sequencing of events are key concurrency issues We will study classical OS concurrency issues, including implementation and use of classic OS mechanisms to support concurrency In later courses on parallel programming you will revisit this material In a later course on distributed systems you may want to use formal tools to better understand and model timing and sequencing Emerging CPUs are typically multi core, and multi threaded Challenges and opportunities to design cost-effective high-performance systems. INF-2201, Tore Brox-Larsen, Spring 2015

INF-2201, Tore Brox-Larsen, Spring 2015 Process (I) An instance of a program under execution Program specifying (logical) control-flow (thread) Data Private address space Open files Running environment The most important operating system concept Used for supporting the concurrent execution of independent or cooperating program instances Used to structure applications and systems INF-2201, Tore Brox-Larsen, Spring 2015

INF-2201, Tore Brox-Larsen, Spring 2015 Processes (II) Classical processes were, using today’s terminology; “Single Threaded” Sequential program: Single process Parallel program: Multiple cooperating processes INF-2201, Tore Brox-Larsen, Spring 2015

INF-2201, Tore Brox-Larsen, Spring 2015 Processes (III) “Modern” process: “Process” and “Thread” are separated as concepts Process—Unit of Resource Allocation—Defines the context Thread—Control Thread—Unit of execution, scheduling Every process must contain one or more threads Every (?) thread exists within the context of a process INF-2201, Tore Brox-Larsen, Spring 2015

User- and Kernel-Level Thread Support User-level threads within a process are Indiscernible by OS Scheduled by (user-level) scheduler in process Kernel-level threads Maintained by OS Scheduled by OS INF-2201, Tore Brox-Larsen, Spring 2015

Supporting and Using Processes Multiprogramming Supporting concurrent execution (parallel or transparently interleaved) of multiple processes (or threads). Achieved by process- or context switching, switching the CPU(s) back and forth among the individual processes, keeping track of each process’ progress Concurrent programs Programs (or threads) that exploit multiprogramming for some purpose (e.g. performance, structure) Operating systems is important application area for concurrent programming. Many others (event driven programs, servers, ++) INF-2201, Tore Brox-Larsen, Spring 2015

Implementing processes OS needs to keep track of all processes Keep track of it’s progress Parent process Metadata (priorities etc.) used by OS Memory management File management Process table with one entry (Process Control Block) per process Will also align processes in queues INF-2201, Tore Brox-Larsen, Spring 2015

Primitives of Processes Creation and termination fork, exec, wait, kill Signals Action, Return, Handler Operations block, yield Synchronization We will talk about this later INF-2201, Tore Brox-Larsen, Spring 2015

INF-2201, Tore Brox-Larsen, Spring 2015 fork (UNIX) Spawns a new process (with new PID) Called in parent process Returns in parent and child process Return value in parent is child’s PID Return value in child is ’0’ Child gets duplicate, but separate, copy of parent’s user-level virtual address space Child gets identical copy of parent’s open file descriptors INF-2201, Tore Brox-Larsen, Spring 2015

INF-2201, Tore Brox-Larsen, Spring 2015 fork, exec, wait, kill Return value tested for error, zero, or positive Zero, this is the child process Typically redirect standard files, and Call Exec to load a new program instead of the old Positive, this is the parent process Wait, parent waits for child’s termination Wait issued before corresponding exit: Parent blocks until exit Exit issued before corresponding wait: Child becomes zombie (un-dead) until wait Kill, specified process terminates INF-2201, Tore Brox-Larsen, Spring 2015

When may OS switch contexts? Only when OS runs Events potentially causing a context switch: Process created (fork) Process exits (exit) Process blocks implicitly (I/O, IPC) Process blocks explicitly (yield) User or System Level Trap HW SW: User level System Call Exception Kernel preempts current process Potential scheduling decision at “any of above” +“Timer” to be able to limit running time of processes Non-Preemptive scheduling Preemptive scheduling INF-2201, Tore Brox-Larsen, Spring 2015

Context Switching Issues Performance Should be no more than a few microseconds Most time is spent SAVING and RESTORING the context of processes Less processor state to save, the better Pentium has a multitasking mechanism, but SW can be faster if it saves less of the state How to save time on the copying of context state? Re-map (address) instead of copy (data) Where to store Kernel data structures “shared” by all processes Memory How to give processes a fair share of CPU time Preemptive scheduling, time-slice defines maximum time interval between scheduling decisions INF-2201, Tore Brox-Larsen, Spring 2015

! Example Process State Transitions PC P4 P3 P2 P1 MULTIPROGRAMMING U s e r L e v e l P r o c e s s e s PC P4 P3 P2 P1 MULTIPROGRAMMING Uniprocessor: Interleaving (“pseudoparallelism”) Multiprocessor: Overlapping (“true paralellism”) ! KERNEL Trap Handler Service Trap Return Handler P2 BlockedQueue Running Blocked Ready Resource becomes available (move to ready queue) Create a process Terminate (call scheduler) Yield Block for resource Scheduler dispatch Scheduler Dispatcher P4 P3 ReadyQueue Current P1 PCB’s Memory resident part

Process State Transition of Non-Preemptive Scheduling Running Blocked Ready Resource becomes available (move to ready queue) Create a process Terminate (call scheduler) Yield Block for resource Scheduler dispatch

INF-2201, Tore Brox-Larsen, Spring 2015 Scheduler Non-preemptive scheduler invoked by explicit block or yield calls, possibly also fork and exit The simplest form Scheduler: save current process state (store to PCB) choose next process to run dispatch (load PCB and run) Does this work? PCB (something) must be resident in memory Remember the stacks INF-2201, Tore Brox-Larsen, Spring 2015

INF-2201, Tore Brox-Larsen, Spring 2015 Stacks Remember: We have only one copy of the Kernel in memory => all processes “execute” the same kernel code => Must have a kernel stack for each process Used for storing parameters, return address, locally created variables in frames or activation records Each process user stack kernel stack always empty when process is in user mode executing instructions Does the Kernel need its own stack(s)? INF-2201, Tore Brox-Larsen, Spring 2015

INF-2201, Tore Brox-Larsen, Spring 2015 More on Scheduler Should the scheduler use a special stack? Yes, because a user process can overflow and it would require another stack to deal with stack overflow because it makes it simpler to pop and push to rebuild a process’s context Must have a stack when booting... Should the scheduler simply be a “kernel process”? You can view it that way because it has a stack, code and its data structure This process always runs when there is no user process “Idle” process In kernel or at user level? INF-2201, Tore Brox-Larsen, Spring 2015

INF-2201, Tore Brox-Larsen, Spring 2015 Win NT Idle No runable thread exists on the processor Dispatch Idle Process (really a thread) Idle is really a dispatcher in the kernel Enable interrupt; Receive pending interrupts; Disable interrupts; Analyze interrupts; Dispatch a thread if so needed; Check for deferred work; Dispatch thread if so needed; Perform power management; INF-2201, Tore Brox-Larsen, Spring 2015

Threads and Processes Project OpSys Trad. Threads Process Threads Processes in individual address spaces Process Threads Kernel threads User Level Kernel Address Space Kernel Level

Where Should PCB Be Saved? Save the PCB on user stack Many processors have a special instruction to do it efficiently But, need to deal with the overflow problem When the process terminates, the PCB vanishes Save the PCB on the kernel heap data structure May not be as efficient as saving it on stack But, it is very flexible and no other problems INF-2201, Tore Brox-Larsen, Spring 2015

INF-2201, Tore Brox-Larsen, Spring 2015 Job swapping The processes competing for resources may have combined demands that results in poor system performance Reducing the degree of multiprogramming by moving some processes to disk, and temporarily not consider them for execution may be a strategy to enhance overall system performance From which states(s), to which state(s)? Try extending the following examples using two suspended states. Check&relate: MOS 3e.: Ch. 2.1.7, 3.2.1 and 3.3 INF-2201, Tore Brox-Larsen, Spring 2015

Job Swapping, ii Swap in Swap out Partially executed swapped-out processes Swap out Ready Queue CPU Terminate I/O I/O Waiting queues INF-2201, Tore Brox-Larsen, Spring 2015

Add Job Swapping to State Transition Diagram Running Blocked Ready Create a process Terminate (call scheduler) Yield Block for resource Scheduler dispatch Resource becomes available (move to ready queue) Swap out Swap in Swapped INF-2201, Tore Brox-Larsen, Spring 2015

Concurrent Programming w/ Processes Clean programming model File tables are shared User address space is private Processes are protected from each other Sharing requires some sort of IPC (InterProcess Communication) Slower execution Process switch, process control expensive IPC expensive INF-2201, Tore Brox-Larsen, Spring 2015

I/O Multiplexing: More than one State Machine per Process select blocks for any of multiple specified I/O events Handle (one of the events) that unblocks select Advance appropriate state machine Repeat See http://csapp.cs.cmu.edu/public/ch12-preview.pdf INF-2201, Tore Brox-Larsen, Spring 2015

Concurrent prog. w/ I/O Multiplexing Establishes several control flows (state machines) in one process Uses select Offers application programmer more control than processor model Easy sharing of data among state machines More efficient (no process switch to switch between control flows in same process) Possibly trickier programming INF-2201, Tore Brox-Larsen, Spring 2015