I/O which
means input or output is mediated by the OS also known as operating system. I/O
resources are shared by multiple programs therefore protection and scheduling
is needed. I/O can causes asynchronous interrupts but there are exception for
the same mechanism. I/O programming is fiddly as OS provides abstractions to
programs.
I/O
Commands
I/O devices
are managed by I/O controller hardware and data are transferring to and fro
device. It also synchronizes operation with software. Command registers will
cause device to do something while status registers indicate what the devices
is doing and occurrence of errors. As for data register, write simply
means transfer data to a device while
read means the other way round.
Technique
of I/O
There are 5
types of I/O techniques:
1)
Programmed
I/O: The CPU issues a command and wait for I/O operations to be complete. The
CPU is faster than the I/O module therefore it is wasteful.
2)
Interrupt
Driven I/O: The CPU will issues commands then proceed to its normal work until
interrupted by I/O devices on the work completion.
3)
DMA(Direct Memory Access) :
In this technique CPU and I/O exchange date without CPU involved.
4)
Memory
Mapped I/O: Memory and I/O are treated as memory only which means no signal
like IO/M.
5)
Isolated
I/O: Address space of memory and I/O is isolated and it uses IO/M signal.
Programmed
I/O
Also called
polling. It check I/O status register periodically and if device is ready
operation will be execute while take action if error occurs. It is common in
small or low-performance real-time embedded systems because of its predictable
timing and low hardware cost while in other system, CPU time is wasted. The
code in the OS for Programmed I/O is more like:
keyboard_wait: ; for get_ch
test Keyboard_Status, 80000000h
jz keyboard_wait
mov eax, Keyboard_Data
and
display_wait: ; for put_ch
test Display_Status, 80000000h
jz display_wait
mov Display_Data, eax
This scheme is known as BUSY WAITING, or
SPIN WAITING. The little loop is called a SPIN WAIT LOOP.
The
problems with Programmed I/O is much time is wasted spin waiting. If it takes
100 instructions to program this, and each instruction takes 20ns to execute,
then it takes
100 * 20nsec = 2000nsec = 2 usec to
execute
If a device
takes 2msec (=2000usec) to deal with one character, then the percent of time
spent waiting
time waiting / total time = 2000us /
2000us +2us =99.9%
However we will likely have a solution that actually spent less time
“doing nothing”.
Interrupt Driven I/O
When a device is ready or an error occurs, controller will interrupts
CPU. Interrupt is like an exception but not synchronized to instruction
execution and can invoke handler between instructions therefore causes
information often identifies the interrupting devices. Priority interrupts are
devices needing more urgent attention thus getting higher priority and can
interrupt handlers for a lower priority interrupt.
Above is the Interrupt Processing and below is the Interrupt
Driven I/O Circle.
I/O Data Transfer
For Polling and Interrupt-Driven I/O, CPU transfer data
between memory and I/O data registers and its time consuming for high speed
devices. Direct Memory Access (DMA) is provided a starting address in memory by
the OS and I/O controller transfer to and fro memory autonomously but interrupt
upon completion or error.
Yap Chi Hian B031210334