A Timely Question.: Pre-Emptively
A Timely Question.: Pre-Emptively
A Timely Question.: Pre-Emptively
Most modern operating systems pre-emptively schedule programs. If you are simultaneously running two programs A and B, the O/S will periodically switch between them, as it sees fit. Specifically, the O/S will: Stop A from running Copy As register values to memory Copy Bs register values from memory Start B running How does the O/S stop program A?
I/O Programming
I/O requests are made by applications or OS involve moving data between peripheral device and main memory Two main ways for programs to communicate with devices: Memory-mapped I/O Isolated I/O Several ways to transfer data between devices and main memory: Programmed I/O Interrupt-driven I/O Direct memory access We will explore some of these in more detail in the MPs
Memory-mapped I/O
With memory-mapped I/O, one address space is divided into two parts. Some addresses refer to physical memory locations. Other addresses actually reference peripherals. For example, my old Apple IIe had a 16-bit address bus which could access a whole 64KB of memory. Addresses C000-CFFF in hexadecimal were not part of memory, but were used to access I/O devices. All the other addresses did reference main memory. The I/O addresses are shared by many peripherals. In the Apple IIe, for instance, C010 is attached to the keyboard while C030 goes to the speaker. Some devices may need several I/O addresses.
FFFF Memory I/O D000 C000
Memory
0000
October 21, 2012 I/O Programming, Interrupts and Exceptions 4
CPU
Memory
Hard disks
CD-ROM
Network
Display
To send data to a device, the CPU writes to the appropriate I/O address. The address and data are then transmitted along the bus. Each device has to monitor the address bus to see if it is the target. The Apple IIe main memory ignores any transactions whose address begins with bits 1100 (addresses C000-CFFF). The speaker only responds when C030 appears on the address bus.
Isolated I/O
FFFFFFFF
Here, there are separate address spaces for memory and I/O devices special instructions that access the I/O space Example (x86): regular instructions like MOV reference RAM special instructions IN and OUT access a separate I/O address space An address could refer to either main memory or an I/O device, depending on the instruction used
Main memory
00000000
I/O devices
0000FFFF
00000000
6
Some things require a sequence of instructions sw $reg, 0xffff0014($0) li $t0, 1 sw $t0, 0xffff0018 # sets bot angle = $reg
SPIMbot coordinates
May 5, 2003
Buses
Done? Yes 9
Interrupt-driven I/O
Continually checking to see if a device is ready is called polling Wastes CPU time: CPU must ask repeatedly CPU must ask often enough to ensure that it doesnt miss anything, which means it cant do much else while waiting Solution: Interrupt-driven I/O Instead of waiting, the CPU continues with other calculations The device interrupts the processor when the data is ready CPU still does the data transfer
No CPU sends read request to device Not ready CPU does other stuff CPU waits .. . for device CPU receives interrupt Ready CPU reads word from device
Done? Yes 10
May 5, 2003
Buses
11
May 5, 2003
Buses
12
13
DMA pictorially
System bus
CPU
Memory
DMA unit
Hard disks
CD-ROM
Network
Since both the processor and the DMA controller may need to access main memory, some form of arbitration is required
14
15
16
Execute Application
17
18
19
Receiving Interrupts
To receive interrupts, the software has to enable them MIPS: done by writing to the Status register (on the co-processor) Enable interrupts by setting bit zero Select which interrupts to receive by setting one or more of bits 8-15
li mtc0
Handling Interrupts
When an interrupt occurs, the Cause register indicates which one For an exception, the exception code field holds the exception type For an interrupt, the exception code field is 0000 and bits will be set for pending interrupts
0000
21