Chapter 5
Chapter 5
Chapter 5
INPUT/OUTPUT
I/O devices
I/O software
Organization of I/O
functions
Disk scheduling
Clocks
1
I/O Devices
Input
Process
Output
I/O devices ..
equipment.
Examples are disk and tape drives, sensors, controller, and actuators.
devices.
Cont
I/O devices cover a huge range in speeds
Input/output component
To view a document stored on a hard disk, you accessed hard disk
coordination .
2.
I/O software
Include different layer of the operating system that mange the I/O devices
Device Controllers
I/O hardware
Electrical engineers view of I/O hardware
chips, wires, power supplies, motors, and all the other
I/O devices
I/O communication
Each controller has a few registers that are used for communicating
with the CPU
10
control registers
Memory-Mapped I/O
11
Cont.
Two alternatives exist for the CPU to communicate with the device controller
Assign I/O port number to each device controller
12
Cont.
Memory-Mapped I/O are assigned addresses at the top of the
address space
Device-control registers are mapped into the address space of the
processor
CPU executes I/O requests using the standard data-transfer
instructions to read/write the device-control registers.
E.g. Graphics controller has a large memory-mapped region to hold
screen contents sending output to screen by writing data into the
memory-mapped region. Controller generates the screen image based on
the contents of this memory.
Simpler and faster to write millions of bytes to the graphics memory
compared to issuing millions of I/O instructions.
13
Memory-Mapped I/O
Advantages:
device control registers are just variables in memory and can be addressed in C
the same way as any other variables
Multiple buses ->Mark non memory ranges and forward to non memory
buses.
14
15
17
18
CHAPTER FIVE
INPUT/OUTPUT
I/O devices
I/O software
Organization of I/O functions
Disk scheduling
Clocks
19
I/O Software
Goals of I/O software design:
device independence
uniform naming.
The name of a file or a device should not depend on the
device in any way
error handling.
errors should be handled as close to the hardware as
possible
synchronous (blocking) versus asynchronous
(interrupt-driven)
I/O Software
Programmed I/O
The simplest form of I/O is to have the CPU do all
21
the work
The operating system then (usually) copies the
buffer with the string to an array, say, p, in kernel
space, where it is more easily accessed (because
the kernel may have to change the memory map to
get at user space).
It then checks to see if the I/O is currently available.
If not, it waits until it is available.
As soon as the I/O is available, the operating system
copies the first character to the printers data
register, in this example using memory-mapped I/O.
I/O Software
Programmed I/O
Consider a user process that wants to print the
22
I/O Software
Programmed I/O
23
I/O Software
Disadvantages:
Tying up the CPU in busy waiting
24
I/O Software
Interrupt-Driven I/O
The processor issues an I/O command on behalf of
I/O Software
After interrupt
Disadvantage:
Handling interrupt after
every char
26
Processor is involved in
I/O Software
I/O Using DMA
A DMA module controls the exchange of
data between main memory and an I/O
module.
The processor sends a request for the
transfer of a block of data to the DMA
module and is interrupted only after the
entire block has been transferred
Lets consider the printing again:
let the DMA controller feed the characters to the
27
I/O Software
Initiate printing
Handling Interrupt
28
CHAPTER FIVE
INPUT/OUTPUT
I/O devices
I/O software
30
Device drivers
Each I/O device attached to a computer
31
Device drivers
Functions:
accept abstract read and write requests from
32
Device driver
33
Device-Independent I/O
Software
The boundary between device-independent I/O
34
Device-Independent I/O
Software
Typical functions:
Uniform interfacing for device drivers
make all I/O devices and drivers look more-or-
Buffering
create a buffer inside the kernel and have the
interrupt handler put the characters there
Error reporting
Many errors are device-specific and must be
handled by the appropriate driver, but the
framework for error handling is device
independent
Allocating and releasing dedicated devices
35
Providing a device-independent block size
operating system
Consists of libraries linked together with
user programs
System calls are normally made by library
procedures
write(filePointer, varBuffer, nobytes);
Library procedure write will be linked with
37
CHAPTER FIVE
INPUT/OUTPUT
I/O devices
I/O software
Organization of I/O functions
Disk scheduling
Clocks
38
Disk scheduling
Disk Structure
39
Disk Structure
40
Disk Structure
Arm
Assembly
41
Disk Structure
42
43
44
Seek time
Rotational delay
Actual transfer time
READING ASSIGNMENT
Disk Arm Scheduling
C-SCAN
C-LOOK
45
CHAPTER FIVE
INPUT/OUTPUT
I/O devices
I/O software
Organization of I/O functions
Disk scheduling
Clocks
46
Clocks
Clock
Clocks (or timers) are essential to the
CPU
Set a timer to trigger operation X at time T
Clocks take the same form as the other
devices:
Hardware
Software
47
Clock Hardware
Programmable clocks typically have several
modes of operation
one-shot mode
Copy value of holding register, decrement counter for every
pulse and interrupt
Wait until explicitly restarted
square-wave mode
after getting to zero and causing the interrupt, the holding
register is automatically copied into the counter, and the
whole process is repeated again indefinitely.
ticks
48
Clock Hardware
All the clock hardware does is generate
49
time)
Preventing processes from running longer than
they are allowed to.
Accounting for CPU usage.
Handling the alarm system call made by user
processes.
Providing watchdog timers for parts of the system
itself.