Welcome to the World of Nachos CPS 110 Spring 2004 Discussion Session 1.

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

Chapter 6 Limited Direct Execution
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.
1 CS 333 Introduction to Operating Systems Class 2 – OS-Related Hardware & Software The Process Concept Jonathan Walpole Computer Science Portland State.
Home: Phones OFF Please Unix Kernel Parminder Singh Kang Home:
OS Spring’03 Introduction Operating Systems Spring 2003.
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.
1 Process Description and Control Chapter 3 = Why process? = What is a process? = How to represent processes? = How to control processes?
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.
Slide 6-1 Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 6.
Basics of Operating Systems March 4, 2001 Adapted from Operating Systems Lecture Notes, Copyright 1997 Martin C. Rinard.
CSE 451: Operating Systems Autumn 2013 Module 6 Review of Processes, Kernel Threads, User-Level Threads Ed Lazowska 570 Allen.
Process Description and Control Chapter 3. Major Requirements of an OS Interleave the execution of several processes to maximize processor utilization.
COP 4600 Operating Systems Spring 2011 Dan C. Marinescu Office: HEC 304 Office hours: Tu-Th 5:00-6:00 PM.
Protection and the Kernel: Mode, Space, and Context.
CS1550 Assignment 5 Multiprogramming Implementation notes Matt Craven.
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.
Contact Information Office: 225 Neville Hall Office Hours: Monday and Wednesday 12:00-1:00 and by appointment.
Threads and Concurrency. A First Look at Some Key Concepts kernel The software component that controls the hardware directly, and implements the core.
Recall: Three I/O Methods Synchronous: Wait for I/O operation to complete. Asynchronous: Post I/O request and switch to other work. DMA (Direct Memory.
Operating Systems ECE344 Ashvin Goel ECE University of Toronto OS-Related Hardware.
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.
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.
Race Conditions Defined 1. Every data structure defines invariant conditions. defines the space of possible legal states of the structure defines what.
Background: Operating Systems Brad Karp UCL Computer Science CS GZ03 / M th November, 2008.
Nachos Tutorial Courtesy: University of Waterloo.
Nachos Instructional OS CS 270, Tao Yang, Spring 2011.
CPS110: Implementing threads Landon Cox. Recap and looking ahead Hardware OS Applications Where we’ve been Where we’re going.
Operating System Structure A key concept of operating systems is multiprogramming. –Goal of multiprogramming is to efficiently utilize all of the computing.
We will focus on operating system concepts What does it do? How is it implemented? Apply to Windows, Linux, Unix, Solaris, Mac OS X. Will discuss differences.
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.
Introduction to Operating Systems and Concurrency.
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.
Processes and Virtual Memory
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.
Process Description and Control Chapter 3. Source Modified slides from Missouri U. of Science and Tech.
© Janice Regan, CMPT 300, May CMPT 300 Introduction to Operating Systems Operating Systems Processes and Threads.
CPS110: Threads review and wrap up Landon Cox February 11, 2009.
Administrivia Nachos guide and Lab #1 are on the web. Form project teams of 2-3. Lab #1 due February 5. Synchronization.
2 Processor(s)Main MemoryDevices Process, Thread & Resource Manager Memory Manager Device Manager File Manager.
Managing Processors Jeff Chase Duke University. The story so far: protected CPU mode user mode kernel mode kernel “top half” kernel “bottom half” (interrupt.
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.
1 Lecture 6 “Nachos” n nachos overview n directory structure n nachos emulated machine n nachos OS n nachos scheduler n nachos threads.
Interrupts and Exception Handling. Execution We are quite aware of the Fetch, Execute process of the control unit of the CPU –Fetch and instruction as.
CPS110: Implementing threads on a uni-processor Landon Cox January 29, 2008.
CSCI/CMPE 4334 Operating Systems Review: Exam 1 1.
Multiprogramming. Readings r Chapter 2.1 of the textbook.
Introduction to Kernel
Processes and threads.
Process concept.
Process Management Process Concept Why only the global variables?
CPS110: Threads review and wrap up
Operating Systems: A Modern Perspective, Chapter 6
Intro to Processes CSSE 332 Operating Systems
More Threads and Synchronization
Structure of Processes
CSE 451: Operating Systems Spring 2012 Module 6 Review of Processes, Kernel Threads, User-Level Threads Ed Lazowska 570 Allen.
Process Description and Control
Lecture Topics: 11/1 General Operating System Concepts Processes
Threads Chapter 4.
Threads Chapter 5 2/17/2019 B.Ramamurthy.
Process Control B.Ramamurthy 2/22/2019 B.Ramamurthy.
Threads Chapter 5 2/23/2019 B.Ramamurthy.
Unix Process Control B.Ramamurthy 4/11/2019 B.Ramamurthy.
Implementing Processes, Threads, and Resources
Presentation transcript:

Welcome to the World of Nachos CPS 110 Spring 2004 Discussion Session 1

Today’s Objective Provide a basic understanding of the structure of Nachos Get ready to get started on Programming Assignment #1

What is Nachos? A real operating system Kernel runs on host hardware Kernel code is written in C++ User programs are written in ANSI C User programs are compiled for MIPS R2/3000, runs on MIPS emulator

Visualize Nachos User Programs Nachos Kernel MIPS HW Syscalls Machine instructions SPARC HW OS Kernel MIPS sim Nachos User Programs Syscalls Machine instructions MIPS instr Nachos calls Abstract ViewReality

Nachos: Simulated Devices Console terminal Disk Timer Network interface (not used)

What you’ll do with Nachos Start with very limited functionality Only one user program at a time Contiguous loading at low end of physical memory (no paging, process loads entire address space) no system calls are implemented (you implement them as a part of the labs) Improve Nachos by designing and implementing missing and inadequate portions of the system

Nachos Assignments Lab 1: The Trouble with Concurrent Programming Lab 1: The Trouble with Concurrent Programming Lab 2: Threads and Synchronization Lab 3: Programming with Threads Lab 4: Multiprogrammed Kernel Lab 5: I/O Lab 6: Virtual Memory

Lab 1: The Trouble with Concurrent Programming Become familiar with Nachos and the behavior of a working (but incomplete) thread system Use what is supplied to experience the joys of concurrent programming All use of the Nachos thread primitives will be internal to your Nachos operating system kernel For now, you are using these internal Nachos primitives to create simple concurrent programs. Instructions on setting globals from the command line:

Learning about Nachos You cannot learn all about software systems from textbooks Read the source code for systems that other people have written As soon as possible, begin reading over the NACHOS source code Try to understand where the various pieces of the system live, and how they fit together It will take a while to develop an understanding. Don't worry!

Traversing the Nachos Files CVS This directory contains control information for the CVS source code management system. Similar subdirectories are present at each level of the tree. You should not change anything in these directories. (optional) Makefile This file controls what happens when you type gmake in the code directory. It describes how to completely compile all the NACHOS code and user application programs.

Traversing the Nachos Files Makefile.common This file contains the lists of source and object files that go into making each version of NACHOS. Each time you add a new source or object file of your own, you will have to edit Makefile.common and add this file to the appropriate lists. Makefile.dep This file contains some system-dependent parameters that control the building of NACHOS. You probably don't need to change this.

Traversing the Nachos Files threads This directory contains source code to support threads (lightweight processes) and synchronization. The threads support is fully functional, though some of the synchronization primitives have not been implemented. Implementation and testing of these synchronization primitives will be part of your job for Homework #2.

Traversing the Nachos Files userprog This directory contains source code to support the loading and execution of user application programs. vm This directory will contain the source code for the virtual memory subsystem, when you implement it for Homework #6. filesys This directory contains source code for a ``stub'' implementation of the NACHOS file system. This implementation is very limited and incomplete. Your job in Homework #5 will be to rewrite and improve it.

Traversing the Nachos Files test This directory contains source code for some simple NACHOS user application programs. It also contains Makefile for compiling these programs and converting them from COFF to NOFF. Makefile machine This directory contains source code for the machine emulator. You would need to look at some of the header files in this directory, but don’t modify anything here.

A Nachos Thread Thread* t machine state name/status, etc. “fencepost” 0xdeadbeef Stack low high stack top unused region thread object or thread control block int stack[StackSize] t = new Thread(name); t->Fork(MyFunc, arg);; currentThread->Yield();

Thread Operations new thread - inits a thread control block Thread::Fork - runs a specified procedure in the newly created thread (allocates stack and makes ready to run) Thread::Finish - cleans up its state Thread::Yield - gives up CPU - makes running thread ready to run and invokes scheduler to choose new running thread

Threads in Nachos SPARC HW OS Kernel Nachos Syscalls Machine instructions thread.h,cc scheduler.h, cc

Nachos Context Switches: Voluntary vs. Involuntary On a uniprocessor, the set of possible execution schedules depends on when context switches can occur. Voluntary: one thread explicitly yields the CPU to another. A Nachos thread can suspend itself wth Thread::Yield. It may also block to wait for some event with Thread::Sleep. Involuntary: the system scheduler suspends an active thread, and switches control to a different thread. Thread scheduler tries to share CPU fairly by timeslicing. Suspend/resume from a timer interrupt handler (e.g., nachos -rs) This can happen “any time”, so concurrency races can occur.

Blocking or Sleeping An executing thread may request some resource or action that causes it to block or sleep awaiting some event. passage of a specific amount of time (a pause request) completion of I/O to a slow device (e.g., keyboard or disk) release of some needed resource (e.g., memory) In Nachos, threads block by calling Thread::Sleep.

Blocking or Sleeping (cont) A sleeping thread cannot run until the event occurs. The blocked thread is awakened when the event occurs. E.g., Wakeup or Nachos Scheduler::ReadyToRun(Thread* t) In an OS, processes may sleep while executing in the kernel to handle a system call or fault.

Nachos Thread State Transitions Ready Running Blocked Scheduler::ReadyToRun Scheduler::Run Thread::Sleep Thread::Yield t = new Thread(name); t->Fork(MyFunc, arg); Thread::Finish

Nachos Thread State Transitions Ready Running in kernel Blocked Scheduler::ReadyToRun Scheduler::Run Thread::Sleep Thread::Yield t = new Thread(name); t->Fork(MyFunc, arg); Running user mode interrupt or exception Machine::Run Thread::Finish

new = scheduler->FindNextToRun();/* get next ready thread */ scheduler->Run(t);/* run it */ Run calls SWITCH(currentThread, new) to suspend current thread and pass control to new thread. The Nachos Scheduler The core of Nachos is the Scheduler class: one global shared scheduler object pool of ready threads (the ready list) readyList

/* * Save context of the calling thread (old), restore registers of * the next thread to run (new), and return in context of new. */ switch/MIPS (old, new) { old->stackTop = SP; save RA in old->MachineState[PC]; save callee registers in old->MachineState restore callee registers from new->MachineState RA = new->MachineState[PC]; SP = new->stackTop; return (to RA) } ++ A Nachos Context Switch Caller-saved registers (if needed) are already saved on the thread’s stack. Caller-saved regs restored automatically on return. Return to last procedure that called switch in new. Save current stack pointer and caller’s return address in old thread object. Switch off of old stack and back to new stack.