Complete Collection of High-Yield Exam Questions
Difference between Computer Organization and Computer Architecture:
Computer Architecture: Refers to those attributes of a system visible to a programmer or those attributes that have a direct impact on the logical execution of a program (e.g., instruction set, number of bits used to represent data types, I/O mechanisms, memory addressing techniques). It answers what* the computer does.
Computer Organization: Refers to the operational units and their interconnections that realize the architectural specifications (e.g., hardware details transparent to the programmer like control signals, interfaces between computer and peripherals, memory technology used). It answers how* the computer does it.
Define Speed-up:
Speed-up ($S$) is a performance metric that quantifies how much faster a task executes on a newly enhanced architecture (like a pipeline) compared to the original, unenhanced architecture.
Show that the maximum speedup of a pipeline is equal to its stages:
Assume a non-pipelined processor takes time $t_n$ to execute a single task. For $N$ tasks, total time is $N \times t_n$.
Now, divide the processor into $k$ equal pipeline stages. Ideally, each stage takes $t_p = t_n / k$ time.
In a $k$-stage pipeline, the first task takes $k \times t_p$ to complete. Every subsequent task completes in exactly $1 \times t_p$ time (since one exits the pipeline every cycle).
Total time for $N$ tasks on pipeline = $(k + (N - 1)) \times t_p$.
Since $t_n = k \times t_p$:
As the number of tasks $N$ approaches infinity ($N \to \infty$), the $k-1$ term becomes negligible compared to $N$:
Thus, the maximum theoretical speedup is equal to the number of stages $k$.
Factors affecting the performance of a pipelined system:
Differentiate between RAW and WAR with an example:
* RAW (Read After Write - True Dependency): Instruction 2 needs to read a register that Instruction 1 has not yet finished writing to. I2 must wait for I1.
Example:*
`I1: ADD R1, R2, R3` (R1 = R2 + R3)
`I2: SUB R4, R1, R5` (R4 = R1 - R5)
Here, `I2` reads `R1`, which is written by `I1`.
* WAR (Write After Read - Anti-Dependency): Instruction 2 needs to write to a register that Instruction 1 is currently reading from. If I2 writes too early, I1 reads the wrong (new) data.
Example:*
`I1: ADD R4, R1, R5` (R4 = R1 + R5)
`I2: SUB R1, R2, R3` (R1 = R2 - R3)
Here, `I2` writes to `R1`, but `I1` is trying to read the old value of `R1`. `I2` must not overwrite `R1` before `I1` reads it.
Parameters used in measuring CPU performance:
What is meant by pipeline stall?
A pipeline stall (also called a bubble) is a deliberate delay injected into the pipeline by the control unit to resolve a hazard. During a stall, subsequent instructions are prevented from advancing to the next stage, effectively wasting clock cycles to wait for data to become available or for a branch target to be resolved.
Why is CPU-time expressed in terms of average CPI?
Because not all instructions take the same amount of time. An ADD might take 1 cycle, while a DIVIDE might take 20 cycles, and a LOAD might suffer a cache miss and take 100 cycles. It's impossible to calculate CPU time using a static number, so we take the weighted average of all instruction types executed in the program (Average CPI) to get an accurate aggregate execution time.
Explain DMA working principle:
Direct Memory Access (DMA) is a specialized hardware controller that takes over the system bus to transfer massive blocks of data directly between an I/O device (like a hard drive) and main memory without CPU intervention. The CPU initiates the transfer by giving the DMA the start address, word count, and I/O port, then returns to other work. The DMA signals the CPU via an interrupt only when the entire transfer is fully complete.
What is meant by pipeline hazard?
A pipeline hazard is any situation in the instruction stream that prevents the next instruction from executing in its designated clock cycle, threatening to cause incorrect execution if not handled by stalling or forwarding.
Data Hazards & Remedies:
Data hazards occur when instructions exhibit data dependency, trying to use data before it is ready.
* Method 1: Internal Forwarding (Bypassing): Hardware paths route the output of the ALU directly back into the ALU inputs for the next instruction, bypassing the slow write-back to the register file.
* Method 2: Software Pipeline Scheduling: The compiler physically reorders the assembly instructions, inserting independent instructions between dependent ones to separate them in time, avoiding stalls.
Branch (Control) Hazards & Remedies:
Occur when the pipeline makes the wrong decision on a branch prediction and fetches the wrong instructions.
* Method 1: Branch Prediction: Hardware predicts whether a branch will be taken based on historical execution (e.g., Branch History Table). If correct, zero penalty.
Method 2: Delayed Branch: The compiler automatically places an independent, useful instruction strictly after* the branch instruction (in the branch delay slot). The CPU executes this instruction regardless of whether the branch is taken, hiding the delay.
What do you mean by pipeline processing?
Pipeline processing is an implementation technique where multiple instructions are overlapped in execution. The computer's hardware is divided into stages (like an assembly line). Instead of processing one instruction entirely before starting the next, the CPU works on different stages of multiple instructions simultaneously.
Instruction pipeline vs Arithmetic pipeline:
* Instruction Pipeline: Overlaps the phases of the instruction cycle (Fetch, Decode, Execute, Write-back) for a stream of instructions.
* Arithmetic Pipeline: Breaks down complex, multi-step mathematical operations (like floating-point multiplication) into sub-operations (e.g., align mantissas, multiply mantissas, normalize result) that can be overlapped for successive inputs.
Use 8-bit 2's complement integer to perform -43 + (-13):
* Convert 43 to binary: 00101011
* 1's comp: 11010100
* 2's comp (-43): 11010101
* Convert 13 to binary: 00001101
* 1's comp: 11110010
* 2's comp (-13): 11110011
* Add them:
` 11010101`
`+ 11110011`
`----------`
`1 11001000` (Discard the 9th overflow bit)
* Result: `11001000`.
* Check: Invert -> 00110111. Add 1 -> 00111000 (which is 56). So the result is -56, which is correct.
Find 2's complement of (1AB)16 in 16-bit format:
* Convert to 16-bit binary: `0000 0001 1010 1011`
* 1's complement: `1111 1110 0101 0100`
* Add 1 (2's comp): `1111 1110 0101 0101` (or `FE55` in hex).
"Instruction execution throughput increases in proportion with the number of pipeline stages." Is it true?
It is strictly a theoretical ideal, not completely true in practice. While splitting a pipeline into $k$ stages ideally multiplies throughput by $k$, practical realities like register latch overhead time, clock skew, and the increasing frequency of data/control hazards mean that actual throughput scales sub-linearly. A 50-stage pipeline won't be 10x faster than a 5-stage one due to massive penalty on branch flushes.
What is pipeline chaining?
In vector processors, chaining allows the output data stream of one vector functional unit (like an adder) to be fed instantly and directly into the input of another functional unit (like a multiplier) without waiting for the entire first vector operation to completely finish and write to registers.
What is job collision?
In non-linear (dynamic) pipelines where stages can be revisited or feed back into themselves, a job collision occurs when two different tasks demand the exact same hardware stage during the exact same clock cycle, forcing one task to stall.
For the given code, show how loop unrolling can help improve ILP:
Original Code Analysis: The code loads an element, adds a scalar, stores it, decrements the pointer, and loops. There is a massive overhead of branching (`BNE`) for every single element processed. Furthermore, `I2` must wait for `I1` (RAW), and `I3` must wait for `I2` (RAW), causing severe pipeline stalls.
Unrolled Code (Unrolled twice): By processing two array elements per loop iteration, we eliminate half of the branch instructions and allow the compiler to reorder independent instructions.
```assembly
Loop1:
Load R0, A(R1) ; Load element i
Load R3, A-8(R1) ; Load element i-1 (Independent!)
Add R0, R2 ; Compute element i
Add R3, R2 ; Compute element i-1 (Independent!)
Store R0, A(R1) ; Store element i
Store R3, A-8(R1) ; Store element i-1
Add R1, -16 ; Decrement by 2 elements
BNE R1, Loop1 ; Branch once per 2 elements
```
Improvement: The compiler can now interleave the independent `Load R3` while waiting for the first `Load R0` to finish, hiding the memory latency and drastically boosting Instruction Level Parallelism (ILP).
Compare Control-Flow, Data-Flow and Demand-Driven mechanism:
* Control-Flow: Execution is strictly determined by a sequential Program Counter (PC). Data passively waits in memory until the CPU requests it. (e.g., standard Von Neumann architectures like x86).
* Data-Flow: Execution has no PC. Instructions are strictly triggered the moment their required input data operands become available. Highly parallel, data pushes execution forward.
* Demand-Driven (Reduction): Instructions only execute when their specific result is actively demanded by another instruction. It prevents calculating results that are never used (lazy evaluation).
How "Reservation Table" helps study performance:
A reservation table is a 2D matrix (Rows = Stages, Columns = Clock Cycles) that visually tracks which hardware stages are occupied by a task over time in a complex, non-linear pipeline. By identifying patterns in the table, architects can calculate forbidden latencies (when issuing a new task would cause a collision) and determine the Minimum Average Latency (MAL) to optimize scheduling and maximize throughput without stalling.
Instructions:
Data Dependencies:
* There are no True Dependencies (RAW) between consecutive instructions! Instruction 2 uses R3, R4 (neither written by 1). Instruction 3 uses R4 (written by 2? No, `ADD R2, R3, R4` usually means `dest, src1, src2`, so R2 is written. If it means `src1, src2, dest` then R4 is written. Let's assume standard `OP Dest, Src1, Src2`).
* Assuming `OP Dest, Src1, Src2`:
* I1 writes R1.
* I2 writes R2, reads R3, R4.
* I3 writes R4, reads R4.
* I4 writes R6, reads R3, R7.
* WAR Dependency: I2 writes R2, but I1 reads R2. (I2 cannot write back before I1 reads). I3 writes R4, but I2 reads R4.
* RAW Dependency: None based on this assumption.
If we assume the format is `OP Src1, Src2, Dest`:
* I1 writes R3.
* I2 reads R3, R4, writes R4. (RAW from I1 on R3).
* I3 reads R4, writes R4. (RAW from I2 on R4).
Let's assume the standard RISC format: `OP Dest, Src1, Src2`.
Since pipelines read in ID stage and write in WB stage, WAR dependencies are naturally resolved because reading happens early (stage 2) and writing happens late (stage 5).
Thus, Delay in pipeline execution due to data dependency = 0 cycles (assuming a modern pipeline with register renaming or simple in-order execution where reads happen before subsequent writes).
Given: 15,000 instructions, 25 MHz clock (40 ns cycle), 5 stages ($k=5$). One instruction per cycle. No branches.
(i) Speedup compared to non-pipelined:
* Execution time of 1 instruction in non-pipelined = $k \times \text{cycle time} = 5 \text{ cycles}$.
* Total time non-pipelined ($T_{np}$) = $15,000 \times 5 = 75,000 \text{ cycles}$.
* Total time pipelined ($T_p$) = $(k + N - 1) = (5 + 15000 - 1) = 15,004 \text{ cycles}$.
* Speedup $S = T_{np} / T_p = 75,000 / 15,004$ = 4.998. (Approaches theoretical maximum of 5).
(ii) Efficiency and Throughput:
* Efficiency ($\eta$): $S / k = 4.998 / 5$ = 99.96%.
* Throughput ($T$): Instructions completed per second. 15,000 instructions took 15,004 cycles.
* Time taken = $15,004 \times 40 \text{ ns} = 600,160 \text{ ns} = 0.6 \text{ ms}$.
* Throughput = $15,000 / (600,160 \times 10^{-9})$ = 24.99 Million Instructions Per Second (MIPS).
Amdahl's Law:
It states that the overall performance improvement gained by optimizing a single part of a system is strictly limited by the fraction of time that the un-optimized part is used.
Where $f$ is the fraction of the code that can be parallelized (or optimized), and $s$ is the speedup factor for that specific fraction.
Significance: It warns architects against diminishing returns. If 20% of a program is strictly serial, you can never achieve more than a 5x total speedup, even if you throw infinite processors at the parallel 80%.
Instruction Addressing Types:
* 3-address: `ADD R1, R2, R3` (Dest, Src1, Src2). Very flexible, but instructions are long.
* 2-address: `ADD R1, R2` (Dest/Src1, Src2 -> R1 = R1 + R2). Overwrites one source operand.
* 1-address: `ADD X` (Accumulator architecture: ACC = ACC + Memory[X]). Relies on an implicit Accumulator register.
* 0-address: `ADD` (Stack architecture: Pops top two elements, adds them, pushes result). Extremely compact code.
Instruction Cycle: The fundamental sequence of steps a CPU takes to process one instruction. It typically includes: Fetch (get instruction from memory), Decode (determine what it is), Execute (perform ALU operations), and Write-back (save result).
Hardwired vs. Microprogrammed Control Unit:
* Hardwired: Uses incredibly complex combinational logic circuits (gates, flip-flops) to directly generate control signals based on the opcode.
Pros:* Blazing fast (RISC philosophy).
Cons:* Nearly impossible to modify or upgrade once manufactured.
* Microprogrammed: Uses a tiny internal ROM memory to store "micro-instructions" for each complex machine instruction. The control unit is basically a tiny, simpler computer running mini-programs to interpret the main program.
Pros:* Extremely flexible, easy to add complex instructions (CISC philosophy), easier to debug.
Cons:* Much slower due to the overhead of reading from the internal ROM.
Given Reservation Table:
```
1 2 3 4
S1: X X
S2: X
S3: X
```
Forbidden Latencies: The distances between 'X's in the same row.
* Row 1: X at t=1, t=4. Difference = 4 - 1 = 3.
* Forbidden Latency Set: {3}
Permissible Latencies: All other integers up to maximum time.
* Initial Collision Vector (ICV): A binary vector where the $i$-th bit from the right is 1 if $i$ is a forbidden latency.
* Since 3 is forbidden, bit 3 is 1. (Index starts at 1 from right).
* ICV = 100 (Bit 3 is 1, bits 2 and 1 are 0).
State Diagram & Cycles:
* State 1: 100 (Start state)
* Shift by permissible latencies (1, 2, 4+):
* Latency 1: Shift 100 right by 1 $\to$ 010. OR with ICV (100) $\to$ 110. (State 2)
* Latency 2: Shift 100 right by 2 $\to$ 001. OR with ICV (100) $\to$ 101. (State 3)
* Latency 4+: Shift clears it to 0. OR with ICV $\to$ 100 (Back to start).
* Cycles: Paths in the diagram. A greedy cycle is one that consistently takes the shortest possible latency.
* Minimum Average Latency (MAL): The minimum average delay between initiating tasks without causing collisions. For this simple table, the lower bound is the max number of Xs in any row (Row 1 has two Xs, so lower bound is 2).
Data Flow Computer: A radical architecture that completely abandons the traditional Program Counter. Instead of executing instructions sequentially, a Data Flow machine represents a program as a directed graph. An instruction node fires and executes only when all necessary data tokens arrive at its input links.
Data Flow vs Control Flow:
Control Flow (Von Neumann):* Driven by the sequential fetch of instructions. Data passively waits in memory registers. Highly structured but struggles with massive parallelism.
Data Flow:* Driven completely by data availability. Inherently parallel—if 50 instructions have their data ready, all 50 execute simultaneously.
Potential Problems:
* Memory Management: Very difficult to handle massive data structures like arrays, because passing an entire array token around the network is impossible.
* Token Matching Overhead: The hardware required to track, match, and route millions of floating data tokens to their correct destination instructions is incredibly complex and slow.
To represent these equations as a data flow graph, visualize a tree where variables flow into mathematical operation nodes.
In a data flow machine, calculations for Z and Y can happen simultaneously the instant X is calculated, exploiting massive implicit parallelism.
Floating Point Arithmetic Operation:
Hardware execution of math involving real numbers represented in IEEE 754 format (Sign, Exponent, Mantissa). These are massively more complex than integer math.
* Addition/Subtraction: Requires comparing the two exponents, shifting the mantissa of the smaller number to explicitly align the radix points, adding the mantissas, and then re-normalizing the result.
* Multiplication: Add the exponents, multiply the mantissas, and normalize.
* Division: Subtract the exponents, divide the mantissas, and normalize.
What is MMX?
MMX (Multimedia Extensions) is a classic SIMD instruction set designed by Intel to accelerate multimedia (video, audio) encoding/decoding. It repurposes 64-bit floating-point registers to hold multiple smaller integers (e.g., eight 8-bit color pixels) and execute a single instruction on all of them simultaneously, greatly speeding up graphical processing.
Given:
* Fraction optimized ($f$) = 50% = 0.5
* Desired overall speedup ($S$) = 10
* Speedup of the enhanced component = $s$
Amdahl's Law Formula:
Conclusion: It is mathematically impossible to achieve an overall speedup of 10 if only 50% of the code is enhanced. Even if the enhanced 50% took literally zero time ($s \to \infty$), the unenhanced 50% remains, meaning the maximum possible theoretical speedup is $\frac{1}{0.5} = 2$.
Major hurdles to ideal speed-up:
Data hazards, control hazards (branch penalties), unequal stage delays, and physical latch overheads all severely restrict a pipeline from reaching its mathematical maximum speedup.
Given Pipeline:
* Stages: IF (50ns), ID (60ns), Ex (110ns), WB (80ns).
* Latch delay (Register overhead): 10ns per stage.
Calculation:
* Non-pipelined execution time ($T_{np}$): The sum of all stages.
Pipelined clock cycle ($T_p$): Dictated by the slowest* stage plus the latch delay.
* Speedup ($S$):
Due to the badly imbalanced Ex stage (110ns), the 4-stage pipeline only achieves a speedup of 2.5x instead of the ideal 4x.
Multiple Issue Processor: A CPU design capable of dispatching and executing multiple instructions into different functional units during a single clock cycle, driving CPI below 1.0.
VLIW (Very Long Instruction Word):
An architecture that forces the compiler to do the heavy lifting of dependency checking. The compiler groups independent instructions into one massive word (e.g., 128 bits wide containing a load, an add, and a multiply). The CPU reads this entire word and executes all components simultaneously.
* Differences from Superscalar: Superscalar uses massive, complex silicon hardware to detect dependencies dynamically at runtime and issue instructions. VLIW relies purely on static compiler analysis, resulting in a much smaller, cooler, and simpler silicon chip.
* Limitations of VLIW: Terrible backwards compatibility. If you run compiled VLIW code on a newer CPU with a different number of functional units, the massive rigid instruction words break. It also suffers from massive code bloat because empty slots in the VLIW instruction must be padded with NOPs (No Operation).
Given:
* Total Instructions = 2500
* Clock Rate = 4 GHz $\implies$ Cycle Time = $1 / (4 \times 10^9) = 0.25 \text{ ns}$
* Mix: Data (50%, 2 cycles), ALU (30%, 5 cycles), Branch (20%, 10 cycles).
Calculation:
A space-time diagram visually maps pipeline stages (Y-axis) against clock cycles (X-axis).
For a 4-stage pipeline (F, D, E, W) executing 3 consecutive independent instructions (I1, I2, I3):
| Stage \ Cycle | 1 | 2 | 3 | 4 | 5 | 6 |
| Fetch | I1 | I2 | I3 | |||
| Decode | I1 | I2 | I3 | |||
| Execute | I1 | I2 | I3 | |||
| Write | I1 | I2 | I3 |
Base System Analysis:
* $CPI_{base} = (0.4 \times 1) + (0.2 \times 4) + (0.3 \times 2) + (0.1 \times 3) = 0.4 + 0.8 + 0.6 + 0.3 = 2.1$
* Base Time $\propto 2.1 / 2\text{GHz} = 1.05$ units
Option 1: Decrease Branch CPI from 4 to 3:
* New $CPI = (0.4 \times 1) + (0.2 \times 3) + (0.3 \times 2) + (0.1 \times 3) = 0.4 + 0.6 + 0.6 + 0.3 = 1.9$
* New Time $\propto 1.9 / 2\text{GHz} = 0.95$ units. (Speedup: $1.05 / 0.95 = 1.105x$)
Option 2: Increase Clock Frequency to 2.3 GHz:
* CPI remains 2.1.
* New Time $\propto 2.1 / 2.3\text{GHz} = 0.913$ units. (Speedup: $1.05 / 0.913 = 1.15x$)
Option 3: Decrease Store CPI from 3 to 2:
* New $CPI = (0.4 \times 1) + (0.2 \times 4) + (0.3 \times 2) + (0.1 \times 2) = 0.4 + 0.8 + 0.6 + 0.2 = 2.0$
* New Time $\propto 2.0 / 2\text{GHz} = 1.0$ units. (Speedup: $1.05 / 1.0 = 1.05x$)
Conclusion: Option 2 (Increasing clock frequency to 2.3 GHz) is the best choice, yielding a 15% speedup across all instructions, whereas fixing specific CPIs yields less overall impact due to their limited occurrence fractions.
To execute $X = (A \times B) + C$ in a pipeline:
```
1 2 3 4 5 6 7 8
S1 X X X
S2 X X
S3 X X X
```
A) Forbidden and Permissible Latencies:
* Row S1 Xs at: 1, 6, 8. Differences: (6-1=5), (8-6=2), (8-1=7).
* Row S2 Xs at: 2, 4. Differences: (4-2=2).
* Row S3 Xs at: 3, 5, 8. Differences: (5-3=2), (8-5=3), (8-3=5).
* Forbidden Latency Set: {2, 3, 5, 7}
* Permissible Latency Set: {1, 4, 6, 8, 9, 10...}
D) Minimum Average Latency (MAL):
* The maximum number of collisions on any single row is 3 (Row S1 and S3 both have 3 'X's).
* According to pipeline scheduling theory, the lower bound on MAL is equal to the maximum number of marks in any single row.
* Therefore, the theoretical minimum average latency is 3.
Original Sequence:
Optimization:
This code endlessly re-reads and overwrites the exact same register (R0). By utilizing internal forwarding (bypassing), the hardware can completely eliminate the need to write intermediate results to R0 and fetch them back. Register tagging tracks the latest producer of a value.
Instead of: `Load -> Store to R0 -> Read R0 -> Add -> Store to R0 -> Read R0 -> Mult...`
The pipeline forwards directly:
`ALU_OUT(Load M1) ---> ALU_IN_1(Add)`
`(Load M2) ---> ALU_IN_2(Add)`
`ALU_OUT(Add) ---> ALU_IN_1(Mult)`
`(Load M2) ---> ALU_IN_2(Mult)`
`ALU_OUT(Mult) ---> DataCache_IN(Store M4)`
The value never needs to actually commit to architectural register R0 until the very end, effectively turning sequential dependencies into a blazing fast chained execution graph.
Given Parameters:
a) Miss penalty for a standard main memory organization:
In a standard (non-interleaved) memory organization, words are accessed sequentially. The address for the block is sent once, but each word must be accessed and sent back individually. This architecture leads to a significant bottleneck because the CPU must wait for the entire sequential process to finish before resuming execution.
b) Miss penalty for a 4-way interleaved main memory:
In a 4-way interleaved memory, all 4 words in the block can be accessed simultaneously across four memory modules. This massively parallelizes the memory fetch phase, which is traditionally the slowest component.
This demonstrates a massive 2.6x speedup simply by physically reorganizing how the memory chips are wired to the bus.
What is m-way memory interleaving?
m-way memory interleaving is an architectural technique used to drastically increase memory bandwidth and overall throughput. By dividing the main memory into `m` independent memory modules (banks), successive memory addresses are assigned to different modules (typically using low-order interleaving). This allows the system to initiate multiple memory accesses simultaneously, overlapping their access times. Think of it like adding more checkout lanes at a grocery store—instead of one long line, multiple customers are served at once.
Is memory interleaving useful in a system with pipeline processing?
Yes, it is absolutely essential. In a pipelined processor, instructions are fetched and executed in rapid succession (ideally one per clock cycle). A single, non-interleaved memory module would become a severe bottleneck because its access time (DRAM) is typically much slower than the processor's clock cycle (SRAM/Logic). Interleaving ensures the memory system can supply instructions and data fast enough to keep the pipeline completely full, reducing memory stalls (bubbles) and maintaining high instruction throughput.
Given Parameters:
i) Average access time of the memory system:
Assuming parallel access (where the system queries cache and main memory simultaneously, aborting the main memory query on a cache hit), the formula is:
(Note: If a strictly hierarchical access model is assumed where the miss penalty is $t_c + t_m$, the average time would be $(0.9 \times 100) + (0.1 \times 1100) = 200 ns$. The parallel access model yielding 190 ns is the most common interpretation for this standard phrasing.)
ii) Average access time without cache memory:
If there is no cache memory, every access goes directly to main memory.
Comparison:
The memory system with the cache (190 ns) is approximately 5.26 times faster than the system relying solely on main memory (1000 ns). This perfectly illustrates the power of the principle of locality.
Given Parameters:
i) CPU execution time assuming no misses:
ii) CPU execution time with a 2% miss rate and 25-cycle miss penalty:
Assuming the 2% miss rate applies only to the data accesses:
Write-through vs. Write-back Cache Policies:
* Advantages: Main memory is always up-to-date (strong consistency); simpler to implement; cache block replacement is fast because the block doesn't need to be written to memory upon eviction.
* Disadvantages: Consumes higher memory bandwidth; write operations are slower as they are bottlenecked by main memory speeds. Often requires a write buffer to mitigate latency.
* Advantages: Much faster write operations (runs at cache speed); significantly reduces memory traffic/bandwidth usage, especially for variables that are updated frequently in loops.
* Disadvantages: Main memory can be out of sync with the cache (stale data); requires a "dirty bit" to track modifications; more complex implementation, particularly regarding cache coherence in multi-core systems.
Problem Breakdown:
The system uses segmented paging, a hybrid approach combining the logical grouping of segmentation with the memory management efficiency of paging.
Physical Address Calculation:
The physical address is formed by appending the Word Offset directly to the Frame Number retrieved from the page table.
Essential Figure Concept (Text Description):
To visualize this, imagine a three-step hardware translation:
The three primary types of cache misses are often referred to as the "3 C's". Understanding these is critical for cache optimization.
Techniques to reduce cache misses:
Given:
a) Direct Mapping Technique:
In direct mapping, the 15-bit main memory address is divided into a Tag and an Index (Line number). A specific memory block can only ever go into one specific cache line.
Format:* `[Tag: 6 bits] | [Index: 9 bits]`
b) Associative Mapping Technique:
In fully associative mapping, any main memory block can be placed in absolutely any cache line. There is no index field dictating its placement.
Format:* `[Tag: 15 bits]`
While associative mapping eliminates conflict misses entirely, it requires highly complex hardware (comparators for every single cache line) to search the entire cache simultaneously, making it too slow and expensive for large L1/L2 caches.
The cache coherence problem occurs in multiprocessor systems where each processor has its own private cache. If processor A updates a shared variable in its cache, processor B might still hold an old, stale version of that variable in its own cache, leading to data inconsistency and fatal software bugs.
Locality of reference is the empirical observation that computer programs tend to access a relatively small portion of their address space repetitively over a short period. It is the fundamental law of computer science that makes cache hierarchies work. It has two forms:
Block replacement in set-associative cache:
When a cache miss maps to a specific set, and that set is completely full, a replacement policy selects which specific block within that set to evict and replace with the new data.
First, map the word addresses to page numbers.
Using Optimal Page Replacement (OPT) with 3 frames:
Total page faults generated = 4.
Calculations:
Virtual Pages: $2^{48} / 2^{12} = 2^{36}$ pages. (This is how many pages a program thinks* it can use).
LRU Page-Fault Rate (Assuming a standard 3 frames):
String: `7, 0, 1, 2, 0, 3, 0, 4, 2, 3, 0, 3, 2, 1, 2, 0, 1, 7, 0, 1`
(M = Miss, H = Hit. Top to bottom represents youngest to oldest in LRU).
Total accesses = 20. Total faults = 12.
What is Set Associative Mapping? A hybrid approach where a memory address maps directly to a specific set of cache lines, but can be placed associatively* anywhere within that specific set.
Global Miss: When the requested data is not found in any* level of the cache hierarchy (e.g., L1, L2, L3) and a slow fetch to main memory is required.
* Segmentation: Logical division of memory based on variable-sized segments (e.g., code, stack, data arrays). Visible to the programmer. Matches how we think about programs. Can suffer from severe external fragmentation.
* Paging: Physical division of memory into fixed-sized blocks (frames/pages). Completely invisible to the programmer. Elegantly solves external fragmentation but suffers from minor internal fragmentation.
* Cache size = 1 KB = 1024 Bytes. Block size = 64 Bytes.
* Number of blocks = $1024 / 64$ = 16 blocks.
* Number of sets (4-way) = $16 / 4$ = 4 sets.
* Offset bits = $\log_2(64)$ = 6 bits. Set Index bits = $\log_2(4)$ = 2 bits.
* (ABCDE)16 in Binary: `1010 1011 1100 1101 1110`.
* Lowest 6 bits (Offset): `011110`
* Next 2 bits (Index): 11 (Decimal 3). Maps to Set 3.
* (EDCBA)16 in Binary: `1110 1101 1100 1011 1010`.
* Lowest 6 bits (Offset): `111010`
* Next 2 bits (Index): 10 (Decimal 2). Maps to Set 2.
Internal: Memory allocated to a process is slightly larger than requested (e.g. allocating a 4KB page for 10 bytes of data), wasting space inside* the allocated block.
External:* Plenty of total free memory exists to satisfy a request, but it is scattered in tiny chunks, meaning no contiguous block is large enough to fulfill the request.
Michael J. Flynn proposed this fundamental taxonomy in 1966. It categorizes all computer architectures based on the number of concurrent instruction streams (control units) and data streams (execution units):
Masking Mechanism in SIMD: Because all Processing Elements (PEs) in a SIMD machine share a single control unit, they must* all execute the same instruction at the same time. Therefore, conditional logic (like an `if/else` statement) requires a masking mechanism. A mask register (essentially a vector of boolean flags, 1s and 0s) determines whether a specific PE should actively write its result to memory or idle (do nothing) for that specific instruction cycle. For an `if/else` block, the machine first executes the `if` code with a specific mask, and then executes the `else` code with the inverted mask.
This mathematical equation represents a "prefix sum" or "scan" operation. In an SIMD architecture where each PE holds one element of array `A`, the PEs need to communicate to calculate this running total. The routing logic involves shifting data across the physical interconnect network connecting the PEs. For N elements, instead of taking N steps linearly through an array, modern SIMD routing networks (like hypercubes or tree structures) can compute this in precisely $\log_2(N)$ steps by adding adjacent pairs, then pairs of pairs, iteratively passing partial sums through the routing network.
Assumed Values from Given Problem:
Calculation Methodology:
* Integer: $50,000 \times 1 = 50,000$ cycles
* Data: $70,000 \times 2 = 140,000$ cycles
* Float: $25,000 \times 2 = 50,000$ cycles
* Branch: $4,000 \times 2 = 8,000$ cycles
* Total Cycles = $50,000 + 140,000 + 50,000 + 8,000 = 248,000 \text{ cycles}$
Execution Time = 4.96 milliseconds
Calculate the effective CPI and MIPS rate:
Using the total cycles (248,000) and total instructions (149,000) calculated previously at a 50 MHz clock rate:
Instruction Level Parallelism (ILP) is a hardware-driven measure of how many of the low-level machine operations in a computer program can be performed simultaneously without changing the logical outcome. It relies entirely on the processor's hardware to identify independent instructions dynamically and execute them in parallel, preserving the program's sequential execution illusion for the programmer.
Techniques to achieve high ILP:
Multiprocessors vs. Multicomputers:
SIMD Distributed vs. Shared Memory Models:
Processing Element (PE) Functionality:
A PE in an SIMD machine is drastically simpler than a standard CPU core. It is basically a naked ALU with some local registers and routing logic. It does not possess its own instruction fetch or decode logic. It simply receives raw control signals (micro-instructions) broadcast from the central Control Unit and executes them mindlessly on its local data stream, provided the local mask bit allows it to be active for that cycle.
MIMD Processor Architecture:
MIMD (Multiple Instruction, Multiple Data) features multiple fully independent processors, each with its own control unit, executing different threads or programs on entirely different datasets simultaneously.
Shared Memory Modes of MIMD:
Why do we need parallel processing?
To overcome the insurmountable physical limits of a single processor core (approaching the speed of light limits on a silicon die, massive power dissipation issues, and the "heat wall") and to solve massive computational problems (weather forecasting fluid dynamics, AI model training, genomic sequencing) in an acceptable timeframe.
Levels of Parallel Processing:
Tightly coupled:* Processors physically share the same main memory over a short, high-speed bus. Communication delay is virtually zero, and data transfer rates are massive, but it cannot scale beyond a few dozen processors due to bus contention.
Loosely coupled:* Each processor has its own private distributed memory, and they communicate via external I/O networks (Ethernet/InfiniBand). Communication delay is much higher, but the architecture scales almost infinitely (like a cloud datacenter).
UMA (Uniform Memory Access):* Hardware guarantees uniform latency regardless of which processor accesses which memory location (typical desktop PC).
NUMA (Non-Uniform Memory Access):* Latency strictly depends on the physical location of the memory relative to the processor requesting it. Accessing the RAM stick physically attached to your own socket is fast; accessing the RAM attached to the other processor socket requires traversing a QPI/Infinity Fabric link and is much slower.
Centralized:* Features one massive, central physical memory block accessed by all via a bus (SMP).
Distributed:* Physically spreads the memory modules across various network nodes, but the hardware maintains a single, unified logical address space for the programmer (NUMA).
Purpose of Data Flow Architecture: To maximize parallel execution natively in hardware without needing complex compilers or out-of-order logic. In a Data Flow machine, there is absolutely no Program Counter. An instruction "fires" and executes only* when all of its required input data tokens (operands) have arrived and are available.
Similarities:* Both architectures utilize multiple processors to execute tasks concurrently to save time.
Dissimilarities:* Multiprocessors share a single, unified memory space and run one instance of an OS (Tightly coupled). Multiple computers (clusters) have totally separate memory spaces, boot separate OS instances, and must communicate manually via network cables (Loosely coupled).
Static:* Point-to-point direct wire connections between nodes that are hardwired and cannot be changed during execution (e.g., Ring, 2D Mesh, 3D Torus, Hypercube).
Dynamic:* Wire connections are not permanent. The path between processors is established on the fly during runtime using physical switches and routing logic (e.g., Crossbar switches, Shared Buses, Multistage switching networks).
Software Parallelism:* The potential theoretical concurrency hidden within an algorithm or program, dictated by data dependencies and explicitly exposed by the programmer (e.g., by using multi-threading libraries like pthreads or OpenMP).
Hardware Parallelism:* The actual physical resources available in the silicon machine to execute tasks concurrently (e.g., number of ALUs, multiple cores, superscalar pipelines). Ideal system performance requires perfectly matching the software parallelism to the available hardware parallelism.
Speeding up memory access:
Vector processors require massive memory bandwidth to continuously feed their deep pipelines. This is primarily achieved through aggressive memory interleaving (organizing memory into multiple independent banks). Because vector elements are usually accessed sequentially or with a highly regular stride, the processor can request successive elements from different banks simultaneously. This effectively retrieves one element per clock cycle after the initial memory access latency is resolved, streaming data directly into the vector registers.
Types of vector instructions:
Superscalar vs. Superpipelined vs. Superscalar-Superpipelined:
Superscalar vs. Super-pipeline vs. VLIW:
VLIW (Very Long Instruction Word): Relies heavily on the compiler* rather than hardware to find independent instructions. The compiler packs these instructions into one massive, fixed-length instruction format (e.g., a 128-bit or 256-bit word). The processor executes the whole word at once. The hardware is simpler and uses less power because it doesn't have to dynamically check for dependencies at runtime, unlike Superscalar, which requires complex, power-hungry dispatch hardware to detect and schedule independent instructions on the fly. Super-pipeline, on the other hand, strictly increases clock speed via pipeline depth without widening the instruction issue width.
Typical Block Diagram components:
Vector Array Processor: A synchronous parallel computer consisting of a central control unit and a massive array of dumb Processing Elements (PEs) executing in lockstep (SIMD). Example:* ILLIAC IV.
Example:* In $$D = (A \times B) + C$$, chaining allows the vector addition operation to start processing elements the exact moment the very first multiplied elements of $(A \times B)$ emerge from the multiplier pipeline, overlapping the execution and slashing total latency.
Vector Processor: Uses deeply pipelined functional units (Temporal Parallelism). Elements flow through pipelines sequentially but are highly overlapped, like an assembly line. Example:* Cray-1.
Array Processor: Uses multiple distinct physical Processing Elements (PEs) operating concurrently on different data elements (Spatial Parallelism). Example:* MasPar, or modern GPUs (to a certain extent).
Low-order Interleaved Memory: The physical memory address is split so the lowest bits select the memory module (bank), and the higher bits select the word* within that module.
Advantage:* Consecutive memory addresses are spread evenly across different hardware modules. This allows a vector processor to fetch contiguous arrays incredibly fast by accessing all modules simultaneously, turning a sequential bottleneck into parallel throughput.
RISC vs. CISC:
RISC (Reduced Instruction Set Computer): Focuses on highly optimized, simple instructions that almost universally execute in exactly one clock cycle. This regular, predictable timing allows for highly efficient deep pipelining. It relies on a Load/Store architecture (memory is only accessed via specific load and store instructions; math is only done on internal registers). Requires larger RAM and higher memory bandwidth to fetch the longer assembly programs compiled by a very smart, optimizing compiler. Examples: ARM (Apple Silicon, smartphones), MIPS, RISC-V.*
CISC (Complex Instruction Set Computer): Focuses on incredibly complex, powerful instructions that can span multiple clock cycles and interact directly with main memory (e.g., "Add the value at memory address X to register Y"). This results in highly compact code sizes, saving precious RAM. It relies heavily on complex internal hardware (microcode ROM inside the CPU) to break down these complex instructions into simpler micro-operations on the fly. Examples: Intel x86, AMD64 (Desktop/Laptop processors).*
Multi-core Systems:
A modern hardware design featuring a single integrated circuit (the physical silicon chip) containing two or more distinct processing units (the cores). Each core acts as a fully independent CPU that can fetch, decode, and execute program instructions simultaneously with the other cores, sharing the L3 cache and main memory bus. This is the industry's answer to the stalling of single-core clock speeds (the "heat wall").
Von Neumann Architecture & Bottleneck:
SPEC Rating:
The Standard Performance Evaluation Corporation (SPEC) rating is an industry-standard benchmark suite used to evaluate and compare the performance of computer systems objectively. Rather than relying on misleading metrics like raw clock speed (GHz) or theoretical MIPS, SPEC uses incredibly heavy, real-world workloads (compiling code, fluid dynamics, AI simulation) to stress the entire system (CPU architecture, memory hierarchy, and compiler efficiency) as a cohesive unit.
Addressing Modes & Relative vs. Direct:
A cluster computer is an architecture composed of a group of loosely coupled, fully independent computers (called nodes) interconnected via a specialized, ultra-high-speed local area network (like InfiniBand). These independent nodes work together so seamlessly and closely that they can be viewed and utilized by the user as a single, incredibly powerful system.
Unlike multi-processors that share RAM, cluster nodes share nothing—they rely heavily on specialized message-passing software libraries (like MPI - Message Passing Interface) to synchronize data over the network. They provide immense horizontal scalability, high availability (if one node crashes, the cluster survives), and fault tolerance, making them the dominant architecture for modern supercomputing tasks (weather forecasting, physics simulations) at a fraction of the cost of custom-built, monolithic mainframes.