Operating Systems. Steven Hand. Michaelmas / Lent Term 2008/ lectures for CST IA. Handout 4. Operating Systems

Similar documents
[08] IO SUBSYSTEM 1. 1

I/O Systems. 04/16/2007 CSCI 315 Operating Systems Design 1

Module 12: I/O Systems

Module 12: I/O Systems

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

Chapter 13: I/O Systems

Chapter 13: I/O Systems

Device-Functionality Progression

Chapter 12: I/O Systems. I/O Hardware

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

Chapter 13: I/O Systems

Chapter 13: I/O Systems. Chapter 13: I/O Systems. Objectives. I/O Hardware. A Typical PC Bus Structure. Device I/O Port Locations on PCs (partial)

Chapter 13: I/O Systems

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

Chapter 13: I/O Systems

Lecture 13 Input/Output (I/O) Systems (chapter 13)

CSE 4/521 Introduction to Operating Systems. Lecture 24 I/O Systems (Overview, Application I/O Interface, Kernel I/O Subsystem) Summer 2018

Chapter 12: I/O Systems

Chapter 13: I/O Systems

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

Che-Wei Chang Department of Computer Science and Information Engineering, Chang Gung University

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

Module 11: I/O Systems

Chapter 13: I/O Systems. Operating System Concepts 9 th Edition

Silberschatz and Galvin Chapter 12

Chapter 13: I/O Systems

Chapter 13: I/O Systems

Chapter 13: I/O Systems

Lecture 15: I/O Devices & Drivers

Ref: Chap 12. Secondary Storage and I/O Systems. Applied Operating System Concepts 12.1

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

COT 4600 Operating Systems Fall Dan C. Marinescu Office: HEC 439 B Office hours: Tu-Th 3:00-4:00 PM

Outline. Operating Systems: Devices and I/O p. 1/18

I/O AND DEVICE HANDLING Operating Systems Design Euiseong Seo

Input/Output Systems

Chapter 11: File-System Interface

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

Chapter 10: File System. Operating System Concepts 9 th Edition

Chapter 10: File-System Interface

Chapter 10: File-System Interface

File Systems: Interface and Implementation

File Systems: Interface and Implementation

Input/Output Systems

Chapter 11: File-System Interface

EI 338: Computer Systems Engineering (Operating Systems & Computer Architecture)

Chapter 11: File-System Interface. Operating System Concepts 9 th Edition

Lecture 10 File Systems - Interface (chapter 10)

Input-Output (I/O) Input - Output. I/O Devices. I/O Devices. I/O Devices. I/O Devices. operating system must control all I/O devices.

Chapter 11: File-System Interface. File Concept. File Structure

Chapter 11: File-System Interface

Operating Systems 2010/2011

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

Input Output (IO) Management

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

File Concept Access Methods Directory and Disk Structure File-System Mounting File Sharing Protection

File-System Interface. File Structure. File Concept. File Concept Access Methods Directory Structure File-System Mounting File Sharing Protection

Chapter 7: File-System

I/O SYSTEMS. Sunu Wibirama

V. File System. SGG9: chapter 11. Files, directories, sharing FS layers, partitions, allocations, free space. TDIU11: Operating Systems

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

CSC Operating Systems Spring Lecture - XIX Storage and I/O - II. Tevfik Koşar. Louisiana State University.

RAID Structure. RAID Levels. RAID (cont) RAID (0 + 1) and (1 + 0) Tevfik Koşar. Hierarchical Storage Management (HSM)

File Systems: Interface and Implementation

Today: I/O Systems. Architecture of I/O Systems

Chapter 11: File System Interface

Operating Systems 2010/2011

Chapter 11: File-System Interface

Chapter 10: File-System Interface. File Concept Access Methods Directory Structure File-System Mounting File Sharing Protection

CS720 - Operating Systems

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

Operating System 1 (ECS-501)

Chapter 11: File-System Interface

Computer System Overview

Chapter 11: File-System Interface. Long-term Information Storage. File Structure. File Structure. File Concept. File Attributes

Chapter 10: File-System Interface. Operating System Concepts 8 th Edition

