Introduction to Nachos Scheduling

Similar documents
Virtual Memory In Nachos

CSE 120 Principles of Computer Operating Systems Fall Quarter, 2002 Halloween Midterm Exam. Instructor: Geoffrey M. Voelker

Using the Debugger. Michael Jantz Dr. Prasad Kulkarni

Semaphores in Nachos. Dr. Douglas Niehaus Michael Jantz Dr. Prasad Kulkarni. EECS 678 Nachos Semaphores Lab 1

Task 1: Run Nachos with Pre-implemented Scheduling System Skeleton

The Shell, System Calls, Processes, and Basic Inter-Process Communication

Administrivia. Nachos guide and Lab #1 are on the web.

CS355 Hw 4. Interface. Due by the end of day Tuesday, March 20.

Processes. Dr. Yingwu Zhu

Solving the Producer Consumer Problem with PThreads

Lecture 17: Threads and Scheduling. Thursday, 05 Nov 2009

CS 326: Operating Systems. Process Execution. Lecture 5

Processes Prof. James L. Frankel Harvard University. Version of 6:16 PM 10-Feb-2017 Copyright 2017, 2015 James L. Frankel. All rights reserved.

Operating Systems Comprehensive Exam. Spring Student ID # 3/16/2006

Course Syllabus. Operating Systems

Pebbles Kernel Specification September 26, 2004

Processes. CS 475, Spring 2018 Concurrent & Distributed Systems

Review: Program Execution. Memory program code program data program stack containing procedure activation records

Review: Program Execution. Memory program code program data program stack containing procedure activiation records

CSE 120 Principles of Operating Systems

Preview. The Thread Model Motivation of Threads Benefits of Threads Implementation of Thread

Scheduling. Scheduling 1/51

Precept 2: Non-preemptive Scheduler. COS 318: Fall 2018

Announcements/Reminders

Lecture 5: Synchronization w/locks

Processes. Operating System CS 217. Supports virtual machines. Provides services: User Process. User Process. OS Kernel. Hardware

Jan 20, 2005 Lecture 2: Multiprogramming OS

Spring CS 170 Exercise Set 1 (Updated with Part III)

OS 1 st Exam Name Solution St # (Q1) (19 points) True/False. Circle the appropriate choice (there are no trick questions).

Last Class: CPU Scheduling. Pre-emptive versus non-preemptive schedulers Goals for Scheduling: CS377: Operating Systems.

Processes and Threads

Virtual Memory. Virtual Memory. Demand Paging. valid-invalid bit. Virtual Memory Larger than Physical Memory

Processes. Overview. Processes. Process Creation. Process Creation fork() Processes. CPU scheduling. Pål Halvorsen 21/9-2005

CS370 Operating Systems

Operating Systems. Lecture 4. Nachos Appetizer

Virtual Memory. CSCI 315 Operating Systems Design Department of Computer Science

Process Time. Steven M. Bellovin January 25,

Operating Systems Structure

Computer Systems II. First Two Major Computer System Evolution Steps

IT 540 Operating Systems ECE519 Advanced Operating Systems

Scheduling. Scheduling 1/51

Questions answered in this lecture: CS 537 Lecture 19 Threads and Cooperation. What s in a process? Organizing a Process

CSE 120 Principles of Operating Systems

Scheduling Mar. 19, 2018

Mid Term from Feb-2005 to Nov 2012 CS604- Operating System

Review: Program Execution. Memory program code program data program stack containing procedure activation records

Project #1 Exceptions and Simple System Calls

Threads. Still Chapter 2 (Based on Silberchatz s text and Nachos Roadmap.) 3/9/2003 B.Ramamurthy 1

Introduction to PThreads and Basic Synchronization

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

CSE 120 Principles of Operating Systems

CS370 Operating Systems

Lecture 4: Memory Management & The Programming Interface

Mon Sep 17, 2007 Lecture 3: Process Management

ECE 7650 Scalable and Secure Internet Services and Architecture ---- A Systems Perspective. Part I: Operating system overview: Processes and threads

Announcements Processes: Part II. Operating Systems. Autumn CS4023

Process- Concept &Process Scheduling OPERATING SYSTEMS

Real Time and Embedded Systems. by Dr. Lesley Shannon Course Website:

mywbut.com UNIX Operating System

CS 3733 Operating Systems

* What are the different states for a task in an OS?

Operating Systems Comprehensive Exam. Spring Student ID # 3/20/2013

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.

ELEC 377 Operating Systems. Week 1 Class 2

int $0x32 // call interrupt number 50

(MCQZ-CS604 Operating Systems)

Lecture 4: Threads; weaving control flow

EECS 678: Intro to Operating Systems Programming Assignment 3: Virtual Memory in Nachos

OPERATING SYSTEMS. COMS W1001 Introduction to Information Science. Boyi Xie

Threads and Concurrency

ECE 550D Fundamentals of Computer Systems and Engineering. Fall 2017

CS 326: Operating Systems. CPU Scheduling. Lecture 6

CS370 Operating Systems

Processes. Process Management Chapter 3. When does a process gets created? When does a process gets terminated?

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)

SMD149 - Operating Systems

TDIU25: Operating Systems II. Processes, Threads and Scheduling

CS 153 Design of Operating Systems Winter 2016

Processes and Non-Preemptive Scheduling. Otto J. Anshus

Process Description and Control. Chapter 3

Chapter 4: Threads. Operating System Concepts 9 th Edit9on

Scheduling in the Supermarket

Scheduling. Scheduling. Scheduling. Scheduling Criteria. Priorities. Scheduling

An Operating System in Action

CHAPTER 2: PROCESS MANAGEMENT

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

Q1. State True/false with jusification if the answer is false:

CS3733: Operating Systems

Review: Program Execution. Memory program code program data program stack containing procedure activation records

System Call. Preview. System Call. System Call. System Call 9/7/2018

Chap 4, 5: Process. Dongkun Shin, SKKU

CS 31: Intro to Systems Operating Systems Overview. Kevin Webb Swarthmore College March 31, 2015

Operating Systems 2014 Assignment 2: Process Scheduling

Operating System Concepts Ch. 5: Scheduling

CPS221 Lecture: Operating System Functions

Chapter 5: CPU Scheduling

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

Motivation of Threads. Preview. Motivation of Threads. Motivation of Threads. Motivation of Threads. Motivation of Threads 9/12/2018.

Announcement. Exercise #2 will be out today. Due date is next Monday

Introducing User Programs into Nachos

Transcription:

Introduction to Nachos Scheduling Michael Jantz Dr. Prasad Kulkarni 1

Introduction In this lab, we will become acquainted with the Nachos simulator, and make a slight change to its scheduling semantics. Untar the Nachos tar file that came with this lab. Also, make it, and tag the source: tar xvzf nachos.tar.gz cd nachos; make ctags -R 2

Nachos Overview Nachos is an operating system simulation that runs in a single Unix process. It implements a multi-process model using POSIX PThreads. The OS level activities are implemented as C++ code and execute as a normal process. User-level processes are each allocated a PThread and are interpreted and executed by the MIPS machine simulator. Unlike a real OS, Nachos doesn't run on bare hardware. To simulate the low-level function of interrupts, clocks, and registers, Nachos simulates a MIPS microprocessor. 3

Nachos Overview (cont.) 4

Executing a User Program Use -x argument to specify a user program for Nachos to simulate, e.g:./userprog/nachos -x./test/nice_free When you start Nachos in this way, a thread for nice_free is allocated, the executable instructions of nice_free are loaded into its (simulated) address space, the MIPS simulator's program counter is initialized to the start address, and the process is simulated (one instruction at a time) using Machine::Run(). 5

Switching to Kernel Mode Main interpreter loop in Machine::Run(): for (;;) { OneInstruction(instr); interrupt->onetick(); } Once a process has been loaded and is being simulated, its execution may be halted by a trap or interrupt. If instr is a Nachos system call, OneInstruction() will raise an exception to execute the system call code defined in Nachos, essentially simulating a trap into kernel mode. interrupt->onetick() will advance the simulated clock by one tick and also call HandleIfDue() to handle all pending interrupts at that point. 6

