Share to: share facebook share twitter share wa share telegram print page

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:

SwitchGenre Drama Fantasi Roman Pembuat Nia Dinata Lucky Kuswandi Pemeran Tatyana Akman Karina Salim Morgan Oey Lagu penutupJaz – Dari MataPenata musikRooftopsoundNegara asalIndonesiaBahasa asliBahasa IndonesiaJmlh. musim1Jmlh. episode13 (daftar episode)ProduksiProduserBayu PontiagustSinematografiMayk WongkarJuru animasiErickson SiregarPenyuntingBernardes SalvanoPengaturan kameraMulti-kameraDurasi20–30 menitRumah produksiKalyana Shira FilmsRilis asliJaringanViuFormat gambar1080pRilis14…

BulakrejoKelurahanKantor Lurah BulakrejoNegara IndonesiaProvinsiJawa TengahKabupatenSukoharjoKecamatanSukoharjoKodepos57551Kode Kemendagri33.11.04.1013 Kode BPS3311040013 Luas... km²Jumlah penduduk... jiwaKepadatan... jiwa/km² Untuk desa di Jawa Timur, lihat Bulakrejo, Balerejo, Madiun. Bulakrejo (Jawa: Bulakreja) adalah kelurahan di kecamatan Sukoharjo, Sukoharjo, Jawa Tengah, Indonesia. Pembagian wilayah Kelurahan Bulakrejo terdiri dari beberapa kampung, antara lain: Banaran Bulakre…

Bride and PrejudicePoster asli filmSutradaraGurinder ChadhaProduserGurinder Chadha,Deepak NayarDitulis olehJane Austen (novel),Gurinder Chadha,Paul Mayeda BergesPemeranAishwarya Rai,Martin Henderson,Alexis BledelDistributorMiramax Films (AS)Pathé (non-AS)Tanggal rilis6 Oktober 2004Durasi107 menitBahasaInggris, HindiAnggaranAS$7.000.000IMDbInformasi di IMDb Bride and Prejudice adalah sebuah film yang dibuat pada 2004 yang merupakan adaptasi Bollywood atas novel Jane Austen tahun 1813 Pride and P…

Cari artikel bahasa  Cari berdasarkan kode ISO 639 (Uji coba)   Cari berdasarkan nilai Glottolog   Kolom pencarian ini hanya didukung oleh beberapa antarmuka Halaman rumpun acak Rumpun bahasaIndo-Arya IndikPersebaranAsia SelatanPenggolongan bahasaIndo-EropaIndo-IranIndo-Arya Zona Barat Laut Zona Utara Zona Tengah Zona Timur Zona Selatan Insular Kode bahasaISO 639-2 / 5incLokasi penuturan  Portal BahasaSunting kotak info • L • B • PWBantuan penggunaan temp…

European Parliament political group This article is about the parliamentary group. For the political party, see European People's Party. European People's Party GroupEuropean Parliament groupNameEuropean People's Party GroupEnglish abbr.EPP Group(22 June 2009 – present) Older: EPP-ED[1](20 July 1999[2] – 22 June 2009) EPP[1](17 July 1979[3] – 20 July 1999[2]) CD[2](23 June 1953[3] – 17 July 1979[3]) French abbr.PPE(22 June 2…

Election in Arkansas Main article: 1928 United States presidential election 1928 United States presidential election in Arkansas ← 1924 November 6, 1928 1932 →   Nominee Al Smith Herbert Hoover Party Democratic Republican Home state New York California Running mate Joseph T. Robinson Charles Curtis Electoral vote 9 0 Popular vote 123,140 77,789 Percentage 61.06% 38.57% County Results Smith   50-60%   60-70%   70-80% …

Ikatan Dokter IndonesiaSingkatanIDITanggal pendirian24 Oktober 1950; 73 tahun lalu (1950-10-24)[1]Kantor pusatJl. Dr. G.S.S.Y. Ratulangi No. 29, Menteng, Jakarta Pusat 10350Jumlah anggota 199.000+[2]Ketua UmumDR. Dr. Moh Adib Khumaidi, Sp.OT [3]Situs webwww.idionline.org Ikatan Dokter Indonesia disingkat IDI adalah organisasi profesi kedokteran di Indonesia. IDI bertugas sebagai organisasi yang menaungi para dokter di seluruh Indonesia. Organisasi ini berafiliasi den…

Japanese manga series Pokémon AdventuresCover of the first tankōbon volume, featuring Red (front) and Pikachu (back)ポケットモンスター SPECIAL(Poketto Monsutā Supesharu)GenreAdventure, fantasy[1] MangaWritten byHidenori KusakaIllustrated byMato [ja] (vol. 1–9)Satoshi Yamamoto (vol. 10–)Published byShogakukanEnglish publisherNA: Viz MediaSG: Shogakukan AsiaImprintTentōmushi ComicsMagazineCoroCoro Ichiban!Pokémon FanClub Sunday (web) (former)Su…

Artikel ini sebatang kara, artinya tidak ada artikel lain yang memiliki pranala balik ke halaman ini.Bantulah menambah pranala ke artikel ini dari artikel yang berhubungan atau coba peralatan pencari pranala.Tag ini diberikan pada Februari 2023. Kantor pusat Colorado Fuel and Iron Company Colorado Fuel dan Iron Company (bahasa Rusia: Колорадо Топливо и Железная Компания) adalah sebuah perusahaan baja asal Rusia yang pernah beroperasi di Amerika Serikat. Pada tahun…

