Out Of Order Execution (Part 1)

Slides:



Advertisements
מצגות קשורות
הכרת תוכנת בקרים. כניסה לתוכנה תתבצע בשלבים הבאים: 1
Advertisements

אוגרים ומונים – Registers & Counters
אוגרים ומונים – Registers & Counters
SQL: שינוי מסד הנתונים- פעולותDDL , DML
הרצאה 02 סוגי משתנים קרן כליף.
מבנה מחשבים ספרתיים זיכרון מטמון - המשך
תרגול מס' 1: מנהלות חזרה על ארכיטקטורת ה- MIPS
תגובות חמצון -חיזור ודוגמאות מחיי היום יום
מבוא לתכנות ב-JAVA מעבדה 1
Trends in Periodic Table Properties
תרגול 11 מלכודות בניית ה-Debugger
Operating Systems 2019, I. Dinur , D. Hendler and M. Kogan-Sadetsky
לולאות Department of Computer Science-BGU 19 יולי 19.
פינוק מסביב לעולם מחזות זמר הסבר הזמנה ומימוש.
נערך ע"י אריק הוד, הגימנסיה העברית הרצליה
Isotopes and Atomic Mass
OOO Execution of Memory Operations
Marina Kogan Sadetsky –
אלקטרושליליות ופולריות הקשר
Jump tables, review questions
תרגול Introduction to C - Fall Amir Menczel.
פעולות אריתמטיות קרן כליף.
Computer Programming תרגול 1 Summer 2016
Present Perfect Simple
Passover in “Tomer” kindergarten
תירגול 11: מיונים וחיפוש בינארי
תרכובות עם יונים פוליאטומים בחיי היום יום
נערך ע"י אריק הוד הגימנסיה העברית הרצליה
A sneak peak of the Passover story at Levine Academy
יסודות מבני נתונים תרגול 13: עץ פורש מינימלי - Minimum Spanning Tree (MST)
Entity Relationship Diagram – ERD
Lean דני חייט MSM.
מבני נתונים תרגול 3 ליאור שפירא.
OOO Execution of Memory Operations
Akiba Academy of Dallas Presents
S. Even, "Graph Algorithms", Computer Science Press, 1979
האם אתם יודעים כיצד כותבים מגילה?
פינוק מסביב לעולם הסבר הזמנה ומימוש.
© האוניברסיטה העברית בירושלים, 2008
Direction of induced current
מבוסס על שקפים מאת יאן ציטרין
זיכרון מטמון 1 מבנה מחשבים ספרתיים
זיכרון מטמון 2 מבנה מחשבים ספרתיים
תורת הקומפילציה תרגול 9: תרגום לקוד ביניים
מבוא לתכנות למערכות מידע
מבנה מחשבים ספרתיים זכרון וירטואלי מבוסס על תרגול של מורן גביש
Computer Architecture and System Programming Laboratory
תיעוד מפעילויות ראש השנה בגן "פרפר נחמד" –עכו-תש"ע
כל הזכויות שמורות לגבריאל אנקרי © 2017
Branch Prediction בעריכת אורן קצנגולד Updated by Franck Sala.
Branch Prediction Oren Katzengold, Franck Sala, Elad Shtiegmann.
Marina Kogan Sadetsky –
Emech at 1 + W = Emech at 2 mgh1 = mgh2
תוכנה 1 תשס"ח סמסטר ב' אוהד ברזילי ליאור שפירא
What is Chemistry? מהי כימיה? Chemistry is the study of matter and its
שימוש בעצם ממחלקה אחרת כמאפיין במחלקה הנוכחית
מבוא לתכנות ב- JAVA מעבדה 4
מבוא לתכנות בWINDOWS ד"ר אבי רוזנפלד.
1. יש להיכנס לאתר הספרייה ולבחור בקטלוג הספרייה
מבוא למדעי המחשב סמסטר ב' – 2008 מרצה: יעל סיגל מתרגל: ענבל בודובסקי.
מבוסס על שקפים מאת יאן ציטרין
Tutorial #10 MIPS commands
מעבדה 2- עיצוב (עבור חלק ג)
תרגול מס' 2: Data and Control Hazards
OOO Execution of Memory Operations
מבנה מחשבים ספרתיים תרגול מס' 4: זכרון מטמון 2.
יינון המים In the ionization of water,
Engineering Programming A
תמליל מצגת:

