5.3.14 · D4Advanced Microarchitecture

Exercises — Simultaneous multithreading (SMT - hyperthreading)

2,579 words12 min readBack to topic

This page is a self-test. Each problem states its level (L1 → L5). Read the problem, try it on paper, THEN open the collapsible solution. Every number you compute is machine-checked in the vault's verify pass, so trust the arithmetic here.

Before we start, let us pin down the only three ideas every problem uses. If you have not read the parent note, read it first — but here is the minimal toolkit, rebuilt from zero.

Look at the figure below before starting — it is the mental model for every SMT timing problem on this page.

Figure — Simultaneous multithreading (SMT - hyperthreading)

The four vertical lanes are the four execution units. A filled box means "busy this cycle", a hollow box means "idle — a wasted slot". The left panel is a single thread (many hollow boxes); the right panel turns on SMT (a second thread colours those boxes). SMT's whole job is to colour hollow boxes with a second thread's work.


Level 1 — Recognition

Exercise 1.1

A core has execution units and a single thread runs at . What is the execution-unit utilization?

Recall Solution

What we do: divide the busy units by the total units. Why: utilization is the fraction of the units in use, and IPC already tells us the average number busy. Look at figure s01, left panel: on average only of lanes are filled — the rest are the hollow, wasted boxes.

Exercise 1.2

Which of these is duplicated per hardware thread in an SMT core, and which is shared? (a) Program Counter, (b) the ALUs, (c) the L1 cache, (d) the architectural register file.

Recall Solution

