5.3.14 · D4 · HinglishAdvanced Microarchitecture

ExercisesSimultaneous multithreading (SMT - hyperthreading)

2,864 words13 min read↑ Read in English

5.3.14 · D4 · Hardware › Advanced Microarchitecture › Simultaneous multithreading (SMT - hyperthreading)

Yeh page ek self-test hai. Har problem apna level batati hai (L1 → L5). Problem padho, paper par try karo, TAB solution collapsible kholo. Jo bhi number tum compute karo woh vault ke verify pass mein machine-checked hain, isliye yahan ki arithmetic par trust karo.

Shuru karne se pehle, sirf teen ideas pin kar lete hain jo har problem use karti hai. Agar tumne parent note nahi padha, pehle woh padho — lekin yahan minimal toolkit hai, zero se rebuild kiya hua.

Shuru karne se pehle neeche wala figure dekho — yeh is page ke har SMT timing problem ka mental model hai.

Figure — Simultaneous multithreading (SMT - hyperthreading)

Chaar vertical lanes hain jo chaar execution units hain. Filled box ka matlab hai "is cycle mein busy", hollow box ka matlab hai "idle — ek wasted slot". Left panel mein single thread hai (bahut saare hollow boxes); right panel mein SMT on hai (ek doosra thread un boxes ko colour karta hai). SMT ka poora kaam hai hollow boxes ko doosre thread ke kaam se colour karna.


Level 1 — Recognition

Exercise 1.1

Ek core mein execution units hain aur ek single thread par run karta hai. Execution-unit utilization kya hai?

Recall Solution

Hum kya karte hain: busy units ko total units se divide karo. Kyun: utilization units ka woh fraction hai jo use mein hai, aur IPC already hume average busy number bata deta hai. Figure s01 ka left panel dekho: average mein sirf of lanes filled hain — baaki hollow, wasted boxes hain.

Exercise 1.2

Inme se kaun sa ek SMT core mein har hardware thread ke liye duplicated hai, aur kaun sa shared hai? (a) Program Counter, (b) ALUs, (c) L1 cache, (d) architectural register file.

Recall Solution

Rule: jo sasta aur per-thread state ho use duplicate karo (kuch registers), jo bada aur expensive ho use share karo (compute machinery).

  • (a) Program Counter — duplicated (har thread ko apna "main kahan hoon" pointer chahiye).
  • (b) ALUs — shared (yahi toh poora point hai: unke idle slots bharo).
  • (c) L1 cache — shared (badi SRAM, copy karna bahut costly hai).
  • (d) architectural register file — duplicated (har thread ke variables independent rehne chahiye).

Exercise 1.3

Ek sentence mein batao ki SMT kya improve karta hai: single-thread latency (ek task ka time) ya system throughput (tasks per second)?

Recall Solution

Throughput. SMT idle execution slots ko doosre thread se bharta hai, isliye har second mein zyada total kaam finish hota hai. Yeh kisi bhi single task ko faster nahi banata — actually ek thread aksar contention ki wajah se thoda slow ho jaata hai.


Level 2 — Application

Exercise 2.1

Ek thread ko instructions par retire karni hain. Kitne cycles lagte hain?

Recall Solution

Kyun divide karte hain: rate instructions per cycle hai; cycles pane ke liye isko flip karo — cycles per instruction instructions.

Exercise 2.2

2-way SMT on karo. Ab thread A par aur thread B par simultaneously run karte hain. 4-unit core par combined throughput aur naya utilization kya hai?

Recall Solution

Throughput (rates add hoti hain — same cycle, same units): Utilization: Ex 1.1 ke single-thread se compare karo — doosre thread ne bahut saare pehle-hollow boxes colour kar diye (figure s01, right panel).

Exercise 2.3

Ex 2.1 aur 2.2 use karke, single thread ke upar 2-way SMT ka throughput speedup compute karo.

Recall Solution

Old work-rate: ek thread IPC par instructions/cycle. New work-rate: do threads instructions/cycle. kyun nahi? Har thread se par aa gaya kyunki ab woh caches, reorder buffer, aur TLB share karte hain — contention cost hai. Isliye , na ki .