Out Of Order Execution (Part 1)

Execution of instructions with variable execution time Problem: Single cycle Execution phase  The longest operation possible in the machine fixes the frequency Example: ADD/SUB=2ns, MUL=10ns, DIV=20ns  cc=20ns Solution: Implement a pipeline in EXE Execution time of certain instructions is now variable (i.e. load with or without cache miss) More pipe stages = bigger penalty on misprediction and more data hazards (but generally an increase in CPI)

דוגמא R1R1+4 R2R3*R3 R4R3+R4 IF ID MEM WB DIV EX M1 M2 M3 M4 Integer unit Multiply divider

דוגמא R1R1+4 R2R3*R3 R4R3+R4 IF ID MEM WB DIV EX M1 M2 M3 M4 Integer unit Multiply divider R2  R3*R3 R1R1+4

דוגמא R1R1+4 R2R3*R3 R4R3+R4 IF ID MEM WB DIV EX M1 M2 M3 M4 Integer unit Multiply divider R1  R1+4 R4  R3+R4 R2  R3*R3

דוגמא R1R1+4 R2R3*R3 R4R3+R4 IF ID MEM WB DIV EX M1 M2 M3 M4 Integer unit Multiply divider R1  R1+4 R2  R3*R3 R4  R3+R4

דוגמא R1R1+4 R2R3*R3 R4R3+R4 IF ID MEM WB DIV EX M1 M2 M3 M4 Integer unit Multiply divider R4  R3+R4 R1  R1+4 R2  R3*R3

דוגמא R1R1+4 R2R3*R3 R4R3+R4 IF ID MEM WB DIV EX M1 M2 M3 M4 Integer unit Multiply divider R4  R3+R4 R2  R3*R3

דוגמא R1R1+4 R2R3*R3 R4R3+R4 IF ID MEM WB DIV EX M1 M2 M3 M4 Integer unit Multiply divider R4  R3+R4 R2  R3*R3

דוגמא R1R1+4 R2R3*R3 R4R3+R4 IF ID MEM WB DIV EX M1 M2 M3 M4 Integer unit Multiply divider R4  R3+R4 R2  R3*R3

דוגמא R1R1+4 R2R3*R3 R4R3+R4 IF ID MEM WB DIV EX M1 M2 M3 M4 Integer unit Multiply divider R4  R3+R4 R2  R3*R3

Execution of instructions with variable execution time Problem: A short operation might get “stuck” waiting for another operation of a different type to leave the Execution phase. Solution: Allow instructions of different types/pipelines to be executed Out of Order. Execute many independent instructions in parallel (in different pipelines). Improves CPI. Execution must keep correctness of the code. Note: If an operation gets “stuck” waiting for another operation of the same type to leave the Execution phase.  Structural Hazard (need to add more execution units to solve).

דוגמא R1R1+4 R2R3*R3 R4R3+R4 IF ID MEM WB DIV EX M1 M2 M3 M4 Integer unit Multiply divider R2  R3*R3 R1R1+4

דוגמא R1R1+4 R2R3*R3 R4R3+R4 IF ID MEM WB DIV EX M1 M2 M3 M4 Integer unit Multiply divider R1  R1+4 R4  R3+R4 R2  R3*R3

דוגמא R1R1+4 R2R3*R3 R4R3+R4 IF ID MEM WB DIV EX M1 M2 M3 M4 Integer unit Multiply divider R1  R1+4 R2  R3*R3 R4  R3+R4

דוגמא R1R1+4 R2R3*R3 R4R3+R4 IF ID MEM WB DIV EX M1 M2 M3 M4 Integer unit Multiply divider R4  R3+R4 R1  R1+4 R2  R3*R3

דוגמא R1R1+4 R2R3*R3 R4R3+R4 IF ID MEM WB DIV EX M1 M2 M3 M4 Integer unit Multiply divider R4  R3+R4 R2  R3*R3

דוגמא R1R1+4 R2R3*R3 R4R3+R4 IF ID MEM WB DIV EX M1 M2 M3 M4 Integer unit Multiply divider R4  R3+R4 R2  R3*R3

