Report, Scrub and Test: The Capstone Step for Memory

A code that repairs a bit on its way out is half of a dependable memory. The other half is what the chip does about it: count it, write it back, and raise an alarm when repair fails.

You Will Be Able To

  • Describe what the error logic does for a corrected error, and for an uncorrectable one.
  • Explain why a repaired read leaves the memory wrong, and how scrubbing removes the error.
  • Name the memory models of ap_soc and what each adds to its port.
Lesson
S3.28
Time
30 min
Runs on
Your browser
Check
6 questions

A satellite has run for a year. Its memory has corrected hundreds of single errors, and nobody was told. One word has kept a flipped bit for months, because reads only repair the copy that leaves. Today a second particle finds that word.

Before You Start

You need the last lesson, S3.27: the syndrome, the overall parity, one error and two errors.

You need an interrupt as a request from a block to the processor: S0.8.

Five questions this page answers
Question
1What does a read do with a word that has one flipped bit?
2Why is the flipped bit still in the memory afterwards?
3What is scrubbing?
4What happens when a word has two flipped bits?
5Which memory models does ap_soc have after this module?

The Idea: Repair the Copy, Then Repair the Word

The decoder of the last lesson sits in the read path. A word with one flipped bit leaves it repaired. The program gets right data and notices nothing. This is correction on read.

But the repair was made on the copy that left. The stored word still holds the flipped bit. Nothing is wrong yet. The danger is a second flip in the same word, some day: two errors cannot be repaired.

So a dependable memory does two more things. First, it reports. A corrected error adds one to a counter that software can read, and the address is kept. An uncorrectable error is urgent: the read ends with an error on the bus, and an interrupt goes to the firmware.

Second, it cleans up. A small machine reads every word of the memory in turn, slowly, in the background. Where a word needs repair, the machine writes the repaired code word back. This is scrubbing. After a pass, every single error is gone, and the count starts again from clean words.

Soft errors are one risk. Broken cells are another, and no code is meant to carry those for long. For them a chip has a self-test of its memories: logic that writes patterns into every word and reads them back. It runs at power-up or in the factory.

New Words

New words on this page
WordMeaning
Correction on readThe decoder repairs the data on its way to the bus. The stored word is not changed.
Corrected errorA read that found one flipped bit and gave the right data all the same.
Uncorrectable errorA read that found two flipped bits. There is no right data to give.
Error counterA register that counts corrected errors. Software reads it now and then.
ScrubbingReading every word in turn and writing back each one that needed repair.
Scrub passOne round of the scrubber through the whole memory.
Built-in self-test (BIST)Test logic that is part of the chip itself.
Self-test of a memoryA built-in self-test for a memory. It writes and reads every word to find broken cells.
Back doorA way for a test bench to reach the stored bits directly, without the port. Used to load a memory and to flip bits.

One Picture: Where the Report Goes

A Corrected Error Is Counted, and an Uncorrectable One InterruptsStep through the picture. The decoder sits in the read path. What it finds goes two ways: the data to the bus, and a report to software.
  • Memory
  • Control / FSM
  • Bus
  • Processor
A Corrected Error Is Counted, and an Uncorrectable One InterruptsStep through the picture. The decoder sits in the read path. What it finds goes two ways: the data to the bus, and a report to software. component Memory code words component Decoder syndrome and overallparity component Bus data, or an erroranswer component Error registers a count and anaddress component Interrupt for an error with norepair component Scrubber walks through everyword readrepaired dataone flip: count ittwo flipsread, then write back
  1. component Memorycode words
    • read → Decoder
  2. component Decodersyndrome and overall parity
    • repaired data → Bus
    • one flip: count it → Error registers
    • two flips → Interrupt
  3. component Busdata, or an error answer
  4. component Error registersa count and an address
  5. component Interruptfor an error with no repair
  6. component Scrubberwalks through every word
    • read, then write back → Memory
  1. Every read passes the decoder

    The memory gives a code word. The decoder works out the syndrome and the overall parity, as in the last lesson.

  2. One flip: repair, and count

    The bus gets the right data, with no delay that the program could notice. A counter goes up by one, and a register keeps the address.

  3. Two flips: an error answer and an interrupt

    There is no right data to give. The bus transfer ends with an error, and an interrupt tells the firmware at once.

  4. The stored word is still wrong

    A repair on the way out does not touch the memory. The flipped bit stays, and waits for a second one.

  5. The scrubber writes it back

    A scrubber reads every word in turn. Where the decoder repairs a word, the scrubber writes the repaired code word back.

