Operating Systems. V. Input / Output

Similar documents
Operating Systems. V. Input / Output. Eurecom

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

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

CIS Operating Systems I/O Systems & Secondary Storage. Professor Qiang Zeng Fall 2017

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

CIS Operating Systems I/O Systems & Secondary Storage. Professor Qiang Zeng Spring 2018

Operating Systems 2010/2011

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

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

I/O Systems. Jo, Heeseung

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

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

Hard Disk Drives (HDDs)

Devices. Today. Comp 104: Operating Systems Concepts. Operating System An Abstract View 05/01/2017. Devices. Devices

Chapter 13: I/O Systems

UNIT 4 Device Management

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

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

Hard Disk Drives (HDDs) Jin-Soo Kim Computer Systems Laboratory Sungkyunkwan University

Device-Functionality Progression

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

Chapter 13: I/O Systems

CS370 Operating Systems

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

Chapter-6. SUBJECT:- Operating System TOPICS:- I/O Management. Created by : - Sanjay Patel

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

I/O SYSTEMS. Sunu Wibirama

Input Output (IO) Management

Module 12: I/O Systems

Chapter 12: Mass-Storage Systems. Operating System Concepts 8 th Edition,

Chapter 13: I/O Systems

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

[08] IO SUBSYSTEM 1. 1

Chapter 13: I/O Systems

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

Chapter 13: I/O Systems

I/O & Storage. Jin-Soo Kim ( Computer Systems Laboratory Sungkyunkwan University

I/O AND DEVICE HANDLING Operating Systems Design Euiseong Seo

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

CSE 451: Operating Systems Winter I/O System. Gary Kimura

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

File. File System Implementation. Operations. Permissions and Data Layout. Storing and Accessing File Data. Opening a File

Chapter 13: I/O Systems

Input/Output 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)

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

Chapter 5 Input/Output. I/O Devices

Module 12: I/O Systems

Chapter 12: I/O Systems

Chapter 13: I/O Systems

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

QUESTION BANK UNIT I

Answer to exercises chap 13.2

Overview of Mass Storage Structure

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

CS370: Operating Systems [Spring 2017] Dept. Of Computer Science, Colorado State University

I/O Management and Disk Scheduling. Chapter 11

CSE 4/521 Introduction to Operating Systems. Lecture 27 (Final Exam Review) Summer 2018

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

CS370 Operating Systems

Principles of Operating Systems CS 446/646

Free Space Management

Operating Systems. IV. Memory Management

Introduction. Operating Systems. Outline. Hardware. I/O Device Types. Device Controllers. One OS function is to control devices

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

Lecture 21 Disk Devices and Timers

The Device Driver Interface. Input/Output Devices. System Call Interface. Device Management Organization

Module 11: I/O Systems

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

Chapter 10: Mass-Storage Systems

Chapter 12: Secondary-Storage Structure. Operating System Concepts 8 th Edition,

CSE 380 Computer Operating Systems

CHAPTER 12: MASS-STORAGE SYSTEMS (A) By I-Chen Lin Textbook: Operating System Concepts 9th Ed.

Introduction. Operating Systems. Outline. Hardware. I/O Device Types. Device Controllers. (done)

V. Mass Storage Systems

CS370: Operating Systems [Fall 2018] Dept. Of Computer Science, Colorado State University

Chapter 5 - Input / Output

I/O Hardwares. Some typical device, network, and data base rates

I/O Device Controllers. I/O Systems. I/O Ports & Memory-Mapped I/O. Direct Memory Access (DMA) Operating Systems 10/20/2010. CSC 256/456 Fall

CS370: Operating Systems [Fall 2018] Dept. Of Computer Science, Colorado State University

Lecture 15: I/O Devices & Drivers

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

Input/Output Management

CIS 21 Final Study Guide. Final covers ch. 1-20, except for 17. Need to know:

Chapter 13: I/O Systems

CS420: Operating Systems. Mass Storage Structure

OPERATING SYSTEMS CS3502 Spring Input/Output System Chapter 9

EIDE, ATA, SATA, USB,

CS370: System Architecture & Software [Fall 2014] Dept. Of Computer Science, Colorado State University

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

Introduction. Operating Systems. Outline. Hardware. I/O Device Types. Device Controllers. One OS function is to control devices

Input/Output. Today. Next. Principles of I/O hardware & software I/O software layers Disks. Protection & Security

C02: Interrupts and I/O

File. File System Implementation. File Metadata. File System Implementation. Direct Memory Access Cont. Hardware background: Direct Memory Access

NWI-IBC019: Operating systems

Chapter 7: Mass-storage structure & I/O systems. Operating System Concepts 8 th Edition,