דוגמא R1R1+4 R2R3*R3 R4R3+R4 IF ID MEM WB DIV EX M1 M2 M3 M4 Integer unit Multiply divider R2  R3*R3

דוגמא R1R1+4 R2R3*R3 R4R3+R4 IF ID MEM WB DIV EX M1 M2 M3 M4 Integer unit Multiply divider R2  R3*R3

CPI במכונות in order כמו שהכרנו עד היום ה-CPI המינימלי שניתן להשיג הוא 1 גם בביצוע שהינו OOO חסם זה קיים כל עוד נאפשר ביצוע מקביל רק של שלב ה-EXE. אם נאפשר ביצוע מספר הוראות במקביל גם בשאר השלבים אזי נוכל לשבור חסם זה. IF ID EXE MEM WB IF ID EXE MEM WB

תלויות מידע (data hazard) להזכירכם אנו מכירים כבר תלות מידע מסוג RAW: ADD R1,R2,R3 ADD R5,R6,R1 :RAW (Read After Write) יעד של הפקודה הראשונה הוא מקור בפקודה השניה. זוהי תלות אמיתית שיש לקיים על מנת לשמור על נכונות התכנית.

תלויות מידע (data hazard) ביצוע שלא על פי הסדר (OOOE) יוצר תלויות חדשות בין פקודות: WAR – Write After Read DIV R1,R2,R3 // many cycles ADD R5,R6,R1 // depends on previous instruction ADD R6,R7,R8 // WAR issue הוראת החילוק הארוכה מעכבת את הוראת החיבור שאחריה (ממתינה לערך של (R1. מכיוון שאנו מאפשרים ביצוע out of order, ההוראה השלישית (שלא מחכה לכלום) תתבצע לפני השנייה, ולכן ההוראה השנייה (כשתתבצע) עלולה לקרוא את הערך של R6 כפי שנכתב ע"י ההוראה השלישית ולא את הערך הקודם (כפי שהתכוון הקומפיילר/מתכנת). הכתיבה ל-R6 ע"י הוראה (3) צריכה לקרות אחרי הקריאה שלו ע"י הוראה (2)

WAW – Write After Write DIV R1,R2,R3 // many cycles ADD R5,R6,R1 // depends on previous instruction ADD R5,R7,R8 // WAW issue גם כאן ההוראה השנייה מעוכבת ואילו השלישית לא, מה שעלול להוביל לכך שההוראה השנייה תכתוב ל-R5 אחרי ההוראה השלישית, כך שבסופו של דבר R5 יכיל ערך לא עדכני. צריך לוודא שהכתיבה של R5 ע"י הוראה (3) תיעשה לאחר הכתיבה שלו ע"י הוראה (2). תלויות אלו נקראות False Dependencies מכיוון שניתן היה להשתמש ברגיסטרים שונים ובכך לשבור את התלות (כלומר הפקודות לא באמת תלויות בגלל ערכים שהן מחשבות, אלא עקב בחירת רגיסטרים זהה אך שרירותית עבורן). אם היו לרשות הקומפיילר/מתכנת יותר רגיסטרים, היה יכול לבחור רגיסטרים שונים לכל פעולה ובכך "לשבור" את התלות.

Register Renaming דרך לפתור את בעיית התלויות החדשות (WAR, WAW) היא ע"י Register Renaming. הרעיון: שמירת שתי מערכות רגיסטרים: זאת אשר גלויה למשתמש (רגיסטרים ארכיטקטונים, למשל R5) וזאת אשר לשימוש המהדר (רגיסטרים פיזיים, למשל P8) ישנו מס' גדול יותר של רגיסטרים פיזיים מאשר רגיסטרים ארכיטקטונים. כאשר פקודה מבקשת להשתמש ברגיסטר ארכ' כלשהו ממנים לה רגיסטר פיזי. שתי פקודות שמבקשות להשתמש באותו רגיסטר, איך אינן תלויות באופן אמיתי (RAW), מקבלות באופן אוטומטי שני רגיסטרים פיזיים שונים: R1  R2+R3  P1  R2+R3 R1  R4+R5  P2  R4+R5 אנו מנהלים שני מיפויים: מיפוי מהרגיסטרים הארכיטקטוניים לרגיסטרים הפיזיים (למשל R5P8) לצורך פתירת בעיות תלויות מדומות. המיפוי הזה נשמר כחלק מהמעבר בין שלב ה-decode לשלב ה-execution מיפוי מהרגיסטרים הפיזיים לארכיטקטוניים (למשל P8R5) לצורך שמירת הערך שפקודה מפיקה חזרה לרגיסטר אליו התכוון הקומפיילר. המיפוי הזה נשמר כחלק משלב ה-commit.