Level 3 — Analysis

Exercise 3.1 (Amdahl for SMT)

Ek workload apne fraction cycles memory-bound mein spend karta hai (execution units idle hain, DRAM ka wait kar rahe hain). SMT model use karke jahan doosra thread un cycles ka idle half bharta hai, speedup compute karo. Phir explain karo kyun term aata hai.

Recall Solution

Plug in karo: ko kyun help nahi milti: CPU-bound fraction ke dauran units already saturated hain — doosre thread ke liye koi idle slots nahi hain, isliye woh time unchanged hai (coefficient ). kyun, nahi: memory-bound cycles ke dauran doosra thread fill in karta hai, lekin conservatively hum assume karte hain ki woh sirf half idle capacity tak pahunchta hai (woh bhi stall karta hai, same starved memory system ke liye compete karta hai). Isliye memory-bound time se shrink hokar ho jaata hai.

Exercise 3.2 (Do complementary threads)

Thread A CPU-bound hai: SMT ke bina, , instr chahiye. Thread B memory-bound hai: SMT ke bina, , instr chahiye. Unhe ek ke baad ek (sequential) run kiya jaata hai. Total cycles?

Recall Solution

Exercise 3.3

Ab A aur B ko SMT ke saath ek saath run karo. Contention unhe , par shift kar deta hai (A thoda slow hota hai, B thoda speed up karta hai kyunki woh "A ki momentum borrow" karta hai). Dono saath shuru hote hain; poora kaam (dono threads done) kab finish hoga? Ex 3.2 ke versus speedup compute karo.

Recall Solution

Har thread ka finish time: Job tab done hota hai jab slow wala finish kare: Speedup: Yeh kaisa dikhta hai (figure s02): B ke lambe memory stalls hollow boxes hain; A ka compute unhe colour in karta hai, isliye A "free mein" B ke wait ke neeche finish ho jaata hai. Lamba pole B ki memory latency hai, lekin idle time ab A ka useful kaam karta hai.


Level 4 — Synthesis

Exercise 4.1 (Do CPU-bound threads — mushkil case)

Dono threads pure integer arithmetic hain (woh same ALUs ke liye ladte hain). Akele, har ek instructions ke liye par run karta hai. SMT ke under, contention har ek ko par le aata hai. (a) Sequential total time? (b) SMT finish time? (c) Speedup? (d) Ek sentence mein, gain itna chhota kyun hai?

Recall Solution

(a) Sequential: (b) SMT (dono par, saath run karo, max lo — lekin woh symmetric hain): (c) Speedup: (d) Itna chhota kyun: dono CPU-bound hain, isliye fill karne ke liye almost koi idle slots nahi hain — units already near-saturated thay. SMT sirf idle capacity donate kar sakta hai, aur yahan woh bahut kam hai. Ex 3.3 ke se compare karo, jahan B ke stalls ne bade gaps chhode.

Exercise 4.2 (Ek co-runner choose karna)

Tumhare paas ek CPU-bound thread ke beside ek free SMT slot hai (units nearly saturated). Do candidate co-runners hain:

  • P: memory-bound, 70% cycles stall karta hai.
  • Q: ek aur CPU-bound thread. Kaun zyada system throughput deta hai, aur kyun? Figure s01 reference karo.
Recall Solution

P choose karo (memory-bound thread). Model se tied reasoning: resident CPU-bound thread zyaatar lanes fill karta hai jab woh run karta hai — lekin woh har cycle run nahi karta agar woh bhi kabhi kabhi stall kare, aur ek saturated thread bhi scattered hollow boxes chhod jaata hai. Memory-bound co-runner ki complementary needs hain: woh ALUs ko barely touch karta hai (woh DRAM ka wait kar raha hai), isliye woh hollow boxes mein bina ladai ke fit ho jaata hai. Q, CPU-bound hone ki wajah se, exactly same ALUs chahiye — yeh seedha takkar hai (yeh Ex 4.1 ka situation hai). Lesson: SMT complementary resource profiles ko reward karta hai.


Level 5 — Mastery

Exercise 5.1 (Break-even threshold design karo)