CPS104 Computer Organization and Programming Lecture 18: Input-Output. Outline of Today s Lecture. The Big Picture: Where are We Now?

Disk Scheduling. Based on the slides supporting the text

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

Transcription:

Operating Systems V. Input / Output Ludovic Apvrille ludovic.apvrille@telecom-paristech.fr Eurecom, office 470 http://soc.eurecom.fr/os/ @OS Eurecom

Devices of a Computer System Applications OS CPU Memory (RAM) 2/45 Fall 2017 Institut Mines-Telecom Operating Systems - Input/Output

From a hardware point of view Fitbit: What are the I/O Components? 3/45 Fall 2017 Institut Mines-Telecom Operating Systems - Input/Output

Issues OS manages devices Protection Sharing Ease-of-use Performance OS = interface between devices and other parts of the system If possible, device-independent interface OS sends commands to devices OS gets information / results from devices OS handles errors High fraction of all lines of code of OS 4/45 Fall 2017 Institut Mines-Telecom Operating Systems - Input/Output

Outline From a hardware point of view Introduction Direct Memory Access Characteristics of Devices From a hardware point of view Introduction Direct Memory Access Characteristics of Devices 5/45 Fall 2017 Institut Mines-Telecom Operating Systems - Input/Output

I/O Architecture Introduction Direct Memory Access Characteristics of Devices CPU Memory Input/Output Device. 6/45 Fall 2017 Institut Mines-Telecom Operating Systems - Input/Output

I/O Architecture (Zoom) Introduction Direct Memory Access Characteristics of Devices CPU Memory Programmable Interrupt controller IRQ line I/O bus Control register Status register Input Input register Output register I/O ports Device's I/O I/O Interface Device's I/O I/O Controller 7/45 Fall 2017 Institut Mines-Telecom Operating Systems - Input/Output

I/O Ports From a hardware point of view Introduction Direct Memory Access Characteristics of Devices Each device connected to the I/O bus has its own set of I/O addresses Read / write: assembly language instructions If special registers: in, ins, out, outs () Privileged assembly instructions (use of syscalls for user processes) If I/O ports mapped in main memory: mov, etc. Protected memory 8/45 Fall 2017 Institut Mines-Telecom Operating Systems - Input/Output

I/O Interface Introduction Direct Memory Access Characteristics of Devices = Hardware circuit between a group of I/O ports and the corresponding device controller Values in the I/O ports translated to commands and data Detects changes in the device s state Updates I/O ports accordingly May send an interrupt request through an IRQ line Two types of interfaces Custom I/O interfaces For one specific hardware: Keyboard, disk interface, etc. General-purpose USB, Thunderbolt, SCSI (Small Computer System Interface), SATA (Serial Advanced Technology Attachment) 9/45 Fall 2017 Institut Mines-Telecom Operating Systems - Input/Output

Introduction Direct Memory Access Characteristics of Devices Device Controller Interprets high-level commands received from the I/O interface Executes specific actions by issuing proper sequences of electrical signals Interprets signals coming from the device Modifies the value of the status register through the I/O interface Example: Disk controller Receives commands such as Write this block of data Issues low-level orders such as Position the disk head on the right track, etc. Very complex because management of cache memory, etc. 10/45 Fall 2017 Institut Mines-Telecom Operating Systems - Input/Output

Introduction Direct Memory Access Characteristics of Devices Polling: OS and Device Controller 11/45 Fall 2017 Institut Mines-Telecom Operating Systems - Input/Output

Introduction Direct Memory Access Characteristics of Devices Interrupt: OS and Device Controller 12/45 Fall 2017 Institut Mines-Telecom Operating Systems - Input/Output

Memory Transfer Introduction Direct Memory Access Characteristics of Devices From main memory to a device memory From a device memory to main memory With e.g. mov instructions Efficient for a small amount of data Quite inefficient for a large amount of data CPU is busy during the whole transfer Direct Memory Access Direct Memory Access Controller: External entity which can be programmed to transfer data DMAC programming is expensive, its use is reserved for large transfers 13/45 Fall 2017 Institut Mines-Telecom Operating Systems - Input/Output

Steps in a DMA Transfer Introduction Direct Memory Access Characteristics of Devices (Source: Tanenbaum) Question: In the figure, what is in fact meant by CPU? 14/45 Fall 2017 Institut Mines-Telecom Operating Systems - Input/Output

Introduction Direct Memory Access Characteristics of Devices Characteristics of Devices Character stream vs. block stream Character: Data transfer of one byte only Block: Data transfer of blocks of bytes Sequential access vs. random access Sequential: Data transfer done in a fixed order forced by the device Random: Data transfer can concern any of the available data storage locations Synchronous vs. asynchronous Synchronous: Predictable response times for data transfer Asynchronous: Irregular or unpredictable response times 15/45 Fall 2017 Institut Mines-Telecom Operating Systems - Input/Output