OOO-Execution Processor רוב המעבדים המודרניים מבצעים את שלבי ה-commit וה- fetch/decode בסדר התוכנית (in order) ואילו רק שלב הביצוע מתבצע out of order. (out-of-order) Fetch & Decode EXE Retire (commit) In-order מקום להוראה הבאה הוראה הבאה שמבצעת commit

ROB (Re-Order Buffer) דרך נפוצה למימוש של Register Renaming היא ע"י ROB, שהוא בעצם חוצץ (buffer) המקבל את ההוראות משלב ה-decode ע"פ הסדר. הכניסה המתאימה ב-ROB מהווה את מספר הרגיסטר הפיזי אליו הפקודה כותבת. לאחר שלב ה-EXE של פקודה כלשהי, התוצאה שלה נכתבת לכניסה המתאימה ב-ROB. הוראות מבצעות את שלב ה-commit (לקראת יציאה מהמעבד לאחר סיום) ע"פ הסדר שלהן ב-ROB: הוראה יכולה לבצע commit רק אם זו שלפניה עשתה זאת.

דוגמא: DIV R1,R2,R3 ADD R2,R4,R1 ADD R2,R3,R3 ADD R4,R3,R2 WAW WAR Arch reg.. Phys reg.. R1 R2 R3 R4 DIV R1,R2,R3 ADD R2,R4,R1 ADD R2,R3,R3 ADD R4,R3,R2 WAW WAR Renamer P0 P1 P2 P3 Pn buffer ציקלי

דוגמא: P0 DIV R1,R2,R3 ADD R2,R4,R1 ADD R2,R3,R3 ADD R4,R3,R2 Renamer Arch reg.. Phys reg.. R1 R2 R3 R4 P0 DIV R1,R2,R3 ADD R2,R4,R1 ADD R2,R3,R3 ADD R4,R3,R2 Renamer P0 P1 P2 P3 Pn R2/R3

דוגמא: P0 DIV R1,R2,R3 P1 ADD R2,R4,R1 ADD R2,R3,R3 ADD R4,R3,R2 Arch reg.. Phys reg.. R1 R2 R3 R4 P0 DIV R1,R2,R3 ADD R2,R4,R1 ADD R2,R3,R3 ADD R4,R3,R2 P1 Renamer P0 P1 P2 P3 Pn R2/R3 R4+P0

דוגמא: P0 DIV R1,R2,R3 P2 ADD R2,R4,R1 ADD R2,R3,R3 ADD R4,R3,R2 Arch reg.. Phys reg.. R1 R2 R3 R4 P0 DIV R1,R2,R3 ADD R2,R4,R1 ADD R2,R3,R3 ADD R4,R3,R2 P2 Renamer P0 P1 P2 P3 Pn R2/R3 R4+P0 R3+R3

