Dependable Memory: Soft Errors and Parity

A memory that works perfectly will still hand back a wrong bit now and then. One extra bit beside the data is enough to notice.

You Will Be Able To

  • Explain what a soft error is, and why it is not a broken cell.
  • Work out a parity bit, and check a word that was read back.
  • Say which errors parity finds, which it misses, and where its bit is stored.
Lesson
S3.12
Time
25 min
Runs on
Your browser
Check
6 questions

A machine has run the same program for two years. One night a valve opens that the program never asked for. The program is unchanged, and every test of the memory passes. For a moment, one bit of one variable was different.

Before You Start

You need the SRAM of S3.15: words, a write, a read, and byte strobes.

You need the exclusive-OR gate, which says whether two bits differ.

Five questions this page answers
Question
1What is a soft error?
2How is a parity bit worked out?
3What does a parity check find, and what does it miss?
4Where are the parity bits kept?
5What can a chip do after a parity error?

The Idea: Notice the Flip

A memory cell holds its bit with a tiny amount of charge. Now and then a particle from outside passes through the chip and leaves charge behind. If it lands on the wrong spot, a stored bit flips.

This is called a soft error. Soft, because nothing is damaged. The cell works, and the next write stores a good value again. No test of the memory will ever find the cell. A cell that is truly broken gives a hard error, and that is a different problem.

Soft errors are rare for one cell. A chip has millions of cells, and a product runs for years. So for some products they are certain to happen.

The simplest defence is one more bit for each word: a parity bit. At the write it is set so that the word and the bit together hold an even number of ones. This is even parity.

At every read, the ones are counted again. One flipped bit makes the count odd. That is a parity error. The memory cannot say which bit is wrong. It can say that the word is not to be trusted.

The parity bit is a check bit: a stored bit that carries no data and exists only to check the others. It lives in the same word as the data, in an extra column of the memory.

New Words

New words on this page
WordMeaning
Soft errorA stored bit that flips by itself, because a particle hit the chip. Nothing is damaged.
Hard errorA wrong bit from a cell that is broken. It comes back after every write.
Check bitA stored bit that carries no data. It exists to check the data bits.
Parity bitOne check bit that makes the number of ones in a word even.
Even parityThe rule that data and parity bit together hold an even number of ones.
Parity errorA read that finds an odd number of ones. At least one bit has flipped.
Error injectorA way for a test to flip a stored bit on purpose. In the lab it is the task hit.

One Picture: Count at the Write, Count Again at the Read

One Extra Bit Beside the Data, Checked on Every ReadStep through the picture. A parity bit is worked out at the write, stored beside the data, and checked at the read.
  • Processor
  • Control / FSM
  • Memory
  • Bus
One Extra Bit Beside the Data, Checked on Every ReadStep through the picture. A parity bit is worked out at the write, stored beside the data, and checked at the read. component Write data 1011_0010 component Count the ones four: even, so the bitis 0 component Stored word 8 data bits and 1parity bit component Particle flips one stored bit component Count again all nine bits component Parity error the count is odd component Read data the count is even datadata and bitflipnine bitsevenodd
  1. component Writedata 1011_0010
    • data → Count the ones
  2. component Count the onesfour: even, so the bit is 0
    • data and bit → Stored word
  3. component Stored word8 data bits and 1 parity bit
    • nine bits → Count again
  4. component Count againall nine bits
    • even → Read data
    • odd → Parity error
  5. component Read datathe count is even
  6. component Particleflips one stored bit
    • flip → Stored word
  7. component Parity errorthe count is odd
  1. At the write: count

    The data has four ones. That is even, so the parity bit is 0. With an odd count it would be 1.

  2. Stored side by side

    The memory is one bit wider than the data. The parity bit is written by the same write, into the same word.

  3. A clean read

    The read counts the ones of all nine bits. The count is even, as it was made to be. The data is accepted.

  4. A particle hits

    Some time later one stored bit flips. Nothing is broken. The cell simply holds the other value now.

  5. The read after the hit

    The count of ones is odd now. The check cannot say which bit flipped. It can say that this word must not be used.

Read the diagram as text
  • Write: data 1011_0010
  • Count the ones: four: even, so the bit is 0
  • Stored word: 8 data bits and 1 parity bit
  • Particle: flips one stored bit
  • Count again: all nine bits
  • Parity error: the count is odd
  • Read data: the count is even
  • Write → Count the ones: data
  • Count the ones → Stored word: data and bit
  • Particle → Stored word: flip
  • Stored word → Count again: nine bits
  • Count again → Read data: even
  • Count again → Parity error: odd

