Ch-Four Input Output - Best
Ch-Four Input Output - Best
Science
1 I/O MNGT
Contents
1. What is I/O Device?
2. Devices controller
3. Memory-mapped I/O
4. Direct memory access(DMA)
5. Interrupt revisited
6. Goals of I/O and issues of software
7. I/O operation
8. I/O software layers
9. Disks
2
I/O MNGT 2
What is I/O Device?
I/O MNGT 3
Example
• Keyboard Input: When a user enters data into a system using a
keyboard
• Mouse Input: When a user interacts with a system through a mouse
• Touchscreen Input: When a user interacts with a system by
touching the screen
• Voice Input: When a user speaks into a system to enter data or
perform an action
• Printer Output: When a system sends data to a printer
• Speaker Output: Used to send data from a system to a user through
an audio output
• Video Output: When a system sends data to a monitor or TV for
display
I/O MNGT 4
I/O devices
I/O devices There are two types of I/O devices blocked
and character.
Block devices
– stores information in Fixed-size blocks, each one
with its own address.
– Common block size range from 512bytes to
32,768bytes.
– All transfers are in units of one or more entire
(consecutive) blocks.
– The essential property of a block device is that it is
possible to read or write each block independently
of all the other ones.
• Example: Hard disks, CO-ROMs, and USB sticks.
I/O MNGT 5
can't…
Character devices
– delivers or accepts stream of character, without
regard to any block structure.
– It is not addressable and does not have any seek
operation.
o Example: Printers, network interfaces, mice (for
pointing),
o most other devices that are not disk-like can be seen
as character devices.
o Some devices just do not fit in to both above
classification.
o Clocks, for example, are not block addressable, Nor
do they generate or accept character streams.
I/O MNGT 6
Device controller
In computer systems, I/O devices do not usually communicate
with the operating system.
The operating system manages their task with the help of one
intermediate electronic device called a device controller.
It knows how to communicate with the operating system as
well as how to communicate with I/O devices.
So device controller is an interface between the computer
system (operating system) and I/O devices.
The device controller communicates with the system using the
system bus.
Indicates the hardware components.
There are two major components – Electronic Component (Device
controller/Adapter) and the Mechanical Component (the moving parts).
I/O MNGT 7
I/O MNGT 8
Cont…
Is a collection of electronics that can operate a
1, port, 2, bus, or devices
For example, the disk controller’s job is to convert
the serial bit stream into a block of bytes and
perform any error correction necessary.
controller has a few registers that are used for
communicating with the CPU.
By writing into these registers, the operating
system can command the device to deliver data,
accept data, switch itself on or off, or otherwise
perform some action.
By reading from these registers, the operating
system can learn what the device's state is,
whether it is prepared to accept a new command,
I/O MNGT 9
and so on.
Memory-mapped I/O
How does the CPU communicate with controllers to
accomplish I/O transfer?
Two alternatives exist.
1. Use of special I/O instruction( IN and OUT):
Each register is assigned an I/O port number, an 8- or 16-
bit integer.
The set of all the I/O ports form the I/O port space
protected ordinary user programs cannot access it (only
the operating system can).
Example:
₋ I N REG, PORT : the CPU can read in control register
PORT and store the result in CPU register REG.
₋ OUT PORT,REG : the CPU can write the contents of
REG to a control register.
I/O MNGT 10
Memory-mapped I/O(con’t….)
2. Mapping controller register to memory
space(memory-mapped I/O):
• Each register is assigned a unique memory
address to which no memory is assigned.
• CPU executes I/O requests using the standard
data transferring instruction to read and write
controller registers.
I/O MNGT 11
4. Direct memory access(DMA)
o Request data from an I/O controller one byte at a
time wastes the CPU's time.
o so a different scheme, called DMA (Direct
Memory Access) chip that can control the flow of
bits between memory and some controller
without constant CPU intervention.
o The CPU sets up the DMA chip, telling it how
many bytes to transfer, the device and memory
addresses involved, and the direction, and lets it
go.
o When the DMA chip is done, it causes an
interrupt.
I/O MNGT 12
5. Interrupt revisited
o When an i/o device has finished the work given to
it, it causes an interrupt
• lt does this by asserting a signal on a bus line that
it has been assigned.
• This signal is detected by the interrupt controller
chip on the parent board, which then decides what
to do.
• If no other interrupts are pending, the interrupt
controller processes the interrupt immediately.
• If another one is in progress, or another device has
made a simultaneous request on a higher-priority
interrupt request line on the bus, the device is just
ignored for the moment.
• In this case it continues to assert an interrupt
signal on the bus until it is serviced by the CPU.
o
I/O MNGT 13
Interrupt revisited (cont….)
o To handle the interrupt:
– The controller puts a number on the address lines
specifying which device wants attention and asserts a
signal to interrupt the CPU.
I/O MNGT 16
Goals and issues of i/o software
o Device types There are two device types
Sharable (such as a disk)
Used by many users at the same time.
No problems are caused by multiple users having open
files on the same disk at the same time.
Dedicated (tape drives)
Have to be dedicated to a single user until that user is
finished.
Having two or more users writing blocks intermixed at
random to the same tape will definitely not work.
I/O MNGT 17
Types of I/O Controller
1. programmed I/O
2. interrupt-driven I/O
3. I/O using DMA
4. Advanced Programmable Interrupt Controller (APIC)
I/O MNGT 18
Programmed I/O
is a method in which the main CPU inputs or
outputs each byte or word and sits in a tight loop
waiting until it can get or send the next one.
The CPU continuously polls the device to see if it
is ready or not. This behavior is often called
polling or busy waiting.
Programmed I/0 is simple but has the
disadvantage of tying up the CPU full time until
all the I/0 is done.
I/O MNGT 19
Interrupt-driven I/O
o is a method in which the CPU starts an I/O
transfer for a character or word and goes off to do
something else until an interrupt arrives signaling
completion of the I/O.
o The advantage of interrupt-driven I/O allows the
CPU to do something else while waiting for the
device to become ready for the next work.
o The disadvantage of interrupt-driven I/0 is
that an interrupt occurs on every character or
word which Interrupts take time, which wastes a
certain amount of CPU time.
I/O MNGT 20
Direct memory access(DMA)
o It, only with the DMA controller doing all the work,
instead of the main CPU.
o This strategy requires special hardware (the DMA
controller) but frees up the CPU during the I/O to do
other work.
o The big win with DMA is reducing the number of
interrupts from one per character to one per
buffer.
o the DMA controller is usually much slower than the
main CPU. If the DMA controller is not capable of driving
the device at full speed, or the CPU usually has nothing
to do anyway while waiting for the DMA interrupt, then
interrupt-driven I/0 or even programmed I/0 may be
better.
I/O MNGT 21
Advanced Programmable Interrupt Controller (APIC)
I/O MNGT 23
Interrupt handlers
o Interrupts
o They should be hidden away deep in the bowels of
the operating system.
o The best way to hide them is to have driver starting
an I/O operation block until the I/O has completed
and the interrupt occurs.
o When the interrupt happens, the interrupt
procedure does whatever it has to in order to
handle the interrupt. Then unblock the driver that
started it.
I/O MNGT 24
Device driver
I/O MNGT 28
Summary of I/O software layers
I/O MNGT 29
9. Disk
o All real disks are organized into cylinders/platter,
each platter is arranged like a record, each one
containing many tracks.
o Each of the tracks then will be divided into sectors
(equal number of sectors or different number of
sectors).
o In the case of equal number of sectors
– The data density as closer to the center (hub) is high.
– The speed increases as the read/write moves to the outer
tracks.
o Modern large hard drives have more sectors per
track on outer tracks e.g. IDE drives.
o Many controllers can read or write on one drive while
seeking on one or more other drives, but floppy disk
controller cannot do that.
I/O MNGT 30
Disk (cont.…)
C
A
B D
I/O MNGT 31
Disk access time
o The time required to read or write a disk block is determined by
three factors
o The seek time: measures the delay for the disk head to reach the
right track.
o The rotational delay: accounts for the time to get to the right
sector.
o Transfer time: is how long the actual data read or write takes.
o There may be additional overhead for the operating system or the
controller hardware on the hard disk drive.
o Rotational speed: measured in revolutions per minute or RPM,
partially determines the rotational delay and transfer time.
o Manufacturers often report average to seek times:8-10ms
o These times average the time to seek from any track to any other
I/O MNGT 32
track.
Disk access time(cont.…)
o Rotational delay depends partly on how fast the disk
platters spin.
o Average rotational delay = 0.5 x rotations x rotational
speed
o For example, a 5400 RPM disk has an average rotational delay
of: 0.5 rotations /(5400 rotations/minute) = 5.55ms.
o The overall response time is the sum of the seek
time, rotational delay, transfer time, and overhead.
Example: Assume a disk has the following
specifications.
An average seek time of 9ms
A 5400 RPM rotational speed
A 10MB/s average transfer rate
2ms of overheads I/O MNGT 33
Disk access time(con’t…)
How long does it take to read a random 1,024-byte sector?
The average rotational delay is 5.55ms.
The transfer time will be about (1024 bytes /
10 MB/s) = 0.1ms.
So the response time is then 9ms + 5.55ms +
0.1ms + 2ms = 16.7ms.
That’s 16,700,000 cycles for a 1GHz processor!
I/O MNGT 34
Disk scheduling algorism
o the seek time dominates the other two times, so
reducing the mean seek time can improve system
performance substantially.
o There are different disk scheduling algorithms
that are used to reduce mean seek time.
First Come First Served (FCFS)
Shortest Seek Time First (SSTF)
SCAN (Elevator) Algorithm
C-SCAN (Modified Elevator) Algorithm (Circular-
SCAN)
I/O MNGT 35
First Come First Served (FCFS)
o Accept a request one at a time and carries them
out in that order.
o Service requests in the order they are received.
o The simplest and the fairest of all, but it doesn’t
improve performance
E.g: Track initial position: 11
Track request: 1,36,16,34,9,12
Service order: 1,36,16,34,9,12
I/O MNGT 36
Shortest Seek Time First (SSTF)
o It handles the closest (the least disk arm
movement) request next, to minimize seek time.
o Performance (efficiency): provides better
performance.
o Possibility of starvation: it lacks fairness
Example: Track initial position: 11
Track request: 1,36,16,34,9,12
Service order: 12,9,16, 1, 34, 36
I/O MNGT 37
SCAN (Elevator) Algorithm
o The disk arm keeps moving in the same direction
until there are no more outstanding requests in
that direction, and then it switches direction.
o It has the head start at track 0 and move towards
the highest numbered track, servicing all
requests for a track as it passes the track.
o SCAN algorithm is guaranteed to service every
request in one complete pass through the disk.
o It provides better service distribution.
Example. Track initial position: 11
Track request: 1,36,16,34,9,12
Direction bit: 1
Service order: 12, 16, 34, 36, 9, 1
I/O MNGT 38
C-SCAN (Modified Elevator) Algorithm (Circular-SCAN)
o A slight modification of the elevator algorithm that has a smaller
variance in response times is always scanned in the same direction.
o When the highest-numbered cylinder with a pending request has
been serviced, the arm goes to the lowest-numbered cylinder with
a pending request and then continues moving in an upward
direction.
o In effect, the lowest-numbered cylinder is thought of as being just
above the highest-numbered cylinder.
o It reduces the maximum delay experienced by new requests.
Example: Track initial position: 11
Track request: 1,36,16,34,9,12
Direction bit: 1
Service order: 12, 16, 34, 36, 1, 9
I/O MNGT 39
Redundant array independent disk(RAID)
o Redundant array of independent disks may be
used to increase disk reliability.
o In a RAID system, a single large file is stored in
several separate disk units by breaking the file up
into a number of smaller pieces and storing these
pieces on different disks.
o When a file is accessed for a read, all disks
deliver their data in parallel.
o RAID may be implemented in hardware or in the
operating system.
I/O MNGT 40
Activity
Track request: 23, 89, 132, 42, 187
• With disk head initially at 100
• FCFS,SSTF,SCAN & C-SCAN
Draw the request graph,
Write the service order and
Calculate the total seek time for each algorithm.
Which one is the best algorithm? And why?
I/O MNGT 41
FCFS SSTF
SCAN C-SCAN
I/O MNGT 42
Practice on the following:
Request sequence =176, 79, 34, 60, 92,
11, 41, 114
Initial head position = 50
1. FCFS
2. SSTF
3. SCAN
4. CSCAN
Draw the request graph,
Write the service order and
Calculate the total seek time for each algorithm.
Which one is the best algorithm? And why?
I/O MNGT 43
Thank
Thank You
You ...
...
I/O MNGT 44