Input/Output s Slide 5-1 The Driver Interface Slide 5-2 write(); Interface Output Terminal Terminal Printer Printer Disk Disk Input or Terminal Terminal Printer Printer Disk Disk Management Organization Slide 5-3 System Call Interface Slide 5-4 File Manager Command Application -Independent -Dependent Status Functions available to application programs Mostly resemble reading/writing files. Abstract all devices (and files) to a few interfaces Make interfaces as similar as possible Block vs character Sequential vs direct access driver implements functions (one entry point per API function) Example: BSD UNIX Driver open Prepare dev for operation close No longer using the device ioctl Character dev specific info read Character dev input op write Character dev output op strategy Block dev input/output ops select Character dev check for data stop Discontinue a stream output op Slide 5-5 Overlapping the Operation of a and the CPU read(dev_i, %d, x); y = f(x) on device startread(dev_i, %d, x); while(stillreading()) ; y = f(x) Variable x Register Slide 5-6 dev_i Memory CPU
Overlapping CPU- Operations in a Slide 5-7 Overlapping ing and I/O Slide 5-8 App I/O Ctlr App 1 App 2 I/O Ctlr t 1 t 2 t 3 t 4 t 5 t 6 t 7 t 8 t 9 t 1 t 2 t 3 t 4 Polling I/O Read Operation Slide 5-9 Interrupt-driven I/O Operation Slide 5-10 1 2 3 4 read(device, ); read function write function 5 1 read driver 2 write driver 3 read(device, ); Status Table 4 7 5 9 Handler Handler Interrupt Handler Handler 8b 6 8a Command Command Status Status Command Command Status Status Independent Function Call Trap Table Slide 5-11 Driver-Kernel Interface Slide 5-12 func i () dev_func_i(devid, ) { // ing common to all devices switch(devid) { case dev0: dev0_func_i(); case dev1: dev1_func_i(); case devm: devm_func_i(); ; // ing common to all devices Drivers are distinct from main part of kernel Kernel makes calls on specific functions, drivers implement them Drivers use kernel functions for: allocation Resource (e.g., memory) allocation Scheduling etc. (varies from OS to OS)
Reconfigurable Drivers Slide 5-13 Handling Interrupts Slide 5-14 System call interface open(){ driver J int read() { // Prepare for I/O save_state(j); out dev# // Done (no return) status table J interrupt handler J void dev_handler() { get_state(j); //Cleanup after op signal(dev[j]); return_from_sys_call(); read(){ etc. Driver for j Entry Points for j Other Kernel services Interrupt Handler driver J Handling Interrupts(2) int read() { out dev# // Return after interrupt wait(dev[j); return_from_sys_call(); Interrupt Handler interrupt handler J void dev_handler() { //Cleanup after op signal(dev[j]); Slide 5-15 The Pure Cycle Water Company Customer Office Water Company Returning the Empties Water Producer Water Consumers Delivering Water Slide 5-16 Hardware Buffering Slide 5-17 Double Buffering in the Driver Slide 5-18 Unbuffered A B reads b i-1 reads b i A B reads b i reads b i+1 Hardware Driver
Circular Buffering Slide 5-19 A Generic Communications Slide 5-20 To data consumer Bus Buffer j Buffer i Generic Local Communications Cabling connecting the controller to the device From data producer Printer Modem Network Rotating Media Slide 5-21 Driver API Storage Slide 5-22 Track (Cylinder) Cylinder (set of tracks) Driver Get disk description Set SCSI parms read/write ops Interrupt hander (a) Multi-surface Disk (b) Disk Surface (b) Cylinders Sector SCSI API commands bits per byte etc. Magnetic Disk (SCSI) Compute vs I/O Bound Slide 5-23 Disk Optimizations Slide 5-24 Compute-bound I/O-bound Time Transfer Time: Time to copy bits from disk surface to memory Disk latency time: Rotational delay waiting for proper sector to rotate under R/W head Disk seek time: Delay while R/W head moves to the destination track/cylinder Access Time = seek + latency + transfer
Optimizing Seek Time Slide 5-25 Optimizing Seek Time (cont) Slide 5-26 Multiprogramming on I/O-bound programs => set of processes waiting for disk Seek time dominates access time => minimize seek time across the set Tracks 0:99; Head at track 75, requests for 23, 87, 36, 93, 66 FCFS: 52+ 64 + 51 + 57 + 27 = 251 steps Requests = 23, 87, 36, 93, 66 SSTF: (75), 66, 87, 93, 36, 23 9 + 21 + 6 + 57 + 13 = 106 steps Scan: (75), 87, 93, 99, 66, 36, 23 12 + 6 + 6 + 33 + 30 + 13 = 100 steps Look: (75), 87, 93, 66, 36, 23 12 + 6 + 27 + 30 + 13 = 87 steps Optimizing Seek Time (cont) Slide 5-27 Networks Slide 5-33 Requests = 23, 87, 36, 93, 66 Circular Scan: (75), 87, 93, 99, 23, 36, 66 12 + 6 + 6 + home + 23 + 13 + 30 = 90 + home Circular Look: (75), 87, 93, 23, 36, 66 12 + 6 + home + 23 + 13 + 30 = 84 + home Technology focus includes protocols and software (more on this later Chapter 15 and beyond...) CPU CPU Memory Memory Network Logical Communication Network Network CPU CPU Memory Memory Network MS Disk Description Slide 5-34 0x00 0x02 <a jump instruction to 0x1e> 0x03 0x0a Computer manufacturer name 0x0b 0x0c Sectors per cluster (MS-DOS reads/writes a cluster of sectors) 0x0d 0x0f Reserved sectors for the boot record 0x10 0x10 Number of FATs 0x11 0x12 Number of root directory entries 0x13 0x14 Number of logical sectors 0x15 0x15 Medium descriptor byte (used only on old versions of MS-DOS) 0x16 0x17 Sectors per FAT 0x18 0x19 Sectors per track 0x1a 0x1b Number of surfaces (heads) 0x1c 0x1d Number of hidden sectors 0x1e Bootstrap program