Introduction Direct Memory Access Characteristics of Devices Characteristics of Devices (Cont.) Sharable vs. dedicated Sharable: Can be used concurrently by several processes Dedicated: Cannot be used concurrently Speed of operations Speed ranges from a few bytes per second to gigabytes per second Read-write, read only, write only Some devices perform both input and output Others support only one data direction 16/45 Fall 2017 Institut Mines-Telecom Operating Systems - Input/Output

From a hardware point of view Introduction Direct Memory Access Characteristics of Devices Aspect Variation Example Data-transfer mode Character Block Access method Sequential Random Transfer schedule Synchronous Asynchronous Sharing Dedicated Shareable Device speed Latency Transfer rate Delay between operation I/O direction Read only Write only Read and Write 17/45 Fall 2017 Institut Mines-Telecom Operating Systems - Input/Output

Outline From a hardware point of view From a hardware point of view 18/45 Fall 2017 Institut Mines-Telecom Operating Systems - Input/Output

Kernel I/O Subsystem Block mode: read(), write(), seek()... Character mode: put(), get(),... Blocking / non blocking system calls I/O Scheduling, buffering, caching, access control, error management 19/45 Fall 2017 Institut Mines-Telecom Operating Systems - Input/Output

Blocking and Non-Blocking System Calls Blocking system call Application is suspended Application is moved to a wait queue When the I/O is completed, the application is moved to a run queue Non-blocking system call E.g., used for keyboard / mouse input Returns immediately Answer is provided as... Modification of variables Signal Call-back routine 20/45 Fall 2017 Institut Mines-Telecom Operating Systems - Input/Output

Blocking I/O Request Handling 21/45 Fall 2017 Institut Mines-Telecom Operating Systems - Input/Output

Kernel I/O Subsystem: Scheduling Main idea to improve performance: Classify I/O requests Requests are classified by device Apply scheduling algorithms on requests Algorithms defined according to device characteristics 22/45 Fall 2017 Institut Mines-Telecom Operating Systems - Input/Output

Kernel I/O Subsystem: Buffering What s for? Fragmentation or reassembly of data Difference of speed between producers and consumers Copy semantics issue! Data that must be copied to a device should be put in another buffer before returning to the application... Why? 23/45 Fall 2017 Institut Mines-Telecom Operating Systems - Input/Output

Kernel I/O Subsystem: Double Buffering 24/45 Fall 2017 Institut Mines-Telecom Operating Systems - Input/Output

Kernel I/O Subsystem: Caching Cache = Memory that holds on a faster storage a copy of data stored elsewhere Main memory can be used to increase I/O operations efficiency For example, files can be cached in main memory Physical I/O operations on disk are deferred Write operation = buffer copy 25/45 Fall 2017 Institut Mines-Telecom Operating Systems - Input/Output

Kernel I/O Subsystem: Access Control Spooling Ex: printer Each job is independent and should not interfere with another one OS uses lists of jobs for each device which requires spooling FIFO policy: each job is sent one after the other Other policies might be used... Exclusive device access A process can allocate a device If the device is not idle, the process might be queued (Windows) or an error is returned The process which obtains the device can authorize other devices / processes / users to access it Parameter in system call 26/45 Fall 2017 Institut Mines-Telecom Operating Systems - Input/Output

Kernel I/O Subsystem: Error Handling I/O system calls return information about I/O completion May return: 1. 1 bit of information 2. Error number (UNIX) 3. Sometimes, the device provides more information (SCSI devices) 27/45 Fall 2017 Institut Mines-Telecom Operating Systems - Input/Output

Performance Issue I/O is a major factor in system performance! How to improve performance? Reduce the number of context switches Reduce frequency of interrupts Use polling if busy-waiting can be minimized Increase concurrency with DMA Increase the efficiency of large transfers with DMA Reduce the number of buffer copies Move processing primitives in hardware whenever possible 28/45 Fall 2017 Institut Mines-Telecom Operating Systems - Input/Output

Outline From a hardware point of view Disk drive management Linux From a hardware point of view Disk drive management Linux 29/45 Fall 2017 Institut Mines-Telecom Operating Systems - Input/Output

Disk drive management Linux Storage Supports Type Capacity Access Transfer Price Usage time rate per Byte Tape Huge Poor High Low Backup HDD SSD Do you know other storage devices? What about their characteristics? 30/45 Fall 2017 Institut Mines-Telecom Operating Systems - Input/Output

Disk Formatting Disk drive management Linux Low-level formatting Organization in sectors Logical formatting File-system data structure is stored on the disk FAT, FAT32, NTFS, ZFS, etc. 31/45 Fall 2017 Institut Mines-Telecom Operating Systems - Input/Output

