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.

Five questions this page answers
Question
1Which block decides when a read command goes out, and which decides where a bit is sampled?
2Two channels of 16 bits make 1600 million transfers each second. How many bytes can they carry?
3Why does more bandwidth not make the first word arrive sooner?
4Why does training choose a setting in the middle of the passing range?
5The 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

New words on this page
WordMeaning
LPDDRLow-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 DRAMRefresh for short. Writing the cells of a DRAM again before their charge is lost. The part being refreshed cannot be read meanwhile.
Memory controllerThe block that queues requests and sends commands to the DRAM at moments when it can take them.
PHYShort for physical interface: the circuit at the pins that launches bits and samples them.
DFIThe interface between the controller and the PHY. The letters stand for DDR PHY Interface.
Memory channelOne set of data pins with commands of its own. Two channels can carry two bursts at once.
Rank of memoryA group of DRAM chips on one channel that are selected together. Ranks share the pins of their channel.
Bank of a DRAMOne of several separate arrays inside a DRAM. Each bank can keep one row ready for quick access.
MT, MT/sMT is a million transfers. MT/s is a million transfers in a second on one pin, with both clock edges counted already.
MB, MB/sMB is a million bytes. MB/s is a million bytes in a second.
Delay tapOne step of an adjustable delay. The PHY moves its sampling edge by whole taps.
Passing rangeThe taps at which a known pattern is read back without an error.

One Picture: The Way Out and Back

Where the First Word Has to TravelFollow one read through the controller, across DFI and out to memory.
  • Bus
  • Memory
  • Clock / reset
  • Pads
Where the First Word Has to TravelFollow one read through the controller, across DFI and out to memory. component Bus port accept the read component Controller choose a command component PHY place and sampleedges component Pads drive the package component LPDDR device open row and returndata requestDFIpinsboard
  1. component Bus portaccept the read
    • request → Controller
  2. component Controllerchoose a command
    • DFI → PHY
  3. component PHYplace and sample edges
    • pins → Pads
  4. component Padsdrive the package
    • board → LPDDR device
  5. component LPDDR deviceopen row and return data
  1. Queue

    The controller accepts a request and finds a legal command slot.

  2. Issue

    The PHY takes the command across the internal interface and drives the pads.

  3. 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.

The bandwidth budget
StepSumResult
Bytes in one transfer, on one channel16 bits ÷ 82 bytes
One channel2 × 1600 million3200 MB/s
Peak, on both channels2 × 32006400 MB/s
Useful, at three quarters6400 × 3 ÷ 44800 MB/s
The camera of ap_phone124,416,000 bytes in a secondAbout 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.

The latency budget of one read
StepTimeTotal so far
The request waits in the queue of the controller12 ns12 ns
A refresh is running, and the command must wait8 ns20 ns: the command goes out
The DRAM finds the data and sends the first beat25 ns45 ns: the first beat is back
32 bytes on one channel, at 3.2 bytes in each ns10 ns55 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

  1. 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.

  2. Rule 2: The PHY decides where in the bit.

    It launches and samples at the pins. It knows nothing about queues.

  3. 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.

  4. Rule 4: One burst uses one channel.

    A second channel adds room for other bursts. It does not make this burst shorter.

  5. 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.

  6. 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.

Printed by the lab on Icarus: the budget, the training sweep, and one 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 ns

Rule 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

ChoiceThe alternativeIts cost
A controller and a PHY, with DFI between themOne block for both jobsThe PHY is tied to one process and one kind of pin. The controller is plain logic that can be used again.
Training at every bootOne delay fixed at design timeBoards, parts and temperature differ. A delay that suits one board fails on the next.
A queue in the controllerLet each requester wait on the busEvery 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

ap_soc~12 blocks
Phone-class SoChundreds of blocks

This section looks ahead, to a memory that a hundred clients share.

  1. 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.

  2. 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.

  3. 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
