Exercises — DMA controllers
6.3.8 · D4· Hardware › Interconnects, Buses & SoC › DMA controllers
Yeh page ek self-test ladder hai. Har exercise parent note DMA controllers par aur usmein define ki gayi machinery par build hoti hai — char registers (, , , ), teen transfer modes (burst, cycle-stealing, transparent), aur timing formulas. Agar koi symbol neeche unfamiliar lage, toh woh parent mein define kiya gaya tha; yeh page uss symbol ko use karti hai, re-derive nahi karti.
Shuru karne se pehle, aao hum woh do timing formulas pin down kar lein jinpar tum sabse zyada lean karoge, taaki hum koi aisa symbol kabhi na likhein jo humne earn na kiya ho.
Level 1 — Recognition
Exercise 1.1 (L1)
Ek DMA controller mein per-channel char registers hain. Ek aisi transfer ke liye jo 2048 bytes ko address 0x2000_0000 se 0x3000_0000 tak copy karti hai, 32-bit (word) width use karke, batao ki har register mein kaunsi initial value honi chahiye, aur CPU last mein kaun sa register set karta hai transfer launch karne ke liye.
Recall Solution
- — source (kahaan se padhna hai).
- — destination (kahaan likhna hai).
- — byte count (woh countdown jo transfer terminate karta hai). Dhyan raho yeh bytes hai, words nahi, isliye yeh hold karta hai, nahi.
- — mode bits (width word ke liye, direction, increment bits). Iska EN bit (bit 0) last mein likha jaata hai: EN ko karna woh hardware signal hai jo transfer state machine ko activate karta hai. Pehle set karo toh DMA fire ho jaayega addresses valid hone se pehle.
Exercise 1.2 (L1)
Parent ke CSR layout ko dekhte hue, bits 4–5 (Direction) mein kaunsi value jaati hai data ko peripheral se memory mein (P2M) move karne ke liye, aur bits 2–3 (Transfer Width) mein halfword ke liye kaunsi value?
Recall Solution
- Direction P2M (binary ).
- Halfword width (binary ).
Level 2 — Application
Exercise 2.1 (L2)
8 KB transfer 32-bit width par, 200 MHz bus par burst mode mein. Setup cycles, cycle. , total cycles, aur total time microseconds mein nikalo.
Recall Solution
bytes. Width bytes, toh Cycles: cycles. par ek cycle hai. Toh
Exercise 2.2 (L2)
Wohi 8 KB, 32-bit, 200 MHz transfer, lekin cycle-stealing mode mein aur cycles ke saath. Total time nikalo, aur Ex 2.1 ke burst result ke muqable slowdown factor bhi nikalo.
Recall Solution
(unchanged). Slowdown (essentially ).
Level 3 — Analysis
Exercise 3.1 (L3)
Ek CPU ek 100 MHz bus share karta hai ek DMA engine ke saath. CPU har cycles mein ek bus access issue karta hai (baaki internal/cache work hain). Ek transparent-mode DMA har idle bus cycle mein ek transfer sneak karta hai. Ek -cycle CPU window mein, DMA ke liye kitne cycles free hain, aur 32-bit width par kaunsa effective DMA throughput (bytes/s) milta hai?
Recall Solution
Har -cycle window mein CPU cycle use karta hai, baaki cycles transparent DMA ke liye free rehti hain. DMA duty cycle . Agar ek transfer cycle leta hai, toh DMA average par transfers per cycle complete karta hai. Transfers per second transfers/s. bytes each par:
Exercise 3.2 (L3)
Teen DMA masters — Disk, Network, Audio — fixed priority Disk > Network > Audio ke saath bus share karte hain. Disk continuously request karta hai aur uska har burst bus ko cycles hold karta hai. Quantitatively explain karo kyun Audio starve kar sakta hai, aur round-robin use kaise bachaata hai. Maano teeno hamesha kaam mein hain.
Recall Solution
Fixed priority: grant hamesha sabse oonche requester ko jaata hai jo abhi bhi maang raha hai. Disk continuously maangta hai, toh har -cycle burst ke baad woh turant re-request karta hai aur phir se jeet jaata hai. Network aur Audio ko kabhi grant nahi milta → unka wait time unbounded (infinite) ho jaata hai. Audio starve ho jaata hai. Round-robin: jab koi master bus use kar leta hai, uski priority ke through bottom mein chali jaati hai. Toh grant order ban jaata hai Disk → Network → Audio → Disk → … Har master zyada se zyada baaki do bursts wait karta hai. masters aur -cycle bursts ke saath, Audio ka worst-case wait hai aur use har cycles mein ek baar bus guarantee hai. Uska bus share hai, finite aur fair.
Level 4 — Synthesis
Exercise 4.1 (L4)
Tumhe ek SSD se sustained 3.0 GB/s par RAM mein stream karna hai 64-bit (8-byte) bus par. DMA burst ya cycle-stealing run kar sakta hai; cycle-stealing mein , per transfer hai; burst mein aur negligible setup hai. Minimum bus frequency nikalo jo har mode ke liye zaroori hai keep up karne ke liye. Kaunsa mode bus par feasible hai?
Recall Solution
Required transfer rate transfers/s mein (8 bytes each): Burst: cycle per transfer, toh cycles/s chahiye: Cycle-stealing: cycles per transfer: bus par: burst ko chahiye ✓ (feasible, headroom ke saath), cycle-stealing ko chahiye ✗ (impossible). Burst mode use karo.
Exercise 4.2 (L4)
Usi 3 GB/s burst stream par ( bus par feasible), ek burst bus ko 1024 transfers ke liye hold karta hai. Har burst ke dauran CPU fully blocked rehta hai. Agar CPU ko bhi bus chahiye aur woh zyada se zyada 2 µs blocking tolerate kar sakta hai, toh kya ek single burst yeh violate karta hai? Agar haan, toh maximum burst length kya hai jo blocking ko ke andar rakhti hai?
Recall Solution
par, ek cycle . Ek -transfer burst (1 cycle each) . Yeh exceed karta hai — CPU bahut zyada der block ho jaata hai. ke andar max transfers: transfers. Toh burst length transfers set karo (parent ka CSR burst field 0–255 hold karta hai, toh practically tum ke bursts program karoge aur engine unhe chain karne do). Jaise -transfer bursts program karo toh sirf block hota hai, limit se comfortably under.
Level 5 — Mastery
Exercise 5.1 (L5)
Design decision. Ek system mein hai: (a) ek real-time UART UART receiver jo har mein 1 byte drip karta hai aur koi byte lose nahi kar sakta, aur (b) ek bulk PCIe PCIe transfer of jo maximum throughput chahta hai. Bus , 32-bit hai. Har DMA channel ke liye ek transfer mode choose karo, numbers se justify karo, aur priority scheme batao. Interrupts aur Cache Coherency ke saath interaction ko consider karo.
Recall Solution
UART channel → cycle-stealing (ya single-transfer). Use sirf har mein byte chahiye — yeh B/s ka rate hai, jo per-transfer arbitration ke saath bhi trivially meet ho jaata hai ( cycles per byte bus par). Jo yeh tolerate nahi kar sakta woh hai latency: agar ek lamba burst bus hold kare, toh UART ka 1-byte FIFO overflow ho jaata hai aur ek byte lost ho jaata hai. Cycle-stealing har transfer ke baad bus release kar deta hai, UART ko prompt service guarantee karta hai.
PCIe channel → burst mode. bytes, transfers. Burst mein cycle each par, /cycle → . Cycle-stealing ( cycles) mein lagta — 4× bura. Bulk data burst chahta hai.
Priority: UART ko higher priority do (fixed priority UART > PCIe) taaki uski rare, latency-critical requests bulk bursts ko preempt kar sakein. Kyunki UART sirf har mein request karta hai aur bus hold karta hai, yeh bus time ka negligible steal karta hai — PCIe ko hardly pata chalta hai. Lekin PCIe burst length limit karo (Ex 4.2 logic) taaki woh itni baar check in kare ki ek UART request kabhi ek chhote burst se zyada wait na kare.
Interrupts: PCIe channel set karta hai taaki 16 MB block complete hone par ek interrupt raise ho (har byte par nahi) — yahi DMA ka programmed I/O ke upar point hai. UART channel per-buffer completion interrupts use kar sakta hai.
Cache coherency: DMA RAM mein likhta hai CPU ke cache ke peeche. PCIe DMA finish hone ke baad, CPU ka un addresses ka cached copy stale ho jaata hai. Ya toh interconnect snoop/invalidate kare (hardware coherency, cf. ARM AMBA AXI ACE) ya driver ko DMA'd data padhne se pehle cache range invalidate karna hoga. Yeh skip karo toh CPU purana garbage padhega.
Recall Numeric summary
- UART rate need: B/s; per-byte cost ⇒ effortless.
- PCIe burst time: ; cycle-steal: (4×).
- UART bus occupancy at 1 byte/: .
Related: Bus Architecture · Memory-Mapped IO · SDRAM Controllers · DMA controllers