Yeh page 5-stage pipeline ke liye ek graded workout hai. Har problem ka ek fully worked solution hai jise tum chupa ke khud se derive kar sakte ho. Levels "kya tum ise naam de sakte ho?" se "kya tum khud reasoning bana sakte ho?" tak chadti hain. Ek level karo, phir uska trap padho.
Figure s01 (neeche) har timing problem ke peeche ki mental picture hai: rows instructions hain, columns cycles hain. Coloured cells ka diagonal pipeline ka "filling" hai. Columns touched count karo = total cycles.
IF — Instruction Fetch: PC mein address par instruction memory se instruction padho; phir PC ← PC + 4.
ID — Instruction Decode / register read: opcode decode karo, register file se source registers padho, immediate ko sign-extend karo.
EX — Execute: ALU arithmetic/logic karta hai, ya memory address compute karta hai, ya branch condition check karta hai.
MEM — Memory access: loads data memory padhti hain, stores likhti hain; baaki sab yahan idle rehte hain.
WB — Write Back: result ko register file mein likho.
Recall Solution L1.2
Registers ID mein read hote hain aur results WB mein write hote hain. Mnemonic: Decode reads, Write writes.
Recall Solution L1.3
Charo hain IF/ID, ID/EX, EX/MEM, MEM/WB. Har ek data (operand values, immediate, ALU result, loaded value) aurcontrol signals (RegWrite, MemRead, MemWrite, …) carry karta hai. ID mein decide kiye gaye control signals WB tak, chaar cycles baad, pahunchne chahiye — registers unhe wahan tak ferry karte hain.
Step (kya):Cycles(N)=k+(N−1) apply karo. Kyun:k=5 cycles pipe fill karne mein (pehla result cycle 5 par), phir N−1 aur results, har ek subsequent cycle mein.
Cycles(8)=5+(8−1)=12.Pehli instruction cycle k=5 mein finish hoti hai (usse saare paanch stages pass karne hain). Figure s01 dekho: top row ka last coloured cell column 5 mein baitha hai.
Recall Solution L2.2
Step (kya): maximum delay lo. Kyun: saare stages ek clock share karte hain; cycle itni lambi honi chahiye ki slowest stage finish kar sake, warna us stage ka result latch hone ke liye ready nahi hoga.
max(250,120,180,250,100)=250 ps (IF aur MEM tie karte hain).Step: latch overhead add karo, kyunki har cycle pipeline register mein likhne mein bhi d spend karta hai.
Tclk=250+15=265 ps.
Recall Solution L2.3
Step: cycles =k+(N−1)=5+599=604.
Step: time =604×265=160,060 ps =160.06 ns. Cycles ko Tclk se multiply kyun? Har clock cycle exactly Tclk chalta hai, aur cycles ek ke baad ek hote hain; isliye total wall-clock time simply "kitne cycles" times "har cycle kitni lambi hai" hai.
Single-cycle time per instruction: ek bada cycle saara combinational kaam plus ek latch fit karna chahiye:
Tsingle=(250+120+180+250+100)+15=900+15=915 ps.Pipelined time per instruction (large N): har Tclk=265 ps mein ek instruction finish hoti hai.
Speedup:265915≈3.45×.Yeh ratio kyun aur k+N−1Nk kyun nahi? Kyunki dono machines ke yahan alag cycle times hain (915 vs. 265), isliye hum seedha per instruction wall-clock time compare karte hain, exactly jaise intro formula box ne warn kiya tha. 5× kyun nahi? Stages unbalanced hain: WB (100 ps) aur ID (120 ps) apne 265-ps slot ka zyaadatar hissa waste karte hain, jabki IF/MEM (250 ps) pace set karte hain. Ideal 5× ke liye har stage equal hona chahiye aurd=0 hona chahiye. Dekho Clocking & Latch Overhead ki d kabhi zero kyun nahi ho sakta.
Recall Solution L3.2
lw $t0, 8($s1) : IF · ID(s1padho)⋅EX(addr=s1+8) · MEM(read) · WB($t0 likho). Saare paanch use karta hai.
sw $t5, 0($s2) : IF · ID(s2,t5 padho) · EX(addr = $s2+0) · MEM(write) · koi WB nahi.
Idle slots kyun rakhte hain? Taaki har instruction ki ek jaisi 5-stage shape ho. Uniform shape ⇒ simple control ⇒ ek instruction phir bhi har cycle finish hoti hai. Stages skip karne se assembly line ka steady rhythm toot jaata.
Recall Solution L3.3
5-stage: Tclk=250+15=265 ps.
10-stage: Tclk=125+15=140 ps.
Step (kya): throughput ratio 265/140≈1.89× banao. Yeh throughput ratio kyun hai? Lambi stream ke liye, har Tclk mein ek instruction finish hoti hai, isliye throughput = 1 / Tclk (instructions per second). Do throughputs compare karna isliye 1/Tclknew1/Tclkold=TclknewTclkold=140265 hai — throughput cycle time ke inverse ke saath scale karta hai, isliye chhota Tclk proportionally faster hai.
Result 1.89× us naive 2× se kam hai jo tum stages double karne par umeed karte. Kyun? Latch overhead dnahi shrink hua; yeh ab cycle ka 15/140≈10.7% hai instead of 15/265≈5.7%. Jaise stages thinner hote hain, d bada fraction khaata hai. Bahut aage push karo aur speedup saturate ho jaata hai ya reverse ho jaata hai.
IF aur MEM dono 250 ps hain. Koi bhi split karne se uske halves 125 ps ho jaate hain, lekin doosra 250-ps stage abhi bhi bacha rehta hai aur max re-set kar deta hai. Isliye akela split maxti ko 250 se neeche nahi laata — naya bottleneck abhi bhi un-split 250-ps stage hai.
maxti=250 ps still⇒Tclk=250+15=265 ps (unchanged!).Insight: koi gain dekhne ke liye tumhe dono 250-ps stages split karne honge. Sirf ek split karna ek extra latch waste karta hai bina kisi kaam ke. Yahi core lesson hai: doosra-slowest stage yeh limit karta hai ki slowest ki help kitni achieve kar sakti hai. Balance global hai, local nahi.
Recall Solution L4.2
Pipelined time < single-cycle time set karo:
(k+N−1)Tclk<N⋅Tsingle(5+N−1)(265)<N(915)(N+4)(265)<915N265N+1060<915N1060<650N⇒N>1.63.
Isliye N=2 se pipeline already jeet jaata hai. Itni jaldi kyun? Single-cycle machine ki per-instruction cost (915) 265 ke comparison mein enormous hai; sirf 4 extra cycles ka fill penalty almost turant pay off ho jaata hai.
(a)max(300,200,350,300,150)=350; Tclk=350+25=375 ps.
(b) Cycles =k+(N−1)=5+999=1004.
(c) Time =1004×375=376,500 ps =376.5 ns.
(d) Total kaam =300+200+350+300+150=1300 ps; single-cycle =1300+25=1325 ps/instr. Large-N pipelined ≈375 ps/instr. Speedup =1325/375≈3.53×.
(e) Balanced ideal: har stage =1300/5=260 ps, isliye Tclk=260+25=285 ps, jo 1325/285≈4.65× deta hai — phir bhi 5× nahi. Theoretical 5× ke liye d=0 bhi chahiye, lekin latch overhead kabhi zero nahi ho sakta (real flip-flops mein setup + propagation time hota hai — dekho Clocking & Latch Overhead). Hazards ise aur erode karenge.
Recall Solution L5.2
Yaad karo ek stall cycle = ek inserted empty cycle jo instruction ko tab tak delay karta hai jab tak uski needed value reachable na ho jaaye. Dono instructions ko timeline par rakho; rows instructions hain, columns clock cycles hain (c1…c7), har cell woh stage hai jo us instruction us cycle mein occupy karti hai.
**Step 1 — find karo ki t0kabproduce(reachable)hotahai.∗∗‘add‘t0 apne WB mein likhta hai, jo cycle 5 hai:
instruction
c1
c2
c3
c4
c5
add
IF
ID
EX
MEM
WB
**Step 2 — find karo ki sub ko t0kabchahiye.∗∗‘sub‘apnesources∗∗ID∗∗meinpadhtahai.Back−to−back,‘sub‘kaIFc2hai,isliyeuska∗natural∗IDc3hai.∗∗Step3—hardwareruleapplykaro.∗∗Same−cyclewrite−then−readnahi,matlab‘sub‘kaIDsirf∗∗add∗∗keWBke∗∗baad∗∗walicyclemeinchalsaktahai—yaani‘sub‘kaIDc3se∗∗c6∗∗parmovehojaatahai.∗∗Step4—stallscountkaro.∗∗NaturalID=c3,requiredID=c6,isliye‘sub‘6 - 3 = 3$ cycles se delay hua → 3 stall cycles. Corrected timeline:
instruction
c1
c2
c3
c4
c5
c6
c7
c8
c9
add
IF
ID
EX
MEM
WB
sub
IF
–
–
–
ID
EX
MEM
WB
(teen "–" cells inserted bubbles hain).
Step 5 — total cycles. Bina stalls ke do instructions k+(N−1)=5+1=6 cycles leti hain; 3 bubbles sub ko 3 se push karte hain, jo 6+3=9 total cycles deta hai (last cell WB c9 mein). Forwarding kyun fix karta hai: ALU result add ke EX (c3) ke baad exist karta hai — ise seedha sub ke EX mein feed karo aur saare 3 stalls gayab ho jaate hain, wapas 6 cycles. Yahi Data Forwarding / Bypassing ka poora motivation hai.
Recall Solution L5.3
Goal: dikhao ki k+N−1Nk<k. Step 1 — fraction clear karo. Kyunki k+N−1>0 hai, dono sides ko inequality flip kiye bina multiply karo:
k+N−1Nk<k⟺Nk<k(k+N−1).Step 2 — right side expand karo.k distribute karo:
k(k+N−1)=k2+kN−k.Step 3 — common kN term cancel karo. Dono sides mein kN hai (left mein Nk hai), isliye ise subtract karo:
Nk<k2+kN−k⟺0<k2−k.Step 4 — factor aur interpret karo.k2−k=k(k−1). Kisi bhi real pipeline ke liye k≥2, k aur k−1 dono positive hain, isliye k(k−1)>0hamesha true hai — lekin notice karo ki is step ne sirf k≥2 use kiya, N se independent. Wait: hum ne kN cancel kiya strict form maanke; strictness actually N≥2 require karti hai taaki pipeline genuinely overlapping ho (N=1 par dono sides k ke barabar hain). Isliye har finite N≥2 ke liye strict inequality hold karta hai.
Step 5 — limit. Equality ke liye k(k−1)=0 chahiye, k≥2 ke liye impossible; lekin jaise N→∞, "−1" in k+N−1 negligible ho jaata hai aur ratio approach karta hai k ko. Matlab:(k−1) cycles ka fill/drain overhead almost nothing amortize ho sakta hai lekin finite stream ke liye kabhi actually remove nahi ho sakta.
Tclk ko stage delays aur latch overhead ke terms mein kya hai?
Tclk=maxi(ti)+d — slowest stage plus woh latch cost jo har cycle pay karta hai.
k-stage pipeline mein N instructions chalane ke liye cycles, koi stalls nahi?
k+(N−1) — k se fill karo, phir har cycle ek result.
Sirf ek slowest stage split karna aksar kyun help nahi karta?
Doosra-slowest stage naya bottleneck ban jaata hai; maxti nahi girta, isliye Tclk unchanged rehta hai.
Real speedup exactly k× kyun kabhi nahi pahunch sakta?
Latch overhead d>0, unbalanced stages slots waste karte hain, aur hazards stalls add karte hain; k+N−1Nk<k saare finite N ke liye.
Kaun si assumption humein speedup k+N−1Nk likhne deti hai?
Dono machines ek hi Tclk share karte hain; jab cycle times alag hon (single-cycle vs. pipelined), seedha wall-clock times compare karo.
Stall cycle kya hota hai?
Ek inserted empty (bubble) cycle jahan ek stage koi useful kaam nahi karta kyunki woh kisi not-yet-reachable value ya resource ka wait kar raha hai; yeh cycle count mein ek add karta hai.