Docsity

Instruction Scheduling, Exams of Operating Systems

Partial preview of the text

Download Instruction Scheduling and more Exams Operating Systems in PDF only on Docsity!

Dynamic Instruction Scheduling

PD-MIRIRamon Canal

Dynamic vs. Static Scheduling • Data hazards in a program cause a processor to stall. • With static scheduling the compiler tries to reorderthese instructions during compile time to reducepipeline stalls. – Uses less hardware – Can use more powerful algorithms • With dynamic scheduling the hardware tries torearrange the instructions during run-time to reducepipeline stalls. – Simpler compiler – Handles dependencies not known at compile time – Allows code compiled for a different machine to run efficiently.

Scoreboarding

•^ The scoreboard implements a centralizedcontrol scheme that^ –^ Detects all resource and data hazards^ –^ Allows instructions to execute out-of-order when noresource hazards or data dependencies •^ First implemented in 1964 by the CDC 6600,which had 18 separate functional units^ –^ 4 FP units (2 multiply, 1 add, 1 divide)^ –^ 7 memory units (5 loads, 2 stores)^ –^ 7 integer units (add, shift, logical, compare, etc.) •^ Our dynamic pipeline (much simpler)^ –^ 2 FP multiply (10 EX cycles)^ –^ 1 FP add (2 EX cycles)^ –^ 1 FP divide (40 EX cycles)^ –^ 1 integer unit (1 EX cycle)

Out-of-Order Execution

•^ Out-of-order execution divides DR stage into:1. Issue—decode instructions, check for structural hazards2. Read operands—wait until no data hazards, then read operands •^ Scoreboards allow instruction to execute whenever1 & 2 hold, not waiting for prior instructions •^ CDC 6600:

In order issue

, out of order execution, out

of order commit (also called completion)

Four Stages of Scoreboard Control^ •^ Decode+Issue (Issue)^ –^ decode instructions^ –^ check for structural and WAW hazards^ –^ stall until structural and WAW hazards are resolved^ •^ Read operands (Read)^ –^ wait until no RAW hazards^ –^ then read operands^ •^ Execution (EX)^ –^ operate on operands^ –^ may be multiple cycles - notify scoreboard when done^ •^ Write result (WB)^ –^ finish execution^ –^ stall if WAR hazard

Three Parts of the Scoreboard1. Instruction status—which of 4 steps the instruction is in:Issue, Read, EX, or WB.2. Functional unit status—Indicates the state of thefunctional unit (FU). 9 fields for each functional unitBusy—Indicates whether the unit is busy or notOp—Operation to perform in the unit (e.g., + or –)Fi—Destination registerFj, Fk—Source-register numbersQj, Qk—Functional units producing source registers Fj, FkRj, Rk—Flags indicating when Fj, Fk are ready3. Register result status—Indicates which functional unitwill write each register, if one exists. Blank when nopending instructions will write that register

Scoreboarding Example Cycle 1 Instruction status^

Operand Execution

Write

Instruction^

j^ k^ Issue

start -complete Read

Result

LD^ F^

34+^ R^

LD^ F^

45+^ R

MULTD^ F^

F2^ F

SUBD^ F^

F6^ F

DIVD^ F

F0^ F

ADDD^ F^

F8^ F

Functional Unit Status^ Time Name

Busy^ Op

Fi^

Fj^ Fk^

Qj^ Qk^

Rj^ Rk

0 Integer^ Yes

Load^ F

R^

Yes

0 Mult1^ No Mult2^ No 0 Add^ No 0 Divide^ No Register result statusClock^

F0^ F^

F4^ F^

F8^ F^

F12^ ...^ F

FU^

Integer

Scoreboarding Example Cycle 2 Instruction status^

Operand Execution

Write

Instruction^

j^ k^ Issue

start -complete Read

Result

LD^ F^

34+^ R^

LD^ F^

45+^ R

MULTD^ F^

F2^ F

SUBD^ F^

F6^ F

DIVD^ F

F0^ F

ADDD^ F^

F8^ F

Functional Unit Status^ Time Name

Busy^ Op

Fi^

Fj^ Fk^

Qj^ Qk^

Rj^ Rk

0 Integer^ Yes

Load^ F

R^

Yes

0 Mult1^ No Mult2^ No 0 Add^ No 0 Divide^ No Register result statusClock^

F0^ F^

F4^ F^

F8^ F^

F12^ ...^ F

FU^

Integer

Issue 2nd Load?

Scoreboarding Example Cycle 4 Instruction status^

Operand Execution

Write

Instruction^

j^ k^ Issue

start -complete Read

Result

LD^ F^

34+^ R^

3 -- 3^4

LD^ F^

45+^ R

MULTD^ F^

F2^ F

SUBD^ F^

F6^ F

DIVD^ F

F0^ F

ADDD^ F^

F8^ F

Functional Unit Status^ Time Name

Busy^ Op

Fi^

Fj^ Fk^

Qj^ Qk^

Rj^ Rk

0 Integer^ Yes

Load^ F

R^

Yes

