Hardware OS & OS- Application interface

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

Anne Bracy CS 3410 Computer Science Cornell University

Anne Bracy CS 3410 Computer Science Cornell University

Syscalls, exceptions, and interrupts, oh my!

Hakim Weatherspoon CS 3410 Computer Science Cornell University

Traps, Exceptions, System Calls, & Privileged Mode

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

Architectural Support for Operating Systems

Prof. Kavita Bala and Prof. Hakim Weatherspoon CS 3410, Spring 2014 Computer Science Cornell University. P&H Chapter 4.9, pages , appendix A.

Traps, Exceptions, System Calls, & Privileged Mode

OPERATING SYSTEMS CS136

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

Lecture 2: Architectural Support for OSes

Operating Systems CMPSCI 377 Spring Mark Corner University of Massachusetts Amherst

Process Scheduling Queues

CSE 120 Principles of Operating Systems

CSE 153 Design of Operating Systems

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

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

COS 318: Operating Systems. Overview. Prof. Margaret Martonosi Computer Science Department Princeton University

Chapter 5 Input/Output. I/O Devices

CS 104 Computer Organization and Design

19: I/O. Mark Handley. Direct Memory Access (DMA)

W4118: interrupt and system call. Junfeng Yang

CSE 153 Design of Operating Systems Fall 18

The Kernel Abstraction

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

CS 134. Operating Systems. April 8, 2013 Lecture 20. Input/Output. Instructor: Neil Rhodes. Monday, April 7, 14

I/O Systems. Jo, Heeseung

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

Architectural Support for Operating Systems

CSE 120 Principles of Operating Systems

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

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

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

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

COS 318: Operating Systems

Processes. Johan Montelius KTH

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

A process. the stack

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

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

CS 5460/6460 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

Mechanisms for entering the system

Protection and System Calls. Otto J. Anshus

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

CS5460: Operating Systems

Computer Architecture CS 355 Busses & I/O System

ECEN 449 Microprocessor System Design. Hardware-Software Communication. Texas A&M University

Virtual Machines & the OS Kernel

Virtual Machines & the OS Kernel

Common Computer-System and OS Structures

Review: Hardware user/kernel boundary

Even coarse architectural trends impact tremendously the design of systems

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

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

The Kernel Abstraction. Chapter 2 OSPP Part I

Interconnecting Components

Operating Systems ECE344

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

CS 550 Operating Systems Spring Interrupt

Operating Systemss and Multicore Programming (1DT089)

John Wawrzynek & Nick Weaver

C02: Interrupts and I/O

Virtual Machines & the OS Kernel

ECE 341. Lecture # 19

[08] IO SUBSYSTEM 1. 1

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

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

Part I Overview Chapter 1: Introduction

Introduction to Operating Systems. Chapter Chapter

Introduction to Operating Systems Prof. Chester Rebeiro Department of Computer Science and Engineering Indian Institute of Technology, Madras

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

Operating Systems. System calls. Guillaume Salagnac. Fall Insa-Lyon IST Semester

hardware interrupts software interrupts

Part I Introduction Hardware and OS Review

Traps, Exceptions, System Calls, & Privileged Mode!

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

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

CS24: INTRODUCTION TO COMPUTING SYSTEMS. Spring 2018 Lecture 18

What Operating Systems Do An operating system is a program hardware that manages the computer provides a basis for application programs acts as an int

INPUT/OUTPUT ORGANIZATION

Operating Systems (2INC0) 2018/19. Introduction (01) Dr. Tanir Ozcelebi. Courtesy of Prof. Dr. Johan Lukkien. System Architecture and Networking Group

Input/Output Problems. External Devices. Input/Output Module. I/O Steps. I/O Module Function Computer Architecture

Architectural Support for Operating Systems

Machines and Virtualization. Systems and Networks Jeff Chase Spring 2006

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

MODERN OPERATING SYSTEMS. Chapter 3 Memory Management

Computer System Overview

Computer System Overview OPERATING SYSTEM TOP-LEVEL COMPONENTS. Simplified view: Operating Systems. Slide 1. Slide /S2. Slide 2.

