Lecture 14, part 1: Input and output

Previous lecture Next lecture

Exam

I/O devices as resources and their management

Important questions:

Resources

I/O device interfacing

Example: PC keyboard

Example: CGA video controller

Example: IDE disk controller

Example: Ethernet controller

Device classes

Interrupts

Interrupt processing sequence on hardware level

Direct Memory Access (DMA)

DMA transfer sequence

I/O addresss space

Device drivers

Polling ("programmed I/O")

... implies active waiting for an I/O device

Pseudo code of an operating system function to print text using polling:

/* Copy character into kernel buffer p */
copy_from_user (buffer, p, count);
/* Loop over all characters */
for (i=0; i<count; i++) {
  /* Wait β€œactively” until printer is ready */
  while (*printer_status_reg != READY);
  /* Print one character */
  *printer_data_reg = p[i];
}
return_to_user ();

Interrupt-driven I/O

... implies that the CPU can be allocated to another process while waiting for a response from the device

Code to initiate the I/O operation:

copy_from_user (buffer, p, count);
/* Enable printer interrupts */
enable_interrupts ();
/* Wait until printer is ready */
while (*printer_status_reg != READY);
/* Print first character */
*printer_data_reg = p[i++];
scheduler ();
return_to_user ();

Interrupt handler:

if (count > 0) {
  *printer_data_reg = p[i];
  count--;
  i++;
} else {
  unblock_user ();
}
acknowledge_interrupt ();
return_from_interrupt ();

Discussion: Interrupts

Discussion: Interrupts (2)

Discussion: Direct Memory Access

Tasks of the OS

Layers of the I/O system

Lecture 14, part 2: I/O in Unix and disk scheduling

Unix device abstractions

Unix device abstractions (2)

Unix device abstractions (3)

special files:

Unix access primitives

A quick overview... (see the man pages for details...)

Unix device specific functions

IOCTL(2) Linux Programmer's Manual IOCTL(2)
NAME
  ioctl - control device
SYNOPSIS
  #include <sys/ioctl.h>
  int ioctl(int d, int request, ...);
CONFORMING TO
  No single standard. Arguments, returns, and semantics of
  ioctl(2) vary according to the device driver in question
  (the call is used as a catch-all for operations that
  don't cleanly fit the Unix stream I/O model). The ioctl
  function call appeared in Version 7 AT&T Unix.

Unix: waiting for multiple devices

Unix: waiting for multiple devices (2)

Buffering of I/O operations

Single I/O buffers

Performance estimation

A simple back-of-the envelope calculation gives an indication of the performance increase when repeatedly reading blockwise with subsequent processing:

T: Duration of the read operation
C: Compute time required for processing
M: Duration of the copy process (system buffer→user process)
B: Overall time required for reading and processing a block

Without buffer: B0 = T + C
With buffer: BE = max (T, C) + M

For T β‰ˆ C und M β‰ˆ 0, B0 β‰ˆ 2Β·BE. Unfortunately, M > 0

Double I/O buffering

Performance estimation

A double buffer enables to execute a read operation in parallel to a copy operation and processing

Without buffer: B0 = T + C
With buffer: BE = max (T, C) + M
With double buffer: BE = max (T, C + M)
If C + M < T, the device could be utilized to 100%

I/O ring buffers

Is what is commonly used.

Discussion: I/O buffers

Device control example: disk

I/O scheduling: FIFO

I/O scheduling: SSTF

I/O scheduling: Elevator

Discussion: I/O scheduling today

Conclusion