Disk Scheduling Disk drive management Linux How to efficiently schedule requests on disks? Understand how hardware works, and use it efficiently! Seek time Time to move the disk arm (head) to the right cylinder Rotational latency Time to move to the desired sector Bandwidth Total number of bytes transferred divided by the total time between the first request for service and the completion of the last transfer Let s work on the seek time! 32/45 Fall 2017 Institut Mines-Telecom Operating Systems - Input/Output

Disk drive management Linux Disk Scheduling: First-Come First-Served (FCFS) 33/45 Fall 2017 Institut Mines-Telecom Operating Systems - Input/Output

Disk drive management Linux Disk Scheduling: Shortest-Seek-Time-First (SSTF) 34/45 Fall 2017 Institut Mines-Telecom Operating Systems - Input/Output

Disk drive management Linux Disk Scheduling: SCAN (Elevator Algo.) 35/45 Fall 2017 Institut Mines-Telecom Operating Systems - Input/Output

Disk drive management Linux Disk Scheduling: C-SCAN 36/45 Fall 2017 Institut Mines-Telecom Operating Systems - Input/Output

Disk drive management Linux Disk Scheduling: C-LOOK 37/45 Fall 2017 Institut Mines-Telecom Operating Systems - Input/Output

Disk drive management Linux Disk Scheduling: Conclusion SSTF is common If heavy load on the disk: SCAN and C-SCAN perform better Performance depends on the number and types of requests Requests for disk service can be influenced by the file-allocation method Either SSTF or LOOK is a reasonable choice for the default algorithm The disk-scheduling algorithm should be written as a separate module of the Operating System, allowing it to be replaced with a different algorithm if necessary A disk-operation scheduling algorithm is sometimes provided within the disk 38/45 Fall 2017 Institut Mines-Telecom Operating Systems - Input/Output

Disk drive management Linux Device Drivers in the Linux Kernel This picture is excerpted from Write a Linux Hardware Device Driver, Andrew O Shauqhnessy, Unix world 39/45 Fall 2017 Institut Mines-Telecom Operating Systems - Input/Output

Device Files Disk drive management Linux Devices can be accessed throughout a file-based interface write(), read() /dev/lp0 Type Either block or character Major number 1... 255: identifies the device type Same major number and same type same device driver Minor number Specific device among a group of devices sharing common features 40/45 Fall 2017 Institut Mines-Telecom Operating Systems - Input/Output

of Device Files Disk drive management Linux Block device Major number Minor number [apvrille@rocky][/dev]$ ls -l sda* brw-rw---- 1 root disk 8, 0 Oct 27 14:41 sda brw-rw---- 1 root disk 8, 1 Oct 27 14:41 sda1 brw-rw---- 1 root disk 8, 2 Oct 27 14:41 sda2 [apvrille@rocky][/dev]$ ls -al rtc* lrwxrwxrwx 1 root root 4 Oct 27 14:40 rtc -> rtc0 crw------- 1 root root 254, 0 Oct 27 14:40 rtc0 [apvrille@rocky][/dev]$ ls -al std* lrwxrwxrwx 1 root root 15 Oct 27 14:40 stderr -> /proc/self/fd/2 lrwxrwxrwx 1 root root 15 Oct 27 14:40 stdin -> /proc/self/fd/0 lrwxrwxrwx 1 root root 15 Oct 27 14:40 stdout -> /proc/self/fd/1 [apvrille@rocky][/dev]$ ls -al console* crw------- 1 root root 5, 1 Oct 27 14:40 console Access rights 41/45 Fall 2017 Institut Mines-Telecom Operating Systems - Input/Output

Device drivers Disk drive management Linux VFS uses a set of common functions init(), open(), read(), write(), close(), etc. A driver is registered as managing a group of devices Monitoring of I/O operations: Polling, Interrupts 42/45 Fall 2017 Institut Mines-Telecom Operating Systems - Input/Output

Polling (Read Operation) Disk drive management Linux 43/45 Fall 2017 Institut Mines-Telecom Operating Systems - Input/Output

Interrupts Disk drive management Linux 1. The device driver starts the I/O operation 2. It invokes the sleep on() function (see on next slide) Or interruptible sleep on() Parameter: I/O wait queue in which it wants to wait for 3. Then, it sleeps 4. When the interrupt occurs, the interrupt handler invokes wake up() on all processes waiting in the corresponding device queue 5. The waked-up device driver can therefore check for the result of the operation 44/45 Fall 2017 Institut Mines-Telecom Operating Systems - Input/Output

Disk drive management Linux Interrupts: sleep on() Function 45/45 Fall 2017 Institut Mines-Telecom Operating Systems - Input/Output