Rule: duplicate what is cheap and per-thread state (a few registers), share what is big and expensive (the compute machinery).

  • (a) Program Counter — duplicated (each thread needs its own "where am I" pointer).
  • (b) ALUs — shared (this is the whole point: fill their idle slots).
  • (c) L1 cache — shared (big SRAM, too costly to copy).
  • (d) architectural register file — duplicated (each thread's variables must survive independently).

Exercise 1.3

State in one sentence what SMT improves: single-thread latency (time for one task) or system throughput (tasks per second)?

Recall Solution

Throughput. SMT fills idle execution slots with a second thread, so more total work finishes per second. It does not make any single task faster — in fact one thread often slows slightly from contention.


Level 2 — Application

Exercise 2.1

A thread must retire instructions at . How many cycles does it take?

Recall Solution

Why divide: rate is instructions per cycle; to get cycles you flip it — cycles per instruction instructions.

Exercise 2.2

Turn on 2-way SMT. Now thread A runs at and thread B at simultaneously. On a 4-unit core, what is the combined throughput and the new utilization?

Recall Solution

Throughput (rates add — same cycle, same units): Utilization: Compare to the single-thread from Ex 1.1 — the second thread coloured in many previously-hollow boxes (figure s01, right panel).

Exercise 2.3

Using Ex 2.1 and 2.2, compute the throughput speedup of 2-way SMT over the single thread.

Recall Solution

Old work-rate: one thread at IPC instructions/cycle. New work-rate: two threads instructions/cycle. Why not ? Each thread dropped from to because they now share caches, the reorder buffer, and TLB — contention costs. So , not .


Level 3 — Analysis

Exercise 3.1 (Amdahl for SMT)

A workload spends fraction of its cycles memory-bound (execution units idle, waiting on DRAM). Using the SMT model where a second thread fills the idle half of those cycles, compute the speedup. Then explain why the term appears.

Recall Solution

Plug in: Why gets no help: during the CPU-bound fraction the units are already saturated — no idle slots for the second thread to steal, so that time is unchanged (coefficient ). Why , not : during memory-bound cycles the second thread fills in, but conservatively we assume it only reaches about half the idle capacity (it too stalls, competes for the same starved memory system). So the memory-bound time shrinks from to .

Exercise 3.2 (Two complementary threads)

Thread A is CPU-bound: without SMT, , needs instr. Thread B is memory-bound: without SMT, , needs instr. They are run one after the other (sequential). Total cycles?

Recall Solution

Exercise 3.3

Now run A and B together with SMT. Contention shifts them to , (A slows a little, B speeds up a little because it "borrows" A's momentum). Both start together; when does the whole job (both threads done) finish? Compute the speedup vs Ex 3.2.

Recall Solution

Each thread's finish time: Job done when the slower one finishes: Speedup: What it looks like (figure s02): B's long memory stalls are hollow boxes; A's compute colours them in, so A finishes "for free" underneath B's wait. The long pole is B's memory latency, but the idle time now does useful A-work.


Level 4 — Synthesis

Exercise 4.1 (Two CPU-bound threads — the hard case)

Both threads are pure integer arithmetic (they fight for the same ALUs). Alone, each runs at for instructions. Under SMT, contention drops each to . (a) Sequential total time? (b) SMT finish time? (c) Speedup? (d) In one sentence, why is the gain so small?

Recall Solution

(a) Sequential: (b) SMT (both at , run together, take the max — but they are symmetric): (c) Speedup: (d) Why so small: both are CPU-bound, so there are almost no idle slots to fill — the units were already near-saturated. SMT can only donate idle capacity, and there is little here. Contrast Ex 3.3's , where B's stalls left huge gaps.

Exercise 4.2 (Choosing a co-runner)

You have one free SMT slot next to a CPU-bound thread (units nearly saturated). Two candidate co-runners:

  • P: memory-bound, stalls 70% of cycles.
  • Q: another CPU-bound thread. Which yields more system throughput, and why? Reference figure s01.
Recall Solution

Choose P (the memory-bound thread). Reasoning tied to the model: the resident CPU-bound thread already fills most lanes when it runs — but it doesn't run every cycle if it, too, occasionally stalls, and even a saturated thread leaves scattered hollow boxes. A memory-bound co-runner has complementary needs: it barely touches the ALUs (it's waiting on DRAM), so it slots into the hollow boxes without a fight. Q, being CPU-bound, wants the exact same ALUs — a head-on collision (this is Ex 4.1's situation). Lesson: SMT rewards complementary resource profiles.


Level 5 — Mastery

Exercise 5.1 (Design a break-even threshold)

Using the Amdahl-SMT model , find the memory-bound fraction at which SMT gives exactly a speedup. Show the algebra.

Recall Solution

Set the model equal to the target: Simplify the denominator: . So Interpretation: you need at least of cycles memory-bound before SMT reaches a throughput gain under this conservative model. Below that, gains fade toward .

Exercise 5.2 (The model's ceiling, and why the "fill half" assumption caps it)

In the same model , take the limit as (an entirely memory-bound workload) to find the model's maximum speedup. Then explain within the model itself why that ceiling exists — i.e. which assumption in the formula prevents the speedup from ever exceeding it, even as .

Recall Solution

Take the limit : So the model's ceiling is exactly , reached only in the idealised all-memory-bound limit. Why the model caps at (not higher): look at the denominator term . The "" is the fill-half assumption — even in a fully idle stretch, the model lets the second thread reclaim only half the idle time, so memory-bound time shrinks from to , never to . If instead we assumed the second thread reclaimed all idle time ( in the denominator), the limit would be . It is precisely the conservative factor — the model's built-in acknowledgement that the second thread also stalls and competes — that pins the ceiling at . (Real hardware lands below even this, at , because the shared cache, ROB, and TLB add contention the model does not include.)

Exercise 5.3 (Full pipeline reasoning)

Two threads share the core. Thread A suffers a branch misprediction (pipeline flush, ~15 idle cycles for A). Thread B is ready with independent instructions. Explain, cycle-by-cycle in words and referencing figure s02, what SMT does with A's 15 flush cycles — and name the two shared structures (from the predictor / memory families) that could reduce this benefit.

Recall Solution

Cycle-by-cycle:

  1. A mispredicts → its in-flight wrong-path instructions are squashed; A has nothing ready for ~15 cycles while the correct path refetches.
  2. Without SMT, those 15 cycles are pure hollow boxes (figure s02, the same hollow-slot pattern as B's memory stalls) — wasted.
  3. With SMT, the scheduler's ready-queue still holds B's instructions. Each of those 15 cycles, it issues from B, colouring the lanes A abandoned.
  4. When A's correct path arrives, A rejoins the ready-queue and the two interleave again.

The two shared structures that erode the gain:

  • Shared branch predictor — B's branches and A's branches update one predictor's history/tables; inter-thread interference (aliasing) can make both mispredict more, so A's flushes become more frequent in the first place.
  • Shared cache / TLB (Memory Hierarchy) — B running during A's flush pulls in B's data, potentially evicting A's working set, so when A returns it faces fresh cache misses. The stolen slots were free, but the cache pollution imposes a delayed cost on A.

Net: SMT reclaims A's 15 flush cycles as useful B-work (the win), but the shared predictor and shared cache/TLB can quietly raise both threads' miss and mispredict rates (the tax). The gain is real but bounded — exactly the story of the whole page.


Recall One-line takeaways (self-quiz)

Time from work and rate ::: . Why SMT speedup is under 2x ::: threads share caches, ROB, TLB → contention lowers each thread's IPC. Parallel finish time of two threads ::: , not the sum. Which threads pair best under SMT ::: complementary resource needs (CPU-bound + memory-bound). Amdahl-SMT model ::: , ceiling as .