A Multitasking Simulator Nachos is a multitasking simulator. That is, it has a scheduler that allows it to manage multiple processes at once. When a user program issues the Nachos-defined Fork() system call, the loop in Machine::Run will raise an exception, Nachos will create another PThread (through use of the host operating system's ABI), populate its address space appropriately, and update its scheduler's data structures appropriately (e.g. add the newly created process to the run queue). With multiple processes being simulated by Nachos, we need some way of determining which process gets to use simulated MIPS processor. Therefore, Nachos needs a scheduling algorithm to determine when the running process will be switched from and which ready process will be switched to. 7

Round Robin Scheduling Algorithm By default, Nachos uses a Round Robin scheduling algorithm with a fixed, unvarying quantum for each process. Before describing its implementation in detail, a few notes on some of the data structures Nachos is using: On initialization, Nachos creates a SchedTimerInterrupt interrupt, which is scheduled to become due every 100 simulated timer ticks (i.e. HandleIfDue(), called by interrupt->onetick(), in the main interpreter loop returns true when the simulated clock has advanced 100 ticks since the last SchedTimerInterrupt). This is how Nachos implements its quantum. The scheduler maintains a FIFO queue of all processes in the ready list (not surprisingly, called the readylist). When processes become ready (e.g. when an I/O request completes, or when a new process has just been forked), they are appended to the end of the ready list. The thread currently using the CPU can be accessed anywhere in the Nachos kernel using the global currentthread pointer. 8

Round Robin Control Flow Main Interpreter Loop OneInstruction(instr); OneTick(); return if SchedTimerInterrupt due branch if yieldonreturn is true SchedTimerInterrupt yieldonreturn = true; yieldonreturn currentthread->yield(); yieldonreturn = false; Thread::Yield() scheduler->readytorun(this) next = scheduler->findnexttorun() scheduler->run(next) retur n 9

Round Robin Details When the SchedTimerInterrupt is handled, it will set the global yieldonreturn to true and return to the main loop. Next, currentthread invokes Yield() to rescind control of the MIPS simulator. In Yield(): scheduler->readytorun(this) places the currentthread on the readylist. For Round Robin, this function appends the currentthread to the end of the readylist. next = scheduler->findnexttorun() returns the next process to run as chosen by the scheduling algorithm. For Round Robin, this function simply chooses the thread at the front of the readylist. scheduler->run(next) actually performs the context switch. When this returns, the running process is no longer this, but the process chosen by the scheduler (next). Now, control returns to the main loop. The registers for the simulated MIPS processor will all point to values for the newly chosen process, and the next execution of OneInstruction(instr) simulates the next instruction of the newly chosen process. 10

Testing Round Robin We can use the nice_free program in the test/ directory to test the behavior of the Nachos scheduler. nice_free forks four processes and each child process prints a different character to stdout. Each process prints until some maximum limit is reached. The order of the characters printed to the screen tells us which process was chosen to run and a rough estimate of how long each process ran between context switches. Two important notes: The Nice() system call used in nice_free currently does nothing. You will implement this system call in the first Nachos assignment. nice_free uses a special Nachos system call - Echo() - to print values to the screen. Echo() is different than Write() in that it will not cause its calling process to block (system calls involving I/O usually do). Therefore, every process in this test will always either be running or on the readylist. This forces the scheduler to choose its next process from a readylist of length more than one. 11

Round Robin Sample Output 12

FCFS Scheduler In today's lab, we will change Nachos to implement a First Come, First Serve scheduler. If you don't remember the semantics of FCFS, review the slides from class. A few notes: FCFS is actually simpler than Round Robin and there are not very many good reasons to actually implement a FCFS scheduler in a real operating system. However, the purpose of this lab is to get you acquainted with the Nachos simulator and to start you thinking about how a real scheduler might work. 13

Suggestions Much of the time in real operating systems programming is spent trying to understand how components of the system work together and where a change should be made. In this sense, this lab and your assignments in class will be very similar to real operating systems programming. Use gdb, grep, find and your tags file to navigate the source tree. e.g., running the following commands will print the stack trace of every function (with filename and line number of declaration) that was called before Nachos entered the Scheduler::Run routine: -bash-3.2$ gdb./userprog/nachos (gdb) b Scheduler::Run (gdb) r -x./test/nice_free (gdb) bt REMEMBER: This should not be a very large change. If you find yourself changing a lot of Nachos code, rethink your approach. 14

FCFS Sample Output 15