操作系统原理与设计. 第 13 章 IO Systems(IO 管理 ) 陈香兰 2009 年 09 月 01 日 中国科学技术大学计算机学院

Similar documents
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)

Module 12: 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

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

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

Module 12: I/O Systems

Chapter 13: 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

Chapter 13: I/O Systems

Chapter 13: I/O Systems

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

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

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

Silberschatz and Galvin Chapter 12

I/O AND DEVICE HANDLING Operating Systems Design Euiseong Seo

Input/Output Systems

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

Chapter 13: I/O Systems

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

Chapter 13: I/O Systems

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

I/O SYSTEMS. Sunu Wibirama

Lecture 15: I/O Devices & Drivers

Module 11: I/O Systems

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

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

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)

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

Input/Output Systems

CS420: Operating Systems. Kernel I/O Subsystem

NWI-IBC019: Operating systems

Understanding IO patterns of SSDs

[08] IO SUBSYSTEM 1. 1

Operating Systems. Chapter 4 Threads. Lei Duan

Chapter 1 (Part 2) Introduction to Operating System

Operating Systems 2010/2011

CHAPTER 12 AND 13 - MASS-STORAGE STRUCTURE & I/O- SYSTEMS

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

如何查看 Cache Engine 缓存中有哪些网站 /URL

Chapter 7: Deadlocks. Operating System Concepts 9 th Edition

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

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

Murrelektronik Connectivity Interface Part I Product range MSDD, cable entry panels MSDD 系列, 电缆穿线板

Chapter 11 SHANDONG UNIVERSITY 1

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.

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

Operating Systems 2010/2011

UNIT-7. Overview of Mass Storage Structure

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

CS370 Operating Systems

ICP Enablon User Manual Factory ICP Enablon 用户手册 工厂 Version th Jul 2012 版本 年 7 月 16 日. Content 内容

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

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

or edit a file, our immediate interest is to read or enter some information, not to compute an answer.

I/O. CS 416: Operating Systems Design Department of Computer Science Rutgers University

Apache Kafka 源码编译 Spark 大数据博客 -

CS370 Operating Systems

The Design of Everyday Things

Supplementary Materials on Semaphores

I/O and Device Drivers

PCU50 的整盘备份. 本文只针对操作系统为 Windows XP 版本的 PCU50 PCU50 启动硬件自检完后, 出现下面文字时, 按向下光标键 光标条停在 SINUMERIK 下方的空白处, 如下图, 按回车键 PCU50 会进入到服务画面, 如下图

AvalonMiner Raspberry Pi Configuration Guide. AvalonMiner 树莓派配置教程 AvalonMiner Raspberry Pi Configuration Guide

: Operating System 计算机原理与设计

测试基础架构 演进之路. 茹炳晟 (Robin Ru) ebay 中国研发中心

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

Input Output (IO) Management

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

计算机科学与技术专业本科培养计划. Undergraduate Program for Specialty in Computer Science & Technology

A Benchmark For Stroke Extraction of Chinese Characters

Multiprotocol Label Switching The future of IP Backbone Technology

Virtual Memory Management for Main-Memory KV Database Using Solid State Disk *

CHINA VISA APPLICATION CONCIERGE SERVICE*

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

武汉大学 学年度第 1 学期 多核架构及编程技术 试卷(A)

浙江大学 学年秋冬学期

: Operating System 计算机原理与设计

VIII. Input/Output Operating Systems Prof. Dr. Marc H. Scholl DBIS U KN Summer Term

Computer Networks. Wenzhong Li. Nanjing University

Technology: Anti-social Networking 科技 : 反社交网络

Green Computing Cloud Computing LSD Tech Co., Ltd SSD server & SSD Storage Cloud SSD Supercomputer LSD Tech Co., LTD

失Answer for homework assignment 4

计算机组成原理第二讲 第二章 : 运算方法和运算器 数据与文字的表示方法 (1) 整数的表示方法. 授课老师 : 王浩宇

Computer Organization ECE514. Chapter 5 Input/Output (9hrs)

操作系统原理与设计. 第 4 章 Threads( 线程 ) 陈香兰. March 28, 2014 中国科学技术大学计算机学院. 陈香兰 ( 中国科学技术大学计算机学院 ) 操作系统原理与设计 March 28, /

上汽通用汽车供应商门户网站项目 (SGMSP) User Guide 用户手册 上汽通用汽车有限公司 2014 上汽通用汽车有限公司未经授权, 不得以任何形式使用本文档所包括的任何部分