דוגמא: P0 DIV R1,R2,R3 P2 ADD R2,R4,R1 ADD R2,R3,R3 ADD R4,R3,R2 P3 Arch reg.. Phys reg. R1 R2 R3 R4 P0 DIV R1,R2,R3 ADD R2,R4,R1 ADD R2,R3,R3 ADD R4,R3,R2 P2 P3 Renamer P0 P1 P2 P3 Pn R2/R3 R4+P0 R3+R3 שים לב: כעת אין תלויות מסוג False Dependencies )אבל RAW עדיין קיים( R3+P2

X86 Structures IDQ RAT / Alloc ROB RS RRF: (4 write ports) Dest (Arch) #phys reg 0: Read from RRF 1: Read from ROB EAX xxx 0 (RRF) EBX 19 1 (ROB) ECX 23 ROB RS # Data Valid Data DST 19 V 12 EBX 23 33 ECX 37 I xxx EAX 38 x v src1 src2 Pdst add 1 97H 12H 37 sub rob37 33H 38 Dest. (Phys Reg) (4 write Ports, 1 entry per uop) Arch reg: value from RRF Phys reg + valid: value from ROB Phys reg + not valid: wait for value RRF: EAX 97H Source & dest values updated after EXE

IBM model 91 First IBM computer to support OOO execution. Tomasulo Algorithm

דוגמא ל-OOO Execution נתונה מכונת ה-P6 שמומשה במעבדי Pentium 2/3. במכונה זו הוראות (CISC) נכנסות לשלב ה-decode ע"פ הסדר, ולפני היציאה ל-Execution הן מפורקות לפקודות פנימיות הנקראות uops (RISC). למשל, הוראת LD R4, (R5+50) מפורקת לשתי uops: פקודה אריתמטית שמחשבת את הכתובת בזכרון פקודת טעינה מהזכרון (של הכתובת שחושבה) אל רגיסטר. הערה: התרגום מהוראות (CISC) לפקודות/uops (RISC) נעשה ברוב המעבדים המודרניים. ה-uops מתבצעות בשלב ה-EXE באופן out-of-order. לבסוף, בשלב ה-retire ה-uops יוצאות מהמכונה בסדר בו נכנסו אליה (כלומר ע"פ הסדר המקורי של ההוראות בתכנית). המכונה מבצעת Register Renaming הממומש ב-ROB (כפי שנלמד). פקודות נכתבות אל ה-ROB כאשר הן יוצאות משלב ה-Decode אל שלב ה-Execution.

התכנית DIV R2,R4,R3 LD R3,R4(50) מס' מחזורי ביצוע לכל פקודה: DIV: 4cc ADD R2,R4,R3 SUB R3,R2,R3 מס' מחזורי ביצוע לכל פקודה: DIV: 4cc LD: 2cc ADD/SUB: 1cc

Instruction Q ROB Execute Retire (WB) RAT R3R2-R3 RF1 R2R4+R3 RF2 R3MEM(R4+50) R2  R4/R3 R1 R2 R3 R4 RF1 Arch Reg. RF2 Program Order RF3 RF4 RS MOB ROB # Valid Data Valid Data DST I x xxx X Phys. Reg. Execute Retire (WB)

Instruction Q Cycle 1 ROB Execute Retire (WB) RAT R3R2-R3 RF1 R3MEM(R4+50) R2  R4/R3 R1 R2 R3 R4 RF1 RF2 RB0 RF3 RF4 RS MOB ROB RB0R4/R3 Comment Valid Data Valid Data DST Execute Retire (WB)

Instruction Q Cycle 2 ROB Execute Retire (WB) RAT R3R2-R3 RF1 R3MEM(R4+50) R2  R4/R3 R1 R2 R3 R4 RF1 RB0 RB1 RB1 RF3 RF4 RS MOB ROB RB0R4/R3 RB1MEM(not rdy) MobR4+50 Comment Valid Data Valid Data DST R2 R4/R3 1 xxx R2 R3MEM(r4+50) R3 Execute RB0R4/R3 (1) Retire (WB)

Instruction Q Cycle 3 ROB Execute Retire (WB) RAT R3R2-R3 RB2 RF1 R3MEM(R4+50) R2  R4/R3 RF4 RS MOB ROB RB1MEM(not Rdy) W MobR4+50 Comment Valid Data Valid Data DST R2 R4/R3 1 xxx R2 R3MEM(R4+50) R3 R1  R2 / R3 RB2RB0/RB1 Execute RB0  R4/R3 (1) (2) Retire (WB)

Instruction Q Cycle 4 ROB Execute Retire (WB) RAT R3R2-R3 R2R4+R3 R3MEM(R4+50) R2  R4/R3 R1 R2 R3 R4 RB2 RB3 RB0 RB1 RF4 RS MOB ROB RB1MEM(not rdy) RB1MEM(R4+50) W (1) RB3R4+RB1 Comment Valid Data Valid Data DST R2 R4/R3 1 xxx R2 R3MEM(R4+50) R3 R1  R2 / R3 R1 R2  R4 + R3 RB2RB0/RB1 W Mob R4+50 Execute RB0R4/R3 (2) (3) Retire (WB)

