CS5460: Operating Systems

Similar documents
CS 5460/6460 Operating Systems

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

Anne Bracy CS 3410 Computer Science Cornell University

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

CSE 153 Design of Operating Systems Fall 18

CSE 120 Principles of Operating Systems

Hardware OS & OS- Application interface

CSE 153 Design of Operating Systems

Syscalls, exceptions, and interrupts, oh my!

Virtual Memory 2: demand paging

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

14 May 2012 Virtual Memory. Definition: A process is an instance of a running program

Anne Bracy CS 3410 Computer Science Cornell University

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

John Wawrzynek & Nick Weaver

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

Architectural Support for Operating Systems

CS 318 Principles of Operating Systems

CS24: INTRODUCTION TO COMPUTING SYSTEMS. Spring 2018 Lecture 18

The Kernel Abstraction. Chapter 2 OSPP Part I

CS 104 Computer Organization and Design

Architecture and OS. To do. q Architecture impact on OS q OS impact on architecture q Next time: OS components and structure

CSE 120 Principles of Operating Systems Spring 2017

Virtual Memory Oct. 29, 2002

Processes, Address Spaces, and Memory Management. CS449 Spring 2016

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

CSE 153 Design of Operating Systems

Architectural Support for OS

Virtual Memory. Daniel Sanchez Computer Science & Artificial Intelligence Lab M.I.T. April 12, 2018 L16-1

Memory Management. Disclaimer: some slides are adopted from book authors slides with permission 1

virtual memory Page 1 CSE 361S Disk Disk

CSE 120 Principles of Operating Systems

CSE 120 Principles of Operating Systems

Motivations for Virtual Memory Virtual Memory Oct. 29, Why VM Works? Motivation #1: DRAM a Cache for Disk

CS 318 Principles of Operating Systems

Processes and Exceptions

Lecture 4: Threads; weaving control flow

@2010 Badri Computer Architecture Assembly II. Virtual Memory. Topics (Chapter 9) Motivations for VM Address translation

Distributed Systems Operation System Support

Machines and Virtualization. Systems and Networks Jeff Chase Spring 2006

Topic 18: Virtual Memory

Slide 6-1. Processes. Operating Systems: A Modern Perspective, Chapter 6. Copyright 2004 Pearson Education, Inc.

CS510 Operating System Foundations. Jonathan Walpole

Misc. Third Generation Batch Multiprogramming. Fourth Generation Time Sharing. Last Time Evolution of OSs

Virtual Memory. CS61, Lecture 15. Prof. Stephen Chong October 20, 2011

Architectural Support for Operating Systems

Exceptions and Processes

Virtual Memory. Motivations for VM Address translation Accelerating translation with TLBs

CS 61C: Great Ideas in Computer Architecture. Lecture 23: Virtual Memory

CS 318 Principles of Operating Systems

CISC 360. Virtual Memory Dec. 4, 2008

Background: Operating Systems

CSE 560 Computer Systems Architecture

CS 31: Intro to Systems Threading & Parallel Applications. Kevin Webb Swarthmore College November 27, 2018

Operating Systems: Virtual Machines & Exceptions

Processes. Johan Montelius KTH

Lecture 2 Fundamental OS Concepts. Bo 2018, Spring

Virtual Memory. Daniel Sanchez Computer Science & Artificial Intelligence Lab M.I.T. November 15, MIT Fall 2018 L20-1

Cache Example, System Control Flow

A process. the stack

Roadmap. Java: Assembly language: OS: Machine code: Computer system:

Multi-level Translation. CS 537 Lecture 9 Paging. Example two-level page table. Multi-level Translation Analysis

Topic 18 (updated): Virtual Memory

Lecture 4: Memory Management & The Programming Interface

Computer Systems Architecture I. CSE 560M Lecture 3 Prof. Patrick Crowley

CS 61C: Great Ideas in Computer Architecture Virtual Memory. Instructors: John Wawrzynek & Vladimir Stojanovic

CS 61C: Great Ideas in Computer Architecture. Lecture 23: Virtual Memory. Bernhard Boser & Randy Katz

Review: Easy Piece 1

Systems Programming and Computer Architecture ( ) Timothy Roscoe

Review: Hardware user/kernel boundary

Carnegie Mellon. 16 th Lecture, Mar. 20, Instructors: Todd C. Mowry & Anthony Rowe

Background. IBM sold expensive mainframes to large organizations. Monitor sits between one or more OSes and HW

Virtual Memory II CSE 351 Spring

