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

Similar documents
Even coarse architectural trends impact tremendously the design of systems

CSE 451: Operating Systems Winter Module 2 Architectural Support for Operating Systems

Even coarse architectural trends impact tremendously the design of systems

Even coarse architectural trends impact tremendously the design of systems. Even coarse architectural trends impact tremendously the design of systems

CS 537 Lecture 2 - Processes

CS 5460/6460 Operating Systems

Architectural Support for Operating Systems

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

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

Hardware OS & OS- Application interface

Operating Systems CMPSCI 377 Spring Mark Corner University of Massachusetts Amherst

CSE 120 Principles of Operating Systems

Operating Systems ECE344

Architectural Support for OS

CSE 120 Principles of Operating Systems

Architectural Support for Operating Systems

for Operating Systems Computer Systems Laboratory Sungkyunkwan University

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

Lecture 2: Architectural Support for OSes

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

CSE 153 Design of Operating Systems Fall 18

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

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

CS5460: Operating Systems

The control of I/O devices is a major concern for OS designers

CSE 153 Design of Operating Systems

Common Computer-System and OS Structures

Chapter 2: System Structures

5.b Principles of I/O Hardware CPU-I/O communication

Anne Bracy CS 3410 Computer Science Cornell University

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

Operating Systems 2010/2011

Process Scheduling Queues

Protection and System Calls. Otto J. Anshus

CS370 Operating Systems

OS: An Overview. ICS332 Operating Systems

Unit 2 : Computer and Operating System Structure

CMSC 313 COMPUTER ORGANIZATION & ASSEMBLY LANGUAGE PROGRAMMING LECTURE 09, SPRING 2013

Introduction. CS3026 Operating Systems Lecture 01

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

CS 550 Operating Systems Spring Interrupt

Operating System Services

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

CSC 2405: Computer Systems II

Operating System Review

Lecture 15: I/O Devices & Drivers

Chap.6 Limited Direct Execution. Dongkun Shin, SKKU

The Kernel Abstraction

Operating Systems: Principles and Practice. Mark Zbikowski Gary Kimura (kudos to Tom Anderson)

Anne Bracy CS 3410 Computer Science Cornell University

Review: Hardware user/kernel boundary

Lecture 2: September 9

Review: Easy Piece 1

Windows Interrupts

CS370 Operating Systems

C02: Interrupts and I/O

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

Lecture 1 Introduction (Chapter 1 of Textbook)

COMP I/O, interrupts, exceptions April 3, 2016

I/O Handling. ECE 650 Systems Programming & Engineering Duke University, Spring Based on Operating Systems Concepts, Silberschatz Chapter 13

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

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

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

Operating System: Chap13 I/O Systems. National Tsing-Hua University 2016, Fall Semester

Syscalls, exceptions, and interrupts, oh my!

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

操作系统概念 13. I/O Systems

The Kernel Abstraction. Chapter 2 OSPP Part I

Four Components of a Computer System

CS510 Operating System Foundations. Jonathan Walpole

Ricardo Rocha. Department of Computer Science Faculty of Sciences University of Porto

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

I/O Systems. Jo, Heeseung

COURSE OVERVIEW & OPERATING SYSTEMS CONCEPT Operating Systems Design Euiseong Seo

CSC227: Operating Systems Fall Chapter 1 INTERRUPTS. Dr. Soha S. Zaghloul

CSCE 313 Introduction to Computer Systems. Instructor: Dezhen Song Spring 2015

CS330: Operating System and Lab. (Spring 2006) I/O Systems

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

ECE 485/585 Microprocessor System Design

7/20/2008. What Operating Systems Do Computer-System Organization

CSCE-313 Introduction to Computer Systems

SYSTEM CALL IMPLEMENTATION. CS124 Operating Systems Fall , Lecture 14

Silberschatz and Galvin Chapter 12

CS 104 Computer Organization and Design

Today s Topics. u Thread implementation. l Non-preemptive versus preemptive threads. l Kernel vs. user threads

x86 architecture et similia

CSE 120 Principles of Operating Systems

Architectural Support for Operating Systems

OPERATING SYSTEM OVERVIEW

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

CSE 410. Operating Systems

Machines and Virtualization. Systems and Networks Jeff Chase Spring 2006

OS structure. Process management. Major OS components. CSE 451: Operating Systems Spring Module 3 Operating System Components and Structure

Traps and Faults. Review: Mode and Space

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

CS24: INTRODUCTION TO COMPUTING SYSTEMS. Spring 2018 Lecture 23

Mechanisms for entering the system

