Pipelining Flashcards
What is a control hazard?
When a branch instruction changes the next instruction
What are the 4 ways to deal with a control hazard?
- stall the pipeline
- assume branch not taken
- branch prediction
- branch delay slots
What is stalling the pipeline?
When the CPU realises it is dealing with a branch instruction, stall the pipeline until we know what the next instruction is
What is assume branch not taken?
Assume the program didn’t take the branch and continue the pipeline as normal
What is branch prediction?
Same as branch not taken, however instead of always assuming the branch was not taken- we try to predict whether it will be based on previous branches
What is branch delay slots?
An instruction that follows a branch instruction that is useful and also independent of the result of the branch,. This will be executed until the program knows the result of the branch.
What is a data hazard?
A data hazard occurs when one instruction immediately uses the result of
another.
3 Types of data hazard
Read after write (RAW)
Write after read (WAR)
Write after write (WAW)
What is forwarding?
Required information is retrieved early from other pipeline register instead of the data register
How does spectre work?
Use speculative execution to access an array out of bounds and store a random value at the index of this value in a second array. Then access all the values and see which ones are accessed quickest. These will be the values that are stored in memory next to the array
How does meltdown work?
Similar to spectre, however instead of using a branch we raise an exception. Exceptions are slow and so the next instruction may still be evaluated under speculative execution.
Meltdown vs spectre
Spectre reads memory from other applications, whereas meltdown reads kernel memory from user space