Chapter 10: File-System Interface. Operating System Concepts with Java 8 th Edition

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

Chapter 10: File System

CS420: Operating Systems. Kernel I/O Subsystem

I/O Systems. Jo, Heeseung

Principles of Operating Systems CS 446/646

Chapter 11: File-System Interface

CS3600 SYSTEMS AND NETWORKS

Virtual Memory cont d.; File System Interface. 03/30/2007 CSCI 315 Operating Systems Design 1

CS370 Operating Systems

Chapter 10: File-System Interface

Comp 204: Computer Systems and Their Implementation. Lecture 18: Devices

Chapter 11: File-System Interface. File Concept. File Structure

CMSC421: Principles of Operating Systems

Lecture 1 Introduction (Chapter 1 of Textbook)

I.-C. Lin, Assistant Professor. Textbook: Operating System Concepts 8ed CHAPTER 10: FILE SYSTEM

Operating Systems. Lecture 09: Input/Output Management. Elvis C. Foster

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

CS370 Operating Systems

CSCI-GA Operating Systems I/O. Hubertus Franke

-Device. -Physical or virtual thing that does something -Software + hardware to operate a device (Controller runs port, Bus, device)

Common Computer-System and OS Structures

Chapter 5 Input/Output. I/O Devices

Chapter 1: Introduction

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

Transcription:

Operating Systems Steven Hand Michaelmas / Lent Term 2008/09 17 lectures for CST IA Handout 4 Operating Systems N/H/MWF@12

I/O Hardware Wide variety of devices which interact with the computer via I/O: Human readable: graphical displays, keyboard, mouse, printers Machine readable: disks, tapes, CD, sensors Communications: modems, network interfaces They differ significantly from one another with regard to: Data rate Complexity of control Unit of transfer Direction of transfer Data representation Error handling hard to present a uniform I/O system which masks all complexity I/O subsystem is generally the messiest part of OS. Operating Systems I/O Subsystem 1

I/O Subsystem Unpriv Application-I/O Interface Virtual Device Layer Priv I/O Buffering I/O Scheduling Common I/O Functions Device Driver Device Driver Device Driver Device Driver Layer H/W Keyboard HardDisk Network Device Layer Programs access virtual devices: terminal streams not terminals windows not frame buffer event stream not raw mouse files not disk blocks printer spooler not parallel port transport protocols not raw ethernet OS deals with processor device interface: I/O instructions versus memory mapped I/O hardware type (e.g. 10 s of serial chips) polled versus interrupt driven processor interrupt mechanism Operating Systems I/O Subsystem 2

Polled Mode I/O * status error (R/O) command-ready (W/O) device-busy (R/O) data (r/w) command read (W/O) write (W/O) Consider a simple device with three registers: status, data and command. (Host can read and write these via bus) Then polled mode operation works as follows: Host repeatedly reads device busy until clear. Host sets e.g. write bit in command register, and puts data into data register. Host sets command ready bit in status register. Device sees command ready and sets device busy. Device performs write operation. Device clears command ready & then device busy. What s the problem here? Operating Systems I/O Subsystem 3

Interrupts Revisited Recall: to handle mismatch between CPU and device speeds, processors provide an interrupt mechanism: at end of each instruction, processor checks interrupt line(s) for pending interrupt if line is asserted then processor: saves program counter, saves processor status, changes processor mode, and jump to a well known address (or its contents) after interrupt-handling routine is finished, can use e.g. the rti instruction to resume where we left off. Some more complex processors provide: multiple levels of interrupts hardware vectoring of interrupts mode dependent registers Operating Systems I/O Subsystem 4

Interrupt-Driven I/O Can split implementation into low-level interrupt handler plus per-device interrupt service routine: interrupt handler (processor-dependent) may: save more registers establish a language environment (e.g. a C run-time stack) demultiplex interrupt in software. invoke appropriate interrupt service routine (ISR) Then interrupt service routine (device-specific but not processor-specific) will: 1. for programmed I/O device: transfer data. clear interrupt (sometimes a side effect of tx). 1. for DMA device: acknowledge transfer. 2. request another transfer if there are any more I/O requests pending on device. 3. signal any waiting processes. 4. enter scheduler or return. Question: who is scheduling who? Operating Systems I/O Subsystem 5