Read the diagram as text
  • Memory: code words
  • Decoder: syndrome and overall parity
  • Bus: data, or an error answer
  • Error registers: a count and an address
  • Interrupt: for an error with no repair
  • Scrubber: walks through every word
  • Memory → Decoder: read
  • Decoder → Bus: repaired data
  • Decoder → Error registers: one flip: count it
  • Decoder → Interrupt: two flips
  • Scrubber → Memory: read, then write back

Correcting hides the error from the program. Reporting keeps it visible to whoever looks after the system.

The Smallest Example, Worked by Hand

A memory of four words uses the code of the last lesson. Word 1 holds the data 1011, stored as 1010 1010. Follow the word through two hits.

One word, two hits, with a scrub pass in between
EventStored word after itWhat the program getsCorrected count
position 5 flips1000 10100
a read1000 1010: unchanged1011, repaired1
a second read1000 1010: unchanged1011, repaired again2
a scrub pass1010 1010: written back3
position 2 flips1010 11103
a read1010 1110: unchanged1011, repaired4

The second hit met a clean word, so it was one error again. The scrub pass made the difference.

Take the scrub pass away. Then the second hit makes the stored word 1000 1110, with two wrong bits. The next read cannot give data at all.

The counter tells a story of its own. Two reads of one bad word count twice. So a count that climbs fast at one address points to a word that is read often, or to a broken cell.

The Rules

  1. Rule 1: A read repairs the data on its way out, and leaves the stored word alone.

    Only a write changes the memory.

  2. Rule 2: A corrected error is counted, and its address is kept.

    The program is not disturbed. Software looks at the count when it has time.

  3. Rule 3: An uncorrectable error ends the read with an error, and raises an interrupt.

    Wrong data must never be handed on as if it were right.

  4. Rule 4: A scrub pass writes back every word that the decoder could repair.

    After the pass the memory holds no single errors.

  5. Rule 5: The time between two scrub passes is the time that errors have to pile up.

    A second flip in one word within that time is the risk that remains.

  6. Rule 6: A self-test looks for broken cells. A code deals with flips.

    Each needs the other.

Sources for These Rules

The code is that of the last lesson (Patterson and Hennessy, section 5.5).

Correction on read without a write-back, the counter, the address register, the interrupt and the scrubber are common practice. No book or standard in the reference library gives them as rules. So they are not checked against one.

ap_soc v1.0 has no error-correcting code, no error registers and no such interrupt. The lab is a model for teaching.

Now Run It

The lab at the end of this page is test code. It adds three things to the memory of the last lesson: a counter with an address register, an interrupt request, and a scrub task.

Printed by the lab on Icarus. The last row shows what software would read from the error registers.
write 1 | data 1011 | code word 10101010
hit   1 | position 5 flips | code word 10001010
read  1 | one error at position 5: corrected on the way out | data 1011 | corrected_count=1
read  1 | one error at position 5: corrected on the way out | data 1011 | corrected_count=2
scrub 1 | one error at position 5: repaired, code word 10101010
scrub pass | 4 words read, 1 repaired
hit   1 | position 2 flips | code word 10101110
read  1 | one error at position 2: corrected on the way out | data 1011 | corrected_count=4
corrected_count=4 error_address=1 irq=0

Rules 1 and 2 at work: rows 3 and 4. Two reads of the same word are both corrected, and both counted. The stored word did not change in between.

Rule 4 at work: rows 5 and 6. The scrub finds word 1, writes 1010 1010 back, and counts one more.

Rule 5 at work: rows 7 and 8. The second hit arrives after the scrub. It is a single error in a clean word, and the read repairs it.

The last row: four corrected errors, all at address 1, and no interrupt.

This lab leaves out how often the scrubber runs, and what the firmware does with the count. Both are decisions of the product.

Why It Is Built This Way

Design choiceThe alternativeWhat the choice buys, and costs
Repair on the way out onlyWrite back at every corrected readThe read path stays a read. Errors stay in the memory until a scrub.
A scrubber in the backgroundNo scrubbingSingle errors are removed before a second one joins them. A little bus time, all the time.
Count corrected errorsHide themA climbing count warns of a failing memory before data is lost. A few registers.
An interrupt for uncorrectable errorsA flag that software pollsWrong data is stopped at once. The firmware needs a plan for that interrupt.

The Trap: The Word That Nobody Read

A team has SEC-DED and no scrubber. Reads repair single errors, they say, so nothing more is needed. One word holds a setting that is written at start-up and read once a month.

The same lab, with no scrub: two hits on word 2, a long time apart, and then the monthly read.
write 2 | data 0110 | code word 01100110
hit   2 | position 5 flips | code word 01000110
hit   2 | position 3 flips | code word 01001110
read  2 | two errors: no data, the bus answers with an error | irq=1 error_address=2
corrected_count=0 error_address=2 irq=1

