Today’s agenda Lab3 assigned (Due: Oct 28) Midterm Review

Slides:



Advertisements
Similar presentations
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.
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,
PA0 due today Anyone tried to submit?. Scheduling Workload assumptions Arrive time, run time, I/O, etc. Policies: FIFO, SJF, STCF, RR, MLFQ, and lottery.
Ch. 7 Process Synchronization (1/2) I Background F Producer - Consumer process :  Compiler, Assembler, Loader, · · · · · · F Bounded buffer.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition, Chapter 6: Process Synchronization.
Cpr E 308 Spring 2004 Recap for Midterm Introductory Material What belongs in the OS, what doesn’t? Basic Understanding of Hardware, Memory Hierarchy.
Operating Systems CMPSC 473 Mutual Exclusion Lecture 13: October 12, 2010 Instructor: Bhuvan Urgaonkar.
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.
Introduction to Operating Systems – Windows process and thread management In this lecture we will cover Threads and processes in Windows Thread priority.
Processes 1 CS502 Spring 2006 Processes Week 2 – CS 502.
1 Process Description and Control Chapter 3 = Why process? = What is a process? = How to represent processes? = How to control processes?
CS 153 Design of Operating Systems Spring 2015 Midterm Review.
CS 153 Design of Operating Systems Spring 2015 Lecture 11: Scheduling & Deadlock.
Scheduling Basic scheduling policies, for OS schedulers (threads, tasks, processes) or thread library schedulers Review of Context Switching overheads.
Lecture 3 Process Concepts. What is a Process? A process is the dynamic execution context of an executing program. Several processes may run concurrently,
Cpr E 308 Spring 2004 Real-time Scheduling Provide time guarantees Upper bound on response times –Programmer’s job! –Every level of the system Soft versus.
CSE 451: Operating Systems Section 5 Midterm review.
1 Review of Process Mechanisms. 2 Scheduling: Policy and Mechanism Scheduling policy answers the question: Which process/thread, among all those ready.
CS399 New Beginnings Jonathan Walpole. 2 Concurrent Programming & Synchronization Primitives.
Processes, Threads, and Process States. Programs and Processes  Program: an executable file (before/after compilation)  Process: an instance of a program.
CSE 153 Design of Operating Systems Winter 2015 Midterm Review.
Concurrency in Shared Memory Systems Synchronization and Mutual Exclusion.
Chapter 2 Process Management. 2 Objectives After finish this chapter, you will understand: the concept of a process. the process life cycle. process states.
What is an Operating System? Various systems and their pros and cons –E.g. multi-tasking vs. Batch OS definitions –Resource allocator –Control program.
Slides created by: Professor Ian G. Harris Operating Systems  Allow the processor to perform several tasks at virtually the same time Ex. Web Controlled.
3/1/2016Page 1 Realtime System Fundamentals : Scheduling B. Ramamurthy.
CE Operating Systems Lecture 8 Process Scheduling continued and an introduction to process synchronisation.
Mutual Exclusion -- Addendum. Mutual Exclusion in Critical Sections.
Big Picture Lab 4 Operating Systems C Andras Moritz
Process Synchronization. Concurrency Definition: Two or more processes execute concurrently when they execute different activities on different devices.
Multiprogramming. Readings r Chapter 2.1 of the textbook.
Deadlock and Starvation
Interprocess Communication Race Conditions
Processes and threads.
Process Management Process Concept Why only the global variables?
Chapter 3: Process Concept
Sarah Diesburg Operating Systems COP 4610
Process Synchronization: Semaphores
Background on the need for Synchronization
IS310 Hardware & Network Infrastructure Ronny L
Process management Information maintained by OS for process management
תרגול 4 – ניהול תהליכים, מבני נתונים למימוש תהליכים
ICS 143 Principles of Operating Systems
Realtime System Fundamentals : Scheduling and Priority-based scheduling B. Ramamurthy 11/22/2018.
Xinu Semaphores.
Processes in Unix, Linux, and Windows
Processor Fundamentals
Synchronization Issues
Semaphore Originally called P() and V() wait (S) { while S <= 0
Today’s agenda Lab 1 Module 4: Process Management
Process Description and Control
Today’s agenda Hardware architecture and runtime system
Lecture 2 Part 2 Process Synchronization
Realtime System Fundamentals : Scheduling and Priority-based scheduling B. Ramamurthy Amrita-UB-MSES /11/2013.
Concurrency: Mutual Exclusion and Process Synchronization
CSE 451: Operating Systems Winter 2003 Lecture 6 Scheduling
February 5, 2004 Adrienne Noble
CSE 451: Operating Systems Autumn 2003 Lecture 7 Synchronization
CS510 Operating System Foundations
CSE 153 Design of Operating Systems Winter 19
CS333 Intro to Operating Systems
Today’s agenda ~10min: file system (UNIX) ~1hr: final review + Q&A
CSE 153 Design of Operating Systems Winter 2019
Chapter 6: Scheduling Algorithms Dr. Amjad Ali
CSE 451 Section 1/27/2000.
CSE 153 Design of Operating Systems Winter 2019
EECE.4810/EECE.5730 Operating Systems
Chapter 3: Process Management
CSE 451: Operating Systems Winter 2001 Lecture 6 Scheduling
Sarah Diesburg Operating Systems CS 3430
Presentation transcript:

Today’s agenda Lab3 assigned (Due: Oct 28) Midterm Review Synchronization: deadlock (recap) CS354-Fall2018

Midterm: Thursday October 11, 6:30 PM-7:30PM, Lilly 1105 Bring your ID (will be checked) Closed book/note/phone/laptop/other electronic Chapter 1-7 + supplementary materials + labs + xinu’s source codes CS354-Fall2018

Midterm Questions T/F will use bubblesheet Short-answer questions Scheduling Synchronization CS354-Fall2018

A Big Picture OS overview Process: concurrent execution Process scheduling Process synchronization + XINU implementation + Supplementary materials for scheduling policies and other synchronization forms CS354-Fall2018

OS Overview OS services OS abstractions between System call Provides abstract computing environment Supplies computational services Manages resources Hides low-level hardware details OS abstractions between API to user space (above) Hardware (below) System call OS service: allocate resources CS354-Fall2018

Sample Questions Quiz 1 [True] Kprintf() is a system call provided by XINU. What else is a system call? Quiz 1 [True] Some instructions cannot be executed in user mode. user mode and privileged mode CS354-Fall2018

XINU Process – Unique process identifier – Owner (e.g., a user) – Scheduling priority – Location of code and all data (including the stack) – Status of the computation – Current program counter – Current values of registers CS354-Fall2018

Process (Process.h) /* Definition of the process table (multiple of 32 bits) */ struct procent { /* Entry in the process table */ uint16 prstate; /* Process state: PR_CURR, etc. */ pri16 prprio; /* Process priority */ char *prstkptr; /* Saved stack pointer */ char *prstkbase; /* Base of run time stack */ uint32 prstklen; /* Stack length in bytes */ char prname[PNMLEN]; /* Process name */ uint32 prsem; /* Semaphore on which process waits */ pid32 prparent; /* ID of the creating process */ umsg32 prmsg; /* Message sent to this process */ bool8 prhasmsg; /* Nonzero iff msg is valid */ int16 prdesc[NDESC]; /* Device descriptors for process */ }; prstate The current status of the process (e.g., whether the process is currently executing or waiting) prprio The scheduling priority of the process prstkptr The saved value of the process’s stack pointer when the process is not executing prstkbase The address of the base of the process’s stack CS354-Fall2018

Process States States: current, ready, suspended, waiting … #define PR_FREE 0 /* Process table entry is unused */ #define PR_CURR 1 /* Process is currently running */ #define PR_READY 2 /* Process is on ready queue */ #define PR_RECV 3 /* Process waiting for message */ #define PR_SLEEP 4 /* Process is sleeping */ #define PR_SUSP 5 /* Process is suspended */ #define PR_WAIT 6 /* Process is on semaphore queue */ #define PR_RECTIM 7 /* Process is receiving with timeout */ Q: What is a legible process? Or what processes will be considered by resched()? Quiz1:  [False] The Xinu scheduler always chooses to run a process that has highest priority. It chooses from eligible processes which are current running or ready to run. CS354-Fall2018

Process: concurrent execution, scheduling & synchronization CS354-Fall2018

Something you must know in XINU (1) create() resume() suspend() ready() resched() wait() signal() kill() ctxsw() nulluser() semcreate() semdelete() CS354-Fall2018

What call resched() or ready()? ready() calls resched() right away. suspend()? resume()? create()? signal()? [True] [True] [False] why? Suspended [True] CS354-Fall2018

When to call resched() Four cases: Current process is no longer eligible Chprio A process becomes eligible Clock interrupt handler Note: choose the highest-priority one among eligible processes (current or ready) CS354-Fall2018

Which process can call suspend()? Similar questions: which process can call create(), resume(), or kill()… ? suspend(): by itself and other process kill(): by itself and other processes resume(): by other process create(): by other process CS354-Fall2018

How to kill() a process? kill.c … PR_CURR: // suicide prptr->prstate = PR_FREE; resched() PR_WAIT: // increments semaphore count semtab[prptr->prsem].scount++; PR_READY: // remove from queue getitem(pid); CS354-Fall2018

Scheduling Three steps Scheduling policy context switch Examine processes that are eligible for execution Select a process to run Switch the processor to the selected process Scheduling policy XINU: At any time, the processor must be executing a highest priority eligible process. Among processes with equal priority, scheduling is round robin. context switch CS354-Fall2018

Scheduling Policy Preemptive vs non-preemptive FCFS? RR? SJF? SRTF? How do they compare with each other? Fairness? Completion time? Waiting time? … Starvation? CPU burst length and quantum How to set quantum? Multi-level Feedback Queue scheduling CS354-Fall2018

Sample Questions Quiz1 [False] The default XINU scheduler is starvation-free [False] RR is always better than FCFS. When RR = FCFS? (quantum = infinity) When FCFS is better than RR? (exec time is equal for each process) [True] CPU-intensive processes typically have longer burst length than for those non-CPU-intensive processes CS354-Fall2018

Sample Questions (con’d) Process Burst Time p1 24 ms p2 3 ms p3 P1 P2 P3 P1 P1 10 3 3 10 4 RR (quantum =10): Average completion time = (13+16+30)/3=19.6 ms How about FCFS, SRTF? CS354-Fall2018

Context Switch A context switch is triggered by Low-level Usually written in assembly language Called by scheduler A context switch is triggered by a hardware interrupt resched() Steps: Given a new process N, and old process O Save copy of all information pertinent to O on process O’s stack or the process table entry for process O Load saved information for N Resume execution of N CS354-Fall2018

Sample Questions Quiz1 [True] The value of the stack pointer is updated during the context switching operation. [False] No context switch can occur during the execution of the function when interrupts are disabled at the beginning of a system call The current process may give it up. Which process executes the context switch code? Both O and N (first O and then N) At any time, one process must be executing. All user processes may be blocked (e.g., in a situation when all applications are waiting for input). Which process executes? NULLPROC CS354-Fall2018

Interrupt Template For System Calls disable() at the start restore() at the end Quiz 2 [False] OS can handle interrupt in many ways. It can examine current interrupt mask. It can also explicitly disable and enable interrupts in system calls. OS can clear interrupt mask to allow interrupts but it can't explicitly enable interrupts in system calls. CS354-Fall2018

Process Coordination Two approaches Hardware: busy waiting Handling mutex exclusion with spinlock also called test-and-set Pros and cons? Pros: It worked in multicore Cons: it doesn’t work in single core; a spin lock is wasteful as a process merely blocks in a loop until access is granted OS: Mutual exclusion CS354-Fall2018

High-Level Mutual Exclusion Counting semaphore semcreate(), wait(), signal(), semdelete() semtab struct sentry semtab[NSEM]; /* Semaphore table */ sentry: scount and queue (waiting process) CS354-Fall2018

Mutual Exclusion With Semaphores Initialize: create a mutex semaphore sid = semcreate(1); Use: bracket critical sections of code with calls to wait and signal wait(sid); ...critical section (use shared resource)... signal(sid); CS354-Fall2018

Producer-Consumer Synchronization With Semaphores Two semaphores suffice (why?) Initialize: create producer and consumer semaphores psem = semcreate(buffer-size); csem = semcreate(0); Producer: ? wait(?); CS; signal (?); Consumer? Producer: repeat forever { wait(psem); fill_next_buffer_slot; signal(csem); } wait(csem); extract_from_buffer_slot; signal(psem); CS354-Fall2018

What values will be scount? semaphore count (scount) A nonnegative semaphore count means that the set of processes is empty. A count of negative N means that the set contains N waiting processes. max? min? CS354-Fall2018

Semaphore Queuing Policy Determines which process to select among those waiting Needed when signal called FCFS (XINU) See signal() … if ((semptr->scount++) < 0) { /* Release a waiting process */ ready(dequeue(semptr->squeue)); } CS354-Fall2018

Wait() …. if (--(semptr->scount) < 0) { /* If caller must block */ prptr = &proctab[currpid]; prptr->prstate = PR_WAIT; prptr->prsem = sem; /* Record semaphore ID */ enqueue(currpid,semptr->squeue); resched(); /* and reschedule */ } CS354-Fall2018

semcreate() and semdelete() semcreate(): dynamic (xinu) Semaphores are created at runtime – More flexible semtab (global table) semdelete() XINU: make process ready when one or more processes may be waiting when semaphore is deleted How? CS354-Fall2018

semdelete() … resched_cntl(DEFER_START); while (semptr->scount++ < 0) { /* Free all waiting processes */ ready(getfirst(semptr->squeue)); } resched_cntl(DEFER_STOP);   CS354-Fall2018

Reader-Writer problem How different from producer-consumer problem? Implementation in the lecture Writer: starvation Implementation variations (see Quiz2) Unbounded Priority Inversion Why it occurs? How to fix it? CS354-Fall2018

Deadlock Dining-Philosophers Problem Bridge Crossing Example Resource allocation graph no cycles  no deadlock a cycle  deadlock CS354-Fall2018

Deadlock (more) Supplementary lecture CS354-Fall2018

Something you must know in XINU (2) currpid NULLPROC (always eligible) proctab semtab readylist: sorted, double-linked readylist = newqueue(); The current process does not appear on the ready list queuetab: struct qentry queuetab[NQENT]; /* Table of process queues */ readylist sleeplist insert(pid32 pid, qid16 q, int32 key) firstkey(), last getitem() // remove from the queue In the XINU queue table (queuetab), the current process will be linked into one of the lists enqueue() dequeue() CS354-Fall2018

Final word: Go through all the materials Slides Quizs Labs XINU Source codes Good luck! CS354-Fall2018