Indian WPWP/P class 7200 by Baldwin from 1947, at the National Rail Museum, New Delhi, in 1993Type and originPower typeSteamBuilderBaldwin Locomotive Works (116)Canadian Locomotive Company (200)Montreal Locomotive Works (120)Fabryka Lokomotyw, (30)Lokomotivfabrik Floridsdorf (30)Chittaranjan Locomotive Works (259)Build date1947–1967Total produced755SpecificationsConfiguration:​ • Whyte4-6-2 • UIC2′C1′ h2Gauge5 ft 6 in (1,676 mm)Leading dia…

mesh segitiga ber-shading Gouraud yang menggunakan model refleksi Phong Pencorakan Gouraud (bahasa Inggris : Gouraud Shading), diberi nama sesuai penemunya Henri Gouraud, adalah metode interpolasi yang digunakan dalam komputer grafis untuk menghasilkan corak (shading) kontinu pada permukaan yang direpresentasikan oleh mesh poligon. Dalam praktiknya, shading Gouraud paling sering digunakan untuk mencapai pencahayaan berkelanjutan pada mesh segitiga dengan menghitung pencahayaan di sudut tiap…

Sampul Buku Petualangan Dawn Treader The Voyage of the Dawn Treader adalah novel fantasi karangan C. S. Lewis yang diterbitkan pertama kali pada 1952. Buku ini adalah buku ketiga dalam The Chronicles of Narnia dan buku kelima menurut kronologi. Buku ini didedikasikan kepada Geoffrey Barfield. Ringkasan Cerita Edmund dan Lucy Pevensie, dikirim ke rumah saudara sepupu mereka yang nakal, Eustace Clarence Scrubb, untuk berlibur. Namun, tanpa disangka-sangka, mereka ditarik ke dalam dunia Narnia, mel…

1981 1988 Élections législatives de 1986 en Ille-et-Vilaine 7 sièges de députés à l'Assemblée nationale 16 mars 1986 Corps électoral et résultats Population 749 764 Inscrits 518 900 Votants 409 928   78,99 %  8,3 Votes exprimés 388 255 Droite parlementaire – Pierre Méhaignerie Liste Union pour la démocratie françaiseCentre des démocrates sociauxParti républicainRassemblement pour la République Voix 142 319 52,68 %  Dép…

ПамятникПамятник Фёдору Коню 54°46′46″ с. ш. 32°02′37″ в. д.HGЯO Страна  Россия Город Смоленск Скульптор О. Н. Комов Архитектор А. К. Анипко Дата основания 1991 Строительство 1991 Статус  ОКН № 6702680000№ 6702680000  Медиафайлы на Викискладе Памятник Фёдору Коню — одна из…

Japanese ball game, non-competitive For the neighborhood of Karachi, see Keamari District. A game of Kemari at Tanzan Shrine Woodblock print depicting Kemari expert Fujiwara no Narimichi (1097–1162) and three monkeys, guardian deities of the game Asukai Masanori Teaching Tokugawa Yoshimune to Play Kemari. Ukiyo-e printed by Tsukioka Yoshitoshi. Kemari field at Kyoto Imperial Palace Kemari (蹴鞠) is an athletic game that was popular in Japan during the Heian (794–1185) and Kamakura period (…

Japanese micro-satellite launched in 2014 Hodoyoshi-4Mission typeEarth observationOperatorNESTRACOSPAR ID2014-033B SATCAT no.40011Mission duration9 years, 11 months, 10 days (ongoing) Spacecraft propertiesManufacturerUniversity of TokyoLaunch mass66 kg (146 lb) Start of missionLaunch date19:11, June 19, 2014 (UTC) (2014-06-19T19:11Z)RocketDneprLaunch siteDombarovsky Orbital parametersReference systemGeocentricEccentricity0Perigee altitude6…

British sitcom BackGenreSitcomCreated bySimon BlackwellWritten by Simon Blackwell John Finnemore Oriane Messina Fay Rusling Will Smith Directed by George Kane Ben Palmer Starring Robert Webb David Mitchell Country of originUnited KingdomOriginal languageEnglishNo. of series2No. of episodes12 (list of episodes)ProductionExecutive producers Kenton Allen David Mitchell Robert Webb Simon Blackwell Victoria Grew Matthew Justice Producers Kate Daughton Lyndsay Robinson Camera setupSingle-cameraRunning…

County in New York, United States Not to be confused with Sullivan, New York. County in New YorkSullivan CountyCountyStream in the hamlet of Rock Hill FlagSealLocation within the U.S. state of New YorkNew York's location within the U.S.Coordinates: 41°43′N 74°46′W / 41.72°N 74.76°W / 41.72; -74.76Country United StatesState New YorkFounded1809Named forJohn SullivanSeatMonticelloLargest villageMonticelloArea • Total997 sq mi (2,580…

AdelantadoPedro de AlvaradoChức vụAdelantado của GuatemalaNhiệm kỳNgày 18 tháng 12 năm 1527 – Ngày 4 tháng 7 năm 1534 Đệ Nhất thống đốc và thống soái của Guatemala(tạm thời, từ năm 1525 cùng với tỉnh San Salvador)Nhiệm kỳ1524 – 1526Tiền nhiệmChức vụ mớiKế nhiệmGonzalo de Alvarado Thống đốc và thống soái thứ 6 của Guatemalacùng với tỉnh San Salvador và từ năm 1531 cùng với tỉnh…

Pre-Columbian languages of subcontinent The principal families of South America (except Quechua, Aymaran, and Mapuche). The indigenous languages of South America are those whose origin dates back to the pre-Columbian era. The subcontinent has great linguistic diversity, but, as the number of speakers of indigenous languages is diminishing, it is estimated that it could become one of the least linguistically diverse regions of the planet. About 600 indigenous languages are known from South Americ…

Kembali kehalaman sebelumnya