计算机系统详解

上传人:wt****50 文档编号:49652687 上传时间:2018-08-01 格式:PPT 页数:42 大小:192KB
返回 下载 相关 举报
计算机系统详解_第1页
第1页 / 共42页
计算机系统详解_第2页
第2页 / 共42页
计算机系统详解_第3页
第3页 / 共42页
计算机系统详解_第4页
第4页 / 共42页
计算机系统详解_第5页
第5页 / 共42页
点击查看更多>>
资源描述

《计算机系统详解》由会员分享,可在线阅读,更多相关《计算机系统详解(42页珍藏版)》请在金锄头文库上搜索。

1、CSAPP L11 Chp11.1Wu Spring 09 USTCComputer Systems: A Programmers Perspective 计算机系统详解 Lecture 11 SYSTEM I/OJune 1, 2009Wu junmin ()CSAPP L11 Chp11.2Wu Spring 09 USTCUnix I/ORobust reading and writingReading file metadataSharing filesI/O redirectionStandard I/OTopicsCSAPP L11 Chp11.3Wu Spring 09 USTC

2、Unix I/O Key Characteristics Classic Unix/Linux I/O: I/O operates on linear streams of Bytes Can reposition insertion point and extend file at end I/O tends to be synchronous Read or write operation block until data has been transferred Fine grained I/O One key-stroke at a time Each I/O event is han

3、dled by the kernel and an appropriate process Mainframe I/O: I/O operates on structured records Functions to locate, insert, remove, update records I/O tends to be asynchronous Overlap I/O and computation within a process Coarse grained I/O Process writes “channel programs” to be executed by the I/O

4、 hardware Many I/O operations are performed autonomously with one interrupt at completionCSAPP L11 Chp11.4Wu Spring 09 USTCA Typical Hardware Systemmain memoryI/O bridgebus interfaceALUregister fileCPU chipsystem busmemory busdisk controllergraphics adapterUSB controllermousekeyboardmonitordiskI/O b

5、usExpansion slots for other devices such as network adapters.CSAPP L11 Chp11.5Wu Spring 09 USTCReading a Disk Sector: Step 1 main memoryALUregister fileCPU chipdisk controllergraphics adapterUSB controllermousekeyboardmonitordiskI/O busbus interfaceCPU initiates a disk read by writing a command, log

6、ical block number, and destination memory address to a port (address) associated with disk controller.CSAPP L11 Chp11.6Wu Spring 09 USTCReading a Disk Sector: Step 2main memoryALUregister fileCPU chipdisk controllergraphics adapterUSB controllermousekeyboardmonitordiskI/O busbus interfaceDisk contro

7、ller reads the sector and performs a direct memory access (DMA) transfer into main memory.CSAPP L11 Chp11.7Wu Spring 09 USTCReading a Disk Sector: Step 3main memoryALUregister fileCPU chipdisk controllergraphics adapterUSB controllermousekeyboardmonitordiskI/O busbus interfaceWhen the DMA transfer c

8、ompletes, the disk controller notifies the CPU with an interrupt (i.e., asserts a special “interrupt” pin on the CPU)CSAPP L11 Chp11.8Wu Spring 09 USTCUnix Files A Unix file is a sequence of m bytes: B0, B1, , Bk , , Bm-1 All I/O devices are represented as files: /dev/sda2 (/usr disk partition) /dev

9、/tty2 (terminal) Even the kernel is represented as a file: /dev/kmem (kernel memory image) /proc (kernel data structures)CSAPP L11 Chp11.9Wu Spring 09 USTCUnix File Types Regular file Binary or text file. Unix does not know the difference! Directory file A file that contains the names and locations

10、of other files. Character special and block special files Terminals (character special) and disks ( block special) FIFO (named pipe) A file type used for interprocess communication Socket A file type used for network communication between processesCSAPP L11 Chp11.10Wu Spring 09 USTCUnix I/O The eleg

11、ant mapping of files to devices allows kernel to export simple interface called Unix I/O. Key Unix idea: All input and output is handled in a consistent and uniform way. Basic Unix I/O operations (system calls): Opening and closing files -open()and close() Changing the current file position (seek) -

12、lseek (not discussed) Reading and writing a file -read() and write()CSAPP L11 Chp11.11Wu Spring 09 USTCOpening Files Opening a file informs the kernel that you are getting ready to access that file. Returns a small identifying integer file descriptor fd = -1 indicates that an error occurred Each pro

13、cess created by a Unix shell begins life with three open files associated with a terminal: 0: standard input 1: standard output 2: standard errorint fd; /* file descriptor */if (fd = open(“/etc/hosts“, O_RDONLY) 0) if (nread = read(fd, bufp, nleft) = 0 */ CSAPP L11 Chp11.20Wu Spring 09 USTCBuffered

14、I/O: Motivation I/O Applications Read/Write One Character at a Time getc, putc, ungetc gets -Read line of text, stopping at newline Implementing as Calls to Unix I/O Expensive Read /* descriptor for this internal buf */int rio_cnt; /* unread bytes in internal buf */char *rio_bufptr; /* next unread b

15、yte in internal buf */char rio_bufRIO_BUFSIZE; /* internal buffer */ rio_t;Bufferrio_bufrio_bufptrrio_cntCSAPP L11 Chp11.22Wu Spring 09 USTCBuffered RIO Input Functions Efficiently read text lines and binary data from a file partially cached in an internal memory buffer rio_readlineb reads a text li

16、ne of up to maxlen bytes from file fd and stores the line in usrbuf.-Especially useful for reading text lines from network sockets. rio_readnb reads up to n bytes from file fd. Calls to rio_readlineb and rio_readnb can be interleaved arbitrarily on the same descriptor.-Warning: Dont interleave with calls to rio_readn#include “csapp.h“void rio_readinitb(r

展开阅读全文
相关资源
相关搜索

当前位置:首页 > 生活休闲 > 社会民生

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号