Hazard (computer architecture)

In the domain of central processing unit (CPU) design, hazards are problems with the instruction pipeline in CPU microarchitectures when the next instruction cannot execute in the following clock cycle,[1] and can potentially lead to incorrect computation results. Three common types of hazards are data hazards, structural hazards, and control hazards (branching hazards).[2]

There are several methods used to deal with hazards, including pipeline stalls/pipeline bubbling, operand forwarding, and in the case of out-of-order execution, the scoreboarding method and the Tomasulo algorithm.

Background

Instructions in a pipelined processor are performed in several stages, so that at any given time several instructions are being processed in the various stages of the pipeline, such as fetch and execute. There are many different instruction pipeline microarchitectures, and instructions may be executed out-of-order. A hazard occurs when two or more of these simultaneous (possibly out of order) instructions conflict.

Types

Data hazards

Data hazards occur when instructions that exhibit data dependence modify data in different stages of a pipeline. Ignoring potential data hazards can result in race conditions (also termed race hazards). There are three situations in which a data hazard can occur:

  1. read after write (RAW), a true dependency
  2. write after read (WAR), an anti-dependency
  3. write after write (WAW), an output dependency
  4. read after read (RAR), a false dependency

Read after read (RAR) is not a hazard case.

Consider two instructions i1 and i2, with i1 occurring before i2 in program order.

Read after write (RAW)

(i2 tries to read a source before i1 writes to it) A read after write (RAW) data hazard refers to a situation where an instruction refers to a result that has not yet been calculated or retrieved. This can occur because even though an instruction is executed after a prior instruction, the prior instruction has been processed only partly through the pipeline.

Example

For example:

i1. R2 <- R5 + R8
i2. R4 <- R2 + R8

The first instruction is calculating a value to be saved in register R2, and the second is going to use this value to compute a result for register R4. However, in a pipeline, when operands are fetched for the 2nd operation, the results from the first have not yet been saved, and hence a data dependency occurs.

A data dependency occurs with instruction i2, as it is dependent on the completion of instruction i1.

Write after read (WAR)

(i2 tries to write a destination before it is read by i1) A write after read (WAR) data hazard represents a problem with concurrent execution.

Example

For example:

i1. R4 <- R1 + R5
i2. R5 <- R1 + R2

In any situation with a chance that i2 may finish before i1 (i.e., with concurrent execution), it must be ensured that the result of register R5 is not stored before i1 has had a chance to fetch the operands.

Write after write (WAW)

(i2 tries to write an operand before it is written by i1) A write after write (WAW) data hazard may occur in a concurrent execution environment.

Example

For example:

i1. R5 <- R4 + R7
i2. R5 <- R1 + R3

The write back (WB) of i2 must be delayed until i1 finishes executing.

Structural hazards

A structural hazard occurs when two (or more) instructions that are already in pipeline need the same resource. The result is that instruction must be executed in series rather than parallel for a portion of pipeline. Structural hazards are sometimes referred to as resource hazards.

Example: A situation in which multiple instructions are ready to enter the execute instruction phase and there is a single ALU (Arithmetic Logic Unit). One solution to such resource hazard is to increase available resources, such as having multiple ports into main memory and multiple ALU (Arithmetic Logic Unit) units.

Control hazards (branch hazards or instruction hazards)

Control hazard occurs when the pipeline makes wrong decisions on branch prediction and therefore brings instructions into the pipeline that must subsequently be discarded. The term branch hazard also refers to a control hazard.

Eliminating hazards

Generic

Pipeline bubbling

Bubbling the pipeline, also termed a pipeline break or pipeline stall, is a method to preclude data, structural, and branch hazards. As instructions are fetched, control logic determines whether a hazard could/will occur. If this is true, then the control logic inserts no operations (NOPs) into the pipeline. Thus, before the next instruction (which would cause the hazard) executes, the prior one will have had sufficient time to finish and prevent the hazard. If the number of NOPs equals the number of stages in the pipeline, the processor has been cleared of all instructions and can proceed free from hazards. All forms of stalling introduce a delay before the processor can resume execution.

Flushing the pipeline occurs when a branch instruction jumps to a new memory location, invalidating all prior stages in the pipeline. These prior stages are cleared, allowing the pipeline to continue at the new instruction indicated by the branch.[3][4]

Data hazards

There are several main solutions and algorithms used to resolve data hazards:

  • insert a pipeline bubble whenever a read after write (RAW) dependency is encountered, guaranteed to increase latency, or
  • use out-of-order execution to potentially prevent the need for pipeline bubbles
  • use operand forwarding to use data from later stages in the pipeline

