CS 5460/6460 Operating Systems

Similar documents
Last 2 Classes: Introduction to Operating Systems & C++ tutorial. Today: OS and Computer Architecture

Operating Systems CMPSCI 377 Spring Mark Corner University of Massachusetts Amherst

CS5460: Operating Systems

CS 537 Lecture 2 Computer Architecture and Operating Systems. OS Tasks

CSE 153 Design of Operating Systems Fall 18

The Kernel Abstraction. Chapter 2 OSPP Part I

Lecture 2: September 9

CSE 120 Principles of Operating Systems

CSE 120 Principles of Operating Systems

CSE 153 Design of Operating Systems

Architectural Support for Operating Systems

SYSTEM CALL IMPLEMENTATION. CS124 Operating Systems Fall , Lecture 14

CS 537 Lecture 2 - Processes

The Kernel Abstraction

Objectives. Chapter 2: Operating-System Structures. 2.1 Operating System Services

Hardware OS & OS- Application interface

Processes. Johan Montelius KTH

A process. the stack

Lecture 2: Architectural Support for OSes

OS and Computer Architecture. Chapter 3: Operating-System Structures. Common System Components. Process Management

Last Class: OS and Computer Architecture. Last Class: OS and Computer Architecture

Anne Bracy CS 3410 Computer Science Cornell University

Operating Systems. Operating System Structure. Lecture 2 Michael O Boyle

Operating Systems ECE344

Lecture 4: Memory Management & The Programming Interface

Last class: Today: Course administration OS definition, some history. Background on Computer Architecture

Protection and System Calls. Otto J. Anshus

Last class: OS and Architecture. OS and Computer Architecture

Last class: OS and Architecture. Chapter 3: Operating-System Structures. OS and Computer Architecture. Common System Components

CSC369 Lecture 2. Larry Zhang, September 21, 2015

Chapter 2: System Structures

Exceptions and Processes

Computer architecture. A simplified model

Anne Bracy CS 3410 Computer Science Cornell University

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

Operating Systems CS 217. Provides each process with a virtual machine. Promises each program the illusion of having whole machine to itself

Lecture 4: Mechanism of process execution. Mythili Vutukuru IIT Bombay

Introduction to the Process David E. Culler CS162 Operating Systems and Systems Programming Lecture 2 Sept 3, 2014

Architectural Support for OS

CSC369 Lecture 2. Larry Zhang

W4118: interrupt and system call. Junfeng Yang

Operating System Review

CPSC 213. Introduction to Computer Systems. The Operating System. Unit 2e

Review: Hardware user/kernel boundary

Address spaces and memory management

Lec 22: Interrupts. Kavita Bala CS 3410, Fall 2008 Computer Science Cornell University. Announcements

The Kernel. wants to be your friend

Mon Sep 17, 2007 Lecture 3: Process Management

I/O Systems. Amir H. Payberah. Amirkabir University of Technology (Tehran Polytechnic)

COS 318: Operating Systems

Operating System Architecture. CS3026 Operating Systems Lecture 03

Background: Operating Systems

CPS104 Computer Organization and Programming Lecture 17: Interrupts and Exceptions. Interrupts Exceptions and Traps. Visualizing an Interrupt