Instruction Q Cycle 6 Cycle 5 ROB Execute Retire (WB) RAT R3R2-R3 RB2 R3MEM(R4+50) R2  R4/R3 R1 R2 R3 R4 RB2 RB3 RB4 RB1 RF4 RS MOB ROB RB1MEM(R4+50) (2) (1) RB3R4+RB1 W Comment Valid Data Valid Data DST R2 R4/R3 1 xxx R2 R3MEM(R4+50) R3 R1  R2 / R3 R1 R2  R4 + R3 R3  R2 – R3 RB2RB0/RB1 W 1 Value2 Value3 RB4RB3-RB1 Execute RB0 R4/R3 (3) (4) Retire (WB)

Instruction Q Cycle 6 ROB Execute Retire (WB) RAT R3R2-R3 RB2 R3MEM(R4+50) R2  R4/R3 R1 R2 R3 R4 RB2 RB3 RB4 RF4 RS MOB ROB RB3R4+RB1 Comment Valid Data Valid Data DST R2 R4/R3 1 Value2 R2 R3MEM(R4+50) Value3 R3 R1  R2 / R3 xxx R1 R2  R4 + R3 R3  R2 – R3 RB2RB0/RB1 RB4RB3-RB1 W Execute Retire (WB)

Instruction Q Cycle 7 ROB Execute Retire (WB) RAT R3R2-R3 RB2 R3MEM(R4+50) R2  R4/R3 R1 R2 R3 R4 RB2 RB3 RB4 RF4 RS MOB ROB Comment Valid Data Valid Data DST R2 R4/R3 1 Value2 R2 R3MEM(r4+50) Value3 R3 R1  R2 / R3 xxx R1 R2  R4 + R3 R3  R2 – R3 R2 RB0 R3 RB1 RB4RB3-RB1 RB3 R4+RB1 1 Value4 RB2 RB0/RB1 (1) Execute (2) Retire (WB)

Instruction Q Cycle 8 ROB Execute Retire (WB) RAT R3R2-R3 RB2 R3MEM(R4+50) R2  R4/R3 R1 R2 R3 R4 RB2 RB3 RB4 RF4 RS MOB ROB Comment Valid Data Valid Data DST R2 R4/R3 R3MEM(R4+50) R1  R2 / R3 1 xxx R1 R2  R4 + R3 Value4 R2 R3  R2 – R3 R3 RB2 RB0/RB1 (3) Execute 1 Value5 RB4RB3-RB1 Retire (WB)

Instruction Q Cycle 9 ROB Execute Retire (WB) RAT R3R2-R3 RB2 R3MEM(R4+50) R2  R4/R3 R1 R2 R3 R4 RB2 RB3 RB4 RF4 RS MOB ROB Comment Valid Data Valid Data DST R2 R4/R3 R3MEM(R4+50) R1  R2 / R3 1 xxx R1 R2  R4 + R3 Value4 R2 R3  R2 – R3 Value5 R3 RB2 RB0/RB1 (3) (4) Execute Retire (WB)

Instruction Q Cycle 10 ROB Execute Retire (WB) RAT R3R2-R3 RB2 R3MEM(R4+50) R2  R4/R3 R1 R2 R3 R4 RB2 RB3 RB4 RF4 RS MOB ROB Comment Valid Data Valid Data DST R2 R4/R3 R3MEM(R4+50) R1  R2 / R3 1 xxx R1 R2  R4 + R3 Value4 R2 R3  R2 – R3 Value5 R3 1 Value6 RB2 RB0/RB1 (4) Execute Retire (WB)

Instruction Q Cycle 11 ROB Execute Retire (WB) RAT R3R2-R3 R2R4+R3 R3MEM(R4+50) R2  R4/R3 R1 R2 R3 R4 RF4 RS MOB ROB Comment Valid Data Valid Data DST R2 R4/R3 R3MEM(R4+50) R1  R2 / R3 1 Value6 R1 R2  R4 + R3 Value4 R2 R3  R2 – R3 Value5 R3 R1RB2 R2RB3 Execute R3RB4 Retire (WB)

Instruction Q Cycle 12 ROB Execute Retire (WB) RAT R3R2-R3 RF1 R3MEM(R4+50) R2  R4/R3 R1 R2 R3 R4 RF1 RF2 RF3 RF4 RS MOB ROB Comment Valid Data Valid Data DST R2 R4/R3 R3MEM(R4+50) R1  R2 / R3 R2  R4 + R3 R3  R2 – R3 Execute Retire (WB)