0 Mult1^ No Mult2^ No 0 Add^ No 0 Divide^ No Register result statusClock^

F0^ F^

F4^ F^

F8^ F^

F12^ ...^ F

FU^

Integer

Scoreboarding Example Cycle 5 Instruction status^

Operand Execution

Write

Instruction^

j^ k^ Issue

start -complete Read

Result

LD^ F^

34+^ R^

3 -- 3^4

LD^ F^

45+^ R^

MULTD^ F^

F2^ F

SUBD^ F^

F6^ F

DIVD^ F

F0^ F

ADDD^ F^

F8^ F

Functional Unit Status^ Time Name

Busy^ Op

Fi^

Fj^ Fk^

Qj^ Qk^

Rj^ Rk

0 Integer^ Yes

Load^ F

R^

Yes

0 Mult1^ No Mult2^ No 0 Add^ No 0 Divide^ No Register result statusClock^

F0^ F^

F4^ F^

F8^ F^

F12^ ...^ F

FU^

Integer

Scoreboarding Example Cycle 7 Instruction status^

Operand Execution

Write

Instruction^

j^ k^ Issue

start -complete Read

Result

LD^ F^

34+^ R^

3 -- 3^4

LD^ F^

45+^ R^

MULTD^ F^

F2^ F^

SUBD^ F^

F6^ F^

DIVD^ F

F0^ F

ADDD^ F^

F8^ F

Functional Unit Status^ Time Name

Busy^ Op

Fi^

Fj^ Fk^

Qj^ Qk^

Rj^ Rk

0 Integer^ Yes

Load^ F

R^

Yes

0 Mult1^ Yes

Mult^ F

F^

F4^ integer

No

Yes

Mult2^ No 0 Add^ Yes^

Sub^ F^

F6^ F^

integer^ Yes

No

0 Divide^ No Register result statusClock^

F0^ F^

F4^ F^

F8^ F^

F12^ ...^ F

FU^ Mult1 Integer

Add

Scoreboarding Example Cycle 8 Instruction status^

Operand Execution

Write

Instruction^

j^ k^ Issue

start -complete Read

Result

LD^ F^

34+^ R^

3 -- 3^4

LD^ F^

45+^ R^

7 -- 7^8

MULTD^ F^

F2^ F^

SUBD^ F^

F6^ F^

DIVD^ F

F0^ F

ADDD^ F^

F8^ F

Functional Unit Status^ Time Name

Busy^ Op

Fi^

Fj^ Fk^

Qj^ Qk^

Rj^ Rk

0 Integer^ Yes

Ld^ F

R^

Yes

0 Mult1^ Yes

Mult^ F

F^

F4^ integer

No

Yes

Mult2^ No 0 Add^ Yes^

Sub^ F^

F6^ F^

integer^ Yes

No

0 Divide^ Yes

Div^ F

F^

F6^ mult^

No^ Yes

Register result statusClock^

F0^ F^

F4^ F^

F8^ F^

F12^ ...^ F

FU^ Mult1 Integer

Add^ Divide

Scoreboarding Example Cycle 10 Instruction status^

Operand Execution

Write

Instruction^

j^ k^ Issue

start -complete Read

Result

LD^ F^

34+^ R^

3 -- 3^4

LD^ F^

45+^ R^

7 -- 7^8

MULTD^ F^

F2^ F^

SUBD^ F^

F6^ F^

DIVD^ F

F0^ F

ADDD^ F^

F8^ F

Functional Unit Status^ Time Name

Busy^ Op

Fi^

Fj^ Fk^

Qj^ Qk^

Rj^ Rk

0 Integer^ No 9 Mult1^ Yes

Mult^ F

F^

F^

Yes^ Yes

Mult2^ No 1 Add^ Yes^

Sub^ F^

F6^ F^

Yes^ Yes

0 Divide^ Yes

Div^ F

F^

F6^ mult^

No^ Yes

Register result statusClock^

F0^ F^

F4^ F^

F8^ F^

F12^ ...^ F

FU^ Mult^

Add^ Divide

Scoreboarding Example Cycle 11 Instruction status^

Operand Execution

Write

Instruction^

j^ k^ Issue

start -complete Read

Result

LD^ F^

34+^ R^

3 -- 3^4

LD^ F^

45+^ R^

7 -- 7^8

MULTD^ F^

F2^ F^

SUBD^ F^

F6^ F^

DIVD^ F

F0^ F

ADDD^ F^

F8^ F

Functional Unit Status^ Time Name

Busy^ Op

Fi^

Fj^ Fk^

Qj^ Qk^

Rj^ Rk

0 Integer^ No 8 Mult1^ Yes

Mult^ F

F^

F^

Yes^ Yes

Mult2^ No 0 Add^ Yes^

Sub^ F^

F6^ F^

Yes^ Yes

0 Divide^ Yes

Div^ F

F^

F6^ mult^

No^ Yes

Register result statusClock^

F0^ F^

F4^ F^

F8^ F^

F12^ ...^ F

FU^ Mult^

Add^ Divide