1 Lecture 6 “Nachos” n nachos overview n directory structure n nachos emulated machine n nachos OS n nachos scheduler n nachos threads.

Slides:



Advertisements
Similar presentations
WHAT IS AN OPERATING SYSTEM? An interface between users and hardware - an environment "architecture ” Allows convenient usage; hides the tedious stuff.
Advertisements

Why Concurrency? Allows multiple applications to run at the same time  Analogy: juggling.
The Kernel Abstraction. Challenge: Protection How do we execute code with restricted privileges? – Either because the code is buggy or if it might be.
CSC 501 Lecture 2: Processes. Von Neumann Model Both program and data reside in memory Execution stages in CPU: Fetch instruction Decode instruction Execute.
Lecture 4: Concurrency and Threads CS 170 T Yang, 2015 Chapter 4 of AD textbook.
1 Processes and Pipes COS 217 Professor Jennifer Rexford.
Home: Phones OFF Please Unix Kernel Parminder Singh Kang Home:
Ceng Operating Systems Chapter 2.1 : Processes Process concept Process scheduling Interprocess communication Deadlocks Threads.
1/23/2008CSCI 315 Operating Systems Design1 Processes Notice: The slides for this lecture have been largely based on those accompanying the textbook Operating.
Multithreading in Java Nelson Padua-Perez Chau-Wen Tseng Department of Computer Science University of Maryland, College Park.
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)
1 Threads Chapter 4 Reading: 4.1,4.4, Process Characteristics l Unit of resource ownership - process is allocated: n a virtual address space to.
Nachos Instructional OS and Project 1 CS 170, Tao Yang.
Welcome to the World of Nachos CPS 110 Spring 2004 Discussion Session 1.
OPERATING SYSTEM OVERVIEW. Contents Basic hardware elements.
Introduction to Processes CS Intoduction to Operating Systems.
CSC 501 Lecture 2: Processes. Process Process is a running program a program in execution an “instantiation” of a program Program is a bunch of instructions.
Threads Many software packages are multi-threaded Web browser: one thread display images, another thread retrieves data from the network Word processor:
Implementing Processes and Process Management Brian Bershad.
CGS 3763 Operating Systems Concepts Spring 2013 Dan C. Marinescu Office: HEC 304 Office hours: M-Wd 11: :30 AM.
Threads and Concurrency. A First Look at Some Key Concepts kernel The software component that controls the hardware directly, and implements the core.
Chapter 1 Process and Thread. 1.2 process The address space of a program – Text – Code – Stack – Heap A set of registers – PC – SP Other resources – Files.
Computer Architecture and Operating Systems CS 3230: Operating System Section Lecture OS-1 Process Concepts Department of Computer Science and Software.
Lecture 3 Process Concepts. What is a Process? A process is the dynamic execution context of an executing program. Several processes may run concurrently,
Operating Systems ECE344 Ashvin Goel ECE University of Toronto Thread Scheduling.
Operating Systems Lecture 7 OS Potpourri Adapted from Operating Systems Lecture Notes, Copyright 1997 Martin C. Rinard. Zhiqing Liu School of Software.
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.
Race Conditions Defined 1. Every data structure defines invariant conditions. defines the space of possible legal states of the structure defines what.
REVIEW OF COMMONLY USED DATA STRUCTURES IN OS. NEEDS FOR EFFICIENT DATA STRUCTURE Storage complexity & Computation complexity matter Consider the problem.
ITEC 502 컴퓨터 시스템 및 실습 Chapter 2-1: Process Mi-Jung Choi DPNM Lab. Dept. of CSE, POSTECH.
Nachos Tutorial Courtesy: University of Waterloo.
Nachos Instructional OS CS 270, Tao Yang, Spring 2011.
Computer Studies (AL) Operating System Process Management - Process.
CS333 Intro to Operating Systems Jonathan Walpole.
Chapter 2 Processes and Threads Introduction 2.2 Processes A Process is the execution of a Program More specifically… – A process is a program.
CS140 Project 1: Threads Slides by Kiyoshi Shikuma.
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.
Concurrency, Processes, and System calls Benefits and issues of concurrency The basic concept of process System calls.
Processes, Threads, and Process States. Programs and Processes  Program: an executable file (before/after compilation)  Process: an instance of a program.
Nachos Lecture 2 Xiaorui Sun. Phase 2 You have got one machine (machine package) You have to implements the incomplete OS (userprog package) Run programs.
© Janice Regan, CMPT 300, May CMPT 300 Introduction to Operating Systems Operating Systems Processes and Threads.
Managing Processors Jeff Chase Duke University. The story so far: protected CPU mode user mode kernel mode kernel “top half” kernel “bottom half” (interrupt.
NachOS Threads System Road Map through the Code Lab 3.
Nachos Project 2 Lecturer: Hao-Hua Chu TA: Chun-Po Wang (Artoo) Date: 2008/10/14 Material Provided by Yuan-Hao Chang, Yung-Feng Lu.
CSCI/CMPE 4334 Operating Systems Review: Exam 1 1.
Processes and threads.
Process concept.
Operating Systems CMPSC 473
CS 6560: Operating Systems Design
CS703 – Advanced Operating Systems
Protection of System Resources
Lecture Topics: 11/1 Processes Process Management
Nachos Threads and Concurrency
Process Virtualization. Process Process is a program that has initiated its execution. A program is a passive entity; whereas a process is an active entity.
Nachos Instructional OS
Concurrency: Threads, Address Spaces, and Processes
More examples How many processes does this piece of code create?
Nachos Assignment#2 Priority Scheduling.
Lecture Topics: 11/1 General Operating System Concepts Processes
Processes and Process Management
Threads Chapter 5 2/17/2019 B.Ramamurthy.
Threads Chapter 5 2/23/2019 B.Ramamurthy.
Still Chapter 2 (Based on Silberchatz’s text and Nachos Roadmap.)
Threads and Concurrency
Unix Process Control B.Ramamurthy 4/11/2019 B.Ramamurthy.
Implementing Processes, Threads, and Resources
Presentation transcript:

1 Lecture 6 “Nachos” n nachos overview n directory structure n nachos emulated machine n nachos OS n nachos scheduler n nachos threads

2 Nachos overview n Nachos is an instructional operating system developed at UC Berkeley n Nachos consists of two main parts: u Operating system F This is the part of the code that you will study and modify F This code is in the threads, userprog, and filesys directories F We will not study networking, so the network directory will not be used u Machine emulator — simulates a (slightly old) MIPS CPU, registers, memory, timer (clock), console, disk drive, and network F You will study this code, but will not be allowed to modify it F This code is in the machine directory n machine emulator is used for user programs only OS is executed on the host machine directly n The OS and machine emulator run together as a single UNIX process

3 Nachos distribution structure Most of the subdirectories of code directory of Nachos distribution contains a separate independent source code for nachos with different features. Nachos is compiled When Nachos is compiled, an executable called nachos is produced in every subdirectory with corresponding features enabled. Important directories: threads - implements threads interface: scheduling, context switch, synchronization machine - implements i/o, interrupts, address translation, console device, disk, etc. no binary is produced here. filesys - Nachos filesystem userprog - execution of user programs vm - virtual memory

4 Nachos — the operating system For now, we will mostly be concerned with code in the threads directory main.cc, threadtest.cc — a simple test of the thread routines. system.h, system.cc — Nachos startup/shutdown routines. thread.h, thread.cc — thread data structures and thread operations such as thread fork, thread sleep and thread finish. scheduler.h, scheduler.cc — manages the list of threads that are ready to run. list.h, list.cc — generic list management. utility.h, utility.cc — some useful definitions and debugging routines switch.h, swtch.h - machine dependent context switch routines in assembly

5 Nachos - the emulated machine Code is in the machine directory machine.h, machine.cc — emulates the part of the machine that executes user programs: main memory, processor registers, etc. mipssim.cc — emulates the integer instruction set of a MIPS R2/3000 CPU. interrupt.h, interrupt.cc — manages enabling and disabling interrupts as part of the machine emulation. timer.h, timer.cc — emulates a clock that periodically causes an interrupt to occur. stats.h — collects execution statistic

6 Nachos threads n As distributed, Nachos does not support multiple processes, only threads u All threads share / execute the same code (the Nachos source code) u All threads share the same global variables (have to worry about synch.) n Threads can be in one of 4 states: u JUST_CREATED — exists, has not stack, not ready yet u READY — on the ready list, ready to run u RUNNING — currently running (variable currentThread points to currently running thread) u BLOCKED — waiting on some external even, probably should be on some event waiting queue

7 Nachos scheduler n The Nachos scheduler is non-preemptive FCFS — chooses next process when: u Current thread calls Thread::Sleep( ) (to block (wait) on some event) u Current thread calls Thread::Yield( ) to explicitly yield the CPU n main( ) (in threads/main.cc) calls Initialize( ) (in threads/system.cc) u which starts scheduler, an instance of class Scheduler (defined in threads/scheduler.h and scheduler.cc) n Interesting functions: u Mechanics of running a thread: F Scheduler::ReadyToRun( ) — puts a thread at the tail of the ready queue F Scheduler::FindNextToRun( ) — returns thread at the head of the ready queue F Scheduler::Run( ) — switches to thread

8 Scheduler’s code Scheduler::Scheduler ( ) { readyList = new List; } void Scheduler::ReadyToRun (Thread *thread) { DEBUG('t', "Putting thread %s on ready list.\n", thread->getName()); thread->setStatus(READY); readyList->Append((void *)thread); } Thread * Scheduler::FindNextToRun ( ) { return (Thread *)readyList->Remove(); }

9 Scheduler’s code (cont.) void Scheduler::Run (Thread *nextThread) { Thread *oldThread = currentThread; oldThread->CheckOverflow(); currentThread = nextThread; currentThread->setStatus(RUNNING); DEBUG('t', "Switching from thread \"%s\" to thread \"%s\"\n", oldThread->getName(), nextThread- >getName()); SWITCH(oldThread, nextThread); DEBUG('t', "Now in thread \"%s\"\n", currentThread->getName()); if (threadToBeDestroyed != NULL) { delete threadToBeDestroyed; threadToBeDestroyed = NULL; } }

10 Working with non-preemptive scheduler n The Nachos scheduler is non-preemptive FCFS — chooses next process when: u Current thread calls Thread::Sleep( ) (to block (wait) on some event) u Current thread calls Thread::Yield( ) to explicitly yield the CPU n Some interesting functions:  Thread::Fork( ) — create a new thread to run a specified function with a single argument, and put it on the ready queue  Thread::Yield( ) — if there are other threads waiting to run, suspend this thread and run another  Thread::Sleep( ) — this thread is waiting on some event, so suspend it, and hope someone else wakes it up later  Thread::Finish( ) — terminate the currently running thread

11 Manipulating threads: fork() void Thread::Fork(VoidFunctionPtr func, int arg) { DEBUG('t',"Forking thread \"%s\" with func = 0x%x, arg = %d\n", name, (int) func, arg); StackAllocate(func, arg); IntStatus oldLevel = interrupt-> SetLevel(IntOff); scheduler->ReadyToRun(this); (void) interrupt->SetLevel(oldLevel); } example: Thread *t = new Thread("forked thread"); t->Fork(SimpleThread, 1)

12 Manipulating threads: yield() void Thread::Yield () { Thread *nextThread; IntStatus oldLevel = interrupt->SetLevel(IntOff); ASSERT(this == currentThread); DEBUG('t', "Yielding thread \"%s\"\n", getName()); nextThread = scheduler->FindNextToRun(); if (nextThread != NULL) { scheduler->ReadyToRun(this); scheduler->Run(nextThread); } (void) interrupt->SetLevel(oldLevel); } example: currentThread->Yield();

13 Manipulating threads: sleep() void Thread::Sleep () { Thread *nextThread; ASSERT(this == currentThread); ASSERT(interrupt->getLevel() == IntOff); DEBUG('t', "Sleeping thread \"%s\"\n", getName()); status = BLOCKED; while ((nextThread = scheduler-> FindNextToRun()) == NULL) interrupt->Idle(); scheduler->Run(nextThread); } example: currentThread->sleep();