Operating Systems Goals of v/o Software e Device independence H programs can access any i/o device without specifying device in advance (read file from floppy, hard drive, or CD-ROM) g Uniform naming H name of a file or device, a string or an integer H not depending on which machine (/usr/ast/backup) ce Error handling w handle as close to the hardware as possible Gao Haichang, Software School, Xidian University 18
Operating Systems Gao Haichang , Software School, Xidian University 18 Goals of I/O Software Device independence programs can access any I/O device without specifying device in advance · (read file from floppy, hard drive, or CD-ROM) Uniform naming name of a file or device, a string or an integer not depending on which machine (/usr/ast/backup) Error handling handle as close to the hardware as possible
Operating Systems Goals of 1/0 Software(2) Sv ynchronous vs asynchronous transters H blocked transfers vs interrupt-driven Buffering w data coming off a device cannot be stored in final destination (VOD) e Sharable vs. dedicated devices a disks are sharable. CD-Rom /Printer would not be oS must be able to handle both shared and dedicated devices in a way that avoids problems Gao Haichang, Software School, Xidian University 19
Operating Systems Gao Haichang , Software School, Xidian University 19 Goals of I/O Software (2) Synchronous vs. asynchronous transfers blocked transfers vs. interrupt-driven Buffering data coming off a device cannot be stored in final destination (VOD) Sharable vs. dedicated devices disks are sharable, CD-Rom/Printer would not be OS must be able to handle both shared and dedicated devices in a way that avoids problems
Operating Systems three ways to perform 1/0 g Programmed o 程序控制ⅣO cG Interrupt-Driven 1O 中断驱动O yO Using DMA 使用DMA的IO Gao Haichang, Software School, Xidian University 20
Operating Systems Gao Haichang , Software School, Xidian University 20 three ways to perform I/O Programmed I/O 程序控制I/O Interrupt-Driven I/O 中断驱动I/O I/O Using DMA 使用DMA的I/O
Operating Systems Programmed 1/0 String to be printed space Printed Printed page page ABCD EFGH AB Next Next Kernel space ABCD ABCD EFGH EFGH Steps in printing a string Gao Haichang, Software School, Xidian University
Operating Systems Gao Haichang , Software School, Xidian University 21 Programmed I/O Steps in printing a string
Operating Systems Programmed 1/0(2) copy from user(buffer p, count /“p是内核缓冲区 for(i=o; i <count; i++) /对每个字符循环* while(* printer status reg!= READY);/循环直到就绪* printer data register=pi /2输出一个字符 Return to user(; Writing a string to the printer using programmed v0 Disadvantage: occupy entire CPU time untill all/o over Gao Haichang, Software School, Xidian University 22
Operating Systems Gao Haichang , Software School, Xidian University 22 Programmed I/O (2) Writing a string to the printer using programmed I/O copy_from_user(buffer,p,count); /*p是内核缓冲区*/ for(i=0;i<count;i++){ /*对每个字符循环*/ while(*printer_status_reg!=READY); /*循环直到就绪*/ *printer_data_register=p[i]; /*输出一个字符*/ } Return_to_user(); Disadvantage: occupy entire CPU time untill all I/O over