π Lecture 30 β Interrupt Priority and Nested Interrupts
π Overview: This lecture examines how interrupt systems handle multiple I/O devices through priority mechanisms and nested interrupts. It quantifies the performance trade-offs between different I/O methodsβpolling, interrupt-driven, and Direct Memory Access (DMA)βthrough a series of detailed numerical examples, demonstrating why DMA is essential for high-speed data transfers.
ποΈ Topics Covered
The lecture begins with Nested Interrupts and Interrupt Masks, then presents six worked examples comparing CPU overhead for polling versus interrupt-driven I/O across different device speeds (hard drive, floppy drive, keyboard). It concludes with a detailed explanation of Direct Memory Access (DMA), its advantages and disadvantages, and how it eliminates the CPU as a bottleneck for high-speed block transfers.
π Lecture Summary
Nested Interrupts
(Read from Book, Jordan Page 391)
Interrupt Mask
(Read from Book, Jordan Page 391)
Priority Mask
(Read from Book, Jordan Page 392)
Examples
Example #1 β Polling Overhead for Three Devices
Three I/O devices are connected to a 32-bit, 10 MIPS CPU. A hard drive (1MB/sec, 32-bit bus), a floppy drive (25KB/sec, 16-bit bus), and a keyboard (polled 30 times/sec). Each polling operation requires 20 instructions per device.
Hard Drive: Transfers 1MB/sec = 250 Γ 2ΒΉβ° 32-bit words/sec. Polling requires 250 Γ 2ΒΉβ° Γ 20 = 5,120,000 instructions/sec. CPU time = (5.12 Γ 10βΆ) / (10 Γ 10βΆ) = 51.2%.
Floppy Drive: Transfers 12.5 Γ 2ΒΉβ° half-words/sec. Polling requires 12.5 Γ 2ΒΉβ° Γ 20 = 256,000 instructions/sec. CPU time = (0.256 Γ 10βΆ) / (10 Γ 10βΆ) = 2.56%.
Keyboard: 30 Γ 20 = 600 instructions/sec. CPU time = 600 / (10 Γ 10βΆ) = 0.006%.
π‘ Why this matters: Polling is acceptable for low-speed devices (keyboard, floppy) but consumes over half the CPU for a hard drive, making it impractical for high-data-rate devices.
Example #2 β Polling Frequency and Delay
a. To achieve an average delay of at most 10 ms, the processor polls every 20 ms (50 times/sec) because average wait = half the polling interval.
b. With 10,000 cycles per poll and a 100 MHz processor: 50 Γ 10,000 = 500,000 cycles/sec. CPU time = (0.5 Γ 10βΆ) / (100 Γ 10βΆ) = 0.5%.
c. For 1 ms average delay: poll every 2 ms (500 times/sec). 500 Γ 10,000 = 5,000,000 cycles/sec. CPU time = 5 / 100 = 5%.
Example #3 β Printer Polling in a Busy Wait Loop
A 20 MIPS processor drives an 80-character line printer (1 ms/char). Total 565 instructions to print a line, with 2 instructions in the polling loop per character (80 Γ 2 = 160 instructions for polling).
Remaining 405 instructions take 405 / (20 Γ 10βΆ) = 20.25 ΞΌsec. Printing 80 chars takes 80 ms. Time spent in polling loop = 80 - 0.02025 = 79.97 ms. This is 79.97/80 = 99.96% of total time.
Example #4 β Maximum Devices with Interrupts
A 20 MIPS processor has devices at 1000 chars/sec. Interrupt handling takes 17 instructions + 1 ΞΌsec hardware response.
Service time per character = 17/(20 Γ 10βΆ) + 1 ΞΌsec = 1.85 ΞΌsec. Each device requires 1.85 ms handling per second. Maximum devices = 1 / (1.85 Γ 10β»Β³) = 540.
Example #5 β Interrupt Overhead for Floppy Drive
A floppy (25KB/sec, 16-bit bus) on a 32-bit, 10 MIPS CPU using interrupt-driven I/O. Interrupt overhead = 20 instructions. Transfer rate = 12.5 Γ 2ΒΉβ° half-words/sec. Overhead = 12.5 Γ 2ΒΉβ° Γ 20 = 256,000 instructions/sec.
Example #6 β Interrupts vs. Polling Comparison
A 500 MHz processor requires 1000 cycles per context switch. ISR = 10,000 cycles. Device makes 200 interrupts/sec. Polling every 0.5 ms during idle, 500 cycles per poll.
a. Cycles/sec with only interrupts: each interrupt = 10,000 + 2 Γ 1000 = 12,000 cycles. Total = 200 Γ 12,000 = 2,400,000 cycles/sec.
b. Fraction of CPU = 2,400,000 / (500 Γ 10βΆ) = 0.48%.
c. With interrupts + polling: Each interrupt takes 12,000 cycles / (500 Γ 10βΆ) = 24 ΞΌsec. For 200 interrupts: 4.8 ms. Remaining 995.2 ms for polling = 1990 polls Γ 500 cycles = 995,000 cycles. Total = 2,400,000 + 995,000 = 3,395,000 cycles/sec.
d. Interrupt overhead = 200 Γ 2000 = 400,000 cycles/sec. Polling overhead = 500 cycles/poll. Equal overhead β 400,000/500 = 800 polls/sec, or every 1.25 ms.
Direct Memory Access (DMA)
Direct Memory Access (DMA) is a technique where the CPU passes control of the system bus to a memory subsystem or peripheral, enabling direct transfer of a contiguous block of data between peripherals and memory without CPU intervention.
Advantage of DMA
The transfer rate is very fast because the system bus is isolated via tri-state buffers, establishing a direct connection between I/O and memory while the CPU is free. DMA is ideal for large data transfers (e.g., hard disk to printer). Compared to interrupt-driven I/O or programmed I/O, DMA is much faster. It requires a DMA controller, which acts as a specialized CPU for synchronizing data transfer.
Example of DMA
The instruction load [2], [9] is illegal in SRC because it requires two steps: load r1, [9] then store r1, [2]. Similarly, out [6], datap must be done as load r1, [6] then out r1, datap. The CPU acts as an unnecessary middleman, causing every data word to travel over the system bus twice, limiting transfer speed.
DMA Approach
The DMA approach electrically disconnects the CPU from the system bus (via tri-state buffers), allowing a peripheral or memory subsystem to communicate directly. This achieves higher transfer rates, approaching the memory's own speed limit.
Disadvantage of DMA
An additional DMA controller is required, making the system more complex and expensive. DMA requests have priority over all other bus activities, including interruptsβno interrupts are recognized during a DMA cycle.
π Definition β Direct Memory Access (DMA): A technique where the CPU passes bus control to allow direct data transfer between I/O and memory without CPU intervention, using a DMA controller for synchronization.
β Key Takeaways
For exam purposes, you must remember that polling is only practical for slow devices (like keyboards) and becomes prohibitively expensive for high-speed devices (like hard drives), where it can consume over 50% of CPU time. Interrupt-driven I/O reduces overhead but still requires CPU cycles for context switching and service routines. DMA eliminates the CPU bottleneck entirely for block transfers, achieving the highest data rates at the cost of additional hardware complexity. The key formulas to master involve calculating CPU utilization as (instructions or cycles for I/O) divided by (total instructions or cycles per second). Always account for both polling frequency (delay = half the interval) and interrupt overhead (context switch + ISR execution) when solving these performance problems.
π§ Quick Revision Questions
- What is the average delay between a device request and its servicing when polling is used every 20 ms?
- For a 20 MIPS processor, what percentage of CPU time is spent polling a floppy drive requiring 256,000 instructions per second?
- How many cycles per second does a single device interrupt consume if the ISR takes 10,000 cycles and each context switch takes 1000 cycles?
- What is the primary advantage of DMA over interrupt-driven I/O for high-speed data transfers?
- Why does polling become impractical for devices with high data transfer rates (e.g., hard drives)?
π Lecture 31 β Direct Memory Access (DMA)
π Overview: This lecture introduces Direct Memory Access (DMA), a technique that allows peripherals to transfer data directly to/from memory without CPU intervention. It explains why DMA achieves higher transfer rates than programmed or interrupt-driven I/O, and covers DMA configurations, protocols, cycle stealing, and I/O channels. Understanding DMA is critical for designing high-performance I/O systems.
ποΈ Topics Covered
The lecture covers DMA definition, advantages and disadvantages, the reason for DMA (CPU as unnecessary middleman), master/slave component definitions, cycle stealing, the three-step data transfer process, DMA transfer protocol with bus request/grant, DMA priority over interrupts, three DMA configurations (single bus detached, single bus integrated, I/O bus), worked examples calculating CPU time with and without DMA, I/O processors vs. I/O channels, types of channels (selector, multiplexer with byte/block multiplexer), virtual and physical addresses, DMA and memory system problems, and three hardware/software solutions for cache coherence.
π Lecture Summary
Introduction
Direct Memory Access (DMA) is a technique that allows a peripheral to read from and/or write to memory without intervention by the CPU. It is a simple form of bus mastering where the I/O device is set up by the CPU to transfer one or more contiguous blocks of memory. After the transfer is complete, the I/O device gives control back to the CPU. Possible DMA transfer combinations include: memory to memory, memory to peripheral, peripheral to memory, and peripheral to peripheral.
The DMA approach is to "turn off" (tri-state and electrically disconnect) the CPU and let a peripheral device communicate directly with memory or another peripheral.
π Advantage: Higher transfer rates (approaching that of memory) can be achieved.
π Disadvantage: A DMA Controller (DMAC) is needed, making the system complex and expensive.
Generally, DMA requests have priority over all other bus activities, including interrupts. No interrupts may be recognized during a DMA cycle.
π‘ Why this matters: DMA offloads the CPU from time-consuming I/O data transfers, freeing it to perform other computation.
Reason for DMA
The instruction load [2], [9] is illegal. Symbols [2] and [9] represent memory locations. This transfer must be done in two steps: load r1, [9] then store r1, bx. Thus, it is not possible to transfer from one memory location to another without involving the CPU. The same applies to transfers between memory and peripherals connected to I/O ports. For example, out [6], datap is illegal; it requires: load r1, [6] then out r1, datap. Similar comments apply to the in instruction.
Thus, the real cause of the limited transfer rate is the CPU itself. It acts as an unnecessary "middleman". Every data word travels over the system bus twice.
Some Definitions
π Master Component: A component connected to the system bus and having control of it during a particular bus cycle.
π Slave Component: A component connected to the system bus with which the master component can communicate during a particular bus cycle. Normally the CPU with its bus control logic is the master component.
π Qualifications to Become a Master: Must have the capability to place addresses on the address bus and direct bus activity during a bus cycle.
π Qualified Components: Processors with their associated bus control logic, and DMA controllers.
π Cycle Stealing: Taking control of the system bus for a few bus cycles.
Data Transfer Using DMA
Data transfer using DMA takes place in three steps:
1st Step: The processor issues a command to the DMA controller with: operation to be performed (read or write), address of I/O device, address of memory block, and size of data to be transferred. After this, the processor becomes free and may perform other tasks.
2nd Step: The entire block of data is transferred directly to or from memory by the DMA controller.
3rd Step: At the end of the transfer, the DMA controller informs the processor by sending an interrupt signal.
The DMA Transfer Protocol
Most processors have a separate line over which an external device can send a request for DMA. Common names include HOLD, RQ, or Bus Request (BR).
The DMA cycle begins with the alternate bus master requesting the system bus by activating the Bus Request line. The CPU completes the current bus cycle (as in interrupts) and responds by floating the address, data, and control lines. A Bus Grant pulse is then output by the CPU to the requesting device. After receiving the Bus Grant pulse and waiting for the CPU's "float delay", the requesting device may drive the system bus to prevent bus contention. To return control to the CPU, the alternate bus master relinquishes bus control and issues a release pulse on the same Bus Request line.
DMA Has Priority Over Interrupt Driven I/O
In interrupt driven I/O, the transfer depends on the speed at which the processor tests and services a device, and many instructions are required per I/O transfer. These factors become a bottleneck for large data blocks. In DMA, I/O transfers occur without CPU intervention; the CPU pauses for only one bus cycle. Therefore, DMA is more efficient for I/O transfers.
DMA Configurations
Single Bus Detached DMA: A single bidirectional bus connects processor, memory, DMA module, and all I/O modules. When an I/O module needs DMA, it requests permission; if granted, it sends read/write address and data size to the DMA module. The I/O module then transfers its contiguous block to/from main memory. The processor cannot execute during the transfer (single bus), but DMA is much faster than processor-mediated transfers.
Single Bus Integrated DMA: The DMA and one or more I/O modules are integrated without the system bus; the DMA may function as part of an I/O module or as a separate module controlling the I/O module.
I/O Bus: The DMA and I/O modules are integrated through an I/O bus, reducing the number of I/O interfaces required between the DMA and I/O modules.
Example 1
An I/O device transfers data at 10MB/s over a 100MB/s bus. Data is transferred in 4KB blocks. The processor operates at 500MHz, and it takes 5000 cycles to handle each DMA request. Find the fraction of CPU time handling the data transfer with and without DMA.
π Without DMA: The processor copies data into memory as sent over the bus. Since the I/O device sends data at 10MB/s over the 100MB/s bus, 10% of each second is spent transferring data. Thus, 10% of CPU time is spent copying data.
π With DMA:
Number of DMA requests per second = 10MB / 4KB = 10,000,000 bytes / 4096 bytes = 2441.41 β 2500 requests/sec
Total cycles for DMA handling = 2500 requests Γ 5000 cycles/request = 12,500,000 cycles
CPU clock = 500 MHz = 500 Γ 10βΆ cycles/sec
Fraction of CPU time = 12,500,000 / (500 Γ 10βΆ) = 0.025 = 2.5%
Example 2
A hard drive with max transfer rate 1MB/s is connected to a 32-bit, 10MIPS CPU at 100 MHz. The DMA-based I/O interface takes 500 clock cycles for CPU to set up DMA, plus 300 clock cycles for interrupt handling at end. Data transfer uses 2KB blocks. Calculate percentage of CPU time consumed handling the hard drive.
π Solution:
Blocks transferred per second = 1MB / 2KB = 1000 KB / 2 KB = 500 blocks/sec
Cycles per DMA transfer = 500 + 300 = 800 cycles
Total cycles per second = 500 Γ 800 = 400,000 cycles/sec
CPU clock = 100 MHz = 100 Γ 10βΆ cycles/sec
Percentage = (400 Γ 10Β³) / (100 Γ 10βΆ) = 4 Γ 10β»Β³ = 0.4%
π‘ Why this matters: In real scenarios, the drive is not active all the time, so actual CPU consumption is much smaller than 0.4%. If cache memory is used, it can free up main memory for the DMAC.
Cycle Stealing
The DMA module takes control of the bus to transfer data to/from memory by forcing the CPU to temporarily suspend its operation. This is called Cycle Stealing because the DMA steals a bus cycle. The CPU suspends for one bus cycle, transfers data, then returns control to the CPU.
I/O Processors
When an I/O module has its own local memory to control a large number of I/O devices without CPU involvement, it is called an I/O processor.
I/O Channels
When an I/O module can execute a specific set of instructions for specific I/O devices in memory without CPU involvement, it is called an I/O channel.
Types of I/O Channels
π Selector Channel: A DMA controller that can do block transfers for several devices but only one at a time.
π Multiplexer Channel: A DMA controller that can do block transfers for several devices at once.
Types of Multiplexer Channel
Byte Multiplexer: Accepts or transmits characters; interleaves bytes from several devices; used for low-speed devices.
Block Multiplexer: Accepts or transmits blocks of characters; interleaves blocks from several devices; used for high-speed devices.
Virtual Address vs. Physical Address
π Virtual Address: Generated logically by the memory management unit for translation.
π Physical Address: The actual address in memory.
DMA and Memory System
DMA disturbs the relationship between the memory system and CPU. Without DMA, all memory accesses are handled by the CPU using address translation and cache mechanisms. With DMA, memory accesses can occur without CPU address translation and cache access, creating problems in virtual memory and cache systems.
Hardware Software Interface Solutions
Solution 1: All I/O transfers are made through the cache to ensure modified data are read and updated in the cache on I/O write. This can decrease processor performance due to infrequent I/O data usage.
Solution 2: Cache is invalidated for I/O read; for I/O write, write-back (flushing) is forced by the operating system. This is more efficient because flushing large cache portions only occurs on DMA block accesses.
Solution 3: Flush cache entries using a hardware mechanism, used in multiprogramming systems to keep cache coherent.
Some Clarifications
- "Serial" and "parallel" refer to computer I/O ports, not the CPU. The CPU always transfers data in parallel.
- "Programmed I/O", "Interrupt driven I/O", and "DMA" refer to how the CPU handles I/O or controls data flow through ports.
- "Simplex" and "duplex" refer to the transmission medium or communication link.
- "Memory mapped I/O" and "Independent I/O" refer to mapping of the interface (CPU control lines used in the interface).
β Key Takeaways
- DMA allows peripherals to transfer data directly to/from memory without CPU intervention, achieving higher transfer rates by eliminating the CPU as a "middleman" and reducing data bus travel from two passes to one.
- The DMA transfer process consists of three steps: CPU setup (providing operation, addresses, and block size), block transfer by DMAC, and interrupt notification upon completion. During setup, the CPU becomes free for other tasks.
- DMA configurations include single bus detached, single bus integrated, and I/O bus architectures; DMA has priority over interrupt-driven I/O, and uses cycle stealing where the CPU suspends for one bus cycle per transfer.
- DMA introduces cache coherence and virtual memory problems because it bypasses CPU address translation and cache mechanisms; solutions include transferring through cache, OS-managed invalidation/flushing, and hardware cache flushing.
- I/O channels extend DMA capability: selector channels handle one device at a time, while multiplexer channels (byte or block) handle multiple devices simultaneously, with byte multiplexers for low-speed and block multiplexers for high-speed devices.
π§ Quick Revision Questions
- What are the three possible data transfer directions in DMA?
- In the three-step DMA transfer process, what information does the CPU provide to the DMA controller in the first step?
- What is cycle stealing and how does it affect CPU operation during a DMA transfer?
- Calculate the percentage of CPU time used for DMA if a device transfers 5MB/s in 1KB blocks, each DMA request takes 2000 cycles, and the CPU runs at 400 MHz.
- What is the difference between a selector channel and a multiplexer channel in I/O channel architecture?
π Lecture 32 β Magnetic Disk Drives
π Overview: This lecture covers the fundamental structure and operation of magnetic hard disk drives, including their static and dynamic properties. It explains how data is organized on disks, the mechanical delays involved in reading and writing data, and compares hard disks with flash memory and semiconductor memory.
ποΈ Topics Covered
The lecture covers hard disk structure including platters, tracks, and sectors; static properties like storage capacity; dynamic properties including seek time, rotational latency, and transfer rate; overhead time and controller delays; several worked examples calculating disk access times; mechanical delays in embedded systems and flash memory as an alternative; and a comparison between semiconductor memory and hard disks based on cost and latency.
π Lecture Summary
Hard Disk
A hard disk is the most frequently used peripheral device. It consists of a set of platters. Each platter is divided into tracks, and each track is subdivided into sectors. To identify each sector, an address is needed. Before the actual data, there is a header consisting of a few bytes (e.g., 10 bytes). Along with the header there is a trailer. Every sector has three parts: a header, a data section, and a trailer.
Static Properties
The storage capacity can be determined from the number of platters and the number of tracks. To keep the density the same for the entire surface, the trend is to use more sectors for outer tracks and fewer sectors for inner tracks.
Dynamic Properties
When data needs to be read from a particular location on the disk, the head moves toward the selected track. This process is called seek. The disk is constantly rotating at a fixed speed. After a short time, the selected sector moves under the head. This interval is called the rotational delay. On average, the data may be available after half a revolution. Therefore, the rotational latency is half a revolution.
The time required to seek a particular track is defined by the manufacturer. Maximum, minimum, and average seek times are specified. Seek time depends upon the present position of the head and the position of the required sector. For calculations, the average value of the seek time is used.
Transfer rate: When a particular sector is found, the data is transferred to an I/O module. This depends on the transfer rate, typically between 30 and 60 MBytes/sec, as defined by the manufacturer.
Overhead time: A request may not find the hard disk immediately available, causing a queuing delay. The hard disk controller (electronics on a printed circuit board on the hard disk) takes time called overhead time.
Example 1
Find the average rotational latency if the disk rotates at 20,000 rpm. Solution: Average latency to the desired data is halfway around the disk. Average rotational latency = 0.5 / (20,000 / 60) = 1.5 ms
Example 2
A magnetic disk has an average seek time of 5 ms. Transfer rate is 50 MB/sec. Disk rotates at 10,000 rpm. Controller overhead is 0.2 msec. Find the average time to read or write 1024 bytes. Solution: Average Tseek = 5 ms. Average Trot = 0.5 * 60 / 10,000 = 3 ms. Ttransfer = 1KB / 50MB = 0.02 ms. Tcontroller = 0.2 ms. Total time = Tseek + Trot + Ttransfer + Tcontroller = 5 + 3 + 0.02 + 0.2 = 8.22 ms
Example 3
A hard disk with 5 platters has 1024 tracks per platter, 512 sectors per track, and 512 bytes/sector. What is the total capacity? Solution: 512 bytes Γ 512 sectors = 0.2 MB/track. 0.2 MB Γ 1024 tracks = 0.2 GB/platter. Total capacity = 5 Γ 0.2 = 1 GB
Example 4
How many platters are required for a 40 GB disk if there are 1024 bytes/sector, 2048 sectors per track, and 4096 tracks per platter? Solution: Capacity of one platter = 1024 Γ 2048 Γ 4096 = 8 GB. For 40 GB, need 40 / 8 = 5 platters
Example 5
Consider a hard disk that rotates at 3000 rpm. Seek time to move between adjacent tracks is 1 ms. There are 64 sectors per track stored in linear order. Read/write head is initially at start of sector 1 on track 7. a. How long to transfer sector 1 on track 7 to sector 1 on track 9? Solution: Time for one revolution = 60/3000 = 20 ms. Time to read or write one sector = 20 / 64 = 0.31 ms/sector. Head movement time from track 7 to track 9 = 1 ms Γ 2 = 2 ms. After reading sector 1 on track 7 (0.31 ms), an additional 19.7 ms rotational delay is needed to line up with sector 1 again. Total time = 0.31 + 19.7 + 0.31 = 20.3 ms
b. How long to transfer all sectors on track 12 to corresponding sectors on track 13? Solution: Time to read or write an entire track = 20 ms. Head movement time = 1 ms (time for approximately 4 sectors to pass under head). After reading track 12 and repositioning, head is on track 13 at 4 sectors past initial sector read. Total transfer time = 20 + 1 + 20 = 41 ms (or 60 ms if writing starts at first sector)
Example 6
Calculate time to read 64 KB (128 sectors) with these parameters: 180 GB, 3.5 inch disk, 12 platters, 24 surfaces, 7,200 RPM (4 ms avg. latency), 6 ms avg. seek, 64 to 35 MB/s (internal), 0.1 ms controller time. Solution: Disk latency = 6 ms + 0.5 Γ 1/(7200 RPM/(60000 ms/M)) + 64 KB/(64 MB/s) + 0.1 ms = 6 + 4.2 + 1.0 + 0.1 = 11.3 ms
Mechanical Delay and Flash Memory
Mechanical movement in data transfer causes mechanical delays, undesirable in embedded systems. To overcome this, flash memory is used. Flash memory is a type of electrically erasable PROM. Each cell consists of two MOSFETs with a control gate between them; the presence or absence of charge indicates a 0 or 1.
The basic idea is to reduce control overheads, which are low for flash chips. Flash memory has low power dissipation. For embedded devices, flash is a better choice than hard disk. Read time is small for flash, but write time may be significant because memory must first be erased before writing. However, in embedded systems, the number of write operations is less, so flash remains a good choice.
Example 7
Calculate time to read 64 KB for the previous disk, using 1/3 of quoted seek time and 3/4 of internal outer track bandwidth. Solution: Disk latency = (0.33 Γ 6 ms) + 0.5 Γ 1/(7200 RPM) + 64 KB/(0.75 Γ 64 MB/s) + 0.1 ms = 2 + 4.2 + 1.3 + 0.1 = 7.6 ms
Semiconductor Memory vs. Hard Disk
At one time, developers thought semiconductor memory would completely replace hard disks. Two important features to consider:
- Cost: Lower for hard disk compared to semiconductor memory.
- Latency: Hard disk latency is in milliseconds. For SRAM, latency is 10β΅ times lower than hard disk.
β Key Takeaways
The average time to access data on a hard disk is the sum of seek time, rotational latency, transfer time, and controller overhead. Seek time depends on head movement distance, while rotational latency averages half a revolution. Transfer rates depend on the internal bandwidth of the disk. For calculations, use the average seek time and compute rotational latency as 0.5 divided by rotations per second. When comparing technologies, hard disks are cheaper per byte than semiconductor memory but have significantly higher latency (milliseconds vs. nanoseconds). Flash memory offers lower power and better mechanical reliability for embedded systems, though write operations are slower due to the erase-before-write requirement.
π§ Quick Revision Questions
- What are the three parts of every sector on a hard disk?
- Why is average rotational latency equal to half a revolution?
- What is the formula for total disk access time?
- Why is flash memory preferred over hard disks in embedded systems?
- How does the latency of a hard disk compare to that of SRAM memory?
π Lecture 33 β Error Control
π Overview: This lecture covers the Operating System interface for disk operations, followed by a detailed examination of error control techniques including parity codes, Hamming codes, and CRC mechanisms. It then introduces RAID (Redundant Array of Independent Disks) and compares various RAID levels, their performance characteristics, and their underlying approaches to data redundancy and access.
ποΈ Topics Covered
This lecture explores the Operating System interface that defines logical blocks for disk communication and insulates users from hardware details. It then delves into error control mechanismsβparity code, Hamming code, and CRCβcovering detection and correction capabilities. Finally, RAID is introduced, with descriptions of RAID Level 0, comparisons between RAID Levels 2 and 3, and details of RAID Levels 4 and 5, including their independent access techniques and write penalty considerations.
π Lecture Summary
Operating System Interface
The Operating System interface plays an important role for disk operation. The operating system defines a logic block telling the controller about the track, sector, etc. There are different ways to define logic blocks. For example, we can define 5 bytes containing this information such that: the first 4 bits contain the disk number (in case of a system having more than one disk), the next 4 bits contain the address of a particular track followed by a sector number and at the end, the number of bytes to be transferred. So this defines a logical block transferred by the controller. Along with this, we have additional information about control and status of the controller. The operating system essentially insulates the users from the hardware details of the disk.
Error Control
There are two main issues in error control:
- Detection of Error
- Correction of Error
For detection of error, we just need to know that there exists an error. When the error is detected, the next step is to ask the source to resend that information. This process is called automatic request for repeat. In some cases, there is also the possibility that redundancy is enough and we reconstruct and find out exactly which particular bits are in error. This is called error correction.
There are three schemes commonly used for error control:
- Parity code
- Hamming code
- CRC mechanism
1. Parity code
Along with the information bits, we add another bit, which is called the parity bit. The objective is to make the total number of 1's either even or odd. If the parity at the receiving end is different, an error is indicated. Once error is found, the CPU may request to repeat that data. The concept of the parity bit could be enhanced. In such a case, we would like to increase the distance between different code words. Consider a code word consisting of four bits, 0000, and a second code word consisting of 1111. The distance between the two codes is four. The distance between two codes is the number of bits in which they differ from each other. The concept of introducing redundancy is to increase this distance. Larger the distance, higher will be the capacity of the code. For single parity, the distance is two, we can only detect the parity. But if the distance is three, we could also correct these single errors.
If D = minimum distance between two code words then D-1 errors could be detected and D/2 errors could be corrected.
π Example: For a single parity bit, D=2, then D-1=1 error can be detected, and D/2=1 error can be corrected only if D>=3.
2. Hamming code
Hamming code is an example of block code. We have an encoder which could be a program or a hardware device. We feed k inputs to it. These are k information input bits. We also feed some extra bits. Let r be the number of redundant bits. So at output we have r+k = m bits. As an example, for parity bit, we have k=7 and r=1 and m=8. So for 7 bits we get eight output bits. π‘ Why this matters: Hamming codes allow for single-bit error correction and multi-bit error detection, which is essential for reliable data transmission and storage systems.
For any positive integer m<=3, a Hamming code with the following parameters exists:
π Definition β Code Length: n = 2α΅ - 1 π Definition β Number of information symbols: k = 2α΅ - 1 - m π Definition β Number of parity-check symbols: n β k = m
π Formula: n = 2α΅ - 1 β Code length in bits π Formula: k = 2α΅ - 1 - m β Number of actual data bits π Formula: n - k = m β Number of redundant parity bits
3. CRC (Cyclic Redundancy Check)
The basic principle for CRC is very simple. We divide a particular code word and make it divisible by a prime number, and if it is divisible by a prime number then it is a valid code word.
CRC does not support error correction but the CRC bits generated can be used to detect multi-bit errors. At the transmitter, we generate extra CRC bits, which are appended to the data word and sent along. The receiving entity can check for errors by re-computing the CRC and comparing it with the one that was transmitted.
CRC has lesser overhead as compared to Hamming code. It is practically quite simple to implement and easy to use. π‘ Why this matters: CRC is widely used in network communications and storage systems because of its efficiency in detecting burst errors with minimal computational overhead.
RAID
The main advantage of having an array of disks is that we could have simultaneous I/O requests. Latency could also be reduced.
RAID Level 0
- Not a true member of the RAID family.
- Does not include redundancy to improve performance.
- In few applications, capacity and performance are primary concerns than improved reliability. So RAID level 0 is used in such applications.
- The user and system data are distributed across all the disks in the array.
- Notable advantage over the use of a single large disk.
- Two requests can be issued in parallel, reducing the I/O queuing time.
Performance of RAID Levels
Performance of RAID Levels depends upon two factors:
- Request pattern of the host system
- Layout of the data
Similarities between RAID Levels 2 and 3
- Make use of parallel access techniques.
- All member disks participate in execution of every request.
- Spindles of the individual drives are synchronized.
- Data striping is used.
- Strips are as small as a single byte or word.
Differences between RAID 2 and RAID 3
- In RAID 2, error-correcting code is calculated across corresponding bits on each data disk.
- RAID 3 requires only a single redundant disk.
- Instead of an error-correcting code, a simple parity bit is computed for the set of individual bits in RAID 3.
RAID Level 4
- Makes use of independent access technique.
- Data striping is used.
- A bit-by-bit parity strip is calculated across corresponding strips on each data disk.
- Involves a write penalty when an I/O write request of small size is performed.
- To calculate the new parity, the array management software must read the old user parity strip.
RAID Level 5
- Organized in a similar fashion to RAID 4.
- The only difference is that RAID 5 distributes the parity strips across all disks, eliminating the write bottleneck associated with a dedicated parity disk.
β Key Takeaways
Error control is achieved through detection (knowing an error exists) and correction (reconstructing the exact erroneous bits). The minimum distance D between code words determines error detection (D-1) and correction (D/2) capabilities. Hamming codes use block coding with m parity bits for a code length of 2α΅-1 bits, enabling single-bit correction, while CRC uses division by a prime number to detect multi-bit errors without correction. RAID levels differ in their approach to redundancy and access: RAID 0 has no redundancy, RAID 2 and 3 use parallel access with error-correcting codes and simple parity respectively, RAID 4 uses dedicated parity strips with a write penalty, and RAID 5 improves upon RAID 4 by distributing parity strips across all disks.
π§ Quick Revision Questions
- What are the two main issues in error control, and what is the process called when the source is asked to resend information after error detection?
- If the minimum distance D between two code words is 3, how many errors can be detected and corrected?
- What is the code length n and number of information symbols k for a Hamming code with m = 3?
- What is the key difference between RAID 2 and RAID 3 in terms of the redundant disk and the type of code used?
- Why does RAID Level 4 involve a write penalty for small I/O write requests, and how does RAID Level 5 address this issue?
π Lecture 34 β Number Systems and Radix Conversion
π Overview: This lecture introduces the Arithmetic Logic Shift Unit (ALSU) and explains the fundamental concepts of number representation in computer systems. It covers radix conversion between different number bases, fixed-point numbers, various integer representation schemes, and the essential operations of multiplication/division using shifts and unsigned addition. Understanding these concepts is critical for designing and working with computer arithmetic units.
ποΈ Topics Covered
The lecture begins with an introduction to the ALSU as a combinational circuit. It then discusses radix conversion algorithms for converting numbers between base b and base c. Fixed-point numbers and scaling are explained. The lecture covers the four main integer representation schemes: sign magnitude, radix complement, diminished radix complement, and biased representation. It concludes with multiplication and division using shift operations and the design of unsigned addition circuits using half and full adders.
π Lecture Summary
Introduction to ALSU
The Arithmetic Logic Shift Unit (ALSU) is a combinational circuit built from AND, OR, NOT, and other logic gates connected together to perform operations like addition, subtraction, and logical functions. Previously, we considered the ALSU as a "black box" with two input operands (a and b), one output (c), and control signals based on the instruction's opcode. To design an ALSU properly, a designer must understand number representation to determine the number of bits needed for source operands and the destination operand to avoid overflow and truncation.
Radix Conversion
Radix conversion is the process of converting a number from one base to another. Since humans work with base 10 (c) and computers with base 2 (b), this is a crucial operation. There are algorithms for converting both integers and fractions between bases.
For integer conversion from base b to base c: The algorithm iteratively processes each digit from the most significant to the least significant, using the formula: X = base * X + digit.
π Definition β Radix Conversion Algorithm (b to c for integers): Start with X=0. For each digit from left to right: X = b Γ X + digit_value. The final X is the number in base c.
π Formula: X = b Γ X + dα΅’ β starting from 0, build the decimal number by repeatedly multiplying by the original base and adding the next digit.
π Example 1: Convert B3ββ to base 10.
- X = 0
- First digit (B=11): X = 0 + 11 = 11
- Second digit (3): X = 16 Γ 11 + 3 = 176 + 3 = 179
- Result: B3ββ = 179ββ
For integer conversion from base c to base b: The algorithm uses repeated division by the target base, collecting remainders from least to most significant.
π Example 2: Convert 390ββ to base 16.
- 390 / 16 = 24 (remainder 6) β xβ = 6
- 24 / 16 = 1 (remainder 8) β xβ = 8
- 1 / 16 = 0 (remainder 1) β xβ = 1
- Read remainders in reverse order: 186ββ
Fixed Point Numbers
A fixed-point number has a radix point at a fixed position. For example, in 16.12, there are two digits left and two digits right of the decimal point. If the number is an integer, the radix point is at the rightmost position (e.g., 1612.0). If it is a fraction, the point is at the leftmost (e.g., 0.1612). Scaling refers to shifting the radix point left or right, which corresponds to dividing or multiplying by the base, respectively.
For fraction conversion from base b to base c: The algorithm processes digits from right to left (least significant first): F = (F + digit) / base.
π Example 3: Convert (.4cd)ββ to base 10.
- F = 0
- F = (0 + d(13)) / 16 = 0.8125
- F = (0.8125 + c(12)) / 16 = 0.80078125
- F = (0.80078125 + 4) / 16 = 0.3000488ββ
For fraction conversion from base c to base b: Repeatedly multiply the fraction by the target base, extracting the integer part as each digit.
π Example 4: Convert 0.24ββ to base 2.
- 0.24 Γ 2 = 0.48 β fββ = 0
- 0.48 Γ 2 = 0.96 β fββ = 0
- 0.96 Γ 2 = 1.92 β fββ = 1
- 0.92 Γ 2 = 1.84 β fββ = 1
- 0.84 Γ 2 = 1.68 β fββ = 1
- Result: 0.24ββ = (0.00111)β (approximately)
π‘ Why this matters: Inexact fraction conversion is common β not all decimal fractions have exact binary representations, which is important for numerical accuracy in computing.
Representation of Numbers
There are four main ways to represent integers:
- Sign magnitude form
- Radix complement form
- Diminished radix complement form
- Biased representation
Sign magnitude form:
- Simplest form for signed numbers
- A symbol (or sign bit) is appended to the left of the number
- This representation complicates arithmetic operations because the sign and magnitude must be handled separately
Radix complement form:
- The most common representation in computers
- For an m-digit base b number x, the radix complement of x is defined as:
- x_c = (b^m β x) mod b^m
- This representation makes arithmetic operations much easier because subtraction can be performed as addition
Diminished radix complement form:
- The diminished radix complement of an m-digit number x is:
- x_c' = b^m β 1 β x
- This complement is easier to compute than the radix complement
- The two complement forms are interconvertible:
- x_c = (x_c' + 1) mod b^m
Table 6.1 and Table 6.2 from the textbook show complement representations for negative numbers in various forms, including 2's complement and 1's complement for 8-bit numbers.
π Example 5: The following table shows decimal values in various representations (2's complement, 1's complement, sign magnitude, 16's complement, and unsigned form) β referenced from the textbook.
Multiplication and Division using Shift Operation
Shift left and shift right operations are used for multiplying or dividing by the base b. However, care must be taken with binary representation size and negative numbers.
π Example 6:
- 6 Γ 4: 00110β Γ 4ββ = 11000β = 24ββ (shift left by 2 bits). Overflow would occur if 4 bits were used instead of 5.
- 60 / 16: 0111100β / 16ββ = 0000011β = 3ββ (shift right by 4 bits). The fractional portion is lost.
π Example 7:
- -6 Γ 4: -6 = (11010)β in 5-bit 2's complement
- Using 5 bits: -6Γ4 = (01000)β = 8 (wrong! Sign changed due to overflow)
- Using 6 bits: -6 = (111010)β, -6Γ4 = (101000)β = -24 (correct)
- Lesson: Using too few bits might change the sign β always ensure sufficient bit width.
π Example 8: Multiplication and division of negative numbers.
- -24 Γ 2: -24 = (101000)β in 6-bit form
- Wrong: -24Γ2 = (010100)β = 20 (overflow)
- Correct: -24Γ2 = (110100)β = -12 (when using proper sign extension)
- Size extension: 24 = 011000 (n=6) β 00011000 (n=8); -24 = 101000 (n=6) β 11101000 (n=8). This demonstrates sign extension β replicating the sign bit when increasing word size.
Unsigned Addition Operation
The addition of two m-digit base b numbers, x and y, is performed digit by digit with carry propagation from least significant to most significant digit.
A 1-bit half adder takes two 1-bit inputs (x and y) and produces a 1-bit sum and a 1-bit carry. It is called a "half adder" because it does not accept an input carry.
A 1-bit full adder takes three inputs (x, y, and carry_in) and produces sum and carry_out. By cascading m 1-bit full adders, we can add two m-bit numbers.
Overflow occurs when the addition of two unsigned m-bit numbers results in an m+1 bit number. This is treated as an exception in some processors, and the overflow flag records the status of the result.
π Definition β Half Adder: A logic circuit that adds two 1-bit binary numbers, producing a sum bit and a carry bit, without considering an input carry.
π Definition β Full Adder: A logic circuit that adds two 1-bit binary numbers along with an input carry, producing a sum bit and a carry-out bit.
π Formula: Sum = x β y; Carry = x Β· y (for half adder)
π Example 9: Unsigned addition in base 2 and base 16 (shown in the textbook figure).
β Key Takeaways
The most critical concepts from this lecture are the radix conversion algorithms for both integers and fractions, as they form the foundation for understanding how computers handle different number systems. The four integer representation schemes β especially radix complement (2's complement) which is the industry standard β are essential for designing arithmetic circuits. Understanding shift operations for multiplication/division and the importance of sign extension and overflow detection in fixed-width arithmetic is vital for avoiding errors in computer arithmetic. Finally, the design of half adders and full adders provides the building blocks for constructing ALSUs that perform addition correctly while detecting overflow conditions.
π§ Quick Revision Questions
- How do you convert the hexadecimal number 2Fββ to decimal using the radix conversion algorithm?
- What is the difference between a half adder and a full adder, and how can full adders be cascaded to add multi-bit numbers?
- When converting the fraction 0.3ββ to binary, why might you need an infinite number of binary digits, and what practical problem does this create?
- In 2's complement representation, why is it important to use enough bits when multiplying a negative number by a positive number using shift operations?
- What is the relationship between radix complement and diminished radix complement, and how can one be derived from the other?