Starting the Threads

Similar documents
Properties of Processes

Scheduling of processes

OPERATING SYSTEMS CS3502 Spring Processor Scheduling. Chapter 5

Chapter 6: CPU Scheduling. Operating System Concepts 9 th Edition

CPU Scheduling. Operating Systems (Fall/Winter 2018) Yajin Zhou ( Zhejiang University

Preview. Process Scheduler. Process Scheduling Algorithms for Batch System. Process Scheduling Algorithms for Interactive System

Operating Systems. Scheduling

Operating System Concepts Ch. 5: Scheduling

CPU Scheduling Algorithms

CS370 Operating Systems

Lecture 5 / Chapter 6 (CPU Scheduling) Basic Concepts. Scheduling Criteria Scheduling Algorithms

Chapter 6: CPU Scheduling

Last Class: Processes

Processes. CS 475, Spring 2018 Concurrent & Distributed Systems

1.1 CPU I/O Burst Cycle

CSE 120 Principles of Operating Systems Spring 2017

Review. Preview. Three Level Scheduler. Scheduler. Process behavior. Effective CPU Scheduler is essential. Process Scheduling

CS370: System Architecture & Software [Fall 2014] Dept. Of Computer Science, Colorado State University

CPU Scheduling. Daniel Mosse. (Most slides are from Sherif Khattab and Silberschatz, Galvin and Gagne 2013)

Operating Systems. Lecture Process Scheduling. Golestan University. Hossein Momeni

8: Scheduling. Scheduling. Mark Handley

CPU Scheduling. The scheduling problem: When do we make decision? - Have K jobs ready to run - Have N 1 CPUs - Which jobs to assign to which CPU(s)

CISC 7310X. C05: CPU Scheduling. Hui Chen Department of Computer & Information Science CUNY Brooklyn College. 3/1/2018 CUNY Brooklyn College

Course Syllabus. Operating Systems

CS 318 Principles of Operating Systems

Job Scheduling. CS170 Fall 2018

Chapter 9 Uniprocessor Scheduling

Uniprocessor Scheduling. Aim of Scheduling

Uniprocessor Scheduling. Aim of Scheduling. Types of Scheduling. Long-Term Scheduling. Chapter 9. Response time Throughput Processor efficiency

CS3733: Operating Systems

Assignment 3 (Due date: Thursday, 10/15/2009, in class) Part One: Provide brief answers to the following Chapter Exercises questions:

Unit 3 : Process Management

CPU Scheduling. The scheduling problem: When do we make decision? - Have K jobs ready to run - Have N 1 CPUs - Which jobs to assign to which CPU(s)

CPU Scheduling (1) CPU Scheduling (Topic 3) CPU Scheduling (2) CPU Scheduling (3) Resources fall into two classes:

Homework Assignment #5

CPU Scheduling. Schedulers. CPSC 313: Intro to Computer Systems. Intro to Scheduling. Schedulers in the OS

CSE 4/521 Introduction to Operating Systems

ALL the assignments (A1, A2, A3) and Projects (P0, P1, P2) we have done so far.

CPU Scheduling. Basic Concepts. Histogram of CPU-burst Times. Dispatcher. CPU Scheduler. Alternating Sequence of CPU and I/O Bursts

Lecture Topics. Announcements. Today: Uniprocessor Scheduling (Stallings, chapter ) Next: Advanced Scheduling (Stallings, chapter

CS370 Operating Systems

Operating Systems ECE344. Ding Yuan

CPU Scheduling. CSE 2431: Introduction to Operating Systems Reading: Chapter 6, [OSC] (except Sections )

Uniprocessor Scheduling

COSC243 Part 2: Operating Systems

Process Scheduling. Copyright : University of Illinois CS 241 Staff

CS370 Operating Systems

CPU Scheduling: Objectives

Announcements. Program #1. Program #0. Reading. Is due at 9:00 AM on Thursday. Re-grade requests are due by Monday at 11:59:59 PM.

CSC Operating Systems Spring Lecture - XII Midterm Review. Tevfik Ko!ar. Louisiana State University. March 4 th, 2008.

Scheduling. The Basics

3. CPU Scheduling. Operating System Concepts with Java 8th Edition Silberschatz, Galvin and Gagn

Announcements. Reading. Project #1 due in 1 week at 5:00 pm Scheduling Chapter 6 (6 th ed) or Chapter 5 (8 th ed) CMSC 412 S14 (lect 5)

Chapter 5: CPU Scheduling

Frequently asked questions from the previous class survey

Last class: Today: CPU Scheduling. CPU Scheduling Algorithms and Systems

Chapter 5: CPU Scheduling

Scheduling. Today. Next Time Process interaction & communication

Chapter 5 CPU scheduling

Scheduling in the Supermarket

Operating Systems. Process scheduling. Thomas Ropars.

Chapter 6: CPU Scheduling. Operating System Concepts 9 th Edition

So far. Next: scheduling next process from Wait to Run. 1/31/08 CSE 30341: Operating Systems Principles

CSE120 Principles of Operating Systems. Prof Yuanyuan (YY) Zhou Scheduling

Uniprocessor Scheduling. Chapter 9

CSE 120 Principles of Operating Systems

Chap 7, 8: Scheduling. Dongkun Shin, SKKU

Introduction to Operating Systems Prof. Chester Rebeiro Department of Computer Science and Engineering Indian Institute of Technology, Madras

OPERATING SYSTEMS. UNIT II Sections A, B & D. An operating system executes a variety of programs:

Chapter 5: CPU Scheduling

CHAPTER 2: PROCESS MANAGEMENT

CPU Scheduling: Part I ( 5, SGG) Operating Systems. Autumn CS4023

CS307: Operating Systems

Chapter 5: CPU Scheduling. Operating System Concepts Essentials 8 th Edition

Ch 4 : CPU scheduling

CSE 120. Fall Lecture 8: Scheduling and Deadlock. Keith Marzullo

CS370 Operating Systems

CPU scheduling. Alternating sequence of CPU and I/O bursts. P a g e 31

Uniprocessor Scheduling. Basic Concepts Scheduling Criteria Scheduling Algorithms. Three level scheduling

OPERATING SYSTEMS. After A.S.Tanenbaum, Modern Operating Systems, 3rd edition. Uses content with permission from Assoc. Prof. Florin Fortis, PhD

CPU Scheduling. Rab Nawaz Jadoon. Assistant Professor DCS. Pakistan. COMSATS, Lahore. Department of Computer Science

Operating Systems Comprehensive Exam. Spring Student ID # 2/17/2011

Scheduling Bits & Pieces

LECTURE 3:CPU SCHEDULING

Chapter 9. Uniprocessor Scheduling

Chapter 5: CPU Scheduling. Operating System Concepts 8 th Edition,

CPU Scheduling. The scheduling problem: When do we make decision? - Have K jobs ready to run - Have N 1 CPUs - Which jobs to assign to which CPU(s)

Chapter 5: Process Scheduling

Operating Systems CS 323 Ms. Ines Abbes

Chapter 6: CPU Scheduling

Operating Systems: Quiz2 December 15, Class: No. Name:

Scheduling Mar. 19, 2018

Practice Exercises 305

Process- Concept &Process Scheduling OPERATING SYSTEMS

FCM 710: Architecture of Secure Operating Systems

CSC 716 Advanced Operating System Fall 2007 Exam 1. Answer all the questions. The maximum credit for each question is as shown.

Announcements. Program #1. Reading. Due 2/15 at 5:00 pm. Finish scheduling Process Synchronization: Chapter 6 (8 th Ed) or Chapter 7 (6 th Ed)

Programming Assignment HW4: CPU Scheduling v03/17/19 6 PM Deadline March 28th, 2019, 8 PM. Late deadline with penalty March 29th, 2019, 8 PM

Sample Questions. Amir H. Payberah. Amirkabir University of Technology (Tehran Polytechnic)

CSL373: Lecture 6 CPU Scheduling

Transcription:

NachOS Example Administrivia You ve just been hired by Mother Nature to help her out with the chemical reaction to form water, which she doesn t seem to be able to get right due to synchronization problems. The trick is to get two H atoms and one O atom all together at the same time. The atoms are threads. Each H atom invokes a procedure hready when it s ready to react, and each O atom invokes a procedure oready when it s ready. For this problem, you are to write the code for hready and oready. The procedures must delay until there are at least two H atoms and one O atom present, and then one of the procedures must call the procedure makewater (which just prints out a debug message that water was made). After the makewater call, two instances of hready and one instance of oready should return. Write the code for hready and oready using either semaphores or locks and condition variables for synchronization. Your solution must avoid starvation and busy-waiting. Last time Some synchronization problems Started CPU Scheduling Today NachOS I project overview (Another set of slides) CPU Scheduling SUNY-BINGHAMTON CS350 SPRING 08 LEC. #10 3 SUNY-BINGHAMTON CS350 SPRING 08 LEC. #10 1 SUNY-BINGHAMTON CS350 SPRING 08 LEC. #10 4 Place this code in threadtest.cc and call it from ThreadTest() Have a simple menu to test the different parts of the project; call the approporiate method depending on user selection void Water() { Thread *t; int i; for(i=0;i<5;i++) { t = new Thread("Oxygen"); t->fork(oready,i); t = new Thread("Hydrogen"); t->fork(hready,i); t = new Thread("Hydrogen"); t->fork(hready,i+5); Starting the Threads Due 10/11 Walkthrough one per person please email me team information (2 preferred, 1 is fine, 3 please talk to me) What is in a walkthrough? three things A brief trace of the code as it is now explaining how it produces the output that it does Your plan for implementing any two parts in the project Answers to the questions in the walkthrough link on class page 2-3 pages max. SUNY-BINGHAMTON CS350 SPRING 08 LEC. #10 2

oready, hready and makewater Sample Run Semaphore *Hydro = new Semaphore("H",0); Semaphore *Oxy = new Semaphore("O",0); void makewater(int i) { printf("oxygen Made Water %d\n", i); void oready(int i) { Oxy->P(); Oxy->P(); makewater(i); Hydro->V(); Hydro->V(); void hready(int i) { Oxy->V(); Hydro->P(); printf("hydrogen %d participated in making water and e bingsun2%./nachos -rs 100101 Oxygen Made Water 2 Hydrogen 2 participated in making water and exited Hydrogen 7 participated in making water and exited Oxygen Made Water 3 Hydrogen 3 participated in making water and exited Hydrogen 8 participated in making water and exited Oxygen Made Water 0 Hydrogen 0 participated in making water and exited Hydrogen 5 participated in making water and exited Oxygen Made Water 1 Hydrogen 1 participated in making water and exited Hydrogen 6 participated in making water and exited Oxygen Made Water 4 Hydrogen 4 participated in making water and exited Hydrogen 9 participated in making water and exited No threads ready or runnable, and no pending interrupts. Assuming the program completed. Machine halting! SUNY-BINGHAMTON CS350 SPRING 08 LEC. #10 5 SUNY-BINGHAMTON CS350 SPRING 08 LEC. #10 6 CPU Scheduling Potential Criteria Recall: Long-term: may I come in? medium-term: to swap or not to swap short-term: scheduling of ready processes our focus How/When: sometimes non-preemptive scheduling (no other choice) occurs process switches from running to waiting state process switches from running to ready (when an interrupt occurs) process switches from being blocked to ready process terminates All other scheduling is preemptive Scheduling problem: process to run next how do we decide what What criteria should the scheduler worry about optimizing? Response time: minimize the amount of delay experienced by users (average? max? variance?) Turnaround time: minimize time between beginning and end of each job Waiting time: minimize the waiting time for each process CPU utilization: maximize the amount of work done by the CPU Throughput: maximize the number of processes completed per time unit Priority: give priorities to some processes over others Real-time scheduling: maximimze deadlines met Fairness: give processes fair access to the CPU (how to define that?) SUNY-BINGHAMTON CS350 SPRING 08 LEC. #10 7 SUNY-BINGHAMTON CS350 SPRING 08 LEC. #10 8

other? Criteria can be conflicting Usually want to optimize for one of the above Process Behavior Alternating CPU and I/O bursts (think of your own programs) Most CPU bursts are short (some are long) CPU vs. I/O bound process classification CPU bound very infrequent I/O (e.g., a numerical simulation) I/O bound frequent I/O (e.g., a database application) Hysteresis resist change When we preemptively switch between processes, we pay for context switch CPU utilization reduced, but response time also reduced SUNY-BINGHAMTON CS350 SPRING 08 LEC. #10 9 SUNY-BINGHAMTON CS350 SPRING 08 LEC. #10 10 First Come First Serve P1 0 5 P2 1 2 P3 4 10 P4 5 1 Idea: schedule processes in the order they arrive Non-preemptive; a process continues running until blocked or terminated Gantt charts (space time charts) are used to illustrate scheduling What do you think of this policy? SUNY-BINGHAMTON CS350 SPRING 08 LEC. #10 11 FCFS Discussion Is it fair? Non-preemptive, so CPU utilization is maximized What happens if a short process gets stuck behind a long process (e.g., 1msec and 10 msec processes that arrive together) More precisely, what is the average waiting time per process; is it minimized by FCFS? Consider the case where an I/O bound process and a CPU bound process are being scheduled what happens? Can we do better? SUNY-BINGHAMTON CS350 SPRING 08 LEC. #10 12

Round Robin (RR) Scheduling Shortest Job First Scheduling (SJF) Each process gets a small unit of CPU time (called quantum) Quantum usually 10-100msecs When this time has passed (quantum expires), the process is preempted The process is added to the end of the ready queue What do you think? What if we make the quantum (q) very large? What if we make q very small? Idea: Pick the shortest process to run next Provably optimal in minimizing average wait time (for nonpreemptive) Redo the Gantt chart for the example Comments/Problems? How does it compare to SJF and FCFS? SUNY-BINGHAMTON CS350 SPRING 08 LEC. #10 15 SUNY-BINGHAMTON CS350 SPRING 08 LEC. #10 13 Example P1 0 7 P2 2 4 P3 3 2 P4 4 4 Assume the time quantum is 1 (what if 2, 5 or 10?) What is the average wait time, turnaround time, response time? What is the number of context switches? SUNY-BINGHAMTON CS350 SPRING 08 LEC. #10 14 Keep an exponential average of the burst length for the process; use it as estimate τn+1 = αtn + (1 α)τn α high, react quickly to changes (but might get fooled by a transient value) α low, react slow, but immune to transients And just how do we know what the burst length is ahead of time? Still a problem if a short process gets stuck behind a long process (any way to fix that?) Starvation of long processes SJF Discussion SUNY-BINGHAMTON CS350 SPRING 08 LEC. #10 16

Discussion What should q be? Unfair to I/O bound processes why? Solution have I/O bound processes come back to a higher priority SUNY-BINGHAMTON CS350 SPRING 08 LEC. #10 17 Highest Response Ratio Next P1 0 1 P2 2 4 P3 3 3 P4 7 2 Intuition favor short processes, but give credit for long processes that have been waiting a long time Optimize the normalized turnaround value Define the Response Ratio as w+s s, where w is the wait time and s is the service time Non-preemptive (can we have a preemptive version? this was a homework problem last year) SUNY-BINGHAMTON CS350 SPRING 08 LEC. #10 18