DOC PREVIEW
Princeton COS 318 - I/O Devices and Drivers

This preview shows page 1-2-22-23 out of 23 pages.

Save
View full document
View full document
Premium Document
Do you want full access? Go Premium and unlock all 23 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 23 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 23 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 23 pages.
Access to all documents
Download any document
Ad free experience
Premium Document
Do you want full access? Go Premium and unlock all 23 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

I/O Devices and DriversGaining FlexibilityWhere Have We Seen This?Using “Virtual Nodes”More Vnode InfoDefinitions & General MethodProgrammed I/O “Slow” Input DeviceProgrammed I/O Output DeviceDirect Memory Access (DMA)Device DriversDevice Driver Design IssuesDevice Driver InterfaceBlock Device InterfaceCharacter Device InterfaceUnix Device Driver Interface Entry PointsWhat Was That Last One?Any Counterparts?Any Other Non-OrthogonalityWhy BufferingAsynchronous I/OOther Design IssuesDynamic Binding with An Indirect TableDynamic BindingI/O Devices and DriversVivek Pai / Kai LiPrinceton University2Gaining FlexibilityQuestion: how do you make a file descriptor refer to non-files?Answer: treat it as an objectSystem calls have a shared part of codeActual work done by calls to function ptrsEach type of object exports a structure of func ptrs that handle all file-related syscalls3Where Have We Seen This?Internals of read( ) system call descending down to fop_read methodOther places where this might be good?Filesystems – want to support local, network, CD-ROM, legacyOther I/O Devices4Using “Virtual Nodes”struct vnode { u_long v_flag; /* vnode flags (see below) */ int v_usecount; /* reference count of users */ int v_writecount; /* reference count of writers */ int v_holdcnt; /* page & buffer references */ u_long v_id; /* capability identifier */ struct mount *v_mount; /* ptr to vfs we are in */ vop_t **v_op; /* vnode operations vector */ TAILQ_ENTRY(vnode) v_freelist; /* vnode freelist */ TAILQ_ENTRY(vnode) v_nmntvnodes; /* vnodes for mount point */[…] enum vtype v_type; /* vnode type */[…] struct vm_object *v_object; /* Place to store VM object */[…] enum vtagtype v_tag; /* type of underlying data */ void *v_data; /* private data for fs */[…]}5More Vnode Infoenum vtype { VNON, VREG, VDIR, VBLK, VCHR, VLNK, VSOCK, VFIFO, VBAD };enum vtagtype { VT_NON, VT_UFS, VT_NFS, VT_MFS, VT_PC, VT_LFS, VT_LOFS, VT_FDESC, VT_PORTAL, VT_NULL, VT_UMAP, VT_KERNFS, VT_PROCFS, VT_AFS, VT_ISOFS, VT_UNION, VT_MSDOSFS, VT_TFS, VT_VFS, VT_CODA, VT_NTFS, VT_HPFS, VT_NWFS, VT_SMBFS };6Definitions & General MethodOverheadCPU time to initiate operation (cannot be overlapped)LatencyTime to perform 1-byte I/O operationBandwidthRate of I/O transfer, once initiatedGeneral methodAbstraction of byte transfersBatch transfers into block I/O for efficiency to prorate overhead and latency over a large unit7Programmed I/O “Slow” Input DeviceDeviceData registersStatus register(ready, busy, interrupt, … )A simple mouse designPut (X, Y) in data registers on a moveInterruptPerform an inputOn an interrupt reads values in X, Y registerssets ready bitwakes up a process/thread or execute a piece of codeCPUMemoryL2CacheI/O BusInterfaceX Y8Programmed I/O Output DeviceDeviceData registersStatus registers (ready, busy, … )Perform an outputPolls the busy bitWrites the data to data register(s)Sets ready bitController sets busy bit and transfers dataController clears the ready bit and busy bit9Direct Memory Access (DMA)Perform DMA from host CPUDevice driver call (kernel mode)Wait until DMA device is freeInitiate a DMA transaction(command, memory address, size)BlockDMA interfaceDMA data to device(size--; address++)Interrupt on completion(size == 0)Interrupt handler (on completion)Wakeup the blocked processCPUMemoryL2CacheI/O BusDMAInterfaceFree to movedata during DMA10Device DriversRest of theoperatingsystemDevicedriverDevicedriver...DevicedriverI/O SystemDevicecontrollerDevicecontroller...DevicecontrollerDeviceDeviceDeviceDevice11Device Driver Design IssuesOperating system and driver communicationCommands and data between OS and device driversDriver and hardware communicationCommands and data between driver and hardwareDriver operationsInitialize devicesInterpreting commands from OSSchedule multiple outstanding requestsManage data transfersAccept and process interruptsMaintain the integrity of driver and kernel data structures12Device Driver InterfaceOpen( deviceNumber )Initialization and allocate resources (buffers)Close( deviceNumber )Cleanup, deallocate, and possibly turnoffDevice driver typesBlock: fixed sized block data transfer Character: variable sized data transferTerminal: character driver with terminal controlNetwork: streams for networking13Block Device Interfaceread( deviceNumber, deviceAddr, bufferAddr )transfer a block of data from “deviceAddr” to “bufferAddr”write( deviceNumber, deviceAddr, bufferAddr )transfer a block of data from “bufferAddr” to “deviceAddr”seek( deviceNumber, deviceAddress )move the head to the correct positionusually not necessary14Character Device Interfaceread( deviceNumber, bufferAddr, size )reads “size” bytes from a byte stream device to “bufferAddr”write( deviceNumber, bufferAddr, size )write “size” bytes from “bufferSize” to a byte stream device15Unix Device Driver Interface Entry Pointsinit( ): Initialize hardwarestart( ): Boot time initialization (require system services)open(dev, flag, id): initialization for read or writeclose(dev, flag, id): release resources after read and writehalt( ): call before the system is shutdownintr(vector): called by the kernel on a hardware interruptread/write calls: data transferpoll(pri): called by the kernel 25 to 100 times a secondioctl(dev, cmd, arg, mode): special request processing16What Was That Last One?The system call “ioctl”SYNOPSIS #include <sys/ioctl.h> int ioctl(int d, unsigned long request, ...);DESCRIPTION The ioctl() function manipulates the underlying device parameters of special files. In particular, many operating characteristics of character special files (e.g. terminals) may be controlled with ioctl() requests. The argument d must be an open file descriptor.17Any Counterparts?“fcntl” – operations on filesDuplicating file descriptorsGet/set/clear “close-on-exec” flagGet/set/clear flags – nonblocking, appending, direct (no-cache), async signal notification, locking & unlockingAlso available as dup( ), dup2( ), lockf( ), flock( ) and others18Any Other Non-OrthogonalitySending data, credentials, file


View Full Document

Princeton COS 318 - I/O Devices and Drivers

Documents in this Course
Overview

Overview

25 pages

Deadlocks

Deadlocks

25 pages

lectute 2

lectute 2

28 pages

Lecturel

Lecturel

24 pages

Real mode

Real mode

49 pages

Lecture 2

Lecture 2

54 pages

lecture 5

lecture 5

27 pages

Load more
Download I/O Devices and Drivers
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view I/O Devices and Drivers and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view I/O Devices and Drivers 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?