Amdahl-SMT model use karke, woh memory-bound fraction nikalo jis par SMT exactly speedup deta hai. Algebra dikhao.

Recall Solution

Model ko target ke barabar set karo: Denominator simplify karo: . Toh Interpretation: is conservative model ke under SMT throughput gain reach karne ke liye tumhe kam se kam cycles memory-bound chahiye. Usse neeche, gains ki taraf fade ho jaate hain.

Exercise 5.2 (Model ki ceiling, aur kyun "fill half" assumption isko cap karti hai)

Same model mein, ki limit lo (completely memory-bound workload) aur model ki maximum speedup nikalo. Phir model ke andar hi explain karo kyun woh ceiling exist karti hai — yaani formula mein kaun sa assumption speedup ko kabhi bhi usse exceed karne se rokta hai, chahe ho.

Recall Solution

Limit lo : Toh model ki ceiling exactly hai, sirf idealized all-memory-bound limit mein reach hoti hai. Model par kyun cap hota hai (zyada nahi): denominator term dekho. "" fill-half assumption hai — even ek fully idle stretch mein, model doosre thread ko sirf half idle time reclaim karne deta hai, isliye memory-bound time se shrink hokar hota hai, kabhi nahi. Agar hum assume karte ki doosra thread sab idle time reclaim kar leta ( denominator mein), toh limit hoti. Yahi conservative factor — model ki built-in acknowledgement ki doosra thread bhi stall karta hai aur compete karta hai — ceiling ko par pin karta hai. (Real hardware to isse bhi neeche par aata hai, kyunki shared cache, ROB, aur TLB contention add karte hain jo model include nahi karta.)

Exercise 5.3 (Full pipeline reasoning)

Do threads core share karte hain. Thread A ko branch misprediction hoti hai (pipeline flush, A ke liye ~15 idle cycles). Thread B independent instructions ke saath ready hai. Words mein cycle-by-cycle explain karo, figure s02 reference karte hue, ki SMT A ke 15 flush cycles ke saath kya karta hai — aur do shared structures naam batao (predictor / memory families se) jo is benefit ko reduce kar sakti hain.

Recall Solution

Cycle-by-cycle:

  1. A mispredicts → uske in-flight wrong-path instructions squash hote hain; A ke paas ~15 cycles ke liye kuch ready nahi jab tak correct path refetch hota hai.
  2. SMT ke bina, woh 15 cycles pure hollow boxes hain (figure s02, B ke memory stalls jaisa same hollow-slot pattern) — wasted.
  3. SMT ke saath, scheduler ki ready-queue mein abhi bhi B ki instructions hain. Un 15 cycles mein se har ek mein, woh B se issue karta hai, un lanes ko colour karta hai jo A ne chhod diye.
  4. Jab A ka correct path aata hai, A ready-queue mein wapas join karta hai aur dono interleave karte hain.

Do shared structures jo gain ko erode karte hain:

  • Shared branch predictor — B ki branches aur A ki branches ek predictor ki history/tables update karti hain; inter-thread interference (aliasing) dono ko zyada mispredict kara sakta hai, isliye A ke flushes pehli jagah par zyada frequent ho jaate hain.
  • Shared cache / TLB (Memory Hierarchy) — A ke flush ke dauran B run karke B ka data pull in karta hai, potentially A ke working set ko evict karta hai, isliye jab A wapas aata hai toh fresh cache misses face karta hai. Stolen slots free the, lekin cache pollution A par delayed cost laata hai.

Net: SMT A ke 15 flush cycles ko useful B-work ke roop mein reclaim karta hai (woh win hai), lekin shared predictor aur shared cache/TLB quietly dono threads ki miss aur mispredict rates badha sakte hain (woh tax hai). Gain real hai lekin bounded — exactly is poore page ki story.


Recall One-line takeaways (self-quiz)

Work aur rate se time ::: . SMT speedup se kam kyun hai ::: threads caches, ROB, TLB share karte hain → contention har thread ki IPC girata hai. Do threads ka parallel finish time ::: , sum nahi. SMT ke under kaun se threads best pair karte hain ::: complementary resource needs (CPU-bound + memory-bound). Amdahl-SMT model ::: , ceiling as .