I/O Systems. Jinkyu Jeong Computer Systems Laboratory Sungkyunkwan University

Today s Topics. u Thread implementation. l Non-preemptive versus preemptive threads. l Kernel vs. user threads

What s An OS? Cyclic Executive. Interrupts. Advantages Simple implementation Low overhead Very predictable

Transcription:

CS 537 Lecture 2 Computer Architecture and Operating Systems Michael Swift OS Tasks What is the role of the OS regarding hardware? What does the OS need from hardware to perform this role? 1

Computer Hardware Organization Computer-system operation One or more CPUs, device controllers connect through common bus providing access to shared memory Concurrent execution of CPUs and devices competing for memory cycles Four Components of a Computer System CPU MEM Device Device Device Device Device 2

OS terminology Marketing: OS is what comes in the box from Microsoft or Apple In this class: OS is the code that provides exposes and manages hardware Kernel = the program that contains the OS Architectural features affecting OS s These features were built primarily to support OS s: timer (clock) operation synchronization instructions (e.g., atomic test-and-set) memory protection I/O control operations interrupts and exceptions protected modes of execution (kernel vs. user) protected instructions system calls (and software interrupts) 3

OS control flow after the OS has booted, all entry to the kernel happens as the result of an event event immediately stops current execution changes mode to kernel mode, event handler is called kernel defines handlers for each event type specific types are defined by the architecture e.g.: timer event, I/O interrupt, system call trap when the processor receives an event of a given type, it transfers control to handler within the OS handler saves program state (PC, regs, etc.) handler functionality is invoked handler restores program state, returns to program Interrupts and exceptions Two main types of events: interrupts and exceptions exceptions are caused by software executing instructions e.g., the x86 int instruction e.g., a page fault, write to a read-only page an expected exception is a trap, unexpected is a fault interrupts are caused by hardware devices e.g., device finishes I/O e.g., timer fires 4

An Interrupt illustrated User process User Mode Mode bit = 1 Resume process Trap Mode bit = 0 Kernel Mode Mode bit = 0 Return Mode bit = 1 Save Caller s state Execute Device Driver Restore state Device Raise Interrupt Clear Interrupt Protected instructions some instructions are restricted to the OS known as protected or privileged instructions e.g., only the OS can: directly access I/O devices (disks, network cards) why? manipulate memory state management page table pointers, TLB loads, etc. why? manipulate special mode bits interrupt priority level why? halt instruction why? 5

OS protection So how does the processor know if a protected instruction should be executed? the architecture must support at least two modes of operation: kernel mode and user mode x86 support 4 protection modes MIPS, SPARC, ALPHA support 2 >hy more than 2? mode is set by status bit in a protected processor register user programs execute in user mode OS executes in kernel mode (OS == kernel) Protected instructions can only be executed in the kernel mode what happens if user mode executes a protected instruction? Crossing protection boundaries So how do user programs do something privileged? e.g., how can you write to a disk if you can t do I/O instructions? User programs must call an OS procedure OS defines a sequence of system calls how does the user-mode to kernel-mode transition happen? There must be a system call instruction, which: causes an exception (throws a software interrupt), which vectors to a kernel handler passes a parameter indicating which system call to invoke saves caller s state (regs, mode bit) so they can be restored OS must verify caller s parameters (e.g., pointers) must be a way to return to user mode once done 6

A kernel crossing illustrated User process System Call User Mode Mode bit = 1 Resume process Trap Mode bit = 0 Kernel Mode Mode bit = 0 Return Mode bit = 1 Save Caller s state Execute system call Restore state System call details How does the kernel know which system call? In a register Where are the parameters? in a register on the stack in a memory block <open>: push %ebx <open+1>: mov 0x10(%esp),%edx <open+5>: mov 0xc(%esp),%ecx <open+9>: mov 0x8(%esp),%ebx <open+13>: mov $0x5,%eax <open+18>: int $0x80 <open+20>: pop %ebx <open+21>: cmp $0xfffff001,%eax <open+26>: jae 0x2a189d <open+29> <open+28>: ret # system call handler stub ENTRY(system_call) pushl %eax # save orig_eax SAVE_ALL GET_THREAD_INFO(%ebp) cmpl $(nr_syscalls), %eax jae syscall_badsys syscall_call: call *sys_call_table(,%eax,4) movl %eax,eax(%esp) # store the return value 7

System call issues What would happen if kernel didn t save state? Why must the kernel verify arguments? How can you reference kernel objects as arguments or results to/from system calls? Why is a table of system calls in the kernel necessary? What functions are system calls? Process control Create process, allocate memory File management Create, read, delete file Device management Open device, read/write device, mount device Information maintenance Get time, get system data/parameters Communications Create/delete channel, send/receive message Programmers generally do not use system calls directly They use runtime libraies (e.g. Java, C) Why? 8