In the case of out-of-order execution, the algorithm used can be:

The task of removing data dependencies can be delegated to the compiler, which can fill in an appropriate number of NOP instructions between dependent instructions to ensure correct operation, or re-order instructions where possible.

Operand forwarding

Examples

In the following examples, computed values are in bold, while Register numbers are not.

For example, to write the value 3 to register 1, (which already contains a 6), and then add 7 to register 1 and store the result in register 2, i.e.:

i0: R1 = 6
i1: R1 = 3
i2: R2 = R1 + 7 = 10

Following execution, register 2 should contain the value 10. However, if i1 (write 3 to register 1) does not fully exit the pipeline before i2 starts executing, it means that R1 does not contain the value 3 when i2 performs its addition. In such an event, i2 adds 7 to the old value of register 1 (6), and so register 2 contains 13 instead, i.e.:

i0: R1 = 6
i2: R2 = R1 + 7 = 13
i1: R1 = 3

This error occurs because i2 reads Register 1 before i1 has committed/stored the result of its write operation to Register 1. So when i2 is reading the contents of Register 1, register 1 still contains 6, not 3.

Forwarding (described below) helps correct such errors by depending on the fact that the output of i1 (which is 3) can be used by subsequent instructions before the value 3 is committed to/stored in Register 1.

Forwarding applied to the example means that there is no wait to commit/store the output of i1 in Register 1 (in this example, the output is 3) before making that output available to the subsequent instruction (in this case, i2). The effect is that i2 uses the correct (the more recent) value of Register 1: the commit/store was made immediately and not pipelined.

With forwarding enabled, the Instruction Decode/Execution (ID/EX) stage of the pipeline now has two inputs: the value read from the register specified (in this example, the value 6 from Register 1), and the new value of Register 1 (in this example, this value is 3) which is sent from the next stage Instruction Execute/Memory Access (EX/MEM). Added control logic is used to determine which input to use.

Control hazards (branch hazards)

To avoid control hazards microarchitectures can:

  • insert a pipeline bubble (discussed above), guaranteed to increase latency, or
  • use branch prediction and essentially make educated guesses about which instructions to insert, in which case a pipeline bubble will only be needed in the case of an incorrect prediction

In the event that a branch causes a pipeline bubble after incorrect instructions have entered the pipeline, care must be taken to prevent any of the wrongly-loaded instructions from having any effect on the processor state excluding energy wasted processing them before they were discovered to be loaded incorrectly.

Other techniques

Memory latency is another factor that designers must attend to, because the delay could reduce performance. Different types of memory have different accessing time to the memory. Thus, by choosing a suitable type of memory, designers can improve the performance of the pipelined data path.[5]

See also

References

  1. ^ Patterson & Hennessy 2009, p. 335.
  2. ^ Patterson & Hennessy 2009, pp. 335–343.
  3. ^ "Branch Prediction Schemes". cs.iastate.edu. 2001-04-06. Retrieved 2014-07-19.
  4. ^ "Data and Control Hazards". classes.soe.ucsc.edu. 2004-02-23. Retrieved 2014-07-19.
  5. ^ Cheng, Ching-Hwa (2012-12-27). "Design Example of Useful Memory Latency for Developing a Hazard Preventive Pipeline High-Performance Embedded-Microprocessor". VLSI Design. 2013: 1–10. doi:10.1155/2013/425105.

General

Read other articles:

Arniza Nilawati Arzina Nilawati (lahir 15 Mei 1970) adalah seorang politikus dan dosen Indonesia kelahiran Palembang. Ia merupakan akademisi di Universitas Muhammadiyah Malang dan Korwil PKH Sumatra Selatan. Dari 2019 sampai 2024, ia menjabat sebagai anggota Dewan Perwakilan Daerah Republik Indonesia (DPD RI) Perwakilan Sumatra Selatan.[1] Referensi ^ HUKUM PEMEKARAN WILAYAH DALAM KAJIAN DEWAN PERWAKILAN DAERAH REPUBLIK INDONESIA. hlm. 28.  Artikel bertopik biografi Indonesi...

 

Modern psychoanalytic theory and clinical applications Not to be confused with Psychology of self. This article has an unclear citation style. The references used may be made clearer with a different or consistent style of citation and footnoting. (May 2013) (Learn how and when to remove this template message) This article is written like a personal reflection, personal essay, or argumentative essay that states a Wikipedia editor's personal feelings or presents an original argument about a t...

 

