Pipelining and Pipeline Hazards PDF

Summary

This document provides a comprehensive overview of pipelining and pipeline hazards in computer architecture. It explains the concept of pipelining, how it increases CPU performance, different pipeline stages, and types of pipeline hazards such as data hazards (RAW, WAR, WAW), structural hazards, and control hazards. The document discusses performance metrics and solutions for dealing with these hazards.

Full Transcript

# Definition of Pipelining * Pipelining is the process of arranging hardware elements of the CPU such that its overall performance is increased. * It allows for the simultaneous execution of more than one instruction in a pipelined processor. * In Pipelining, multiple instructions are overlapped i...

# Definition of Pipelining * Pipelining is the process of arranging hardware elements of the CPU such that its overall performance is increased. * It allows for the simultaneous execution of more than one instruction in a pipelined processor. * In Pipelining, multiple instructions are overlapped in execution. ## Non-Pipeline vs. Pipeline * In a non-pipeline system, a process cannot start until the previous process is complete. This leads to performance issues. * In a pipeline, if one process is running on a particular stage, another process can run on a different stage, leading to an overlapping state. ### Pipelining Stages * In pipelining, there are multiple stages, such as instruction fetch(IF), instruction decode(ID), operand fetch (OF), execution (EX), memory access (MEM), and write back (WB). * Instructions pass through these stages sequentially, but the stages themselves can overlap. ### Example of Pipelining Stages | Clock Cycle | IF | ID | OF | EX | MEM | WB | |---|---|---|---|---|---|---| | 1 | I<sub>1</sub> | | | | | | | 2 | I<sub>2</sub> | I<sub>1</sub> | | | | | | 3 | I<sub>3</sub> | I<sub>2</sub> | I<sub>1</sub> | | | | | 4 | I<sub>4</sub> | I<sub>3</sub> | I<sub>2</sub> | I<sub>1</sub> | | | | 5 | I<sub>5</sub> | I<sub>4</sub> | I<sub>3</sub> | I<sub>2</sub> | I<sub>1</sub> | | | 6 | I<sub>6</sub> | I<sub>5</sub> | I<sub>4</sub> | I<sub>3</sub> | I<sub>2</sub> | I<sub>1</sub> | | 7 | I<sub>7</sub> | I<sub>6</sub> | I<sub>5</sub> | I<sub>4</sub> | I<sub>3</sub> | I<sub>2</sub> | | 8 | I<sub>8</sub> | I<sub>7</sub> | I<sub>6</sub> | I<sub>5</sub> | I<sub>4</sub> | I<sub>3</sub> | | 9 | | I<sub>8</sub> | I<sub>7</sub> | I<sub>6</sub> | I<sub>5</sub> | I<sub>4</sub> | | 10 | | | I<sub>8</sub> | I<sub>7</sub> | I<sub>6</sub> | I<sub>5</sub> | | 11 | | | | I<sub>8</sub> | I<sub>7</sub> | I<sub>6</sub> | | 12 | | | | | I<sub>8</sub> | I<sub>7</sub> | ## Pipelining Performance Metrics * **K**: Number of stages in the pipeline * **n**: Number of instructions * **Instructions per clock cycle (IPC)**: The number of instructions completed per clock cycle. * **Speedup**: The ratio of the time taken to execute a program in a non-pipelined system to the time taken in a pipelined system. * **Efficiency**: The percentage of time that the pipeline is actively used. * **Clock cycles needed**: The total number of clock cycles required to execute the program. ## Hazards In Pipelining * **Hazards** are problems that arise in pipelining due to the interdependence of instructions. **Types of Hazards:** 1. **Data Hazards**: Occur when an instruction depends on the result of a previous instruction that has not yet been computed. This can be classified as: * **RAW (Read After Write):** An instruction tries to read a register before it is written by an earlier instruction. * **WAR (Write After Read):** An instruction tries to write a register before it is read by an earlier instruction. * **WAW (Write After Write):** An instruction tries to write a register before it is written by an earlier instruction. 2. **Structural Hazards**: Occur when multiple instructions need to access the same resource at the same time. 3. **Control Hazards**: Occur when the execution flow of the program changes based on a branch condition or a jump instruction. ## Example Of Data Hazards **Consider the following instructions:** * **I<sub>1</sub>:** R2 ← R2 + R3 * **I<sub>2</sub>:** R5 ← R2 + R4 * **I<sub>3</sub>:** IF/D OF EX MEM WB -final value R * **I<sub>4</sub>:** IF/D OF EX MEM WB - R2→Read **RAW (Read After Write) Occurs**: I<sub>2</sub> tries to read R2 before I<sub>1</sub> has completed writing to R2, resulting in I<sub>2</sub> using an incorrect value. ## Dealing with Hazards **Solutions:** 1. **Stalling**: Introduce a delay in the pipeline until a hazard is resolved. 2. **Forwarding/bypassing**: Use specialized hardware to bypass the waiting stages and send the result directly to the instruction requiring it. 3. **Resource Duplication**: Use multiple resources (memory, functional units, etc.) to overcome structural hazards. 4. **Reordering**: Change the order of instructions to minimize hazards. **Conclusion:** Pipelining offers significant performance benefits in computer systems, but careful consideration must be given to hazards. By understanding the different types of hazards and implementing appropriate solutions, efficient and high-throughput execution can be achieved.

Use Quizgecko on...
Browser
Browser