Memory protection OS must protect user programs from each other maliciousness, ineptitude OS must also protect itself from user programs integrity and security what about protecting user programs from OS? Simplest scheme: base and limit registers are these protected? Prog A Prog B Prog C base reg limit reg base and limit registers are loaded by OS before starting program More sophisticated memory protection coming later in the course paging, segmentation, virtual memory page tables, page table pointers translation lookaside buffers (TLBs) page fault handling 9

I/O operations I/O is moving data between main memory and a device controller E.g. network, disk, graphics I/O devices and the CPU can execute concurrently. A device driver for every device Knows details of the device Presents a uniform interface to the rest of OS Accessing I/O Devices Memory Mapped I/O I/O devices appear as regular memory to CPU Regular loads/stores used for accessing device Hardware Port I/O CPU has separate bus for I/O devices Special instructions are required 10

Polling I/O Each device controller typically has: Data-in register (for host to receive input from device) Data-out (for host to send output to device) Status register (read by host to determine device state) Control register (written by host to invoke command) Polling I/O handshaking: To write data to a device: Host repeatedly reads busy bit in status register until clear Host sets write bit in command register and writes output in data-out register Host sets command-ready bit in control register Controller notices command-ready bit, sets busy bit in status register Controller reads command register, notices write bit: reads data-out register and performs I/O (magic) Controller clears command-ready bit, clears the error bit (to indicate success) and clears the busy bit (to indicate it s finished) 11

Polling I/O What s the problem? CPU could spend most its time polling devices, while other jobs go undone. But devices can t be left to their own devices for too long Limited buffer at device - could overflow if doesn t get CPU service. Modern operating systems uses Interrupts to solve this dilemma. Interrupts: Notification from interface that device needs servicing Interrupts CPU hardware has a interrupt-request line (a wire) it checks after processing each instruction. Device controller raises interrupt, CPU catches it, interrupt handler dispatches and clears it. Modern OS needs more sophisticated mechanism: Ability to defer interrupt Efficient way to dispatch interrupt handler Multilevel interrupts to to distinguish between high and low priority interrupts. 12

Even interrupts are sometimes to slow: Device driver loads controller registers appropriately Controller examines registers, executes I/O Controller signals I/O completion to device driver Using interrupts High overhead for moving bulk data (i.e. disk I/O): One interrupt per byte.. Direct Memory Access (DMA) Transfer data directly between device and memory No CPU intervention Device controller transfers blocks of data Interrupts when block transfer completed As compared to when byte is completed Very useful for high-speed I/O devices 13

Interrupt Timeline Example I/O Program CPU Data Interrupt I/O Request Instruction execution cycle Data movement DMA Memory Instructions and Data Keyboard Disk Device Driver Driver and Keyboard Disk Controller Perform I/O Read Data 14

Timers How can the OS prevent runaway user programs from hogging the CPU (infinite loops?) use a hardware timer that generates a periodic interrupt before it transfers to a user program, the OS loads the timer with a time to interrupt quantum : how big should it be set? when timer fires, an interrupt transfers control back to OS at which point OS must decide which program to schedule next very interesting policy question: we ll dedicate a class to it Should the timer be privileged? for reading or for writing? Synchronization Interrupts cause a wrinkle: may occur any time, causing code to execute that interferes with code that was interrupted OS must be able to synchronize concurrent processes Synchronization: guarantee that short instruction sequences (e.g., readmodify-write) execute atomically one method: turn off interrupts before the sequence, execute it, then re-enable interrupts architecture must support disabling interrupts another method: have special complex atomic instructions read-modify-write test-and-set load-linked store-conditional 15

Concurrent programming Management of concurrency and asynchronous events is biggest difference between systems programming and traditional application programming modern event-oriented application programming is a middle ground Arises from the architecture Can be sugar-coated, but cannot be totally abstracted away Huge intellectual challenge Unlike vulnerabilities due to buffer overruns, which are just sloppy programming How do arch. trends impact OS design? Human:computer ratio Batch - time sharing - personal computers - embedded / pervasive computing Single job - time shared - internetworked Programmer:processor cost ratio assembly to C to Java to Perl languages command line to GUI to pen / voice interfaces Networking Isolation to dialup to LAN to WAN OS must devote more effort to communications Disconnected to wired to wireless OS must manage connectivity more Isolated to shared to attacked OS must provide more security / protection 16