University Coege London 1B11 Operating Systems Input/Output and s Prof. Steve R Wibur s.wibur@cs.uc.ac.uk Lecture Objectives How do the bits of the I/O story fit together? What is a device driver? 1B11-5 1999 Side 2 12/06/99 1
s Department of Computer Science University Coege London There are ots of different devices that can be attached to a computer: o Storage magnetic, optica disk, tape, etc. o Dispay, Keyboard, Pointer (mouse,tracker) o Network Interface Card o Audio, Video o Robot arms, toaster, coffee machine, 350bhp Chryser V8 eectronic ignition engine management system Good to have a unified interface in OS 1B11-5 1999 Side 3 Drivers Software in OS to manage I/O to a device is caed a device driver s can source or sink data s may need to be controed in specific ways, e.g. rewind So an OO design for a generic device driver might incude two casses, each with a set of methods: o open(), read(), write(), cose() o contro(), hande_event() Unix (Unified Interface to everything) has simiar interface to devices fies and networks! 1B11-5 1999 Side 4 12/06/99 2
University Coege London Drivers - 2 A device driver abstracts specific device hardware into a generic mode of I/O device Resut is abstract modes of disks, tapes, screens etc. Makes it easy to port OS and appications to new hardware - device independence Internay, device driver is programmed with detais of specific device, but presents reevant abstraction at its interface 1B11-5 1999 Side 5 Drivers - 3 However, we can t be competey generic s can be cassed broady into a sma number of categories: o character (byte) devices o ] modem, keyboard, maybe mouse bock (buk) devices ] disk, net, screen Categories are an engineering trade-off to keep reasonabe efficiency and functionaity 1B11-5 1999 Side 6 12/06/99 3
University Coege London Interna to Driver Driver needs to cope with device characteristics: ] poed, DMA and interrupts ] memory mapped ] device controer commands etc So typica device driver incudes: ] initiaise device (at OS boot time) ] start output ] start input ] contro device (seek or rewind) ] shutdown device (at OS shutdown time) ] interrupt service routine for input (and output and contro) 1B11-5 1999 Side 7 The Big Picture User Space Threads Library Appication ISAM Library Fie Extra Library OS Interface System Ca Hander (TRAPs) Generic fie and I/O Hander Kerne Space Disk Driver Keyb d Driver Screen Driver Disk Driver Hardware C Disk C C C Keyb d Screen Disk 1B11-5 1999 Side 8 12/06/99 4
University Coege London Exampe - Write to Disk Simpified version! User makes system ca to write specified bock of data to disk Processor switches to kerne mode System Ca Hander invoked (TRAP) and sysca parameters checked Generic fie and I/O Hander caed (TRAP function indicates I/O) User data copied to OS buffer or ocked to prevent it being swapped out whie I/O pending (or overwritten by user if asynchronous I/O) driver start() method caed - buffer passed as argument driver adds buffer to queue of pending I/O requests o may order queue e.g. to minimise disk head movement o wi get processed in due course Return to generic I/O hander which suspends user process and resumes next ready process 1B11-5 1999 Side 9 Exampe - Write to Disk - 2 Other side of device driver When a disk transfer compete interrupt occurs (from earier transfer) interrupt service routine (ISR) removes indicates competion detais in buffer and removes bocked indicator from that Ps PCB for the scheduer to use Look on pending request Q for new work, set up DMA registers for transfer and start transfer Return from interrupt Notes: o if no new work the ISR just returns o if Q is empty when start() is caed the device driver wi start the transfer immediatey 1B11-5 1999 Side 10 12/06/99 5
University Coege London Interrupt Service Routines These are instaed by the device initiaisation code (boot time) o by adding them to the jump tabe in the generic interrupt hander for the device s interrupt eve They are caed by the device controer (C in diagram) sending an interrupt signa to the processor ISR then saves a sma part of the current context (OS or User) and jumps to the code for the hander.. Which saves any extra state, and deas with it. 1B11-5 1999 Side 11 Buffers Bock mode DMA devices need buffers (for queueing data between the device and the user) The operating system keeps and manages a poo of these bocks of memory - typicay of severa different sizes, for different cases 1B11-5 1999 Side 12 12/06/99 6
University Coege London 1 Driver I/O Request Q Procedure ca Data transfer Interrupt 3 c Generic I/O hander 2 Start() Interrupt Service Routine b Generic (first eve) Interrupt Hander Driver d a Controer 1B11-5 1999 Side 13 Notes Fie abstraction deat with by generic code (hander) abstraction deat with by device driver - maps to rea device Q is used to manage producer-consumer reationship between two haves of device driver 1B11-5 1999 Side 14 12/06/99 7
University Coege London Network s Abstract network device is provided in simiar way Generic network functions ca network device drivers Same/simiar interface whatever type of inks and devices actuay used to physicay connect computers - another abstraction!!! 1B11-5 1999 Side 15 Graphic Dispays Bitmap dispays are usuay impemented sighty differenty o dispay typicay refreshed from a bock of dua-ported cheap memory o written by the processor, and read by the CRT controer So windows systems simpy write bitmaps to this area - has the effect of updating the screen (1 scan time ater) (Character mode dispays are driven through seria interface - now virtuay obsoete) 1B11-5 1999 Side 16 12/06/99 8
University Coege London Pointers/trackers Pointing devices o interrupt with the current x/y position of the pointer o or deta-x, deta-y since ast interrupt o i.e. they provide a stream of events These may be conveyed to user process via software interrupts to give the programmer the iusion of event streams Fits thread mode very we 1B11-5 1999 Side 17 Summary abstraction is common in OS to group devices by broad cass, and provide a standard API s are accessed via a tabe - another piece of book-keeping that the OS must do For some groups of devices, further ayers of abstraction are aso provided - incuding: o fie systems, networks, dispays, etc 1B11-5 1999 Side 18 12/06/99 9