Hakim Weatherspoon CS 3410 Computer Science Cornell University

CS 326: Operating Systems. Process Execution. Lecture 5

Computer Architecture Lecture 13: Virtual Memory II

Memory Protection. Machines and Virtualization. Architectural Foundations of OS Kernels. Memory and the CPU. Introduction to Virtual Addressing

Lecture 2: Architectural Support for OSes

Processes (Intro) Yannis Smaragdakis, U. Athens

Lecture 19: Virtual Memory: Concepts

Memory Management. Disclaimer: some slides are adopted from book authors slides with permission 1

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

COS 318: Operating Systems

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

SYSTEM CALL IMPLEMENTATION. CS124 Operating Systems Fall , Lecture 14

Xen and the Art of Virtualization. CSE-291 (Cloud Computing) Fall 2016

Administrivia. Lab 1 due Friday 12pm. We give will give short extensions to groups that run into trouble. But us:

Memory Management. Kevin Webb Swarthmore College February 27, 2018

COS 318: Operating Systems. Overview. Andy Bavier Computer Science Department Princeton University

Fall 2017 :: CSE 306. Process Abstraction. Nima Honarmand

CS333 Intro to Operating Systems. Jonathan Walpole

9/19/18. COS 318: Operating Systems. Overview. Important Times. Hardware of A Typical Computer. Today CPU. I/O bus. Network

Lecture 2: September 9

Traps, Exceptions, System Calls, & Privileged Mode

Random-Access Memory (RAM) Systemprogrammering 2007 Föreläsning 4 Virtual Memory. Locality. The CPU-Memory Gap. Topics

Protection and System Calls. Otto J. Anshus

Memory Management. Disclaimer: some slides are adopted from book authors slides with permission 1

Processes and Virtual Memory Concepts

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

Transcription:

CS5460: Operating Systems Lecture 2: OS Hardware Interface (Chapter 2)

Course web page: http://www.eng.utah.edu/~cs5460/ CADE lab: WEB L224 and L226 http://www.cade.utah.edu/ Projects will be on Linux machines in CADE You don t need to go there, just ssh in Join the class mailing list Go to: https://sympa.eng.utah.edu/sympa/ So far 30 out of 61 have subscribed

Last Time OS History Mainframe era Minicomputer era PC era Ubiquitous era Basic OS principles apply over the entire 60-year history Concurrency Resource management Providing usable abstractions Hiding complexity Etc.

Operating System Organization

What is an Operating System? Interface between user and hardware Exports simpler virtual machine interface Hides ugly details of real hardware Manages shared resources CPU, memory, I/O devices, Ensure fairness Protect processes from one another Provides common services File system, VM, CPU scheduling, OS design reacts to HW changes What OS can do dictated by architecture Arch support (or lack thereof) can greatly simplify (of complicate) OS design Example: Early PCs, Motorola 68000 User Applications Operating System Hardware Virtual Machine Interface Physical Machine Interface

Modern OS Functionality 1 Provides a virtual processor for application code Clean up after an application when it finishes Applications are isolated from each other by default Can communicate (using the OS) when desired Concurrency Overlap I/O and computation even for a single thread Optionally, multiple threads even for a single processor Support running across multiple processors Manage I/O devices OS usually sees an asynchronous interface (initiate -> interrupt) OS usually provides a synchronous interface

Modern OS Functionality 2 Memory management Provides a virtual address space for each process Moves data between DRAM and disk OS decides how much memory each application gets Files Fast access to slow storage devices Coherence model Network OS provides a high-level interface to the Internet Security OS implements a security policy Other: Accounting, logging, error recovery,

Generic Computer Architecture CPU: ALUs, pipeline, LD/ST, Memory: virtual vs physical addrs System bus Split transaction, addr/data/io/cntl Separate interrupt lines Bus adapter Converts system bus à PCI/SCSI/ Device controllers CPU writes to mem-mapped IO regs Devices signal CPU via interrupts Things to consider: Interrupts and traps Memory-mapped I/O devices VA à PA translation DMA CPU Core RDs/WRs Memory Controller DRAM Interrupts Virtual addrs Trap I/O bus TLB/MMU Physical I/O bus adapter (e.g., PCI, SCSI) Disk ctlr Serial ctlr addrs Network controller L2$ L1$ tag tags System bus

OS Abstractions of HW Hardware Resource CPU Main memory Disk Network Devices OS abstraction Processes / Threads Address spaces File system Sockets / ports Virtual devices