Parity turns silent wrong data into a known error. It does not bring the right data back.

The Smallest Example, Worked by Hand

Two bytes are written, and each gets its parity bit. Then each takes a hit.

Two bytes, their parity bits, and one flip each
StepDataParity bitOnes in all nine bitsThe check says
write 1011_00101011_001004: even
write 0000_01110000_011114: even
bit 3 of the first byte flips1011_101005: oddparity error
the parity bit of the second flips0000_011103: oddparity error

A flip of the parity bit itself is found too. The data is fine in that case, and the check cannot know that.

In hardware the count is a chain of exclusive-OR gates. The exclusive-OR of all bits is 1 exactly when the number of ones is odd. So the parity bit is the exclusive-OR of the data bits, and the check is the exclusive-OR of all nine.

Now the cost. A word of 32 bits with one parity bit is 33 bits wide. With one parity bit for each byte it is 36 bits wide. The SRAM of ap_soc has 16,384 words, so that choice adds 65,536 bits.

The Rules

  1. Rule 1: A soft error flips a stored bit and damages nothing.

    The next write of that word stores good bits again.

  2. Rule 2: The parity bit is the exclusive-OR of the data bits.

    Data and parity bit together then hold an even number of ones.

  3. Rule 3: Every read checks all the bits, the parity bit too.

    An odd count is a parity error.

  4. Rule 4: Parity finds any odd number of flips, and misses any even number.

    One flip is found. Two flips in one word pass.

  5. Rule 5: Parity cannot repair.

    It does not know which bit flipped. The right data must come from somewhere else.

  6. Rule 6: The check bits live beside the data.

    They are written by the same write, read by the same read, and hit by the same particles.

Sources for These Rules

The textbook "CMOS VLSI Design" by Weste and Harris, section 7.3.4, "Soft Errors". It describes random errors that do not recur. They were first traced to alpha particles, and today most come from neutrons of cosmic radiation.

The textbook "Computer Organization and Design" by Patterson and Hennessy, section 5.5. See the part on parity: one bit makes the count of ones even, one flipped bit is found, and two are not.

Even parity is a choice. Odd parity works the same way with the opposite bit.

Now Run It

The lab at the end of this page is test code. It has a memory of four words. A word is 9 bits wide: 8 data bits and a parity bit. The task hit is the error injector.

Printed by the lab on Icarus. A stored word is shown with the parity bit first, then the 8 data bits.
write 0 | data 10110010 | parity bit 0 | stored 0_10110010
write 1 | data 00000111 | parity bit 1 | stored 1_00000111
read  0 | stored 0_10110010 | the ones are even | data 10110010 accepted
read  1 | stored 1_00000111 | the ones are even | data 00000111 accepted
hit   0 | bit 3 flips | stored 0_10111010
read  0 | stored 0_10111010 | the ones are odd | parity error: the data is not used
hit   1 | bit 8 flips | stored 0_00000111
read  1 | stored 0_00000111 | the ones are odd | parity error: the data is not used
reads=4 parity_errors=2

Rule 2 at work: rows 1 and 2. Four ones give a parity bit of 0. Three ones give 1.

Rule 3 at work: rows 3 and 4. Both words are read back with an even count, and are accepted.

Rules 3 and 4 at work: rows 5 and 6. One data bit flips, the count is odd, and the read refuses the data.

Rule 6 at work: rows 7 and 8. The particle hits the parity bit itself. The data is right, and the read still refuses it.

This lab stops at "the data is not used". What a chip does next depends on whether another copy exists. That is in At Scale, and in S3.28.

Why It Is Built This Way

Design choiceThe alternativeWhat the choice buys, and costs
A parity bitNo check at allA flipped bit is noticed and not used. One more bit in every word, and a tree of gates in every read.
One bit for each byteOne bit for a whole wordA write of one byte renews only its own bit. Two flips in different bytes are both found. Four bits a word.
Check bits in the same wordA separate memory for themOne access reads both. A particle can hit them as well.
Detect onlyDetect and repairVery little logic. The data must be fetched again from somewhere, or the system must stop.

The Trap: Two Flips in One Word

A team protects its SRAM with parity and calls the memory safe. One word is written and then left alone for a long time. It is hit twice before anyone reads it.

The same lab: two hits on word 0, and then one read.
write 0 | data 10110010 | parity bit 0 | stored 0_10110010
hit   0 | bit 3 flips | stored 0_10111010
hit   0 | bit 6 flips | stored 0_11111010
read  0 | stored 0_11111010 | the ones are even | data 11111010 accepted

