---
title: Problem set 10
heading: "Problem set 10: coherence, consistency and parallel programs"
eyebrow: S4 · Problem set 10
type: problems
---

::: hook
These problems use lessons 2, 31 to 34 and 49: parallel speedup, snooping and directory coherence, on-chip networks, consistency and synchronization, and the MESI coherence project. They follow parallel programs from their speedup limits down to the messages and misses that set them.
:::

::: pool
pick: 12

::: check
kind: parts
given: W = 64 | 128 | 256; f = 2 | 3; i = 1 | 2; m = 0.001 | 0.005; B = 64 | 128

## A snooping bus moves {W} GB/s; cores run at {f} GHz and IPC {i}, each making {m} bus misses per instruction with {B}-byte lines.

::: part
answer: W/(f*i*m*B)
unit: cores
tolerance: 0.5%

### How many cores can it support?

::: misses
- [any] Bus bandwidth over each core's traffic.
:::
:::
:::

::: check
kind: parts
given: n = 100 | 1000 | 10000

## A thread reads and then writes {n} lines that no other core holds.

::: part
answer: 2*n
unit: transactions
tolerance: 0

### How many bus transactions does MSI need?

::: misses
- [any] A BusRd to read, then a BusUpgr to write, per line.
:::
:::

::: part
answer: n
unit: transactions
tolerance: 0

### And MESI?

::: misses
- [any] The read brings the line in E, and the write is silent.
:::
:::
:::

::: check
kind: parts
given: N = 8 | 64; c = 4 | 8

## {N} threads each update their own {c}-byte counter.

::: part
answer: 64/c
unit: counters
tolerance: 0

### How many counters share each line when packed?

::: misses
- [any] Line size over counter size.
:::
:::

::: part
answer: N*64
unit: bytes
tolerance: 0

### How much memory do the counters take when padded to a line each?

::: misses
- [any] One line per thread.
:::
:::
:::

::: check
kind: parts
given: N = 64 | 256 | 1024; B = 64 | 128; p = 4 | 8

## A directory serves {N} cores with {B}-byte lines.

::: part
answer: N/(8*B)*100
unit: %
tolerance: 0.5%

### What does a full bit vector add to memory?

::: misses
- [any] $N/(8B)$.
:::
:::

::: part
answer: p*ceil(log(N)/log(2) - 1e-9)/(8*B)*100
unit: %
tolerance: 0.5%

### And {p} limited pointers?

::: misses
- [any] $p\lceil\log_2N\rceil$ bits per line.
:::
:::
:::

::: check
kind: parts
given: s = 3 | 15 | 63

## A core writes a line shared by {s} other caches, on a directory protocol.

::: part
answer: s
unit: messages
tolerance: 0

### How many invalidations does the home send?

::: misses
- [any] One per sharer.
:::
:::

::: part
answer: 2*s + 2
unit: messages
tolerance: 0

### How many messages in all, counting the request, acknowledgments and the reply?

::: misses
- [any] $2s + 2$.
:::
:::
:::

::: check
kind: parts
given: k = 4 | 8 | 16; t = 2 | 5; o = 5 | 20; m = 2 | 3

## A directory miss has {m} critical-path messages on a {k} × {k} mesh, each crossing the average distance at {t} ns per hop plus {o} ns of overhead.

::: part
answer: m*(2*k/3*t + o)
unit: ns
tolerance: 0.5%

### What is its latency?

::: misses
- [any] Messages × (hops × per hop + overhead).
:::
:::
:::

::: check
kind: parts
given: c = 0.01 | 0.05 | 0.1; N = 8 | 32 | 128

## {N} threads each spend {c} of their time holding one lock.

::: part
answer: 1/c
tolerance: 0.5%

### What is the most throughput, in threads' worth, the lock allows?

::: misses
- [any] $1/c$.
:::
:::

::: part
answer: 1/((1 - c)/N + c)
tolerance: 0.5%

### What speedup does Amdahl's law give, treating the critical section as serial?

::: misses
- [any] $1/((1 - c)/N + c)$.
:::
:::
:::

::: check
kind: parts
given: N = 8 | 32 | 128

## {N} cores take turns with a lock until each has held it once.

::: part
answer: N*(N - 1)
unit: transactions
tolerance: 0

### How many does a test-and-test-and-set lock take?

