Memory consistency Flashcards
What is memory consistency?
A problem that occurs between different programs when you have multiple cores active.
A contract between the programmer and the hardware.
Is a set of rules that dictates how observable memory operations are performed. This means, that when you have designed a program, how does it translate to actual memory execution.
The programmer must be aware of this set of rules when creating programs.
Hardware designers must also follow these rules when designing out-of-order cores.
Consistency is NOT optional, and is not an optimisation feature.
Consistency models are NOT the same between different ISAs, meaning it is an inate part of the ISA and dictates how a program can e restructured during execution.
What is the difference between cache coherence and memory consistency?
Memory consistency is a different multi-core problem, whereas coherence deals with making sure the memory has the correct value.
Consistency is NOT optional, and is not an optimisation feature.
Who must follow the memory consistency rules?
Hardware designers when designing ooo cores
Programmers when creating programs
Why is memory consistency needed?
Ensures we have synchronisation between programs executing in parallel. When programs are executing across cores, we do not know exactly when things are happening. Memory consistency helps avoiding problems such as race conditions.
Ensures ability to execute atomic operations.
What would happen to programs if we did not have memory consistency?
Programs would suffer from race conditions more, and ambiguity.
What is observability in memory systems?
When executing a program on a core in a multicore system, some memory operations will be visible to other threads.
What memory operations are visable?
Shared cache line:
- readings from the cache line is visable
All writes are visible as it changes memory values. Even if it is not in a cache line that is shared.
What difference in the goals of a SW and HW designer?
A SW designer wants to write programs that are correct and optimised. A typical optimisation is introducing parallelism, which comes with new problem areas.
A HW designer wants to execute memory operations when these are ready, but not necessarily in order (long latency, etc.). This means that memory operations might not execute in the program code order.
What is memory order?
Order of executed observable memory operations in the actual core.
What is program order?
Order of instructions as they appear in the machine code.
Defines the programmers intention for program execution/purpose. This means that if a programmer puts a load before a write, they expect the load to happen before the write.
What limits the reordering of memory operations?
Consistency rules and ready instructions.
An instruction will execute when it is ready, if it is legal according to the consistency rules.
What is the Sequential Consistency model (SC)
The baseline
Memory operations are performed in program order.
When having multiple processes, these are ordered in respect to each other - in some arbitrary order.
Within a program, all operations are executed in order. And all programs are ordered in regards to each other, in some arbitrary order.
No processes are performing memory operations at the same time.
Only one valid ordering (translation from program to execution order), when considering a single program/thread. And that is the program order.
What is sequential consistency at a local level?
Every operation executes as ordered in the program code
What is sequential consistency at a global level?
There are some ordering of processes in regards to each other
How can you quickly define a memory consistency model?
The translation from program order to execution order.
What are ordering rules?
When talking about consistency models, we have the 4 following rules:
Read followed by read
Read followed by write
Write followed by read
Write followed by write
Notation:
R0, R1: 0 - first operation, 1 - second operation
<p: Before in program order
<m: Before in memory order
What are ordering rules for sequential consistency?
R0 <p R1 -> R0 <m R1
R0 <p W0 -> R0 <m W0
W0 <p R0 -> W0 <m R0
W0 <p W1 -> W0 <m W1
No reordering of execution. A rule says observable operations must happen in program order.
Why is talking about SC important?
It is trivial ti implement
- all mem-ops are in program order
- all updates become fully visable before a value is read
Very intuitiv, it does what the programmer “expects” will happen
Very low performance - very limited when we can execute mem-ops. Not just when they are ready.