绝佳的并行处理 - FPGA 加速的根本基石

Microsemi - Leading Innovation for China s Hyperscale Data Centers

Microsoft RemoteFX: USB 和设备重定向 姓名 : 张天民 职务 : 高级讲师 公司 : 东方瑞通 ( 北京 ) 咨询服务有限公司

: Operating System 计算机原理与设计

I/O Systems. Jo, Heeseung

OpenCascade 的曲面.

Generic Model of I/O Module Interface to CPU and Memory Interface to one or more peripherals

Transcription:

第 13 章 IO Systems(IO 管理 ) 中国科学技术大学计算机学院 2009 年 09 月 01 日

提纲 I/O Hardware 1 I/O Hardware Polling Interrupts Direct Memory Access (DMA) I/O hardware summary 2 Block and Character Devices Network Devices Clocks and Timers Blocking and Nonblocking I/O 3 I/O Scheduling Buffering Caching, Spooling & device reservation Error Handling I/O Protection Kernel Data Structures 4 5 6

Overview I/O devices vary widely The control of devices connected to the computer is a major concern of OS designers How OS manages and controls various peripherals?

Outline I/O Hardware 1 I/O Hardware Polling Interrupts Direct Memory Access (DMA) I/O hardware summary 2 Block and Character Devices Network Devices Clocks and Timers Blocking and Nonblocking I/O 3 I/O Scheduling Buffering Caching, Spooling & device reservation Error Handling I/O Protection Kernel Data Structures 4 5 6 Polling Interrupts Direct Memory Access (DMA)

I/O Hardware I Polling Interrupts Direct Memory Access (DMA) Incredible variety of I/O devices

I/O Hardware II Polling Interrupts Direct Memory Access (DMA) Common concepts : CPU PORT BUS Controller Port Bus (daisy chain or shared direct access) PCI (Peripheral Component Interconnect ) SCSI (Small computer systems interface) Expansion bus Controller (host adapter) How can the processor command controller? Controller has one or more registers for data and control signals The process communicates with the controller by reading and writing bit patterns in the registers

I/O Hardware III Polling Interrupts Direct Memory Access (DMA) I/O instructions control devices Two communication approaches Direct I/O instructions Access the port address Each port typically contains of four registers, ie, status, control, data-in and data-out eg, In, out Memory-mapped I/O eg, 0xa0000 0xfffff are reserved to ISA graphics cards and BIOS routines Device I/O Port Locations on PCs (partial)

I/O Hardware IV Polling Interrupts Direct Memory Access (DMA)

I/O Control Methods Polling Interrupts Direct Memory Access (DMA) 1 Polling 2 Interrupts 3 DMA 4 ( 在汤书上 : 还有通道的概念 )

Polling I I/O Hardware Polling Interrupts Direct Memory Access (DMA) Need handshaking Determines state of device command-ready busy Error In command register 1: a command is available for the controller In status register 0: ready for the next command; 1: busy To indicate whether an I/O is ok

Polling II I/O Hardware Polling Interrupts Direct Memory Access (DMA) Basic handshaking notion for writing output 1 Host repeatedly reads the busy bit until it is 0 2 Host sets write bit in command register and writes a byte into data-out register 3 Host sets command-ready bit 4 When controller notices command-ready, sets busy bit 5 Controller gets write command and data, and works 6 Controller clears command-ready bit, error bit and busy bit Step1: Busy-wait cycle to wait for I/O from device polling

Interrupts I Polling Interrupts Direct Memory Access (DMA) CPU Interrupt-request line triggered by I/O device Interrupt handler receives interrupts Basic interrupt scheme Raise Catch Dispatch Clear Interrupt-Driven I/O Cycle

Interrupts II Polling Interrupts Direct Memory Access (DMA)

Interrupts III Polling Interrupts Direct Memory Access (DMA) More sophisticated interrupt-handling features Defer interrupt handling Maskable to ignore or delay some interrupts Nonmaskable Efficient dispatching without polling the devices Interrupt vector to dispatch interrupt to correct handler Interrupt chaining: to allow more device & more interrupt handlers Distinguish between high- and low-priority interrupts Interrupt priority Interrupt mechanism also used for exceptions

Polling Interrupts Direct Memory Access (DMA) Intel Pentium Processor Event-Vector Table

Direct Memory Access (DMA) I Polling Interrupts Direct Memory Access (DMA) Used to avoid programmed I/O for large data movement, and bypasses CPU to transfer data directly between I/O device and memory Requires DMA controller the host prepares a DMA command block in memory a pointer to the source of a transfer a pointer to the destination of the transfer a count of the number of bytes to be transfered CPU writes the address of the DMA command block to DMA controller, and then goes on with other work Handshaking between DMA controller & device controller