Nobody read the word between the two hits. So nothing ever saw the first flip. The read finds two errors, the bus answers with an error, and the interrupt is raised.

The code was strong enough for each hit alone. Rule 5 names the real limit: how long a flipped bit may wait. Without a scrubber that time has no end for a word that is rarely read.

Capstone Step: The Memories of ap_soc Behind Their Ports

Module S3 leaves ap_soc with these memory blocks. Two of them are your own answers to practice problems, because they are graded.

The memory blocks of ap_soc after module S3
BlockWhat it isWhere it comes from
ap_romThe Boot ROM: 1,024 words. A read port, no write pin. A test bench loads it by the back door.New in this step
ap_sramThe SRAM: 16,384 words, with byte strobes.S3.15
ap_sram_parityThe same port with a parity bit for each byte, and one more output, named parity_error. An option.New in this step
The wrapper between the bus and the SRAM portOne SRAM access for each bus transfer.Your answer to S3.1.2
The SEC-DED coder for words of 32 bitsIt would take the place of the parity bits.Your answer to S3.12.1

ap_soc v1.0 ships with ap_rom and ap_sram. Parity and SEC-DED are options that a product would choose.

Here are the two new blocks at work. The bench loads two words into the ROM by the back door. Then it writes a word into the SRAM, flips one stored bit by the back door, and reads.

Printed by a second lab on Icarus (wrappersLab in s3f-labs.mjs), which runs ap_rom.sv and ap_sram_parity.sv.
rom read  word 0 | 00000013
rom read  word 1 | 800000b7
ram write word 5 | strobes 1111 | 11223344
ram read  word 5 | 11223344 | parity_error 0000
ram read  word 5 | 11233344 | parity_error 0100
ram write word 5 | strobes 0100 | 00550000
ram read  word 5 | 11553344 | parity_error 0000

Row 5 is the parity check of S3.12 in hardware. The flipped bit lies in byte 2, and bit 2 of parity_error is 1.

Rows 6 and 7 show why the parity is kept for each byte. A write of byte 2 alone renews its parity bit, and the word is clean again.

At Scale

This page4 words, 1 scrubber
A serverevery memory protected, every error logged

This section looks ahead. On a large chip, memory errors are a system matter, with rules for every memory.

  1. Self-test hardware

    The logic that tests each memory, and how it shares the port, is in Memory Self-Test.

  2. Caches

    A cache of clean data can use parity and fetch again. A cache with written data needs a code that repairs. Common practice.

  3. The interrupt

    An uncorrectable error is one of the few interrupts that the firmware must never ignore: the interrupt path.

  4. Testing the checkers

    An error injector lets a test prove that the counter, the interrupt and the scrubber work. Verification uses it as a hook.

Try It

Run the lab. Check each row against the hand table.

Remove the scrub call. Predict the last two rows before you run it.

Add a third hit on word 1 after the last read, and a scrub. What is the final count?

RUNIcarus Verilog · in your browser
Edit the code, then run it
Expected: write 1 | data 1011 | code word 10101010 hit 1 | position 5 flips | code word 10001010 read 1 | one error at position 5: corrected on the way out | data 1011 | corrected_count=1 read 1 | one error at position 5: corrected on the way out | data 1011 | corrected_count=2 scrub 1 | one error at position 5: repaired, code word 10101010 scrub pass | 4 words read, 1 repaired hit 1 | position 2 flips | code word 10101110 read 1 | one error at position 2: corrected on the way out | data 1011 | corrected_count=4 corrected_count=4 error_address=1 irq=0

Check Yourself