NameMeaning
budgetThe bandwidth budget: peak with every transfer used, and useful with three quarters of them.
read tap, passOne step of the training sweep: the tap that was tried, and 1 when the known pattern came back whole.
selected, trainedThe tap that was chosen, and 1 when a second pattern passed at that tap.
acceptThe controller takes the request into its queue. The times of this read are counted from here.
commandThe read command leaves the controller.
first, beatThe first beat of data is back: its time and its value, 16 bits in hex.
endThe last beat is back. first_latency and burst_window repeat the two times of the read.
RUNIcarus Verilog · in your browser
Edit the code, then run it
Expected: 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 ns

Check Yourself

Predict the outputIn this run the wait in the queue is 2 ns in place of 12 ns. What is the last line? Its form is: end t=.. ns first_latency=.. ns burst_window=.. ns
`timescale 1ns/1ns
module tb;
  // Exercise inputs. Rate already counts transfers on both clock edges.
  parameter CHANNELS=2, BITS=16, RATE_MT=1600, USE_PERCENT=75;
  parameter QUEUE_NS=2, REFRESH_NS=8, DEVICE_NS=25;
  parameter BURST_BYTES=32;
  parameter FIRST_PASS=2, LAST_PASS=5;
  localparam logic [7:0] PATTERN = 8'ha5;
  logic [31:0] words [0:1];
  bit [31:0] address;
  bit request, first_valid;
  logic [BITS-1:0] first_beat;
  bit trained;
  int left_tap=-1, right_tap=-1, selected;
  int peak, useful, first_ns, burst_ns;
  // One low byte lane is skewed outside the digital pass window.
  function automatic logic [7:0] sample_lane(input logic [7:0] bits_in, input int tap);
    return tap>=FIRST_PASS && tap<=LAST_PASS ? bits_in : bits_in ^ 8'h01;
  endfunction

  // Behavioral memory service. Address is a local byte offset.
  initial begin : controller
    logic [31:0] word_at_address;
    time issued;
    wait (request);
    if (!trained) $fatal(1,"port closed");
    issued = $time;
    $display("accept t=%0t ns",$time);
    #(QUEUE_NS + REFRESH_NS);
    $display("command t=%0t ns",$time);
    word_at_address = words[address/4];
    #DEVICE_NS;
    first_ns = $time-issued;
    first_beat = word_at_address;
    first_beat[7:0] = sample_lane(word_at_address[7:0],selected);
    first_valid = 1;
    // One burst stays on one channel. Round its wire time up to whole ns.
    burst_ns = (BURST_BYTES*1000 + BITS/8*RATE_MT-1)/(BITS/8*RATE_MT);
    #burst_ns;
    $display("end t=%0t ns first_latency=%0d ns burst_window=%0d ns",
             $time,first_ns,burst_ns);
    $finish;
  end
  initial begin
    peak = CHANNELS * (BITS/8) * RATE_MT;
    useful = peak * USE_PERCENT / 100;
    $display("budget peak=%0d MB/s useful=%0d MB/s",peak,useful);
    // Controller-side boot policy. A digital pass window replaces analog pins.
    words[0] = {24'd0,PATTERN};
    words[1] = 32'h42;
    for (int tap=0; tap<8; tap++) begin
      bit pass;
      pass = sample_lane(words[0][7:0],tap) == PATTERN;
      if (pass) begin
        if (left_tap < 0) left_tap = tap;
        right_tap = tap;
      end
      $display("read tap=%0d pass=%0b",tap,pass);
    end
    if (left_tap < 0) $fatal(1,"no passing tap");
    selected = (left_tap + right_tap)/2;
    words[0] = {24'd0,~PATTERN};
    trained = sample_lane(words[0][7:0],selected) == 8'(~PATTERN);
    $display("selected=%0d trained=%0b",selected,trained);
    // Bus-functional client reads the second word after validation.
    address = 4;
    request = 1;
    wait (first_valid);
    $display("first t=%0t ns beat=%h",$time,first_beat);
  end
endmodule
ConceptWhich block decides when a read command goes out?
ConceptTwo channels of 16 bits make 1600 million transfers in a second on each pin. What is the peak bandwidth?
ConceptA second channel is added. What happens to the first beat of one waiting read?
ConceptTaps 2 to 5 pass. Why does training not keep tap 2?

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.

Practice

Report a problem with this page