The Memory Subsystem: LPDDR Controller, PHY and Training
The memory of a large chip is a chip of its own, outside the package. A controller decides when each command goes out. A circuit at the pins decides where in a bit to sample. The two are budgeted apart.
You Will Be Able To
- Follow one read from the bus port through the controller and the PHY to the DRAM, and back.
- Work out a bandwidth budget and a latency budget, and keep the two apart.
- Explain what training finds, and why the first passing setting is a poor choice.
- Lesson
- S10.4
- Time
- 25 min
- Runs on
- Your browser
- Check
- 5 questions
The board boots at the slow memory setting. Turn the rate up, and now and then the first word comes back with one bit wrong.
Is the fault in the controller, at the pins or in the memory chip?
Before You Start
You need From Microcontroller to Application Processor: DRAM outside the package, and a camera that sends 124,416,000 bytes each second.
You need Bursts, Locks and the Waiting Request. A burst is several transfers for one request, and a beat is one of them.
You need One Access, End to End: latency, the time from a request to its answer.
| Question | |
|---|---|
| 1 | Which block decides when a read command goes out, and which decides where a bit is sampled? |
| 2 | Two channels of 16 bits make 1600 million transfers each second. How many bytes can they carry? |
| 3 | Why does more bandwidth not make the first word arrive sooner? |
| 4 | Why does training choose a setting in the middle of the passing range? |
| 5 | The wait in the queue falls from 12 ns to 2 ns. What does the lab print last? |
The Idea: When to Send, and Where in the Bit to Sample
A DRAM keeps each bit as a small charge, and it sits outside the package. Both facts make it harder to use than SRAM. The charge leaks away, so every cell must be written again from time to time. That rewriting is called a refresh. And the bits cross pins and board wires so fast that the exact moment of sampling matters.
So the memory subsystem splits the work in two. The memory controller answers the question of when. It keeps a queue of requests, and it sends each command at a moment when the DRAM can take it. While a refresh runs, it has to wait.
The PHY answers the question of where. It is the circuit at the pins. It launches every bit that goes out and samples every bit that comes back. Its sampling edge must fall in the middle of a bit, and it has to find that place first. Finding it is called training.
Two jobs give two budgets. Bandwidth is bytes in a second, and the pins set it. Latency is the time until the first data, and waiting sets most of it. A chip can have plenty of the one and too little of the other.
New Words
| Word | Meaning |
|---|---|
| LPDDR | Low-power DDR: a family of DRAM for phones. DDR is short for double data rate: one transfer on each edge of the clock. |
| Refresh of a DRAM | Refresh for short. Writing the cells of a DRAM again before their charge is lost. The part being refreshed cannot be read meanwhile. |
| Memory controller | The block that queues requests and sends commands to the DRAM at moments when it can take them. |
| PHY | Short for physical interface: the circuit at the pins that launches bits and samples them. |
| DFI | The interface between the controller and the PHY. The letters stand for DDR PHY Interface. |
| Memory channel | One set of data pins with commands of its own. Two channels can carry two bursts at once. |
| Rank of memory | A group of DRAM chips on one channel that are selected together. Ranks share the pins of their channel. |
| Bank of a DRAM | One of several separate arrays inside a DRAM. Each bank can keep one row ready for quick access. |
| MT, MT/s | MT is a million transfers. MT/s is a million transfers in a second on one pin, with both clock edges counted already. |
| MB, MB/s | MB is a million bytes. MB/s is a million bytes in a second. |
| Delay tap | One step of an adjustable delay. The PHY moves its sampling edge by whole taps. |
| Passing range | The taps at which a known pattern is read back without an error. |
One Picture: The Way Out and Back
- Bus
- Memory
- Clock / reset
- Pads
- Queue
The controller accepts a request and finds a legal command slot.
- Issue
The PHY takes the command across the internal interface and drives the pads.
- Sample
Read data travels back through the pads and sampler to the waiting client.
Read the diagram as text
- Bus port: accept the read
- Controller: choose a command
- PHY: place and sample edges
- Pads: drive the package
- LPDDR device: open row and return data
- Bus port → Controller: request
- Controller → PHY: DFI
- PHY → Pads: pins
- Pads → LPDDR device: board
Drawn architecture of the exercise subsystem. The lab models elapsed time and a digital sampling window.
The Smallest Example, Worked by Hand
No simulator yet. The memory of ap_phone has two channels of 16 data bits. Each pin makes 1600 million transfers in a second. Three quarters of the transfers carry data. The rest are lost to refresh and to turning the pins around.
| Step | Sum | Result |
|---|---|---|
| Bytes in one transfer, on one channel | 16 bits ÷ 8 | 2 bytes |
| One channel | 2 × 1600 million | 3200 MB/s |
| Peak, on both channels | 2 × 3200 | 6400 MB/s |
| Useful, at three quarters | 6400 × 3 ÷ 4 | 4800 MB/s |
| The camera of ap_phone | 124,416,000 bytes in a second | About 124 MB/s: under 3 percent of the useful budget |
Now one read of 32 bytes, as one burst. Add up the time until its last beat.
| Step | Time | Total so far |
|---|---|---|
| The request waits in the queue of the controller | 12 ns | 12 ns |
| A refresh is running, and the command must wait | 8 ns | 20 ns: the command goes out |
| The DRAM finds the data and sends the first beat | 25 ns | 45 ns: the first beat is back |
| 32 bytes on one channel, at 3.2 bytes in each ns | 10 ns | 55 ns: the burst has ended |
Set the two tables side by side. The pins could carry the load of 38 such cameras. Yet the first beat of one read takes 45 ns, and 20 of those pass before the command has even left.
The Rules
Rule 1: The controller decides when.
It queues requests, and sends a command only when the DRAM can take it. A refresh makes it wait.
Rule 2: The PHY decides where in the bit.
It launches and samples at the pins. It knows nothing about queues.
Rule 3: Bandwidth is channels times bytes in a transfer times transfers in a second.
A rate in MT/s counts both clock edges already. Do not double it again.
Rule 4: One burst uses one channel.
A second channel adds room for other bursts. It does not make this burst shorter.
Rule 5: Latency is a sum of waits.
The queue, the refresh and the DRAM itself come before the first beat. More bandwidth removes none of them.
Rule 6: Training picks the middle of the passing range.
The first passing tap has no margin on one side. Until training has passed, no client may read.
Sources for These Rules
DRAM cells that lose their charge and need a refresh: Patterson and Hennessy, Computer Organization and Design, ARM edition, section 5.2. The same section has rows kept ready for repeated access, banks, ranks, and transfers on both clock edges.
A bit must be steady for a short time around the sampling edge: Harris and Harris, Digital Design and Computer Architecture, ARM edition, section 3.5.1.
The LPDDR standards of JEDEC and the DFI specification are not in our reference library. The names LPDDR, PHY and DFI, and the split between controller and PHY, are given from common usage. No rule here is quoted from those documents.
Rule 6 is common practice for a sweep of delay taps. Every number on this page is an exercise value.
Now Run It
The lab at the end of this page is the two hand tables, with training in front. It is a sheet with delays, not a memory. A bus-functional model stands in for the processor: test code that asks for one burst.
budget peak=6400 MB/s useful=4800 MB/s
read tap=0 pass=0
read tap=1 pass=0
read tap=2 pass=1
read tap=3 pass=1
read tap=4 pass=1
read tap=5 pass=1
read tap=6 pass=0
read tap=7 pass=0
selected=3 trained=1
accept t=0 ns
command t=20 ns
first t=45 ns beat=0042
end t=55 ns first_latency=45 ns burst_window=10 nsRule 3 at work, in the first row: peak=6400 MB/s and useful=4800 MB/s, as in the first hand table.
Rule 6, in the eight rows that start with read. The PHY writes a known pattern and tries every tap. Taps 0 and 1 fail, taps 2 to 5 pass, taps 6 and 7 fail. The lab takes tap 3, the lower of the two middle taps. It checks a second pattern there and prints selected=3 trained=1.
Rule 1, in the rows accept and command. The request is taken at 0 ns, and the command leaves at 20 ns. That is 12 ns in the queue and 8 ns behind a refresh.
Rule 5, in the row first. The first beat is back at 45 ns, and it carries 0042, the low 16 bits of the word.
Rule 4, in the last row. The burst ends at 55 ns. Its 32 bytes took 10 ns on one channel, whatever the other channel did.
This lab leaves things out. It sends no LPDDR command and models no voltage at a pin. The passing range is two parameters, and DFI is not modelled at all.
Why It Is Built This Way
| Choice | The alternative | Its cost |
|---|---|---|
| A controller and a PHY, with DFI between them | One block for both jobs | The PHY is tied to one process and one kind of pin. The controller is plain logic that can be used again. |
| Training at every boot | One delay fixed at design time | Boards, parts and temperature differ. A delay that suits one board fails on the next. |
| A queue in the controller | Let each requester wait on the bus | Every refresh would block the bus port. With a queue the requester can leave its address and go. |
The split also tells you where to look. A command that leaves late is a question for the controller. A bit that changes when the sampling edge moves is a question for the PHY.
The Trap: Double Data Rate, Doubled Twice
A budget sheet takes 1600 MT/s and multiplies by two, "because it is double data rate". It promises 12,800 MB/s. The pins carry 6400. Rule 3 says why: a transfer rate has counted both edges already.
The second trap is the first passing tap. This is the board from the top of the page. Its bring-up code stopped the sweep at tap 2, the first that passed. On the bench that worked. Warm, the passing range moved by one tap, and one bit came back wrong.
The third trap is spare bandwidth beside a late read. A display misses a fetch while the counter shows free capacity. Its burst waited behind camera writes on one channel, and the other channel was idle. Rule 4 and rule 5 together explain it.
At Scale
This section looks ahead, to a memory that a hundred clients share.
Where the bytes are
Measure the load for each channel and each bank, not only in total. One part can be full while another is idle.
Rows cost time
A read from a row that a bank keeps ready is quick. A change of row in the same bank needs more commands first. A good controller orders its queue to change rows less often.
Margins move
The passing range shifts with temperature and voltage. So a chip trains again from time to time, and keeps the whole sweep of a failing pin for the engineer.
Try It
Run the lab. The parameters at the top are the numbers of the two hand tables.
Change QUEUE_NS, then CHANNELS. After each run, compare the budget row, the time of the first beat and the length of the burst.
Set FIRST_PASS to 4. Predict which tap the lab selects, before you run it.
Names Printed by the Lab
| Name | Meaning |
|---|---|
| budget | The bandwidth budget: peak with every transfer used, and useful with three quarters of them. |
| read tap, pass | One step of the training sweep: the tap that was tried, and 1 when the known pattern came back whole. |
| selected, trained | The tap that was chosen, and 1 when a second pattern passed at that tap. |
| accept | The controller takes the request into its queue. The times of this read are counted from here. |
| command | The read command leaves the controller. |
| first, beat | The first beat of data is back: its time and its value, 16 bits in hex. |
| end | The last beat is back. first_latency and burst_window repeat the two times of the read. |
budget peak=6400 MB/s useful=4800 MB/s read tap=0 pass=0 read tap=1 pass=0 read tap=2 pass=1 read tap=3 pass=1 read tap=4 pass=1 read tap=5 pass=1 read tap=6 pass=0 read tap=7 pass=0 selected=3 trained=1 accept t=0 ns command t=20 ns first t=45 ns beat=0042 end t=55 ns first_latency=45 ns burst_window=10 nsCheck Yourself
Common Mistakes
Wrong Multiply a rate in MT/s by two for double data rate.
The rate has counted both clock edges already.
Fix Multiply transfers in a second by the bytes in one transfer.
Wrong Use the bandwidth of all channels for one burst.
One burst stays on one channel.
Fix Use the width and the rate of that channel.
Wrong Keep the first tap that passes.
It has no margin on one side.
Fix Find the whole passing range, and take a tap in its middle.
Remember
- The controller decides when a command goes out. The PHY decides where in a bit to sample.
- Bandwidth is channels times bytes in a transfer times transfers in a second.
- Latency is a sum of waits, and more bandwidth removes none of them.
- Training finds the passing range and takes a tap in its middle.