Direct Memory Access (DMA) II Polling Interrupts Direct Memory Access (DMA) 1 Device controller raises DMA-request when one word is 2 available DMA controller seizes memory bus, places the desired address on memory-address wires, and raises 3 DMA-acknowledge Device controller transfers the word to memory, and removes 4 the DMA-request signal Goto 1 DMA controller interrupts the CPU

Polling Interrupts Direct Memory Access (DMA) Six Step Process to Perform DMA Transfer Cycle stealing: when DMA seizes the memory bus, CPU is momentarily prevented from accessing main memory

A bus Block and Character Devices Network Devices Clocks and Timers Blocking and Nonblocking I/O A controller An I/O port and its registers The handshaking relationship between the host and a device controller The execution of this handshaing in a pooling loop via interrupts the offloading of this work to a DMA controller for large transfer

Outline I/O Hardware 1 I/O Hardware Polling Interrupts Direct Memory Access (DMA) I/O hardware summary 2 Block and Character Devices Network Devices Clocks and Timers Blocking and Nonblocking I/O 3 I/O Scheduling Buffering Caching, Spooling & device reservation Error Handling I/O Protection Kernel Data Structures 4 5 6 Block and Character Devices Network Devices Clocks and Timers Blocking and Nonblocking I/O

I/O control challenges Block and Character Devices Network Devices Clocks and Timers Blocking and Nonblocking I/O Wide variety of devices Two challenges Applications OS Devices How can the OS give a convenient, uniform I/O interface to applications? How can the OS be designed such that new devices can be attached to the computer without the OS being rewritten?

OS device Block and Character Devices Network Devices Clocks and Timers Blocking and Nonblocking I/O For device manufacturers, device-driver layer hides differences among I/O controllers from kernel A Kernel I/O Structure

Block and Character Devices Network Devices Clocks and Timers Blocking and Nonblocking I/O For applications, I/O system calls encapsulate device behaviors in generic classes 设备独立性 : 应用程序与具体的物理设备无关 Device-driver layer hides differences among I/O controllers from kernel Devices vary in many dimensions Character-stream or block Sequential or random-access Sharable or dedicated Speed of operation read-write, read only, or write only

Characteristics of I/O Devices Block and Character Devices Network Devices Clocks and Timers Blocking and Nonblocking I/O

Major Device Access Conventions Block and Character Devices Network Devices Clocks and Timers Blocking and Nonblocking I/O Block I/O Character-stream I/O Memory-mapped file access Network sockets Clock and Time

Block and Character Devices Block and Character Devices Network Devices Clocks and Timers Blocking and Nonblocking I/O Block devices include disk drives Commands include read, write, seek Raw I/O or file-system access Memory-mapped file access possible Character devices include keyboards, mice, serial ports Commands include get, put Libraries layered on top allow line editing

Network Devices Block and Character Devices Network Devices Clocks and Timers Blocking and Nonblocking I/O Varying enough from block and character to have own interface Unix and Windows NT/9x/2000 include socket interface Separates network protocol from network operation Server socket, bind, listen, accept Client socket, connect Includes select functionality Approaches vary widely (pipes, FIFOs, streams, queues, mailboxes)

Clocks and Timers Block and Character Devices Network Devices Clocks and Timers Blocking and Nonblocking I/O Provide current time, elapsed time, timer Hardware clocks Real Time Clock (RTC) Time Stamp Counter (TSC) Programmable Interval Timer (PIT, 8253 or 8254) used for timings, periodic interrupts ioctl (on UNIX) covers odd aspects of I/O such as clocks and timers

RTC I/O Hardware Block and Character Devices Network Devices Clocks and Timers Blocking and Nonblocking I/O Integrated with CMOS RAM, always tick Seconds from 00:00:00 January 1, 1970 UTC Can be used as an alarm clock IRQ8 Interrupt frequency: 2HZ 8192HZ I/O address (port no): 0x70, 0x71 Example: Motorola 146818: CMOS RAM + RTC Second year, month, date, week HOW?

TSC I/O Hardware Block and Character Devices Network Devices Clocks and Timers Blocking and Nonblocking I/O 64bit TSC register in the processor Pentium and after Incremented at each clock signal on CLK input pin example: CPU frequency 400MHZ adds 1 per 25 ns = adds 400 10 6 per second Instruction: rdtsc How to know CPU frequency?