General election in Montana 2022 Montana elections ← 2020 November 8, 2022 (2022-11-08) 2024 → Elections in Montana Federal government Presidential elections 1892 1896 1900 1904 1908 1912 1916 1920 1924 1928 1932 1936 1940 1944 1948 1952 1956 1960 1964 1968 1972 1976 1980 1984 1988 1992 1996 2000 2004 2008 2012 2016 2020 2024 Presidential primaries Democratic 2000 2004 2008 2016 2020 Republican 2008 2012 2016 2020 2024 U.S. Senate elections 1890 1895 1895 ...

Ernest Newland (1903–1992) meraih gelar BA dari Wittenberg College ditahun1925 dan gelar Ph.D. di bawah Sidney Pressey di negara bagian Ohio pada tahun 1931.Setelah tujuh tahun bekerja di universitas Bucknell, Newland dengan menjadi Kepala Bagian pendidikan khusus di departemen pendidikan dan pengajaran umum pennsylvania.[1] Saat ini bekerja dari 1938-1942 pelayanan terhadap anak-anak luar biasa berkembang dengan cepat, baik dalam jumlah anak yang dilayani maupun dalam mutu pemoprog...

 

この記事は検証可能な参考文献や出典が全く示されていないか、不十分です。出典を追加して記事の信頼性向上にご協力ください。(このテンプレートの使い方)出典検索?: コルク – ニュース · 書籍 · スカラー · CiNii · J-STAGE · NDL · dlib.jp · ジャパンサーチ · TWL(2017年4月) コルクを打ち抜いて作った瓶の栓 コルク(木栓、�...

 

この記事は検証可能な参考文献や出典が全く示されていないか、不十分です。出典を追加して記事の信頼性向上にご協力ください。(このテンプレートの使い方)出典検索?: コルク – ニュース · 書籍 · スカラー · CiNii · J-STAGE · NDL · dlib.jp · ジャパンサーチ · TWL(2017年4月) コルクを打ち抜いて作った瓶の栓 コルク(木栓、�...

Canadair CT-114 Tutor (perusahaan model CL-41 ) adalah jet standar latih (trainer) Royal Canadian Air Force (RCAF), dan kemudian Pasukan Kanada, antara 1960-an dan 2000. Dirancang dan dibangun oleh Canadair, Canadair CT-114 Tutor itu dipesan pada bulan September 1961. Tutor ini menjabat sebagai latih (trainer) utama jet Angkatan Kanada sampai digantikan oleh CT-155 Hawk dan CT-156 Harvard II pada tahun 2000. Model CL-41G dipasok ke Malaysia dibangun sebagai pesawat serang darat. Tutor ini sa...

 

Taylor Mac nel 2015 Taylor Mac Bowyer (Laguna Beach, 24 agosto 1973) è un artista, commediografo, regista teatrale, musicista, produttore teatrale e drag queen statunitense. Indice 1 Biografia 2 Note 3 Altri progetti 4 Collegamenti esterni Biografia Figlio di Joy Aldrich e del veterano della guerra del Vitnam Robert Mac Bowyer, Taylor Mac si trasferì a New York nel 1994 per studiare all'Accademia americana di arti drammatiche. Dopo il diploma cominciò a lavorare nell'Off Broadway e nell'Of...

 

Defunct American record label Del-Fi RecordsParent companyWarner Music GroupFounded1958 (1958)FounderBob KeaneDefunct2003 (2003)StatusDefunctDistributor(s)Self-distributedGenreVariousCountry of originU.S.LocationHollywood, California Del-Fi Records was an American record label based in Hollywood, California was founded 1958 and owned by Bob Keane. The label's first single released was Caravan by Henri Rose released in 1958, but the label was most famous for signing Ritchie Valens. V...

Questa voce sull'argomento storia contemporanea è solo un abbozzo. Contribuisci a migliorarla secondo le convenzioni di Wikipedia. Segui i suggerimenti del progetto di riferimento. Atto d'accusa – Norimberga – Tribunale Militare Internazionale (1945) I processi secondari di Norimberga furono una serie di dodici processi tenuti da tribunali militari statunitensi per crimini di guerra contro i membri sopravvissuti del potere militare, politico ed economico della Germania nazista. Ten...

 

Para otros usos de este término, véase Santiago de Chile (desambiguación). Santiago Capital de Chile De arriba a abajo, de izquierda a derecha.1.ª fila: Panorámica de Santiago. 2.ª fila: Estatua de la Inmaculada Concepción en el Santuario del cerro San Cristóbal, y Sanhattan, principal distrito financiero de la ciudad. 3.ª fila: Fuente de Neptuno en el cerro Santa Lucía, y Biblioteca Nacional. 4.ª fila: Casas centrales de la Universidad de Chile y Pontificia Universidad Católica ...

 

Main article: 1988 United States presidential election 1988 United States presidential election in Indiana ← 1984 November 8, 1988 1992 →   Nominee George H. W. Bush Michael Dukakis Party Republican Democratic Home state Texas Massachusetts Running mate Dan Quayle Lloyd Bentsen Electoral vote 12 0 Popular vote 1,297,763 860,643 Percentage 59.84% 39.69% County Results Bush   50–60%   60–70%   70–80%   ...

جرينلاند (أي «الأرض الخضراء»)، (بالجرينلاندية: Kalaallit Nunaat، و بالدنماركية: Grønland) وتعني أرض الناس. هي ثاني أكبر جزيرة في العالم بعد أستراليا وهي بلد عضو في مملكة الدانمرك، تقع بين منطقة القطب الشمالي و المحيط الأطلسي ، إلى الشرق من أرخبيل القطب الشمالي الكندي. وعلى رغم انتماء ج...

 

Book by Joan Phipson The Family Conspiracy First editionAuthorJoan PhipsonLanguageEnglishGenreChildren's fictionPublisherAngus and Robertson (Aus)Constable (UK)Publication date1962Publication placeAustraliaMedia typePrintPages188ppPreceded byThe Boundary Riders Followed byThreat to the Barkers  The Family Conspiracy (1962) is a novel for children by Australian author Joan Phipson; it was illustrated by Margaret Horder. It won the Children's Book of the Year Award: Old...

 

Звёздные войны: Пробуждение силыангл. Star Wars: The Force Awakens Жанр эпическая космическая опера Режиссёр Дж. Дж. Абрамс Продюсеры Кэтлин Кеннеди Дж. Дж. Абрамс Брайан Берк На основе персонажей Джорджа Лукаса Авторысценария Лоуренс Кэздан Дж. Дж. Абрамс Майкл Арндт В главныхр...

French painter This article needs additional citations for verification. Please help improve this article by adding citations to reliable sources. Unsourced material may be challenged and removed.Find sources: François-Guillaume Ménageot – news · newspapers · books · scholar · JSTOR (January 2021) (Learn how and when to remove this message) Self portrait (before 1800) Death of Leonardo da Vinci (now at the observatory and museum of Amboise). Françoi...

 

This article needs additional citations for verification. Please help improve this article by adding citations to reliable sources. Unsourced material may be challenged and removed.Find sources: Liegnitz region – news · newspapers · books · scholar · JSTOR (May 2021) (Learn how and when to remove this message) Districts in Silesia (1905):  Regierungsbezirk LiegnitzRegierungsbezirk Liegnitz was an administrative region in the Prussian ...

 

British Forces CyprusBritish Forces Tri-Service badgeAllegiance United KingdomBranch British Army Royal Air Force Royal NavySize3,500 military personnel[1] 7,000 civilians[1]Part ofUK Ministry of DefenceGarrison/HQAkrotiri and Dhekelia, CyprusCommandersCBF (Commander British Forces Cyprus)Air Vice-Marshal Peter Squires OBENotablecommandersAir Chief Marshal Sir Michael Wigston KCB CBE ADCMilitary unit British Forces Cyprus (BFC) is the name given to the British Armed ...

Rugby playerJoe TuineauFull nameJoseph Mark Laifone TuineauDate of birth (1981-08-18) 18 August 1981 (age 43)Place of birthSuva, FijiHeight2.03 m (6 ft 8 in)Weight120 kg (18 st 13 lb; 265 lb)SchoolKing's CollegeRugby union careerPosition(s) LockCurrent team DaxSenior careerYears Team Apps (Points)2008–2011 Southland 34 (25)2010–2011 Highlanders 7 (0)2011–2012 Montpellier 5 (0)2012–2013 Provence 27 (20)2013–2014 Lyon 29 (25)2015– Dax 66 (25)...

 

This article may rely excessively on sources too closely associated with the subject, potentially preventing the article from being verifiable and neutral. Please help improve it by replacing them with more appropriate citations to reliable, independent, third-party sources. (May 2024) (Learn how and when to remove this message) Ethnic group Bulgarians in HondurasTotal population7,500–10,000[1]Regions with significant populationsLa Ceiba, Gracias a Dios, TocoaLanguagesBulgarian, Spa...