Input/Output: Operating Systems CSE 4300
Input/Output: Operating Systems CSE 4300
Input/Output: Operating Systems CSE 4300
CSE 4300
Instructor:Mohammad Maifi Hasan Khan
Chapter 5
Input/Output
I/O Devices
• Block Devices
– Info in fixed size
• Character Device
– Accepts stream of
character, keyboard
• Clock??
• Device Controller
– Convert streams of bits in
block of bytes
– Perform error correction
• Controller’s job –
– Convert the serial bits stream into a block of bytes
– Perform error checking and correction
– Copy to main memory
How to communicate with Device
Controllers?
• Option – I
– Each control register assigned a I/O port number (I/O port space)
– IN REG, PORT / OUT PORT, REG
• Option – II
– Map control registers to memory space
– Each register assigned a unique memory address to which no
memory is assigned
Memory-Mapped I/O (1)
(A)
IN REG, PORT
OUT PORT, REG
IN R0, 4
MOV R0,4
Two different things!
READY:
Disadvantage of Memory-Mapped I/O
- Caching of memory words
LOOP: TEST PORT_4
BEQ READY
BRANCH LOOP
READY:
- Requires selectively disabling caching
Memory-Mapped I/O (2)
-Having multiple bus makes it harder to inspect
every memory reference
-Option 1: Send all addresses to memory first,
if fail to respond, send to other buses
-Option 2: Snooping device
-Option 3: Filter address in PCI bridge
chip: Uses range registers to check
How an interrupt happens. The connections between the devices and the interrupt
controller actually use interrupt lines on the bus rather than dedicated wires.
• I/O Device raises interrupt by asserting a signal on a bus line
• If no other interrupt pending, interrupt controller
handles the interrupt by putting a number on address line and
asserts a signal to interrupt the CPU
• Address on the bus is used as an index to interrupt vector table
• Gets the new PC from the table
• The interrupt service procedure acknowledge the interrupt by
writing a value to interrupt controller’s I/O port
Interrupt Handlers (1)
1. Save registers not already been saved by
interrupt hardware.
2. Set up a context for the interrupt service
procedure.
3. Set up a stack for the interrupt service procedure.
4. Acknowledge the interrupt controller. If there is no
centralized interrupt controller, reenable
interrupts.
5. Copy the registers from where they were saved to
the process table.
Interrupt Handlers (2)
6. Run the interrupt service procedure.
7. Choose which process to run next.
8. Set up the MMU context for the process to run
next.
9. Load the new process’ registers, including its
PSW.
10. Start running the new process.
Precise and Imprecise Interrupts (1)
Properties of a precise interrupt
Writing a string to the printer using interrupt-driven I/O. (a) Code executed at the time
the print system call is made. (b) Interrupt service procedure for the printer.
Interrupt-Driven I/O
ch ar ac t e r!
t s o c cu r on every
Interru p
Writing a string to the printer using interrupt-driven I/O. (a) Code executed at the time
the print system call is made. (b) Interrupt service procedure for the printer.
I/O Using DMA
Printing a string using DMA. (a) Code executed when the print
system call is made. (b) Interrupt service procedure.
I/O Using DMA
Printing a string using DMA. (a) Code executed when the print
system call is made. (b) Interrupt service procedure.
Let us look at some real devices!
• Magnetic Disk
• Clocks
• Keyboards
• Displays
Magnetic Disks (1)
Disk parameters for the original IBM PC 360-KB floppy disk and a
Western Digital WD 18300 hard disk.
Magnetic Disks (2)
z s ecto r s/ track
li n d er s, y heads,
is i ns tr u c te d x cy
The softwa
re
t r o lle r r e m aps!
Con
A disk sector.
Disk Formatting
Cylinder skew?
A programmable clock.
Clock Software
Typical duties of a clock driver
1. Maintaining the time of day.
2. Preventing processes from running longer than
they are allowed to.
3. Accounting for CPU usage.
4. Handling alarm system call made by user
processes.
5. Providing watchdog timers for parts of the
system itself.
Task 1 Maintaining the time of day.
Task 2 Preventing processes from running longer
than they are allowed to.
Example scenario:
Ack not received within certain time
Example Scenario
Floppy disk startup
Soft Timers (Aron and Druschel 1999)
Main Idea:
Two ways for I/O.
•Polling: Delay in response.
•Interrupt: Too much overhead due to context switch (pipeline, TLB, cache ).
Soft timers succeed according to rate at which kernel entries are made
because of:
1.System calls.
2.TLB misses.
3.Page faults.
4.I/O interrupts.
5.The CPU going idle.
(a) Running at full clock speed. (b) Cutting voltage by two cuts
clock speed by two and power consumption by four.
I/O Software Layers
1. Smaller pits
(0.4 microns versus 0.8 microns for CDs).
2. A tighter spiral
(0.74 microns between tracks versus 1.6
microns for CDs).
3. A red laser
(at 0.65 microns versus 0.78 microns for CDs).
DVD (2)
DVD Formats