Salta al contenuto
Note per Studenti Input-Output Modules and Programmed Input-Output Report

Input-Output Modules and Programmed Input-Output

In questa pagina 5
In questa pagina 4

Why an I/O module

Peripherals differ greatly (formats, speeds from a few bytes/s for a keyboard to GB/s for an SSD) and almost all are slower than the CPU. Connecting them directly to the bus would be impossible: the I/O module (controller, interface) acts as an intermediary between the system bus and one or more devices.

Functions:

  • control and timing of the data flow;
  • communication with the CPU: command decoding, data exchange, status reporting, recognition of its own address;
  • communication with the device: commands, status, data;
  • buffer: absorbs the speed difference;
  • error detection (mechanical, transmission).

The device performs transduction: it converts between binary data and physical quantities (movement, light, sound, magnetisation).

The module presents the CPU with registers: data, status (for example "ready" bit, "error" bit) and control (commands).

Addressing of devices

Definition (memory-mapped I/O and isolated I/O)

Memory-mapped I/O Isolated I/O
address space single: the module registers occupy memory addresses separate for I/O
instructions the same load/store as memory dedicated instructions (IN, OUT in x86)
pros no special instructions; all addressing modes available the memory space stays entirely for memory
cons uses up memory addresses limited set of I/O instructions

Example. In ARM (memory-mapped I/O) the data register of the UART at 0x101F1000 is written with STRB r0, [r1], the same instruction as a store to memory.

ARM uses memory-mapped I/O. Example: the status register of a UART at 0x101F1018, bit 5 = "transmit buffer full", data register at 0x101F1000.

Programmed I/O

Definition (programmed I/O with polling). The CPU does everything: it gives the command, then repeatedly interrogates the status register (polling) until the device is ready, then transfers the datum.

Example. With a printer of 10001000 characters/s and a CPU of 10910^9 instructions/s, about 109/1000=10610^9/1000=10^6 polling instructions are wasted for each character.

armasm
        LDR  r1, =0x101F1000    @ base of the UART
wait:   LDR  r2, [r1, #0x18]    @ reads the status register
        TST  r2, #0x20          @ bit 5: buffer full?
        BNE  wait               @ yes: wait (busy waiting)
        STRB r0, [r1]           @ no: writes the character to the data register

Problem: busy waiting. If the CPU executes 10910^9 instructions per second and a printer accepts 1000 characters per second, for each character the CPU wastes about a million instructions checking the status.

The three techniques

Definition (programmed I/O, interrupt-driven I/O and DMA)

Example. For a block of 10241024 words interrupt-driven I/O requires 10241024 interrupts, DMA only one, at the end of the block.

Typical mistakes

  • Thinking that with memory-mapped I/O the data pass through the cache: device registers must be marked non-cacheable, otherwise the CPU would read stale values.
  • Confusing isolated I/O (separate address space) with "peripheral not connected to the bus".

Versione ripasso

Module

Intermediary between system bus and devices (very different formats and speeds, mostly slower than the CPU). Functions: control and timing, communication with CPU and device, buffer, error detection. Device does transduction. Registers: data, status (ready, error), control.

Addressing

  • Memory-mapped: registers in the memory space, ordinary load/store, all addressing modes; uses addresses. ARM uses this: UART data 0x101F1000, status 0x101F1018 (bit 5 = transmit buffer full), written with STRB r0,[r1].
  • Isolated: separate space, dedicated instructions (IN, OUT on x86), memory space kept whole.

Programmed I/O

CPU gives the command and polls the status register: LDR r2,[r1,#0x18]; TST r2,#0x20; BNE wait; STRB r0,[r1]. Busy waiting: printer 1000 char/s on a 10910^9 instr/s CPU wastes about 10610^6 instructions per character.

Three techniques

1024 words: 1024 interrupts against 1 with DMA.

Typical mistakes: device registers must be non-cacheable; isolated I/O means a separate address space, not a device off the bus.

Teoria collegata