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.
| Question | |
|---|---|
| 1 | What does a read do with a word that has one flipped bit? |
| 2 | Why is the flipped bit still in the memory afterwards? |
| 3 | What is scrubbing? |
| 4 | What happens when a word has two flipped bits? |
| 5 | Which 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
| Word | Meaning |
|---|---|
| Correction on read | The decoder repairs the data on its way to the bus. The stored word is not changed. |
| Corrected error | A read that found one flipped bit and gave the right data all the same. |
| Uncorrectable error | A read that found two flipped bits. There is no right data to give. |
| Error counter | A register that counts corrected errors. Software reads it now and then. |
| Scrubbing | Reading every word in turn and writing back each one that needed repair. |
| Scrub pass | One 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 memory | A built-in self-test for a memory. It writes and reads every word to find broken cells. |
| Back door | A 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
- Memory
- Control / FSM
- Bus
- Processor
- 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.
- 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.
- 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.
- 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.
- 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.
| Event | Stored word after it | What the program gets | Corrected count |
|---|---|---|---|
| position 5 flips | 1000 1010 | 0 | |
| a read | 1000 1010: unchanged | 1011, repaired | 1 |
| a second read | 1000 1010: unchanged | 1011, repaired again | 2 |
| a scrub pass | 1010 1010: written back | 3 | |
| position 2 flips | 1010 1110 | 3 | |
| a read | 1010 1110: unchanged | 1011, repaired | 4 |
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
Rule 1: A read repairs the data on its way out, and leaves the stored word alone.
Only a write changes the memory.
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.
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.
Rule 4: A scrub pass writes back every word that the decoder could repair.
After the pass the memory holds no single errors.
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.
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.
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=0Rules 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 choice | The alternative | What the choice buys, and costs |
|---|---|---|
| Repair on the way out only | Write back at every corrected read | The read path stays a read. Errors stay in the memory until a scrub. |
| A scrubber in the background | No scrubbing | Single errors are removed before a second one joins them. A little bus time, all the time. |
| Count corrected errors | Hide them | A climbing count warns of a failing memory before data is lost. A few registers. |
| An interrupt for uncorrectable errors | A flag that software polls | Wrong 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.
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=1Nobody 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.
| Block | What it is | Where it comes from |
|---|---|---|
| ap_rom | The 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_sram | The SRAM: 16,384 words, with byte strobes. | S3.15 |
| ap_sram_parity | The 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 port | One SRAM access for each bus transfer. | Your answer to S3.1.2 |
| The SEC-DED coder for words of 32 bits | It 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.
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 0000Row 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 section looks ahead. On a large chip, memory errors are a system matter, with rules for every memory.
Self-test hardware
The logic that tests each memory, and how it shares the port, is in Memory Self-Test.
Caches
A cache of clean data can use parity and fetch again. A cache with written data needs a code that repairs. Common practice.
The interrupt
An uncorrectable error is one of the few interrupts that the firmware must never ignore: the interrupt path.
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?
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=0Check Yourself
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.