What is an Operating System? A Whirlwind Tour of Operating Systems. How did OS evolve? How did OS evolve?

CSE 120. Overview. July 27, Day 8 Input/Output. Instructor: Neil Rhodes. Hardware. Hardware. Hardware

Example Networks on chip Freescale: MPC Telematics chip

Processes and Non-Preemptive Scheduling. Otto J. Anshus

EE458 - Embedded Systems Exceptions and Interrupts

Lecture 11: Interrupt and Exception. James C. Hoe Department of ECE Carnegie Mellon University

Chap.6 Limited Direct Execution. Dongkun Shin, SKKU

Transcription:

CS 4410 Operating Systems Hardware OS & OS- Application interface Summer 2013 Cornell University 1

Today How my device becomes useful for the user? HW-OS interface Device controller Device driver Interrupts OS-App interface System Call Privilege Levels Exceptions 2

A modern computer system disks mouse keyboard printer monitor CPU Disk controller USB controller Graphics adapter memory 3

HW-OS interface device device controller CPU device driver OS memory 4

HW-OS interface Device Controller: A set of chips on a plug-in board. It has local buffer storage and/or a set of special purpose registers. Responsible for moving data between device and registers/buffer. Responsible for making data available to the device driver. 5

HW-OS interface Device Driver: Device-specific software Part of the OS. Communicates with the device controller. Presents a uniform interface to the rest of the OS. 6

HW-OS interface Driver to Controller: device controller device Programmed I/O Bus device driver CPU CPU has dedicated, special instructions CPU has additional input/output wires (I/O bus) Instruction specifies device and operation Memory-mapped I/O Device communication goes over the memory bus Reads/Writes to special addresses are converted into I/O operations by dedicated device hardware Each device appears as if it is part of the memory address space Memory-mapped I/O is the predominant device interfacing technique in use 7

HW-OS interface controller to driver: Polling device controller device Bus device driver CPU CPU constantly checks controller for new data What's wrong with this scheme? How bad is it? Interrupt driven I/O Controller alerts CPU for an event CPU can do other things while it waits 8

Interrupt Driven I/O devices interrupt controller CPU memory An interrupt controller mediates between competing devices Raises an interrupt flag to get the CPU s attention Identifies the interrupting device Can disable (aka mask) interrupts if the CPU so desires 9

Interrupt Management Interrupt controllers manage interrupts Interrupt descriptors describe device Maskable/unmaskable interrupts Why? Examples? Interrupt priority A priority selector circuit examines all interrupting devices, reports highest level to the CPU Can optionally remap priority levels How are masks and priorities set? 10

Interrupt-driven I/O summary Normal interrupt-driven operation with memory-mapped I/O: 1. Application issues read() syscall 2. OS (driver) writes to device controller register How? 3. OS finds something useful to do with the CPU For example? 4. Meanwhile, the device asynchronously performs the operation. 5. Later, the device controller interrupts the CPU. 6. The CPU stops the current computation. 7. The CPU transfers the execution to the service routine (in the device driver). 8. The interrupt service routine executes. 9. On completion, the CPU resumes the interrupted computation. Can this be better? 11

Direct Memory Access (DMA) Transfer data directly between device and memory No CPU intervention required for moving bits Device raises interrupts solely when the block transfer is complete Critical for high-performance devices Examples? 12

OS-App interface device device controller CPU OS device driver Application memory 13

OS-App interface Application to Driver: System Calls Like calling a routine of the OS. Driver to Application: Pass data from OS memory space to application memory space. 14

System Calls Why do we need System Calls? Provide system services to applications Access hardware Communicate Request resources Examples? Need access control e.g. HALT, change MMU settings, set clock, reset devices, manipulate device settings, 15

Privilege Levels How the CPU knows if an application has the right to execute a privileged command? Use a privilege mode bit in the processor 0 = Untrusted = user, 1 = Trusted = OS 16

Privilege Mode Privilege mode bit indicates if the current program can perform privileged operations On system startup, privilege mode is set to 1, and the processor jumps to a well-known address The operating system (OS) boot code resides at this address The OS sets up the devices, initializes the MMU, loads applications, and resets the privilege bit before invoking the application Applications must transfer control back to OS for privileged operations Back to System Calls... 17