Predict the outputWord 0 is hit, a scrub runs, word 0 is hit again, and a scrub runs again. Then word 3 is hit and read. What does the last row say?
// A memory with a Hamming code, and the logic that reports errors and repairs them.
module tb;
  logic [7:0] mem [0:3];              // one code word of 8 bits for each word. Bit p is position p

  function automatic logic [7:0] encode(input logic [3:0] d);
    logic [7:0] c;
    c[3] = d[0];  c[5] = d[1];  c[6] = d[2];  c[7] = d[3];   // data sits where the position is not a power of two
    c[1] = c[3] ^ c[5] ^ c[7];                               // check bit 1: the positions with a 1 in bit 0 of their number
    c[2] = c[3] ^ c[6] ^ c[7];                               // check bit 2: the positions with a 1 in bit 1
    c[4] = c[5] ^ c[6] ^ c[7];                               // check bit 4: the positions with a 1 in bit 2
    c[0] = c[1] ^ c[2] ^ c[3] ^ c[4] ^ c[5] ^ c[6] ^ c[7];   // the overall parity: every other position
    return c;
  endfunction
  function automatic logic [2:0] syndrome(input logic [7:0] c);   // the three checks, done again on what was read
    return {c[4] ^ c[5] ^ c[6] ^ c[7], c[2] ^ c[3] ^ c[6] ^ c[7], c[1] ^ c[3] ^ c[5] ^ c[7]};
  endfunction

  task automatic write(input int a, input logic [3:0] d);
    mem[a] = encode(d);
    $display("write %0d | data %04b | code word %08b", a, d, mem[a]);
  endtask
  task automatic hit(input int a, input int p);          // a particle flips one stored bit
    mem[a] = mem[a] ^ (8'd1 << p);
    $display("hit   %0d | position %0d flips | code word %08b", a, p, mem[a]);
  endtask
  // What software can see.
  int         corrected_count = 0;    // a counter register: errors that were corrected
  logic [1:0] error_address = 0;      // a register: the word of the last error
  logic       irq = 0;                // the interrupt request: an error that could not be corrected

  // kind: 0 no error, 1 one error (c is repaired), 2 two errors.
  task automatic decode(inout logic [7:0] c, output int kind, output int position);
    logic [2:0] s;
    logic odd;
    s = syndrome(c);  odd = ^c;  position = s;
    if (s == 0 && !odd) kind = 0;
    else if (odd) begin kind = 1;  c = c ^ (8'd1 << s); end
    else kind = 2;
  endtask

  // A read by the program. The data is corrected on its way out. The stored word is left as it is.
  task automatic read(input int a);
    logic [7:0] c;
    int kind, position;
    c = mem[a];  decode(c, kind, position);
    if (kind == 0) $display("read  %0d | no error | data %b%b%b%b", a, c[7], c[6], c[5], c[3]);
    else if (kind == 1) begin
      corrected_count++;  error_address = a;
      $display("read  %0d | one error at position %0d: corrected on the way out | data %b%b%b%b | corrected_count=%0d", a, position, c[7], c[6], c[5], c[3], corrected_count);
    end else begin
      irq = 1;  error_address = a;
      $display("read  %0d | two errors: no data, the bus answers with an error | irq=1 error_address=%0d", a, a);
    end
  endtask

  // One scrub pass: read every word, and write back each word that could be repaired.
  task automatic scrub;
    logic [7:0] c;
    int kind, position, repaired = 0;
    for (int a = 0; a < 4; a++) begin
      c = mem[a];  decode(c, kind, position);
      if (kind == 1) begin
        mem[a] = c;  repaired++;  corrected_count++;  error_address = a;
        $display("scrub %0d | one error at position %0d: repaired, code word %08b", a, position, c);
      end else if (kind == 2) begin
        irq = 1;  error_address = a;
        $display("scrub %0d | two errors: cannot repair | irq=1", a);
      end
    end
    $display("scrub pass | 4 words read, %0d repaired", repaired);
  endtask
  task automatic totals;
    $display("corrected_count=%0d error_address=%0d irq=%b", corrected_count, error_address, irq);
  endtask

  initial begin
    for (int a = 0; a < 4; a++) mem[a] = encode(4'b0000);
    write(0, 4'b1100);
    hit(0, 6);
    scrub;
    hit(0, 1);
    scrub;
    hit(3, 4);
    read(3);
    totals;
  end
endmodule
ConceptA read finds one flipped bit and gives right data. What is in the memory afterwards?
ConceptWhat does a scrub pass do?
ConceptWhat should happen at a read with two flipped bits?
ConceptWhy are corrected errors counted?
ConceptWhich risk does a longer time between scrub passes raise?

Common Mistakes

Wrong Assume that a corrected read has healed the memory.

The repair was made on the data that left. The stored word still holds the flipped bit.

Fix Scrub: read every word in turn, and write back the ones that were repaired.

Wrong Hide corrected errors from software.

A memory that is wearing out looks perfect until the day it loses data.

Fix Count them, keep the address, and let software read the count.

Wrong Hand on the data of an uncorrectable read.

The program would use wrong data as if it were right.

Fix End the transfer with an error, and raise an interrupt.

Remember

  • A corrected read repairs the data that leaves. The stored word stays wrong.
  • Corrected errors are counted. Uncorrectable ones end the read with an error and raise an interrupt.
  • Scrubbing writes repaired words back, so that single errors do not wait for a second flip.
  • ap_soc now has ap_rom and ap_sram behind their ports, with parity as an option.

Practice

Report a problem with this page