Device Classes Homogenising device API completely not possible OS generally splits devices into four classes: 1. Block devices (e.g. disk drives, CD): commands include read, write, seek raw I/O or file-system access memory-mapped file access possible 2. Character devices (e.g. keyboards, mice, serial ports): commands include get, put libraries layered on top to allow line editing 3. Network Devices varying enough from block and character to have own interface Unix and Windows/NT use socket interface 4. Miscellaneous (e.g. clocks and timers) provide current time, elapsed time, timer ioctl (on UNIX) covers odd aspects of I/O such as clocks and timers. Operating Systems I/O Subsystem 6

I/O Buffering Buffering: OS stores (its own copy of) data in memory while transferring to or from devices to cope with device speed mismatch to cope with device transfer size mismatch to maintain copy semantics OS can use various kinds of buffering: 1. single buffering OS assigns a system buffer to the user request 2. double buffering process consumes from one buffer while system fills the next 3. circular buffers most useful for bursty I/O Many aspects of buffering dictated by device type: character devices line probably sufficient. network devices bursty (time & space). block devices lots of fixed size transfers. (last usually major user of buffer memory) Operating Systems I/O Subsystem 7

Blocking v. Nonblocking I/O From the programmer s point of view, I/O system calls exhibit one of three kinds of behaviour: 1. Blocking: process suspended until I/O completed easy to use and understand. insufficient for some needs. 2. Nonblocking: I/O call returns as much as available returns almost immediately with count of bytes read or written (possibly 0). can be used by e.g. user interface code. essentially application-level polled I/O. 3. Asynchronous: process continues to run while I/O executes I/O subsystem explicitly signals process when its I/O request has completed. most flexible (and potentially efficient).... but also most difficult to use. Most systems provide both blocking and non-blocking I/O interfaces; modern systems (e.g. NT, Linux) also support asynchronous I/O, but used infrequently. Operating Systems I/O Subsystem 8

Other I/O Issues Caching: fast memory holding copy of data can work with both reads and writes key to I/O performance Scheduling: e.g. ordering I/O requests via per-device queue some operating systems try fairness... Spooling: queue output for a device useful for single user devices which can serve only one request at a time (e.g. printer) Device reservation: system calls for acquiring or releasing exclusive access to a device (careful!) Error handling: e.g. recover from disk read, device unavailable, transient write failures, etc. most I/O system calls return an error number or code when an I/O request fails system error logs hold problem reports. Operating Systems I/O Subsystem 9

I/O and Performance I/O is a major factor in overall system performance demands CPU to execute device driver, kernel I/O code, etc. context switches due to interrupts data copying, buffering, etc (network traffic especially stressful) Improving performance: reduce number of context switches reduce data copying reduce # interrupts by using large transfers, smart controllers, adaptive polling (e.g. Linux NAPI) use DMA where possible balance CPU, memory, bus and I/O for best throughput. Improving I/O performance is a major remaining OS challenge Operating Systems I/O Subsystem 10

File Management user space filing system text name user file-id information requested from file Directory Service Storage Service I/O subsystem Disk Handler Filing systems have two main components: 1. Directory Service maps from names to file identifiers. handles access & existence control 2. Storage Service provides mechanism to store data on disk includes means to implement directory service Operating Systems Filing Systems 11

File Concept What is a file? Basic abstraction for non-volatile storage. Typically comprises a single contiguous logical address space. Internal structure: 1. None (e.g. sequence of words, bytes) 2. Simple record structures lines fixed length variable length 3. Complex structures formatted document relocatable object file Can simulate 2,3 with byte sequence by inserting appropriate control characters. All a question of who decides: operating system program(mer). Operating Systems Files and File Meta-data 12

Naming Files Files usually have at least two kinds of name : 1. system file identifier (SFID): (typically) a unique integer value associated with a given file SFIDs are the names used within the filing system itself 2. human-readable name, e.g. hello.java what users like to use mapping from human name to SFID is held in a directory, e.g. Name SFID hello.java 12353 Makefile 23812 README 9742 directories also non-volatile must be stored on disk along with files. 3. Frequently also get user file identifier (UFID) used to identify open files (see later) Operating Systems Files and File Meta-data 13