Architectural Support for Operating Systems. Jinkyu Jeong ( Computer Systems Laboratory Sungkyunkwan University

Mechanisms for entering the system

CS 550 Operating Systems Spring Interrupt

Syscall Proxying. Simulating Remote Execution. Maximiliano Cáceres.

CS 201. Exceptions and Processes. Gerson Robboy Portland State University

Processes and Exceptions

Architectural Support for Operating Systems. Jin-Soo Kim Computer Systems Laboratory Sungkyunkwan University

Chapter 13: I/O Systems

for Operating Systems Computer Systems Laboratory Sungkyunkwan University

Processes (Intro) Yannis Smaragdakis, U. Athens

Operating Systems and Protection CS 217

CSE 120 Principles of Operating Systems

The Process Abstraction. CMPU 334 Operating Systems Jason Waterman

Design Overview of the FreeBSD Kernel CIS 657

by I.-C. Lin, Dept. CS, NCTU. Textbook: Operating System Concepts 8ed CHAPTER 13: I/O SYSTEMS

Design Overview of the FreeBSD Kernel. Organization of the Kernel. What Code is Machine Independent?

PROCESS CONTROL BLOCK TWO-STATE MODEL (CONT D)

Sandboxing Untrusted Code: Software-Based Fault Isolation (SFI)

CS 326: Operating Systems. Process Execution. Lecture 5

Last time: introduction. Networks and Operating Systems ( ) Chapter 2: Processes. This time. General OS structure. The kernel is a program!

Shell Code For Beginners

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

CS 318 Principles of Operating Systems

John Wawrzynek & Nick Weaver

by Marina Cholakyan, Hyduke Noshadi, Sepehr Sahba and Young Cha

Inf2C - Computer Systems Lecture 16 Exceptions and Processor Management

Chapter 13: I/O Systems

Even coarse architectural trends impact tremendously the design of systems

Syscalls, exceptions, and interrupts, oh my!

CSE 120 Principles of Operating Systems Spring 2017

Last class: Today: Thread Background. Thread Systems

CS 550 Operating Systems Spring System Call

CS5460: Operating Systems

MASSACHUSETTS INSTITUTE OF TECHNOLOGY Computer Systems Engineering: Spring Quiz I Solutions

CS 471 Operating Systems. Yue Cheng. George Mason University Fall 2017

Princeton University Computer Science 217: Introduction to Programming Systems Exceptions and Processes

Processes. CS439: Principles of Computer Systems January 30, 2019

Lecture 2 Fundamental OS Concepts. Bo 2018, Spring

EEE3052: Introduction to Operating Systems. Fall Project #1

Chapter 12: I/O Systems

Chapter 13: I/O Systems

Chapter 12: I/O Systems. Operating System Concepts Essentials 8 th Edition

OS COMPONENTS OVERVIEW OF UNIX FILE I/O. CS124 Operating Systems Fall , Lecture 2

Architectural Support for Operating Systems

Exceptions and Processes

THE PROCESS ABSTRACTION. CS124 Operating Systems Winter , Lecture 7

3. Process Management in xv6

Transcription:

CS 5460/6460 Operating Systems Fall 2009 Instructor: Matthew Flatt Lecturer: Kevin Tew TAs: Bigyan Mukherjee, Amrish Kapoor 1

Join the Mailing List! Reminders Make sure you can log into the CADE machines 2

Modern Operating System Functionality Concurrency - doing many things at the same time (I/0, processing, multiple programs, etc.) Several users work at the same time as if each has a private machine Threads (unit of OS control) - one thread on the CPU at a time, but many threads active concurrently Virtualization different OS or multiple copies of the same OS running on a single system Namespacing - separation or isolation 3

Modern Operating System Functionality cont. I/O devices - let the CPU work while an I/O device is working (especially a device like a slow terminal.) Memory management - OS coordinates allocation of memory and moving data between disk and main memory. Files - OS coordinates how space is used for files, in order to find files and to store multiple files Distributed systems & networks - allow a group of workstations to work together on distributed hardware 4

Some Operating System Principles OS as juggler: providing the illusion of a dedicated machine with infinite memory and CPU. OS as government: protecting users from each other, allocating resources efficiently and fairly, and providing secure and safe communication. OS as complex system: keeping OS design and implementation as simple as possible is the key to getting the OS to work. OS as history teacher: learning from past to predict the future, i.e., OS design tradeoffs change with technology. 5

6

Generic Computer Architecture CPU - the processor that performs the actual computation I/O devices - terminal, disks, video board, printer, etc. Memory - RAM containing data and programs used by the CPU System bus - the communication medium between the CPU, memory, and peripherals 7

OS Provides a High-Level Version of Hardware: CPU Processes, Threads Main Memory Address spaces Disk Hierarchical Filesystem Devices Virtual devices 8

Example Concepts Services Threads I/O Redirection Concurrency Deadlock Paging Virtual Memor File Systems Distributed Systems RPC Security Processes CPU Scheduling Pipes Synchronization Memory Management Segmentation Page Replacement I/O Systems Networks Distributed Filesystems Embedded Systems 9

Architectural Features Motivated by OS Services OS Service Protection Virtual memory System calls Asynchronous CPU scheduling and accounting Interprocessor communication Synchronization Hardware Support Kernel/User mode Protected Instructions Base and Limit Registers Translation look-aside buffers Trap instructions and trap vectors I/O Interrupts Timer interrupts Interprocessor interrupts Atomic instructions 10

Protection 11

From who? 12

ANY CODE that violates the OS security policy faulty or malicious local or remote 13

Restricted Instructions Some instructions are restricted to use only by the OS From user-mode you cannot: access I/O devices directly access out-of-bounds memory use instructions that manipulate the state of memory protection (page table pointers, TLB load, etc.) set the mode bits that determine user or kernel mode disable and enable interrupts halt the machine but in kernel mode, the OS can do all these things. 14

Kernel mode vs. User mode: The architecture must support at least kernel and user mode. A status bit in a protected processor register indicates the mode. Protected instructions can only be executed in kernel mode. User programs get access to protected functionality through system calls Important: OS must never permit arbitrary code to be executed in kernel mode 15

Syscall Kernel Trap 16

Crossing Protection Boundaries Users make a system call to an OS procedure to execute privileged instructions (e.g., I/O) A System Call: Program puts system call parameters in registers. Program executes a trap: Minimal processor state (PC, PSW) pushed on the stack. CPU vectors (jumps) to the trap handler in the OS kernel. The trap handler uses the parameter to the system call to jump to the appropriate handler (fork, exec, open, etc.). The architecture must permit the OS to verify the caller s parameters. The architecture must also provide a way to return to user mode when finished. 17

Unix System Calls Familiar examples: open, close, read, write, select, fork, exec, sleep Esoteric: brk, setsid, unlink, waitpid Arguments tend to be: pointers to blocks of memory (strings, file buffers, socket buffers) integer constants (buffer size, file offset, permission mask, delay time) names file descriptor: small int naming a file (process-relative) pid: small int naming a process path: string naming a location in the filesystem Often, return value of -1 indicates an error. See man pages for exceptions As a programmer, always always check return codes 18

Unix System Calls Principle: Dialogue between user-mode and kernel should be semantically simple. Why? 19

Unix System Calls Principle: Dialogue between user-mode and kernel should be semantically simple. Why? Simple interfaces are easier to work with (from both sides) Simple interfaces can sometimes be implemented correctly (complex ones almost never can) Simple interfaces tend to be broadly useful Simple interfaces tend to have efficient implementations) 20