Sample System Calls Print character to screen Needs to multiplex the shared screen resource between multiple applications Send a packet on the network Needs to manipulate the internals of a device whose hardware interface is unsafe Allocate a page Needs to update page tables & MMU 18

System Calls A system call is a controlled transfer of execution from unprivileged code to the OS A potential alternative is to make OS code read-only, and allow applications to just jump to the desired system call routine. Why is this a bad idea? A SYSCALL instruction transfers control to a system call handler at a fixed address (software interrupt). 19

SYSCALL instruction SYSCALL instruction does an atomic jump to a controlled location Switches the SP to the kernel stack Saves the syscall number Saves arguments Saves the old (user) SP, PC (next command), privilege mode Sets the new privilege mode to 1 Sets the new PC to the kernel syscall handler Kernel system call handler carries out the desired system call Saves callee-save registers Examines the syscall number Checks arguments for sanity Performs operation Stores result in v0 Restores callee-save registers Performs a return from syscall instruction, which restores the privilege mode, SP and PC 20

Libraries and Wrappers Compilers do not emit SYSCALL instructions They do not know the interface exposed by the OS Instead, applications are compiled with standard libraries, which provide syscall wrappers printf() -> write(); malloc() -> sbrk(); recv(); open(); close(); Wrappers are: written in assembler, internally issue a SYSCALL instruction, pass arguments to kernel, pass result back to calling application 21

Typical Process Layout Libraries provide the glue between user processes and the OS libc linked in with all C programs Provides printf, malloc, and a whole slew of other routines necessary for programs Activation Records OBJECT1 OBJECT2 HELLO WORLD GO BIG RED CS! printf(char * fmt, ) { create the string to be printed SYSCALL 80 } malloc() { } strcmp() { } main() { printf ( HELLO WORLD ); printf( GO BIG RED CS );! Stack Heap Data Library Program Text 22

Full System Layout The OS is omnipresent and steps in where necessary to aid application execution Typically resides in high memory When an application needs to perform a privileged operation, it needs to invoke the OS Kernel Activation Records USER OBJECT1 OBJECT2 LINUX syscall_entry_point() { } Activation Records OBJECT1 OBJECT2 HELLO WORLD GO BIG RED CS! printf(char * fmt, ) { main() { } OS Stack OS Heap OS Data OS Text Stack Heap Data Library Program 23

Exceptional Situations System calls are control transfers to the OS, performed under the control of the user application Sometimes, need to transfer control to the OS at a time when the user program least expects it Division by zero, Alert from the power supply that electricity is about to go out, Alert from the network device that a packet just arrived, Clock notifying the processor that the clock just ticked, Some of these causes for interruption of execution have nothing to do with the user application Need a (slightly) different mechanism, that allows resuming the user application 24

Interrupts & Exceptions On an interrupt or exception Switches the sp to the kernel stack Saves the old (user) SP value Saves the old (user) PC value Saves the old privilege mode Saves cause of the interrupt/exception Sets the new privilege mode to 1 Sets the new PC to the kernel interrupt/exception handler Kernel interrupt/exception handler handles the event Saves all registers Examines the cause Performs operation required Restores all registers Performs a return from interrupt instruction, which restores the privilege mode, SP and PC 25

Syscall vs. Interrupt The differences lie in how they are initiated, and how much state needs to be saved and restored Syscall requires much less state saving Caller-save registers are already saved by the application Interrupts typically require saving and restoring the full state of the processor Why? 26

Terminology Trap Any kind of a control transfer to the OS Syscall Synchronous, program-initiated control transfer from user to the OS to obtain service from the OS e.g. SYSCALL Exception Asynchronous, program-initiated control transfer from user to the OS in response to an exceptional event e.g. Divide by zero, segmentation fault Interrupt Asynchronous, device-initiated control transfer from device to the OS e.g. Clock tick, network packet 27

Today How my device becomes useful for the user? HW-OS interface Device controller Device driver Interrupts OS-App interface System Call Privilege Levels Exceptions 28

Activity If we want to add the System Call machine_active_time ; how many hours the machine is ON, which SW components do we have to add and where? 29