PIT I/O Hardware Block and Character Devices Network Devices Clocks and Timers Blocking and Nonblocking I/O 8253, 8254 Issues time interrupt in a programmable time internal Can also be used to calculate processor frequency during boot up 8253 14,3178 MHz crystal 4,772,727 Hz system clock 1,193,180 Hz to 8253 using 16 bit divisor interrupt every 838 ns 54925493 ms

Blocking and Nonblocking I/O Block and Character Devices Network Devices Clocks and Timers Blocking and Nonblocking I/O Blocking - process suspended until I/O completed Easy to use and understand Insufficient for some needs Nonblocking - I/O call returns as much as available User interface, data copy (buffered I/O) Implemented via multi-threading Returns quickly with count of bytes read or written Asynchronous - process runs while I/O executes Difficult to use I/O subsystem signals process when I/O completed

Two I/O Methods Block and Character Devices Network Devices Clocks and Timers Blocking and Nonblocking I/O

Outline I/O Hardware 1 I/O Hardware Polling Interrupts Direct Memory Access (DMA) I/O hardware summary 2 Block and Character Devices Network Devices Clocks and Timers Blocking and Nonblocking I/O 3 I/O Scheduling Buffering Caching, Spooling & device reservation Error Handling I/O Protection Kernel Data Structures 4 5 6 I/O Scheduling Buffering Caching, Spooling & device reservation Error Handling I/O Protection Kernel Data Structures

Services I/O Scheduling Buffering Caching, Spooling & device reservation Error Handling I/O Protection Kernel Data Structures I/O Scheduling Buffering Caching Spooling Device reservation Error handling

I/O Scheduling I I/O Scheduling Buffering Caching, Spooling & device reservation Error Handling I/O Protection Kernel Data Structures To schedule a set of I/O requests means to determine a good order in which to execute them issued rarely issuing order is the best choice Scheduling can improve overall system performance can share device access fairly among processes can reduce the average waiting time for I/O to complete Some I/O request ordering via per-device queue Some OSes try fairness, some not Eg, Disk read:

I/O Scheduling II I/O Scheduling Buffering Caching, Spooling & device reservation Error Handling I/O Protection Kernel Data Structures 0, 50, 100, now at 100 OS maintaining a wait queue of request for each device Device-status Table

I/O Scheduling III I/O Scheduling Buffering Caching, Spooling & device reservation Error Handling I/O Protection Kernel Data Structures Another way to improve performance is by using storage space in main memory or on disk Buffering Caching Spooling

Buffering( 缓冲机制 ) I/O Scheduling Buffering Caching, Spooling & device reservation Error Handling I/O Protection Kernel Data Structures Buffering Buffer A memory area that stores data while they are transferred between two devices or between a device and an application Store data in memory while transferring between devices Why buffering? To cope with device speed mismatch To cope with device transfer size mismatch To maintain copy semantics

I/O Scheduling Buffering Caching, Spooling & device reservation Error Handling I/O Protection Kernel Data Structures Sun Enterprise 6000 Device-Transfer Rates

Buffering I I/O Scheduling Buffering Caching, Spooling & device reservation Error Handling I/O Protection Kernel Data Structures Single buffer 单缓冲用户区 (OS, 时间 M) 缓冲区 ( 设备, 时间 T) 设备 假设计算时间为 C Current C 与 next T 可并行,max (C, T) + M

Buffering II I/O Scheduling Buffering Caching, Spooling & device reservation Error Handling I/O Protection Kernel Data Structures Double buffer ( 双缓冲 ) max (C, T); 连续输入 (C < T) 或者连续计算 (C > T)

Buffering III I/O Scheduling Buffering Caching, Spooling & device reservation Error Handling I/O Protection Kernel Data Structures 缓冲的另一种用法 : 用于两个机器之间的通信

Buffering IV I/O Scheduling Buffering Caching, Spooling & device reservation Error Handling I/O Protection Kernel Data Structures Circular buffer 多个 ( 种 ) 缓冲区 + 多个缓冲区指针 空缓冲区和 Nexti; 满缓冲区和 Nextg; 当前消费中的缓冲区 Current 类似前面介绍的经典的具有有限缓冲区的生产者和消费者问题 Buffer pool 前三种, 缓冲区是专用的为提高缓冲区利用率 : 设置公共的缓冲池