::: misses
- [any] Two per waiter per handoff.
:::
:::

::: part
answer: N*(N - 1)/2
unit: misses
tolerance: 0

### And a ticket lock?

::: misses
- [any] One per waiter per handoff.
:::
:::

::: part
answer: N - 1
unit: transfers
tolerance: 0

### And an MCS lock?

::: misses
- [any] One per handoff.
:::
:::
:::

::: check
kind: parts
given: N = 64 | 1024 | 4096; k = 2 | 4 | 16; t = 40 | 80; a = 20 | 40

## {N} threads meet at a barrier: a tree of fan-in {k} at {t} ns per level, or a centralized counter at {a} ns per atomic.

::: part
answer: ceil(log(N)/log(k) - 1e-9)*t
unit: ns
tolerance: 0.5%

### How long does the tree take?

::: misses
- [any] Levels × time per level.
:::
:::

::: part
answer: N*a
unit: ns
tolerance: 0.5%

### And the counter?

::: misses
- [any] N serialized atomics.
:::
:::
:::

::: check
kind: parts
given: N = 16 | 64 | 256; p = 0.9 | 0.99

## A program's parallel fraction, measured on {N} processors, is {p}.

::: part
answer: N - (1 - p)*(N - 1)
tolerance: 0.5%

### What scaled speedup does Gustafson's law give?

::: misses
- [any] $N - (1 - p)(N - 1)$.
:::
:::

::: part
answer: 1/((1 - p) + p/N)
tolerance: 0.5%

### And what fixed-size speedup would Amdahl's law give, if p were the single-processor fraction?

::: misses
- [any] $1/((1 - p) + p/N)$.
:::
:::
:::

::: check
kind: parts
given: s = 0.05 | 0.1 | 0.2; d = 10 | 30; i = 1 | 3; f = 2 | 4

## A core at {f} GHz and IPC {i} issues stores as {s} of its instructions; each store waits {d} cycles in the store buffer before it drains.

::: part
answer: s*i*d
unit: entries
tolerance: 0.5%

### How many store-buffer entries are occupied on average?

::: misses
- [any] Little's law: store rate per cycle × time in the buffer.
:::
:::
:::

::: check
kind: parts
given: F = 1e5 | 1e6 | 1e7; c = 20 | 50 | 100

## A program executes {F} fences a second, each draining the store buffer for {c} ns.

::: part
answer: F*c*1e-9*100
unit: %
tolerance: 0.5%

### What fraction of the time do fences cost?

::: misses
- [any] Fences per second × cost.
:::
:::
:::

::: check
kind: parts
given: p = 0.3 | 0.6 | 0.9

## Under contention, a load-reserved/store-conditional pair succeeds with probability {p} per attempt.

::: part
answer: 1/p
unit: attempts
tolerance: 0.5%

### How many attempts does an update take on average?

::: misses
- [any] Geometric distribution: $1/p$.
:::
:::

::: part
answer: (1 - p)^3*100
unit: %
tolerance: 0.5%

### What fraction of updates need more than three attempts?

::: misses
- [any] Three failures in a row.
:::
:::
:::

::: check
kind: parts
given: k = 0.5 | 2 | 5; L = 80 | 200; c = 0.6 | 1

## A parallel program suffers {k} coherence misses per thousand instructions, each costing {L} cycles, on cores whose CPI is otherwise {c}.

::: part
answer: k/1000*L
tolerance: 0.5%

### What CPI do coherence misses add?

::: misses
- [any] Misses per instruction × latency.
:::
:::

::: part
answer: (k/1000*L)/(c + k/1000*L)*100
unit: %
tolerance: 0.5%

### What share of the time do they take?

::: misses
- [any] Their CPI over the total.
:::
:::
:::

::: check
kind: parts
given: n = 4 | 8 | 16; w = 100 | 1000

## In a MESI system, {n} cores each read a line, then one of them writes it {w} times with no other access in between.

::: part
answer: n - 1
unit: invalidations
tolerance: 0

### How many copies does the first write invalidate?

::: misses
- [any] Every other sharer.
:::
:::

::: part
answer: 0
unit: transactions
tolerance: 0

### How many bus transactions do the remaining writes need?

::: misses
- [any] The line is now in M: writes are silent.
:::
:::
:::
:::
