CSE120 Discussion 5 Xinxin Jin. Where Are We?  Now we have finished some thread mechanisms to support Nachos kernel  Next, we want to enable user-level.

Slides:



Advertisements
Similar presentations
Lecture 101 Lecture 10: Kernel Modules and Device Drivers ECE 412: Microcomputer Laboratory.
Advertisements

Christo Wilson Project 2: User Programs in Pintos
CSCC69: Operating Systems
Chapter 7 Process Environment Chien-Chung Shen CIS, UD
Discussion Week 5 TA: Kyle Dewey. Overview HW 3.10 and 6.2 review Binary formats System call execution in NACHOS Memory management in NACHOS I/O in NACHOS.
Operating System Tracing the Nachos code in Java Instructor: Dr. Lee, Hahn-Ming. ( 李漢銘 教授 ) TA (Reporter): Mao, Ching-Hao 毛敬豪 Chen, Wei-Da 陳威達 2006/3/14.
CS 4284 Systems Capstone Project 2 Hints Slides created by Jaishankar Sundararaman.
Files. System Calls for File System Accessing files –Open, read, write, lseek, close Creating files –Create, mknod.
Operating System Tracing the nachos code in Java
Inter Process Communication:  It is an essential aspect of process management. By allowing processes to communicate with each other: 1.We can synchronize.
Home: Phones OFF Please Unix Kernel Parminder Singh Kang Home:
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.
CS 162 Nachos Tutorial Image courtesy of Thomas Andersen:
CSE 451 Section 4 Project 2 Design Considerations.
1 User-Level Processes Needed to test the system call you implement The “Noff” format file required –Look at the Makefile in test MIPS “syscall” instruction.
POSIX: Files Introduction to Operating Systems: Discussion 1 Read Solaris System Interface Guide: Ch. 5.1 Basic File I/O.
The Programming Interface. Main Points Creating and managing processes – fork, exec, wait Performing I/O – open, read, write, close Communicating between.
CSE 451: Operating Systems Autumn 2013 Module 6 Review of Processes, Kernel Threads, User-Level Threads Ed Lazowska 570 Allen.
System Calls 1.
Welcome to the World of Nachos CPS 110 Spring 2004 Discussion Session 1.
OS provide a user-friendly environment and manage resources of the computer system. Operating systems manage: –Processes –Memory –Storage –I/O subsystem.
Nachos Assignment#1 System calls implementation. What are system calls? Enable you to interact with OS kernel. A switch from User Mode to Kernel Mode.
Programming With C.
Lecture 3 Process Concepts. What is a Process? A process is the dynamic execution context of an executing program. Several processes may run concurrently,
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 CSE 451 Section 2: Interrupts, Syscalls, Virtual Machines, and Project 1.
Project 2: Initial Implementation Notes Tao Yang.
Nachos Project 4 Lecturer: Hao-Hua Chu TA: Chun-Po Wang (Artoo) Date: 2008/10/25.
Source: Operating System Concepts by Silberschatz, Galvin and Gagne.
Interrupt driven I/O. MIPS RISC Exception Mechanism The processor operates in The processor operates in user mode user mode kernel mode kernel mode Access.
Concurrency, Processes, and System calls Benefits and issues of concurrency The basic concept of process System calls.
Nachos Overview Lecturer: Hao-Hua Chu TA: Chun-Po Wang (Artoo) Date: 2008/09/18 Material Provided by Yuan-Hao Chang, Yung-Feng Lu.
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.
Functions Math library functions Function definition Function invocation Argument passing Scope of an variable Programming 1 DCT 1033.
Lecture 4 Mechanisms & Kernel for NOSs. Mechanisms for Network Operating Systems  Network operating systems provide three basic mechanisms that support.
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.
Project 2: User Programs Abdelmounaam Rezgui Acknowledgment: The content of some slides is partly taken from Josh Wiseman’s presentation.
Interrupt driven I/O Computer Organization and Assembly Language: Module 12.
File Systems - Part I CS Introduction to Operating Systems.
What is a Process ? A program in execution.
Chapter 7 Process Environment Chien-Chung Shen CIS/UD
Of Privilege, Traps, Interrupts & Exceptions Prof. Sirer CS 316 Cornell University.
1 COMP 3500 Introduction to Operating Systems Project 4 – Processes and System Calls Part 4: Managing File System State Dr. Xiao Qin Auburn University.
7/9/ Realizing Concurrency using Posix Threads (pthreads) B. Ramamurthy.
CS/COE 0449 (term 2174) Jarrett Billingsley
Exceptional Control Flow
Process Tables; Threads
Realizing Concurrency using the thread model
Protection of System Resources
CS 3305 System Calls Lecture 7.
Exceptional Control Flow: System Calls, Page Faults etc.
Structure of Processes
Operation System Program 4
Lecture 14 Virtual Memory and the Alpha Memory Hierarchy
System Calls.
Processes in Unix, Linux, and Windows
Process Tables; Threads
CSE 451: Operating Systems Spring 2012 Module 6 Review of Processes, Kernel Threads, User-Level Threads Ed Lazowska 570 Allen.
Exceptions Control Flow
System Calls David Ferry CSCI 3500 – Operating Systems
Process Control B.Ramamurthy 2/22/2019 B.Ramamurthy.
CSE 451: Operating Systems Autumn 2003 Lecture 2 Architectural Support for Operating Systems Hank Levy 596 Allen Center 1.
CSE 451: Operating Systems Autumn 2001 Lecture 2 Architectural Support for Operating Systems Brian Bershad 310 Sieg Hall 1.
Virtual Memory: Systems CSCI 380: Operating Systems
CSE 451: Operating Systems Winter 2007 Module 2 Architectural Support for Operating Systems Brian Bershad 562 Allen Center 1.
Unix Process Control B.Ramamurthy 4/11/2019 B.Ramamurthy.
CSE 451: Operating Systems Winter 2003 Lecture 2 Architectural Support for Operating Systems Hank Levy 412 Sieg Hall 1.
Interrupts & Syscalls.
Presentation transcript:

CSE120 Discussion 5 Xinxin Jin

Where Are We?  Now we have finished some thread mechanisms to support Nachos kernel  Next, we want to enable user-level program to access these kernel routines via system calls

Prjoect 2 Introduction  You will touch two parts of the code base: The operating system running java programs as you saw in project 1 (mainly /userprog class) User programs written in C and compiled into MIPS machine code (under /test directory).

Project 2 Tasks  Implement file system calls creat,open,read,write,close,and unlink, documented in test/syscall.h  Support multiprogramming – Memory partitioning for multi-processes  Implement process control system calls exec,join,and exit, also documented in syscall.h

Task 1: Implement File System Calls  creat - Create a file and return a file descriptor  close – Close a file  unlink – Delete a file  open – Open a file and return a file descriptor, an integer specifying the position of this open file in the table of open files for the current process  read – Read data from an open file to user process  write – Write data to an open file from user process

Don’t be scared by the lengthy instructions. We will reach the end step by step !

My Suggestions  Understand the the workflow of syscall in Nachos  Read /test/syscall.h. Understand the functionality and the arguments of each syscall.  Add syscall handler at the right place  Start from the simplest prototype of each syscall leave the complex restrictions alone for the first implementation  Add the restrictions back piece by piece  Don’t forget more sanity checks ! When does this syscall fail ?

Recap: System Call

Nachos Syscall: User space program  Syscall interface (defined in syscall.h)  Syscall code (defined in syscall.h)  Match syscall name with syscall code (start.s)  The instruction that traps to nachos kernel (start.s) #define syscallHalt 0 Void halt() SYSCALLSTUB(halt, syscallHalt) syscall

Compile User progarm  Set up MIPS cross compiler on linux machine (see instructions on the website) Avoid running the compiler on Windows or Mac  Run “make” under /test Generate *.coff executable file for MIPS processor  Add your own program Write hello.c under /test Add hello to the end of TARGETS in Makefile Run “make hello”, you will see hello.coff

Nachos Syscall: The Kernel Program  Some changed fields in nachos.conf Machine.stubFileSystem = true -- You need to access the stubFileSystem returned by Machine.stubFileSystem() --The filesystem access /test directory (same as root dir on linux machine) Machine.console = true --Now we have a simulated console for standard input and standoutput Processor.numPhysPages = The total number of available physical pages of the machine Kernel.shellProgram = halt.coff --The kernel executes the user program halt.coff by default -- Run nachos –x hello.coff to overrwite the default user progarm Kernel.processClassName = nachos.userprog.UserProcess -- Manage user process. You will heavily work on this class Kernel.kernel = nachos.userprog.UserKernel -- The nachos kernel for project2

/userprog Package  UserKernel.java Nachos kernel that supports multiprogramming  UserProcess.java Manage the state of user processes, method handleSyscall is called to handle system calls made by user programs  UThead.java User level thread, a subclass of Kthread, contains a reference to a UserProcess  SynchConsole.java – Simulate a console for stdin and stdout

Sycall Handler in Kernel  The entry point of syscall handler handleSyscall(int syscall, int a0, int a1, int a2, int a3)  The syscall code (e.g. syscallHalt) defined in UserProcess.java is consistent with the one defined syscall.h

System Call Execution Flow Summary

Let’s Get Started  Read the description of creat() and open() in syscall.h  Add syscall handlers of these two Leave the method body empty for now

Pass Parameter by Virtual Address  “Pass by value” vs.“Pass by address” read (int fd, char *buffer, int size) buffer is passed as virtual address, which is a pointer to an array of bytes, so use readVirtualMemory and writeVirtualMemory for these parameters.  open(char *fileName) fileName is passed as a pointer its first character, so use readVirtualMemoryString to get this parameter.

Support Concurrently Open Files  Your implementation should support at least 16 concurrently open files per process  Each file that a process has opened should have a unique file descriptor associated with it If a program call open() on the same file twice, just return different file descriptors  A given file descriptor can be reused if the file associated with it is closed

Open File Descriptor Table  File descriptor is used by user program to refer to a file creat and open return a file descriptor to user program this descriptor will be used for the following read/write  FD table is an array associated with every process each entry corresponds to one open file creat and open add an entry to the table, return the descriptor to user program close delete an entry from the table

Support Large Data Transfer In read()/write()  You cannot allocate unlimited buffer size  What is the appropricate buffer size to pass data between the file and memory ?

Syscall Parameter Sanity Check  OS should never allow a user program to screw up the kernel or other user programs  For example, in read( int fd, char *buffer, int size ), what kinds of parameters should be rejected ? Is the file descriptor valid ? Is size valid ? Is buffer and (buffer + size) in this process’s virtual address space ?