oses: 12. iosys 1 operating systems v objectives –discuss how an os manages and controls i/o...
TRANSCRIPT
![Page 1: OSes: 12. IOSys 1 Operating Systems v Objectives –discuss how an OS manages and controls I/O operations and I/O devices Certificate Program in Software](https://reader035.vdocuments.mx/reader035/viewer/2022062621/551c19ef5503469e4f8b57fc/html5/thumbnails/1.jpg)
OSes: 12. IOSys 1
Operating SystemsOperating Systems
ObjectivesObjectives– discuss how an OS manages and controls discuss how an OS manages and controls
I/O operations and I/O devicesI/O operations and I/O devices
Certificate Program in Software DevelopmentCSE-TC and CSIM, AITSeptember--November, 2003
12. I/O Systems(Ch. 12, S&G)
![Page 2: OSes: 12. IOSys 1 Operating Systems v Objectives –discuss how an OS manages and controls I/O operations and I/O devices Certificate Program in Software](https://reader035.vdocuments.mx/reader035/viewer/2022062621/551c19ef5503469e4f8b57fc/html5/thumbnails/2.jpg)
OSes: 12. IOSys 2
ContentsContents
1.1. IssuesIssues
2.2. I/O HardwareI/O Hardware
3.3. Application I/O InterfacesApplication I/O Interfaces
4.4. Kernel I/O SubsystemsKernel I/O Subsystems
5.5. From I/O Requests to HardwareFrom I/O Requests to Hardware
6.6. PerformancePerformance
![Page 3: OSes: 12. IOSys 1 Operating Systems v Objectives –discuss how an OS manages and controls I/O operations and I/O devices Certificate Program in Software](https://reader035.vdocuments.mx/reader035/viewer/2022062621/551c19ef5503469e4f8b57fc/html5/thumbnails/3.jpg)
OSes: 12. IOSys 3
1. Issues1. Issues
I/O is the main job in most computersI/O is the main job in most computers– processing is secondaryprocessing is secondary
An OS must deal with a wide variety of I/O An OS must deal with a wide variety of I/O devices with different properties:devices with different properties:– mouse, hard disk, CD-ROM,mouse, hard disk, CD-ROM,
joystick, keyboard, etc.joystick, keyboard, etc.
continued
![Page 4: OSes: 12. IOSys 1 Operating Systems v Objectives –discuss how an OS manages and controls I/O operations and I/O devices Certificate Program in Software](https://reader035.vdocuments.mx/reader035/viewer/2022062621/551c19ef5503469e4f8b57fc/html5/thumbnails/4.jpg)
OSes: 12. IOSys 4
Increase the standardization of the I/O Increase the standardization of the I/O software and hardware interfaces.software and hardware interfaces.
Support many types of devices.Support many types of devices.
Performance.Performance.
One solutionOne solution::– device driver modules with standard interfacesdevice driver modules with standard interfaces
Principal Design AimsPrincipal Design Aims
![Page 5: OSes: 12. IOSys 1 Operating Systems v Objectives –discuss how an OS manages and controls I/O operations and I/O devices Certificate Program in Software](https://reader035.vdocuments.mx/reader035/viewer/2022062621/551c19ef5503469e4f8b57fc/html5/thumbnails/5.jpg)
OSes: 12. IOSys 5
2. I/O Hardware2. I/O Hardware Some terminology:Some terminology:
– portport: a device’s connection point to the main : a device’s connection point to the main processor (computer)processor (computer)
– busbus: a connection line allowing several devices : a connection line allowing several devices to access the processorto access the processor
– controllercontroller: a chip or circuit board in the device : a chip or circuit board in the device that manages interaction between the device that manages interaction between the device and processorand processor
![Page 6: OSes: 12. IOSys 1 Operating Systems v Objectives –discuss how an OS manages and controls I/O operations and I/O devices Certificate Program in Software](https://reader035.vdocuments.mx/reader035/viewer/2022062621/551c19ef5503469e4f8b57fc/html5/thumbnails/6.jpg)
OSes: 12. IOSys 6
2.1. Typical PC Bus Structure2.1. Typical PC Bus StructureFig. 12.1, p.399
diskdisk
disk
disk
monitor
graphicscontroller SCSI controller
processor
bridge/memorycontroller
cache
memory
disk disk
IDE disk controller
disk disk
expansion bus interface keyboard
parallel port serial port
PCI Bus
Expansion Bus
SC
SI
bus
![Page 7: OSes: 12. IOSys 1 Operating Systems v Objectives –discuss how an OS manages and controls I/O operations and I/O devices Certificate Program in Software](https://reader035.vdocuments.mx/reader035/viewer/2022062621/551c19ef5503469e4f8b57fc/html5/thumbnails/7.jpg)
OSes: 12. IOSys 7
2.2. Controller Features2.2. Controller Features Runs microcode for specific tasksRuns microcode for specific tasks
– e.g. a hard disk controller may do bad-sector e.g. a hard disk controller may do bad-sector avoidance, bufferingavoidance, buffering
Use registers for holding data, control signalsUse registers for holding data, control signals– the processor communicates with the controller by the processor communicates with the controller by
reading/writing to these registersreading/writing to these registers
Registers may be visible to a processor as I/O Registers may be visible to a processor as I/O port addresses.port addresses.
![Page 8: OSes: 12. IOSys 1 Operating Systems v Objectives –discuss how an OS manages and controls I/O operations and I/O devices Certificate Program in Software](https://reader035.vdocuments.mx/reader035/viewer/2022062621/551c19ef5503469e4f8b57fc/html5/thumbnails/8.jpg)
OSes: 12. IOSys 8
2.3. Some PC I/O Port Addresses2.3. Some PC I/O Port Addresses
I/O Address Range (Hex)I/O Address Range (Hex) DeviceDevice000-00F000-00F DMA controllerDMA controller040-043040-043 timertimer320-32F320-32F hard disk controllerhard disk controller378-37F378-37F parallel portparallel port3D0-3DF3D0-3DF graphics controllergraphics controller3F0-3F73F0-3F7 floppy drive controllerfloppy drive controller : : ::
Fig. 12.2, p.400
![Page 9: OSes: 12. IOSys 1 Operating Systems v Objectives –discuss how an OS manages and controls I/O operations and I/O devices Certificate Program in Software](https://reader035.vdocuments.mx/reader035/viewer/2022062621/551c19ef5503469e4f8b57fc/html5/thumbnails/9.jpg)
OSes: 12. IOSys 9
2.4. Registers <--> I/O Port2.4. Registers <--> I/O Port
Typically, an I/O port address is made up Typically, an I/O port address is made up of 4 registers.of 4 registers.
One register is usually 1- 4 bytesOne register is usually 1- 4 bytes
Different bits/bytes of a register are used Different bits/bytes of a register are used for manipulating different parts of the for manipulating different parts of the device.device.
![Page 10: OSes: 12. IOSys 1 Operating Systems v Objectives –discuss how an OS manages and controls I/O operations and I/O devices Certificate Program in Software](https://reader035.vdocuments.mx/reader035/viewer/2022062621/551c19ef5503469e4f8b57fc/html5/thumbnails/10.jpg)
OSes: 12. IOSys 10
statusstatus: read by a processor (host) to see if a : read by a processor (host) to see if a device is ready to execute a command, or has device is ready to execute a command, or has finished a command, etc.finished a command, etc.
control/commandcontrol/command: written by a processor (host) : written by a processor (host) to tell the device to start/change its settings, etc.to tell the device to start/change its settings, etc.
data-indata-in: read by a procesor (host): read by a procesor (host)
data-outdata-out: written by a processor (host): written by a processor (host)
Register NamesRegister Names
![Page 11: OSes: 12. IOSys 1 Operating Systems v Objectives –discuss how an OS manages and controls I/O operations and I/O devices Certificate Program in Software](https://reader035.vdocuments.mx/reader035/viewer/2022062621/551c19ef5503469e4f8b57fc/html5/thumbnails/11.jpg)
OSes: 12. IOSys 11
2.5. Handshaking2.5. Handshaking
HandshakingHandshaking is one possible protocol is one possible protocol between a host (processor) and a controller.between a host (processor) and a controller.
ExampleExample: the host writes a byte to the : the host writes a byte to the device:device:– 1. The host repeatedly reads the busy bit of the 1. The host repeatedly reads the busy bit of the
device’s device’s statusstatus register until is it clear/false register until is it clear/false busy-waiting (polling)busy-waiting (polling)
continued
![Page 12: OSes: 12. IOSys 1 Operating Systems v Objectives –discuss how an OS manages and controls I/O operations and I/O devices Certificate Program in Software](https://reader035.vdocuments.mx/reader035/viewer/2022062621/551c19ef5503469e4f8b57fc/html5/thumbnails/12.jpg)
OSes: 12. IOSys 12
– 2. The host sets the write bit of the device’s 2. The host sets the write bit of the device’s commandcommand register and writes a byte into the register and writes a byte into the data-outdata-out register. register.
– 3. The host sets the ready bit of the 3. The host sets the ready bit of the commandcommand register.register.
– 4. When the device’s controller notices the 4. When the device’s controller notices the ready bit, it sets the busy bit of its ready bit, it sets the busy bit of its statusstatus register. register.
continued
![Page 13: OSes: 12. IOSys 1 Operating Systems v Objectives –discuss how an OS manages and controls I/O operations and I/O devices Certificate Program in Software](https://reader035.vdocuments.mx/reader035/viewer/2022062621/551c19ef5503469e4f8b57fc/html5/thumbnails/13.jpg)
OSes: 12. IOSys 13
– 5. The controller sees the write bit of its 5. The controller sees the write bit of its commandcommand register. It then reads the byte from register. It then reads the byte from the the data-outdata-out register, and does the I/O. register, and does the I/O.
– 6. The controller clears the 6. The controller clears the commandcommand ready ready bit, and clears the bit, and clears the statusstatus busy bit. busy bit.
![Page 14: OSes: 12. IOSys 1 Operating Systems v Objectives –discuss how an OS manages and controls I/O operations and I/O devices Certificate Program in Software](https://reader035.vdocuments.mx/reader035/viewer/2022062621/551c19ef5503469e4f8b57fc/html5/thumbnails/14.jpg)
OSes: 12. IOSys 14
Polling a DevicePolling a Device
Polling often requires only 3 CPU Polling often requires only 3 CPU instructions:instructions:– readread the status register the status register
– use a use a logical-andlogical-and operation to extract the operation to extract the busy bitbusy bit
– branchbranch (goto) is not zero (goto) is not zero
continued
![Page 15: OSes: 12. IOSys 1 Operating Systems v Objectives –discuss how an OS manages and controls I/O operations and I/O devices Certificate Program in Software](https://reader035.vdocuments.mx/reader035/viewer/2022062621/551c19ef5503469e4f8b57fc/html5/thumbnails/15.jpg)
OSes: 12. IOSys 15
Polling becomes inefficient if done too Polling becomes inefficient if done too often.often.
An alternative is to have the device An alternative is to have the device interrupt the host (CPU) when it is free.interrupt the host (CPU) when it is free.
![Page 16: OSes: 12. IOSys 1 Operating Systems v Objectives –discuss how an OS manages and controls I/O operations and I/O devices Certificate Program in Software](https://reader035.vdocuments.mx/reader035/viewer/2022062621/551c19ef5503469e4f8b57fc/html5/thumbnails/16.jpg)
OSes: 12. IOSys 16
2.6. Interrupt Driven I/O Cycle2.6. Interrupt Driven I/O CycleFig. 12.3, p.403
device driverinitiates I/O
CPU checks for interruptsbetween instructions
CPU receives interrupt,transfers control tointerrupt handler
interrupt handler: processes data, returns
CPU resumesinterruped task
CPU
initiates I/O
input ready, or outputcomplete, or error
generate interrupt signal
I/O Controller12
3
4
56
7
![Page 17: OSes: 12. IOSys 1 Operating Systems v Objectives –discuss how an OS manages and controls I/O operations and I/O devices Certificate Program in Software](https://reader035.vdocuments.mx/reader035/viewer/2022062621/551c19ef5503469e4f8b57fc/html5/thumbnails/17.jpg)
OSes: 12. IOSys 17
More SophisticationMore Sophistication
Defer interrupt handling during critical Defer interrupt handling during critical processing.processing.
Use more efficient ways of finding the Use more efficient ways of finding the right interrupt handler.right interrupt handler.
Multi-level interrupts.Multi-level interrupts.
Multiple interrupt request lines:Multiple interrupt request lines:– nonmaskablenonmaskable and and maskablemaskable lines lines
![Page 18: OSes: 12. IOSys 1 Operating Systems v Objectives –discuss how an OS manages and controls I/O operations and I/O devices Certificate Program in Software](https://reader035.vdocuments.mx/reader035/viewer/2022062621/551c19ef5503469e4f8b57fc/html5/thumbnails/18.jpg)
OSes: 12. IOSys 18
Interrupt Vector TableInterrupt Vector Table
An An interrupt vector tableinterrupt vector table is used to map an is used to map an interrupt to a routineinterrupt to a routine– done by treating the interrupt number as an offset in done by treating the interrupt number as an offset in
the tablethe table– called an called an interrupt vectorinterrupt vector
Each entry in the table may be a list (chain) of Each entry in the table may be a list (chain) of handlershandlers– allows overloading of the interrupt numberallows overloading of the interrupt number
![Page 19: OSes: 12. IOSys 1 Operating Systems v Objectives –discuss how an OS manages and controls I/O operations and I/O devices Certificate Program in Software](https://reader035.vdocuments.mx/reader035/viewer/2022062621/551c19ef5503469e4f8b57fc/html5/thumbnails/19.jpg)
OSes: 12. IOSys 19
Part of a Pentium Vector TablePart of a Pentium Vector Table
Vector NumberVector Number DescriptionDescription00 Divide errorDivide error33 BreakpointBreakpoint55 Bound range errorBound range error77 Device not availableDevice not available1212 Stack faultStack fault1313 General protectionGeneral protection1414 Page faultPage fault19-3119-31 Intel reservedIntel reserved32-25532-255 Maskable interruptsMaskable interrupts
Fig. 12.4, p.404
![Page 20: OSes: 12. IOSys 1 Operating Systems v Objectives –discuss how an OS manages and controls I/O operations and I/O devices Certificate Program in Software](https://reader035.vdocuments.mx/reader035/viewer/2022062621/551c19ef5503469e4f8b57fc/html5/thumbnails/20.jpg)
OSes: 12. IOSys 20
Threads and InterruptsThreads and Interrupts
A threaded kernel is useful for A threaded kernel is useful for implementing multiple interrupt priorities.implementing multiple interrupt priorities.
The Solaris thread scheduler allows low The Solaris thread scheduler allows low priority interrupt handlers (threads) to be priority interrupt handlers (threads) to be pre-empted by high priority interrupt pre-empted by high priority interrupt handlers (threads).handlers (threads).
![Page 21: OSes: 12. IOSys 1 Operating Systems v Objectives –discuss how an OS manages and controls I/O operations and I/O devices Certificate Program in Software](https://reader035.vdocuments.mx/reader035/viewer/2022062621/551c19ef5503469e4f8b57fc/html5/thumbnails/21.jpg)
OSes: 12. IOSys 21
2.7. Direct Memory Access (DMA)2.7. Direct Memory Access (DMA)
When the host’s CPU does device When the host’s CPU does device handshaking, it is called handshaking, it is called Programmed I/OProgrammed I/O (PIO)(PIO)– a waste of CPU resourcesa waste of CPU resources
Instead, offload the work to a DMA controllerInstead, offload the work to a DMA controller– the CPU sends the I/O command to the DMA, the CPU sends the I/O command to the DMA,
then goes on with other workthen goes on with other work
continued
![Page 22: OSes: 12. IOSys 1 Operating Systems v Objectives –discuss how an OS manages and controls I/O operations and I/O devices Certificate Program in Software](https://reader035.vdocuments.mx/reader035/viewer/2022062621/551c19ef5503469e4f8b57fc/html5/thumbnails/22.jpg)
OSes: 12. IOSys 22
Higher CPU performance since:Higher CPU performance since:– less kernel communicationless kernel communication– less context switchingless context switching
AdvantagesAdvantages
![Page 23: OSes: 12. IOSys 1 Operating Systems v Objectives –discuss how an OS manages and controls I/O operations and I/O devices Certificate Program in Software](https://reader035.vdocuments.mx/reader035/viewer/2022062621/551c19ef5503469e4f8b57fc/html5/thumbnails/23.jpg)
OSes: 12. IOSys 23
DMA DiagramDMA Diagram Fig. 12.5, p.407
disk disk disk disk
CPU
cache
CPU/memory busDMA controller memory buffer
IDE disk controller
PCI Bus
![Page 24: OSes: 12. IOSys 1 Operating Systems v Objectives –discuss how an OS manages and controls I/O operations and I/O devices Certificate Program in Software](https://reader035.vdocuments.mx/reader035/viewer/2022062621/551c19ef5503469e4f8b57fc/html5/thumbnails/24.jpg)
OSes: 12. IOSys 24
Cycle StealingCycle Stealing
Cycle stealingCycle stealing occurs when the DMA occurs when the DMA controller uses the CPU memory buscontroller uses the CPU memory bus– the CPU is prevented from accessing memorythe CPU is prevented from accessing memory
– this can slow down the CPU’s computationthis can slow down the CPU’s computation
![Page 25: OSes: 12. IOSys 1 Operating Systems v Objectives –discuss how an OS manages and controls I/O operations and I/O devices Certificate Program in Software](https://reader035.vdocuments.mx/reader035/viewer/2022062621/551c19ef5503469e4f8b57fc/html5/thumbnails/25.jpg)
OSes: 12. IOSys 25
Direct Virtual Memory Access (DVMA)Direct Virtual Memory Access (DVMA)
In DVMA, data is transferred between two In DVMA, data is transferred between two memory-mapped devices (i.e. from memory-mapped devices (i.e. from controller to controller) without requiring controller to controller) without requiring main memorymain memory– no cycle stealing requiredno cycle stealing required
![Page 26: OSes: 12. IOSys 1 Operating Systems v Objectives –discuss how an OS manages and controls I/O operations and I/O devices Certificate Program in Software](https://reader035.vdocuments.mx/reader035/viewer/2022062621/551c19ef5503469e4f8b57fc/html5/thumbnails/26.jpg)
OSes: 12. IOSys 26
3. Application I/O Interfaces3. Application I/O Interfaces
OSes treat I/O devices in a standard way OSes treat I/O devices in a standard way using:using:– abstraction, encapulation, software layeringabstraction, encapulation, software layering
The user/programmer sees a standardized The user/programmer sees a standardized set of I/O functions.set of I/O functions.
Differences are hidden inside kernel Differences are hidden inside kernel modules called modules called device driversdevice drivers..
![Page 27: OSes: 12. IOSys 1 Operating Systems v Objectives –discuss how an OS manages and controls I/O operations and I/O devices Certificate Program in Software](https://reader035.vdocuments.mx/reader035/viewer/2022062621/551c19ef5503469e4f8b57fc/html5/thumbnails/27.jpg)
OSes: 12. IOSys 27
A Kernel I/O StructureA Kernel I/O StructureFig. 12.6, p.409
SCSIdevicedriver
keyboarddevicedriver
mousedevicedriver
PCI busdevicedriver
floppydevicedriver
ATAPIdevicedriver
SCSIdevice
controller
keyboarddevice
controller
mousedevice
controller
PCI busdevice
controller
floppydevice
controller
ATAPIdevice
controller
SCSIdevices
keyboard mouse PCI busfloppy
disk drivesdisk &
tape drives
kernel I/O subsystem
kernel
![Page 28: OSes: 12. IOSys 1 Operating Systems v Objectives –discuss how an OS manages and controls I/O operations and I/O devices Certificate Program in Software](https://reader035.vdocuments.mx/reader035/viewer/2022062621/551c19ef5503469e4f8b57fc/html5/thumbnails/28.jpg)
OSes: 12. IOSys 28
AdvantagesAdvantages
Simplifies OS developer’s work.Simplifies OS developer’s work. Benefits hardware manufacturersBenefits hardware manufacturers
But…But…– different OSes have different ‘standard’ different OSes have different ‘standard’
device driver interfaces.device driver interfaces.
![Page 29: OSes: 12. IOSys 1 Operating Systems v Objectives –discuss how an OS manages and controls I/O operations and I/O devices Certificate Program in Software](https://reader035.vdocuments.mx/reader035/viewer/2022062621/551c19ef5503469e4f8b57fc/html5/thumbnails/29.jpg)
OSes: 12. IOSys 29
3.1. Characteristics of I/O Devices3.1. Characteristics of I/O Devices
AspectAspect VariationVariation ExampleExampledisk-transfer modedisk-transfer mode character character terminalterminal
block block diskdisk
access methodaccess method sequentialsequential modemmodemrandomrandom CD-ROMCD-ROM
transfer scheduletransfer schedule synchronoussynchronous tapetapeasynchronousasynchronous keyboardkeyboard
sharingsharing dedicateddedicated tapetapesharablesharable keyboardkeyboard
: :
Fig. 12.7, p.410
continued
![Page 30: OSes: 12. IOSys 1 Operating Systems v Objectives –discuss how an OS manages and controls I/O operations and I/O devices Certificate Program in Software](https://reader035.vdocuments.mx/reader035/viewer/2022062621/551c19ef5503469e4f8b57fc/html5/thumbnails/30.jpg)
OSes: 12. IOSys 30
AspectAspect VariationVariation ExampleExampledevice speeddevice speed latencylatency
seek timeseek timetransfer ratetransfer ratedelay between opsdelay between ops
I/O directionI/O direction read-onlyread-only CD-ROMCD-ROMwrite-onlywrite-only graphics graphics
ctrllerctrllerread-writeread-write diskdisk
![Page 31: OSes: 12. IOSys 1 Operating Systems v Objectives –discuss how an OS manages and controls I/O operations and I/O devices Certificate Program in Software](https://reader035.vdocuments.mx/reader035/viewer/2022062621/551c19ef5503469e4f8b57fc/html5/thumbnails/31.jpg)
OSes: 12. IOSys 31
3.2. Character and Block Devices3.2. Character and Block Devices
Character device:Character device:– transfer byte by bytetransfer byte by byte
Block device:Block device:– treat blocks of bytes as the transfer unittreat blocks of bytes as the transfer unit
Standard file-system interface:Standard file-system interface:– read(), write(), seek(), etcread(), write(), seek(), etc
Memory mapping:Memory mapping:– useful for executing kernel modules/servicesuseful for executing kernel modules/services
![Page 32: OSes: 12. IOSys 1 Operating Systems v Objectives –discuss how an OS manages and controls I/O operations and I/O devices Certificate Program in Software](https://reader035.vdocuments.mx/reader035/viewer/2022062621/551c19ef5503469e4f8b57fc/html5/thumbnails/32.jpg)
OSes: 12. IOSys 32
3.3. Network Devices3.3. Network Devices
Distinguished due to differences in Distinguished due to differences in addressing and performance (reliablility, addressing and performance (reliablility, data sequencing, speed).data sequencing, speed).
Standard interface:Standard interface:– sockets, message packets, streamssockets, message packets, streams– select() for monitoring collections of socketsselect() for monitoring collections of sockets
continued
![Page 33: OSes: 12. IOSys 1 Operating Systems v Objectives –discuss how an OS manages and controls I/O operations and I/O devices Certificate Program in Software](https://reader035.vdocuments.mx/reader035/viewer/2022062621/551c19ef5503469e4f8b57fc/html5/thumbnails/33.jpg)
OSes: 12. IOSys 33
Other UNIX (inter-process) communication Other UNIX (inter-process) communication features:features:– half-duplex pipeshalf-duplex pipes– full-duplex FIFOs (queues)full-duplex FIFOs (queues)– message queuesmessage queues
![Page 34: OSes: 12. IOSys 1 Operating Systems v Objectives –discuss how an OS manages and controls I/O operations and I/O devices Certificate Program in Software](https://reader035.vdocuments.mx/reader035/viewer/2022062621/551c19ef5503469e4f8b57fc/html5/thumbnails/34.jpg)
OSes: 12. IOSys 34
3.4. Clocks and Timers3.4. Clocks and Timers
Basic uses:Basic uses:– get the current time/the elapsed timeget the current time/the elapsed time– set a timer to trigger an operation at time Tset a timer to trigger an operation at time T
(e.g. time-slice a process)(e.g. time-slice a process)
Timers have coarse resolution (20-60 Timers have coarse resolution (20-60 ticks/sec), which limits the precision of ticks/sec), which limits the precision of triggerstriggers– a CPU can execute ~100M instructions/seca CPU can execute ~100M instructions/sec
![Page 35: OSes: 12. IOSys 1 Operating Systems v Objectives –discuss how an OS manages and controls I/O operations and I/O devices Certificate Program in Software](https://reader035.vdocuments.mx/reader035/viewer/2022062621/551c19ef5503469e4f8b57fc/html5/thumbnails/35.jpg)
OSes: 12. IOSys 35
3.5. Blocking & Nonblocking I/O3.5. Blocking & Nonblocking I/O
Blocking (synchronous) I/OBlocking (synchronous) I/O– the application is suspended until the I/O is the application is suspended until the I/O is
completedcompleted– easy to understand/implementeasy to understand/implement
Nonblocking (asynchronous) I/ONonblocking (asynchronous) I/O– the application does not waitthe application does not wait
continued
![Page 36: OSes: 12. IOSys 1 Operating Systems v Objectives –discuss how an OS manages and controls I/O operations and I/O devices Certificate Program in Software](https://reader035.vdocuments.mx/reader035/viewer/2022062621/551c19ef5503469e4f8b57fc/html5/thumbnails/36.jpg)
OSes: 12. IOSys 36
Some software requires nonblocking I/OSome software requires nonblocking I/O– most games software has to be able to receive most games software has to be able to receive
user input from the keyboard at any time while user input from the keyboard at any time while updating the screen continuouslyupdating the screen continuously
![Page 37: OSes: 12. IOSys 1 Operating Systems v Objectives –discuss how an OS manages and controls I/O operations and I/O devices Certificate Program in Software](https://reader035.vdocuments.mx/reader035/viewer/2022062621/551c19ef5503469e4f8b57fc/html5/thumbnails/37.jpg)
OSes: 12. IOSys 37
Implementing Nonblocking I/OImplementing Nonblocking I/O
ThreadsThreads– place the blocking I/O in one thread, and let the place the blocking I/O in one thread, and let the
other behaviour execute in other threadsother behaviour execute in other threads
Use nonblocking I/O system callsUse nonblocking I/O system calls– they return immediately with whatever was they return immediately with whatever was
availableavailable– e.g. select() called with a time-out of 0e.g. select() called with a time-out of 0
continued
![Page 38: OSes: 12. IOSys 1 Operating Systems v Objectives –discuss how an OS manages and controls I/O operations and I/O devices Certificate Program in Software](https://reader035.vdocuments.mx/reader035/viewer/2022062621/551c19ef5503469e4f8b57fc/html5/thumbnails/38.jpg)
OSes: 12. IOSys 38
Use asynchronous I/O system callsUse asynchronous I/O system calls– they return immediately, but the completed they return immediately, but the completed
I/O result is ‘available’ some time laterI/O result is ‘available’ some time later
– the result can be made ‘available’ in the result can be made ‘available’ in different ways:different ways:
a special variablea special variable raising a signal (software interrupt)raising a signal (software interrupt) calling a callback functioncalling a callback function
(e.g. used in Java’s event model)(e.g. used in Java’s event model)
![Page 39: OSes: 12. IOSys 1 Operating Systems v Objectives –discuss how an OS manages and controls I/O operations and I/O devices Certificate Program in Software](https://reader035.vdocuments.mx/reader035/viewer/2022062621/551c19ef5503469e4f8b57fc/html5/thumbnails/39.jpg)
OSes: 12. IOSys 39
4. Kernel I/O Subsystems4. Kernel I/O Subsystems
These are features built on top of the These are features built on top of the hardware and device-driver infrastructure, hardware and device-driver infrastructure, including:including:– I/O schedulingI/O scheduling– bufferingbuffering– cachingcaching– spoolingspooling
![Page 40: OSes: 12. IOSys 1 Operating Systems v Objectives –discuss how an OS manages and controls I/O operations and I/O devices Certificate Program in Software](https://reader035.vdocuments.mx/reader035/viewer/2022062621/551c19ef5503469e4f8b57fc/html5/thumbnails/40.jpg)
OSes: 12. IOSys 40
4.1. I/O Scheduling4.1. I/O Scheduling
Scheduling (re-ordering) is carried out to:Scheduling (re-ordering) is carried out to:– improve overall system performanceimprove overall system performance
– share device access fairlyshare device access fairly
– reduce average waiting timereduce average waiting time
![Page 41: OSes: 12. IOSys 1 Operating Systems v Objectives –discuss how an OS manages and controls I/O operations and I/O devices Certificate Program in Software](https://reader035.vdocuments.mx/reader035/viewer/2022062621/551c19ef5503469e4f8b57fc/html5/thumbnails/41.jpg)
OSes: 12. IOSys 41
Scheduling Example Scheduling Example
Three jobs want to read from a hard disk. Three jobs want to read from a hard disk. The read arm is currently near the The read arm is currently near the beginning of the disk.beginning of the disk.– job 1: requests a block at the end of the diskjob 1: requests a block at the end of the disk– job 2: requests a block near the startjob 2: requests a block near the start– job 3: requests a block in the middlejob 3: requests a block in the middle
New scheduleNew schedule: jobs 2, 3, 1: jobs 2, 3, 1
![Page 42: OSes: 12. IOSys 1 Operating Systems v Objectives –discuss how an OS manages and controls I/O operations and I/O devices Certificate Program in Software](https://reader035.vdocuments.mx/reader035/viewer/2022062621/551c19ef5503469e4f8b57fc/html5/thumbnails/42.jpg)
OSes: 12. IOSys 42
4.2. Buffering4.2. Buffering
A A bufferbuffer is a memory area that stores data is a memory area that stores data while it is being transferred between two while it is being transferred between two devices, or between a device and a process.devices, or between a device and a process.
![Page 43: OSes: 12. IOSys 1 Operating Systems v Objectives –discuss how an OS manages and controls I/O operations and I/O devices Certificate Program in Software](https://reader035.vdocuments.mx/reader035/viewer/2022062621/551c19ef5503469e4f8b57fc/html5/thumbnails/43.jpg)
OSes: 12. IOSys 43
Three Uses for BufferingThree Uses for Buffering
Cope with speed mismatchesCope with speed mismatches– e.g. between a modem and hard diske.g. between a modem and hard disk– double bufferingdouble buffering may be used may be used
Cope with different data-transfer sizesCope with different data-transfer sizes– e.g. packet transfer over a networke.g. packet transfer over a network
Support Support copy semanticscopy semantics for application I/O for application I/O– e.g. so write() data cannot be changede.g. so write() data cannot be changed
![Page 44: OSes: 12. IOSys 1 Operating Systems v Objectives –discuss how an OS manages and controls I/O operations and I/O devices Certificate Program in Software](https://reader035.vdocuments.mx/reader035/viewer/2022062621/551c19ef5503469e4f8b57fc/html5/thumbnails/44.jpg)
OSes: 12. IOSys 44
Double Buffering IllustratedDouble Buffering IllustratedVUW cs305
Slow producer
Fast consumer
buffer
buffer
harddisk
![Page 45: OSes: 12. IOSys 1 Operating Systems v Objectives –discuss how an OS manages and controls I/O operations and I/O devices Certificate Program in Software](https://reader035.vdocuments.mx/reader035/viewer/2022062621/551c19ef5503469e4f8b57fc/html5/thumbnails/45.jpg)
OSes: 12. IOSys 45
Slow producer
Fast consumer
buffer
buffer
harddisk
![Page 46: OSes: 12. IOSys 1 Operating Systems v Objectives –discuss how an OS manages and controls I/O operations and I/O devices Certificate Program in Software](https://reader035.vdocuments.mx/reader035/viewer/2022062621/551c19ef5503469e4f8b57fc/html5/thumbnails/46.jpg)
OSes: 12. IOSys 46
Slow producer
Fast consumer
buffer
buffer
harddisk
![Page 47: OSes: 12. IOSys 1 Operating Systems v Objectives –discuss how an OS manages and controls I/O operations and I/O devices Certificate Program in Software](https://reader035.vdocuments.mx/reader035/viewer/2022062621/551c19ef5503469e4f8b57fc/html5/thumbnails/47.jpg)
OSes: 12. IOSys 47
4.3. Caching4.3. Caching
A A cachecache is a region of ‘fast memory’ that is a region of ‘fast memory’ that holds copies of data:holds copies of data:– used to speed-up reuse and updatesused to speed-up reuse and updates– e.g. recently read instructions copied from the e.g. recently read instructions copied from the
hard diskhard disk
Cache and buffer difference:Cache and buffer difference:– a buffer may hold the a buffer may hold the onlyonly copy of a data item copy of a data item
![Page 48: OSes: 12. IOSys 1 Operating Systems v Objectives –discuss how an OS manages and controls I/O operations and I/O devices Certificate Program in Software](https://reader035.vdocuments.mx/reader035/viewer/2022062621/551c19ef5503469e4f8b57fc/html5/thumbnails/48.jpg)
OSes: 12. IOSys 48
4.4. Spooling4.4. Spooling
A A spoolspool is a buffer (or buffers) used to hold is a buffer (or buffers) used to hold output for a device while the device is output for a device while the device is processing the current job.processing the current job.
The device can only process one job at onceThe device can only process one job at once– e.g. a printer, tape readere.g. a printer, tape reader
Spool management is often done by a dedicated Spool management is often done by a dedicated system system daemondaemon (process) (process)
![Page 49: OSes: 12. IOSys 1 Operating Systems v Objectives –discuss how an OS manages and controls I/O operations and I/O devices Certificate Program in Software](https://reader035.vdocuments.mx/reader035/viewer/2022062621/551c19ef5503469e4f8b57fc/html5/thumbnails/49.jpg)
OSes: 12. IOSys 49
Spooling DiagramSpooling Diagram VUW, cs305
Program
Program
Program
Printerdriver
spooldaemon
Printerdriver
![Page 50: OSes: 12. IOSys 1 Operating Systems v Objectives –discuss how an OS manages and controls I/O operations and I/O devices Certificate Program in Software](https://reader035.vdocuments.mx/reader035/viewer/2022062621/551c19ef5503469e4f8b57fc/html5/thumbnails/50.jpg)
OSes: 12. IOSys 50
4.5. UNIX I/O Kernel Data Structures4.5. UNIX I/O Kernel Data StructuresFig. 12.9, p.419
file-system record
inode pointerpointers to functions:read(), write(), select(),...
network record
socket d.s. pointerpointers to functions:read(), write(), select(),...
filedescriptor
process open-file
table
user process
system open-file table
activeinode table
network infotable
kernel
![Page 51: OSes: 12. IOSys 1 Operating Systems v Objectives –discuss how an OS manages and controls I/O operations and I/O devices Certificate Program in Software](https://reader035.vdocuments.mx/reader035/viewer/2022062621/551c19ef5503469e4f8b57fc/html5/thumbnails/51.jpg)
OSes: 12. IOSys 51
A variety of I/O components are A variety of I/O components are controlled/monitored through the open controlled/monitored through the open file table.file table.
Details are hidden from the user by Details are hidden from the user by standard abstractions:standard abstractions:– e.g. read() works with files and network e.g. read() works with files and network
socketssockets
![Page 52: OSes: 12. IOSys 1 Operating Systems v Objectives –discuss how an OS manages and controls I/O operations and I/O devices Certificate Program in Software](https://reader035.vdocuments.mx/reader035/viewer/2022062621/551c19ef5503469e4f8b57fc/html5/thumbnails/52.jpg)
OSes: 12. IOSys 52
5. From I/O Requests to Hardware5. From I/O Requests to Hardware
How does the OS convert an I/O request How does the OS convert an I/O request into hardware commands?into hardware commands?
Consider how UNIX reads from a file on Consider how UNIX reads from a file on disk.disk.
![Page 53: OSes: 12. IOSys 1 Operating Systems v Objectives –discuss how an OS manages and controls I/O operations and I/O devices Certificate Program in Software](https://reader035.vdocuments.mx/reader035/viewer/2022062621/551c19ef5503469e4f8b57fc/html5/thumbnails/53.jpg)
OSes: 12. IOSys 53
Lifecycle of an I/O RequestLifecycle of an I/O RequestFig. 12.10, p.422
Request I/O
can satisfyalready?
Send request todevice driver.Block process.
system call
I/O completed
Transfer datato process
userprocess
yes
no
kernelI/O subsystem
return from call
kernelI/O subsystem
continuedtime
![Page 54: OSes: 12. IOSys 1 Operating Systems v Objectives –discuss how an OS manages and controls I/O operations and I/O devices Certificate Program in Software](https://reader035.vdocuments.mx/reader035/viewer/2022062621/551c19ef5503469e4f8b57fc/html5/thumbnails/54.jpg)
OSes: 12. IOSys 54
Carry out request.Send commands tocontroller. Block.
Determine whenI/O completed.
Tell I/O subsystem.
device controller commands
Monitor device.Interrupt when I/O completed
Receive interrupt.Store data in dd buffer.
Signal dd.
I/O completed.Generate interrupt.
devicedriver
interrupthandler
keyboarddevice
controller
time
![Page 55: OSes: 12. IOSys 1 Operating Systems v Objectives –discuss how an OS manages and controls I/O operations and I/O devices Certificate Program in Software](https://reader035.vdocuments.mx/reader035/viewer/2022062621/551c19ef5503469e4f8b57fc/html5/thumbnails/55.jpg)
OSes: 12. IOSys 55
Filename to Disk ControllerFilename to Disk Controller
A UNIX path name has no clear separation A UNIX path name has no clear separation of the device portion:of the device portion:/home/fidji/ad/public_html/index.html/home/fidji/ad/public_html/index.html
UNIX stores a mount table (in UNIX stores a mount table (in /etc/mnttab/etc/mnttab) ) of device name to pathname details:of device name to pathname details:
/dev/dsk/c1t1d0s0 /home/fidji …/dev/dsk/c1t1d0s0 /home/fidji …/dev/dsk/c1t2d0s0 /home/hawai …/dev/dsk/c1t2d0s0 /home/hawai …/dev/dsk/c1t4d0s0 /home/corse …/dev/dsk/c1t4d0s0 /home/corse …
continued
![Page 56: OSes: 12. IOSys 1 Operating Systems v Objectives –discuss how an OS manages and controls I/O operations and I/O devices Certificate Program in Software](https://reader035.vdocuments.mx/reader035/viewer/2022062621/551c19ef5503469e4f8b57fc/html5/thumbnails/56.jpg)
OSes: 12. IOSys 56
The name (e.g. The name (e.g. /dev/dsk/c1t1d0s0/dev/dsk/c1t1d0s0) is ) is looked up in the file-system, and UNIX looked up in the file-system, and UNIX finds:finds:– <major, minor> device numbers<major, minor> device numbers
The The major device numbermajor device number identifies the identifies the device driver type (e.g. character/block device driver type (e.g. character/block transfer).transfer).
continued
![Page 57: OSes: 12. IOSys 1 Operating Systems v Objectives –discuss how an OS manages and controls I/O operations and I/O devices Certificate Program in Software](https://reader035.vdocuments.mx/reader035/viewer/2022062621/551c19ef5503469e4f8b57fc/html5/thumbnails/57.jpg)
OSes: 12. IOSys 57
The The minor device numberminor device number can be used to can be used to index into a device table to find the device index into a device table to find the device controller’s I/O port address or its memory controller’s I/O port address or its memory mapped address.mapped address.
![Page 58: OSes: 12. IOSys 1 Operating Systems v Objectives –discuss how an OS manages and controls I/O operations and I/O devices Certificate Program in Software](https://reader035.vdocuments.mx/reader035/viewer/2022062621/551c19ef5503469e4f8b57fc/html5/thumbnails/58.jpg)
OSes: 12. IOSys 58
Stream ModulesStream Modules UNIX System V allows pipelines of driver UNIX System V allows pipelines of driver
code to be assembled dynamically for an code to be assembled dynamically for an application.application.
module 1
module 2
module N
hardware
Applicationstream head
driver end
![Page 59: OSes: 12. IOSys 1 Operating Systems v Objectives –discuss how an OS manages and controls I/O operations and I/O devices Certificate Program in Software](https://reader035.vdocuments.mx/reader035/viewer/2022062621/551c19ef5503469e4f8b57fc/html5/thumbnails/59.jpg)
OSes: 12. IOSys 59
6. Performance6. Performance
I/O is a major factor in system I/O is a major factor in system performance:performance:– it uses the CPU heavily to execute device it uses the CPU heavily to execute device
drivers, schedule processesdrivers, schedule processes– cycle stealingcycle stealing– costs of interrupt processingcosts of interrupt processing– network trafficnetwork traffic
![Page 60: OSes: 12. IOSys 1 Operating Systems v Objectives –discuss how an OS manages and controls I/O operations and I/O devices Certificate Program in Software](https://reader035.vdocuments.mx/reader035/viewer/2022062621/551c19ef5503469e4f8b57fc/html5/thumbnails/60.jpg)
OSes: 12. IOSys 60
Network Comms.Network Comms. Fig. 12.11, p.425
char typed
interrupt generated
interrupt handled
device driver
kernel
user process kernel
device driver
network adapter
interrupt generated
interrupt handled
system call completes
contextswitch
state saved
hardware
state saved
context switch
network
contextswitch Sending
System
![Page 61: OSes: 12. IOSys 1 Operating Systems v Objectives –discuss how an OS manages and controls I/O operations and I/O devices Certificate Program in Software](https://reader035.vdocuments.mx/reader035/viewer/2022062621/551c19ef5503469e4f8b57fc/html5/thumbnails/61.jpg)
OSes: 12. IOSys 61
network
packet receive
d
network adapter
interrupt generated
device driver
kernel
networkdaemon
kernel
networksubdaemon
contextswitch
state saved
hardware
network
contextswitch
context switch
ReceivingSystem
![Page 62: OSes: 12. IOSys 1 Operating Systems v Objectives –discuss how an OS manages and controls I/O operations and I/O devices Certificate Program in Software](https://reader035.vdocuments.mx/reader035/viewer/2022062621/551c19ef5503469e4f8b57fc/html5/thumbnails/62.jpg)
OSes: 12. IOSys 62
Ways to Improve I/O EfficiencyWays to Improve I/O Efficiency
Reduce the number of context switches.Reduce the number of context switches.
Reduce the number of data copys to/from Reduce the number of data copys to/from memory.memory.
Reduce the number of interrupts.Reduce the number of interrupts.
continued
![Page 63: OSes: 12. IOSys 1 Operating Systems v Objectives –discuss how an OS manages and controls I/O operations and I/O devices Certificate Program in Software](https://reader035.vdocuments.mx/reader035/viewer/2022062621/551c19ef5503469e4f8b57fc/html5/thumbnails/63.jpg)
OSes: 12. IOSys 63
Offload I/O work to other processors.Offload I/O work to other processors.
Move more processing into hardware.Move more processing into hardware.
Balance the performance of CPU, memory, Balance the performance of CPU, memory, bus, and the I/O.bus, and the I/O.
![Page 64: OSes: 12. IOSys 1 Operating Systems v Objectives –discuss how an OS manages and controls I/O operations and I/O devices Certificate Program in Software](https://reader035.vdocuments.mx/reader035/viewer/2022062621/551c19ef5503469e4f8b57fc/html5/thumbnails/64.jpg)
OSes: 12. IOSys 64
Efficiency ExamplesEfficiency Examples
The telnet daemon in Solaris runs inside a The telnet daemon in Solaris runs inside a kernel thread:kernel thread:– that eliminates context switching between the that eliminates context switching between the
daemon and the kerneldaemon and the kernel
Front-end processorsFront-end processors– e.g. terminal concentratorse.g. terminal concentrators
continued
![Page 65: OSes: 12. IOSys 1 Operating Systems v Objectives –discuss how an OS manages and controls I/O operations and I/O devices Certificate Program in Software](https://reader035.vdocuments.mx/reader035/viewer/2022062621/551c19ef5503469e4f8b57fc/html5/thumbnails/65.jpg)
OSes: 12. IOSys 65
DMA controllersDMA controllers
I/O channelsI/O channels– an I/O channel is a dedicated CPU for an I/O channel is a dedicated CPU for
offloading I/O work from the main CPUoffloading I/O work from the main CPU
![Page 66: OSes: 12. IOSys 1 Operating Systems v Objectives –discuss how an OS manages and controls I/O operations and I/O devices Certificate Program in Software](https://reader035.vdocuments.mx/reader035/viewer/2022062621/551c19ef5503469e4f8b57fc/html5/thumbnails/66.jpg)
OSes: 12. IOSys 66
Where to put I/O Functionality?Where to put I/O Functionality?Fig. 12.12, p.426
application code
kernel code
device driver code
device controller code
(hardware)
device code(hardware)
I/O functionalityimplemented using:
incr
ease
d de
velo
pmen
t tim
e
incr
ease
d ef
fici
ency
incr
ease
d de
velo
pmen
t cos
t
incr
ease
d fl
exib
ilit
y
incr
ease
d hi
ding
fro
m u
ser