File Meta-data SFID Metadata Table (on disk) f(sfid) File Control Block Type (file or directory) Location on Disk Size in bytes Time of creation Access permissions As well as their contents and their name(s), files can have other attributes, e.g. Location: pointer to file location on device Size: current file size Type: needed if system supports different types Protection: controls who can read, write, etc. Time, date, and user identification: for protection, security and usage monitoring. Together this information is called meta-data. It is contained in a file control block. Operating Systems Files and File Meta-data 14

Directory Name Space (I) What are the requirements for our name space? Efficiency: locating a file quickly. Naming: user convenience allow two (or more generally N) users to have the same name for different files allow one file have several different names Grouping: logical grouping of files by properties (e.g. all Java programs, all games) First attempts: Single-level: one directory shared between all users naming problem grouping problem Two-level directory: one directory per user access via pathname (e.g. bob:hello.java) can have same filename for different user but still no grouping capability. Operating Systems Directories 15

Directory Name Space (II) Ann Bob Yao mail A D E F java I J sent B C G H Get more flexibility with a general hierarchy. directories hold files or [further] directories create/delete files relative to a given directory Human name is full path name, but can get long: e.g. /usr/groups/x11r5/src/mit/server/os/4.2bsd/utils.c offer relative naming login directory current working directory What does it mean to delete a [sub]-directory? Operating Systems Directories 16

Directory Name Space (III) Ann Bob Yao mail A D E F java I J sent B C G H Hierarchy good, but still only one name per file. extend to directed acyclic graph (DAG) structure: allow shared subdirectories and files. can have multiple aliases for the same thing Problem: dangling references Solutions: back-references (but require variable size records); or reference counts. Problem: cycles... Operating Systems Directories 17

Directory Implementation /Ann/mail/B Name Ann Bob Yao D Y Y Y SFID 1034 179 7182 Name mail A D Y N SFID 2165 Name 5797 sent B C D Y N N SFID 434 2459 25 Directories are non-volatile store as files on disk, each with own SFID. Must be different types of file (for traversal) Explicit directory operations include: create directory delete directory list contents select current working directory insert an entry for a file (a link ) Operating Systems Directories 18

File Operations (I) UFID SFID File Control Block (Copy) 1 2 3 4 23421 3250 10532 7122 location on disk, size,... " " " " " " Opening a file: UFID = open(<pathname>) 1. directory service recursively searches for components of <pathname> 2. if all goes well, eventually get SFID of file. 3. copy file control block into memory. 4. create new UFID and return to caller. Create a new file: UFID = create(<pathname>) Once have UFID can read, write, etc. various modes (see next slide) Closing a file: status = close(ufid) 1. copy [new] file control block back to disk. 2. invalidate UFID Operating Systems Filesystem Interface 19

File Operations (II) start of file already accessed to be read end of file current file position Associate a cursor or file position with each open file (viz. UFID) initialised at open time to refer to start of file. Basic operations: read next or write next, e.g. read(ufid, buf, nbytes), or read(ufid, buf, nrecords) Sequential Access: above, plus rewind(ufid). Direct Access: read N or write N allow random access to any part of file. can implement with seek(ufid, pos) Other forms of data access possible, e.g. append-only (may be faster) indexed sequential access mode (ISAM) Operating Systems Filesystem Interface 20

Other Filing System Issues Access Control: file owner/creator should be able to control what can be done, and by whom. normally a function of directory service checks done at file open time various types of access, e.g. read, write, execute, (append?), delete, list, rename more advanced schemes possible (see later) Existence Control: what if a user deletes a file? probably want to keep file in existence while there is a valid pathname referencing it plus check entire FS periodically for garbage existence control can also be a factor when a file is renamed/moved. Concurrency Control: need some form of locking to handle simultaneous access may be mandatory or advisory locks may be shared or exclusive granularity may be file or subset Operating Systems Filesystem Interface 21