The last row is the failure. The data is 1111_1010, and 1011_0010 was written. The count of ones is even again, so the read accepts it.

Parity did nothing wrong. Rule 4 says what it can see. Two flips in one word are rare, and they grow less rare the longer a word waits.

So parity fits memories that are rewritten often, or that hold copies. A memory that holds the only copy for a long time needs more: the next lesson.

At Scale

This page1 check bit for 8 data bits
The SRAM of ap_soc, as an option4 check bits for 32 data bits, in 16,384 words

This section looks ahead. Every large memory is protected, and the kind of memory decides how.

  1. After a parity error

    A cache of code can drop the block and fetch it again. A memory with the only copy can only raise an alarm. Common practice.

  2. Repair

    A few more check bits can name the flipped bit, so that the read repairs it: the next lesson.

  3. Height matters

    There are far more neutrons at the height where aircraft fly than at sea level. Weste and Harris, section 7.3.4.

  4. Wires too

    A bit can also flip on its way over a bus. Buses can carry parity bits of their own: APB parity protection.

Try It

Run the lab. Check each parity bit by counting ones.

Add a second hit on word 0 before its last read. Predict the row.

Change the memory to odd parity. Which two lines change?

RUNIcarus Verilog · in your browser
Edit the code, then run it
Expected: write 0 | data 10110010 | parity bit 0 | stored 0_10110010 write 1 | data 00000111 | parity bit 1 | stored 1_00000111 read 0 | stored 0_10110010 | the ones are even | data 10110010 accepted read 1 | stored 1_00000111 | the ones are even | data 00000111 accepted hit 0 | bit 3 flips | stored 0_10111010 read 0 | stored 0_10111010 | the ones are odd | parity error: the data is not used hit 1 | bit 8 flips | stored 0_00000111 read 1 | stored 0_00000111 | the ones are odd | parity error: the data is not used reads=4 parity_errors=2

Check Yourself

Predict the outputThe byte 1111_1111 is written and read. Then bit 0 flips, and the word is read again. What does the last row say?
// A small memory. Each word is 9 bits wide: 8 data bits, and one parity bit beside them.
module tb;
  logic [8:0] mem [0:3];              // bit 8 is the parity bit. Bits 7 to 0 are the data
  int reads = 0, parity_errors = 0;

  task automatic write(input int a, input logic [7:0] d);
    mem[a] = {^d, d};                 // the parity bit makes the number of ones even
    $display("write %0d | data %08b | parity bit %b | stored %b_%08b", a, d, mem[a][8], mem[a][8], mem[a][7:0]);
  endtask
  task automatic hit(input int a, input int b);          // a particle flips one stored bit
    mem[a] = mem[a] ^ (9'd1 << b);
    $display("hit   %0d | bit %0d flips | stored %b_%08b", a, b, mem[a][8], mem[a][7:0]);
  endtask
  task automatic read(input int a);
    reads++;
    if (^mem[a] == 1'b0) $display("read  %0d | stored %b_%08b | the ones are even | data %08b accepted", a, mem[a][8], mem[a][7:0], mem[a][7:0]);
    else begin
      parity_errors++;
      $display("read  %0d | stored %b_%08b | the ones are odd | parity error: the data is not used", a, mem[a][8], mem[a][7:0]);
    end
  endtask
  task automatic totals;
    $display("reads=%0d parity_errors=%0d", reads, parity_errors);
  endtask

  initial begin
    write(2, 8'b1111_1111);
    read(2);
    hit(2, 0);
    read(2);
    totals;
  end
endmodule
ConceptWhat is a soft error?
ConceptWhich parity bit does even parity store beside 0101_0001?
ConceptTwo bits of one stored word flip. What does the parity check say?
ConceptWhere is the parity bit of a word kept?
ConceptWhy can parity not repair a word?

Common Mistakes

Wrong Call a memory with parity error-free.

Two flips in one word leave the count even, and pass.

Fix Say what it finds: any odd number of flips in a word.

Wrong Leave the parity bit out of the check.

Then the check compares nothing. The stored bit is what makes the count even.

Fix Take the exclusive-OR of the data bits and the parity bit together.

Wrong Hunt for a broken cell after a soft error.

Nothing is broken. The next write heals the word.

Fix Count the errors. A cell that fails again and again is a hard error.

Remember

  • A soft error is a flipped bit in a working cell. A product with much memory and long use will meet some.
  • A parity bit makes the count of ones even. An odd count at a read is a parity error.
  • Parity finds an odd number of flips and misses an even number. It cannot repair.
  • Check bits are stored beside the data, in a wider word.

Practice

Report a problem with this page