Example: A System Call in Linux You write: static char buf[] = "hello\n"; int main (void) { write (1, buf, 6); } 21

Example: A System Call in Linux You write: main() contains: static char buf[] = "hello\n"; int main (void) { write (1, buf, 6); } movl movl movl call $0x1,(%esp,1) $0x80a034c,0x4(%esp,1) $0x6,0x8(%esp,1) 804cd40 < libc_write> 22

Example: A System Call in Linux You write: static char buf[] = "hello\n"; int main (void) { write (1, buf, 6); } main() contains: movl $0x1,(%esp,1) movl $0x80a034c,0x4(%esp,1) movl $0x6,0x8(%esp,1) call 804cd40 < libc_write> libc write() is: mov 0x10(%esp,1),%edx mov 0xc(%esp,1),%ecx mov 0x8(%esp,1),%ebx mov $0x4,%eax int $0x80 cmp $0xfffff001,%eax jae 804d550 < syscall_error> ret 23

Example: A System Call in Linux You write: static char buf[] = "hello\n"; int main (void) { write (1, buf, 6); } main() contains: movl $0x1,(%esp,1) movl $0x80a034c,0x4(%esp,1) movl $0x6,0x8(%esp,1) call 804cd40 < libc_write> libc write() is: mov 0x10(%esp,1),%edx mov 0xc(%esp,1),%ecx mov 0x8(%esp,1),%ebx mov $0x4,%eax int $0x80 cmp $0xfffff001,%eax jae 804d550 < syscall_error> ret Question: Why load "4" into eax? Note: For this class you will need to read assembly code at this level 24

Memory Protection Architecture must provide support so the OS can protect user programs from each other, and protect the OS from user programs. Architecture may or may not protect User programs from the OS. The simplest technique is to use base and limit registers. Base and limit registers are loaded by the OS before starting a program. The CPU checks each user reference (instruction and data addresses), ensuring it falls between the base and limit register values. Virtual memory and segmented memory have additional requirements and more complex solutions. 25

Virtual Memory Virtual memory allows users to run programs without loading the entire program in memory at once. Instead, pieces of the program are loaded as they are needed. The OS must keep track of which pieces are in which parts of physical memory and which pieces are on disk. In order for pieces of the program to be located and loaded without causing a major disruption to the program, the hardware provides a translation lookaside buffer to speed the lookup. 26

Traps Architecture must detect special conditions: page fault write to a read-only page bad address trap floating point exception privileged instruction trap system call etc... 27

Traps We call these traps. When the processor detects these conditions, it must save state on trap (PC, stack, etc.), so that the process may be restarted after the trap is serviced, and then The CPU transfers control to the appropriate trap handler (OS routine) via a memory-mapped trap vector. The CPU indexes the trap vector with the trap number, then jumps to the address given in the vector, and starts to execute at that address. When the handler completes, the OS resumes the execution of the process that caused the trap. 28

Traps Modern OS use Virtual Memory traps for many functions: debugging, distributed VM, garbage collection, copy-on-write, etc. Question: Why are traps so useful? 29

Traps Modern OS use Virtual Memory traps for many functions: debugging, distributed VM, garbage collection, copy-on-write, etc. Question: Why are traps so useful? Because they are efficient. Instead of using software to test for a condition, special-purpose logic in the processor does the work without slowing down your application. 30

31

32