I/O Scheduling Buffering Caching, Spooling & device reservation Error Handling I/O Protection Kernel Data Structures Caching, Spooling & device reservation Caching - fast memory holding copy of data ( 前面讲过 ) Always just a copy Key to performance Spooling - hold output for a device ( 前面也讲过 ) Dedicated device can serve only one request at a time Spooling is a way of dealing with I/O devices in a multiprogramming system ie, Printing Device reservation - provides exclusive access to a device System calls for allocation and deallocation Watch out for deadlock

Spooling I I/O Scheduling Buffering Caching, Spooling & device reservation Error Handling I/O Protection Kernel Data Structures Out-line I/O ( 脱机 I/O), 使用外围机 SPOOL: Simultaneous Peripheral Operation On-Line ( 外部设备联机并行操作, 假脱机 ) Dedicated device sharable device Using processes of multiprogramming system Structure Input-well, output-well Input-buffer, output-buffer

Spooling II I/O Scheduling Buffering Caching, Spooling & device reservation Error Handling I/O Protection Kernel Data Structures Input-process SPin, output-process SPout Requested-queue

Error Handling I/O Scheduling Buffering Caching, Spooling & device reservation Error Handling I/O Protection Kernel Data Structures OS can recover from disk read, device unavailable, transient write failures eg: read() again, resend(),, according to some sepecified rules Most return an error number or code when I/O request fails System error logs hold problem reports

I/O Protection I I/O Scheduling Buffering Caching, Spooling & device reservation Error Handling I/O Protection Kernel Data Structures User process may accidentally or purposefully attempt to disrupt normal operation via illegal I/O instructions to prevent users from performing illegal I/O All I/O instructions defined to be privileged I/O must be performed via system calls Memory-mapped and I/O port memory locations must be protected too Use of a System Call to Perform I/O (figure)

I/O Protection II I/O Scheduling Buffering Caching, Spooling & device reservation Error Handling I/O Protection Kernel Data Structures

Kernel Data Structures I I/O Scheduling Buffering Caching, Spooling & device reservation Error Handling I/O Protection Kernel Data Structures Kernel keeps state info for I/O components, including open file tables, network connections, character device state Many, many complex data structures to track buffers, memory allocation, dirty blocks Some use object-oriented methods and message passing to implement I/O Example: UNIX I/O Kernel Structure

Kernel Data Structures II I/O Scheduling Buffering Caching, Spooling & device reservation Error Handling I/O Protection Kernel Data Structures

Outline I/O Hardware 1 I/O Hardware Polling Interrupts Direct Memory Access (DMA) I/O hardware summary 2 Block and Character Devices Network Devices Clocks and Timers Blocking and Nonblocking I/O 3 I/O Scheduling Buffering Caching, Spooling & device reservation Error Handling I/O Protection Kernel Data Structures 4 5 6

I/O Requests to Hardware Operations Consider reading a file from disk for a process: Determine device holding file Translate name to device representation Physically read data from disk into buffer Make data available to requesting process Return control to process

Life Cycle of An I/O Request

Outline I/O Hardware 1 I/O Hardware Polling Interrupts Direct Memory Access (DMA) I/O hardware summary 2 Block and Character Devices Network Devices Clocks and Timers Blocking and Nonblocking I/O 3 I/O Scheduling Buffering Caching, Spooling & device reservation Error Handling I/O Protection Kernel Data Structures 4 5 6

I/O a major factor in system performance: Demands CPU to execute device driver, kernel I/O code Context switches due to interrupts Data copying Network traffic especially stressful

Intercomputer Communications

Improving Reduce number of context switches Reduce data copying Reduce interrupts by using large transfers, smart controllers, polling Use DMA Balance CPU, memory, bus, and I/O performance for highest throughput

Device-Functionality Progression

Outline I/O Hardware 1 I/O Hardware Polling Interrupts Direct Memory Access (DMA) I/O hardware summary 2 Block and Character Devices Network Devices Clocks and Timers Blocking and Nonblocking I/O 3 I/O Scheduling Buffering Caching, Spooling & device reservation Error Handling I/O Protection Kernel Data Structures 4 5 6

小结 I/O Hardware 1 I/O Hardware Polling Interrupts Direct Memory Access (DMA) I/O hardware summary 2 Block and Character Devices Network Devices Clocks and Timers Blocking and Nonblocking I/O 3 I/O Scheduling Buffering Caching, Spooling & device reservation Error Handling I/O Protection Kernel Data Structures 4 5 6

作业 设备控制方式有哪几种? 脱机 I/O 和 SPOOLing 为什么要引入缓冲机制? 有哪几种缓冲机制?

谢谢!