Motivation
- Single cores have hit diminishing returns: there’s limited ILP to extract, out-of-order hardware grows in complexity, and the power wall stops clock speed increases.
- Moore’s law still gives more transistors each generation. The best use for them is multiple cores on one chip (CMPs).
Three problems come up as soon as cores share memory:
| Issue |
Question it answers |
| Cache coherence |
If several caches hold copies of the same block, how do they all see the latest value? |
| Synchronization |
How do threads get controlled, atomic access to shared data? |
| Memory consistency |
In what order do memory operations to different addresses become visible to other cores? |
Two ways to implement coherence:
- Snooping (bus-based SMPs): every cache watches a shared bus. Works for fewer than about 16 processors.
- Directory (scalable): a directory tracks who has each block. Works for many processors.
Flynn’s taxonomy
|
Single data stream |
Multiple data streams |
| Single instruction stream |
SISD: an ordinary uniprocessor |
SIMD: one instruction on many data elements (vector units, GPUs, SSE/AVX) |
| Multiple instruction streams |
MISD: rare (redundant systems, systolic arrays) |
MIMD: multiprocessors, each core runs its own instruction stream. This unit’s focus. |
Thread-level parallelism and shared memory
- Thread-level parallelism (TLP): independent tasks that don’t start or stop together, and that share data loosely and dynamically. Example: a web or database server where each query is a thread.
- Shared memory: all threads share one address space. That can mean different programs (MIMD), or more often many copies of one program (SPMD).
The running example: an ATM withdrawal.
accts is shared, so it lives in memory.
id and amt are private to each thread, kept in r1 and r2.
- The sequence is: load the balance, check it, subtract, store it back.
Why caches break correctness
Two $100 withdrawals hit the same account, which starts at $500, on two processors.