HW Support for OS Abstractions OS Service Isolation between processes Virtual memory System calls Asynchronous I/O CPU scheduling / accounting Synchronization Hardware Support Kernel/user mode Protected instructions Memory management unit MMU / TLB Traps Interrupts / DMA Timer interrupts Atomic instructions Question: Which pieces of HW support are truly necessary?

Typical OS Structure User-level Applications Libraries: many common OS functions Example: malloc() vs sbrk() Kernel-level Top-level: machine independent Bottom-level: machine dependent Runs in protected mode Need a way to switch (user ß à kernel) Hardware-level Device maker exports known interface Device driver initiates operations by writing to device registers Devices use interrupts to signal completion DMA (offloads work, but has restrictions) User Apps Trap OS kernel I/O regs DMA Hardware Libs Direct manipulation Thrd File VM SIG CPU Disk Mem Int Interrupts DMA

Virtual Address Space (Simplified) Parts of the address space: Code: binary image of program Data/BSS: Static variables (globals) Heap: explicitly alloc d data (malloc) Stack: implicitly alloc d data I/O registers: not shown Huge unmapped areas exist, especially on 64-bit Small unmapped region around 0 Kernel mapped into all processes Question: How might we support shared libraries? MMU hardware: Remaps VAs to PAs Supports read-only, supervisor-only Detects accesses to unmapped regions Supervisor-only User mode 0xffffffff Read Only 0x80000000 Read Only 0x00000000 User stack segment User heap User data segment User code segment Kernel heap Kernel data segment Kernel code segment

Kernel Mode vs User Mode Some instructions can only be used in kernel mode Direct access to I/O devices (typically) Instructions to manipulate VAà PA mappings and TLB Enable/disable interrupts Halt the machine Architecture typically supports: Status bit in protected processor register indicating mode Restricts ability to perform certain instructions if not kernel mode How do user applications get access to protected instructions? Trap or interrupt à indirect jump via OS-managed function table System call typically implemented with special TRAP instruction

Anatomy of a System Call User applications make system calls to execute privileged instructions Anatomy of a system call: Program puts syscall params in registers Program executes a trap:» Minimal processor state (PC, PSW) pushed on stack» CPU switches mode to KERNEL» CPU vectors to registered trap handler in the OS kernel Trap handler uses param to jump to desired handler (e.g., fork, exec, open, ) When complete, reverse operation» Place return code in register» Return from exception foo: movl r1, (arg1) movl r0, #foo syscall syscallhdlr(){ switch (r0){ case: foo r0 ß foo( ); } asm( ret ); } User Kernel foo() { return res; }

System Calls Arguments passed in registers: (Why?) Integer constants (e.g., buffer size, file offset, fileid) Pointers to blocks of memory (e.g., strings, file buffers, ) Handles (e.g., file handle, socket handle, ) OS typically returns: Return code (value of 1 often denotes error) Other results written into buffers in user space You should always (always!) check syscall return values Principle: Dialogue between user-mode and kernel should be semantically simple Simpler interfaces easier to work with Simpler interfaces easier to implement correctly Simpler interfaces tend to be easier to make efficient

System Call Example Source void foo (void) { } write(1, hello\n, 6); Q: Where do all the magic numbers in the assembly come from? Note: For this class you will need to be able to read x86 and x86-64 assembly code Assembly Code <main>: pushq %rax mov $0x6,%edx mov $0x694010,%esi mov $0x1,%edi callq libc_write xorl %eax,%eax popq %rdx ret <libc_write>: mov $0x1,%eax syscall cmp $0xfffffffffffff001,%rax jae < syscall_error> retq

Traps Architecture detects special events: trap instruction invalid memory access floating point exception privileged instruction by user mode code When processor detects condition: Save minimal CPU state (PC, sp, ) done by hardware Switches to KERNEL mode Transfers control to trap handler» Indexes trap table w/ trap number» Jumps to address in trap table (*)» Handler saves more state and may disable interrupts RTE instruction reverses operation TRAP VECTOR: 0x0082404 Illegal address 0x0084d08 Mem Violation 0x008211c Illegal instruction 0x0082000 System call Here, 0x82404 is address of handle_illegal_addr().

Important from Today HW provides support for OS abstractions Make them possible to implement Make them easier to implement Make them more efficient User programs run in processes Each see its own virtual address space Kernel has a very different view of memory Modern processors support (at least) two modes User mode and kernel mode The kernel is not a process User programs trap into kernel mode to access OS functionality