Step Compare Against End-of-Test Memory Compare

There are two ways to check a core with a model. Compare every record as it retires, or run the model to the end and compare memory images. This page runs both on two recorded core bugs and measures what each one catches, when, and at what cost.

You Will Be Able To

  • Describe the step compare and the end-of-test memory compare, and what each needs.
  • Explain why an end-of-test compare can report late or never.
  • Read the cost of each method from measured runs.
  • Choose a method for a given bench, and say why.
Lesson
V5.5
Time
26 min
Runs on
Your browser
Check
5 questions

A kernel on this page runs 1,004,426 cycles on a faulty chip, and only its final memory is wrong. Which of its 697,213 instructions made the bad word? The image cannot say. A step compare stops at the first one.

Two Bugs, Two Ways of ComparingStep through the four recorded outcomes: each bug under the step compare and under the end-of-test memory compare.
  • Processor
  • Debug
  • Memory
  • Data
Two Bugs, Two Ways of ComparingStep through the four recorded outcomes: each bug under the step compare and under the end-of-test memory compare. processor Bug 1: SLL shiftsright the shift kernel processor Bug 2: SRL fillsfrom the sign the byte kernel debug Step compare cycle 34: pc and field memory Memory compare cycle 1,004,426: aword differs debug Step compare cycle 24: pc and field memory Memory compare never: the imagesagree at once1,004,392 cycleslaterat oncemasked
  1. processor Bug 1: SLL shifts rightthe shift kernel
    • at once → Step compare
    • 1,004,392 cycles later → Memory compare
  2. debug Step comparecycle 34: pc and field
  3. memory Memory comparecycle 1,004,426: a word differs
  4. processor Bug 2: SRL fills from the signthe byte kernel
    • at once → Step compare
    • masked → Memory compare
  5. debug Step comparecycle 24: pc and field
  6. memory Memory comparenever: the images agree
  1. Bug 1, step compare

    The first wrong SLL differs from the model at cycle 34; the bench stops the run.

  2. Bug 1, memory compare

    With the model off, the run goes on to its end at cycle 1,004,426. Then the image differs from the model's.

  3. Bug 2, step compare

    The first SRL of a negative word differs at cycle 24.

  4. Bug 2, memory compare

    The kernel keeps only bytes of each result: the wrong high bits never reach memory, and the images agree.

Read the diagram as text
  • Bug 1: SLL shifts right: the shift kernel
  • Bug 2: SRL fills from the sign: the byte kernel
  • Step compare: cycle 34: pc and field
  • Memory compare: cycle 1,004,426: a word differs
  • Step compare: cycle 24: pc and field
  • Memory compare: never: the images agree
  • Bug 1: SLL shifts right → Step compare: at once
  • Bug 1: SLL shifts right → Memory compare: 1,004,392 cycles later
  • Bug 2: SRL fills from the sign → Step compare: at once
  • Bug 2: SRL fills from the sign → Memory compare: masked

Recorded on ap_soc v1.5: two kernels of 1,200 rounds, each on a chip with one core fault of stage E9.

Before You Start

Read Lockstep With an Instruction-Level Model first.

Five questions this page answers
Question
1What does each method compare, and when?
2Why can an end-of-test compare report a bug late, or not at all?
3What does each method name when it reports?
4What does the step compare cost in run time?
5When is the end-of-test compare the right choice?

The Idea: Every Step, or the Final Picture

The step compare runs the model in lockstep and checks every record, as on the lockstep page. It needs the trace and a model that can follow the core exactly. It reports at the first wrong instruction, and names it.

The end-of-test compare runs the model alone, on the same program, to its end. Then it compares the memory image the model left with the one the chip left. It needs no trace and no exact timing, only two images. It reports at the end, and names a word.

Between the bug and the end, two things can happen. The wrong value can spread and be overwritten, so the word you find is far from the cause. Or it can vanish: masked, overwritten or never stored. Then the images agree and nothing is reported.

New Words

New words on this page
WordMeaning
Step compareComparing the chip's retire record with the model's, on every record.
End-of-test compareComparing the final memory image of the chip with the model's, once, after the run.
Memory imageThe contents of a memory at one moment, word by word.
Masked faultA wrong value that never reaches anything the check looks at.
Detection latencyThe cycles between a bug happening and a check reporting it.

The Smallest Example: One Wrong Bit, Masked

Take one step of the byte kernel by hand. After the chip's faulty SRL by 8 the word is 0xffdaa674; the model's is 0x00daa674. The kernel keeps only byte 1 of it: andi t1, t1, 0xff.

One result, two machines
After srli by 8After andi 0xffStored
Chip (faulty SRL)ffdaa67400000074byte 1 + byte 2
Model00daa67400000074byte 1 + byte 2

The first mismatch line of the recorded byte kernel: ISS mismatch cycle=24 pc=80000038 field=rd_wdata rtl=ffdaa674 model=daa674

The step compare reports the srli record. The andi removes every wrong bit, so the stored word is the same on both. At the end, the images agree.

The Rules

  1. Rule 1: The step compare reports at the first wrong record.

    Its latency is zero records; it names the pc and the field.

  2. Rule 2: The end-of-test compare reports at the end, or never.

    Its latency is the rest of the run; a masked fault is never reported.

  3. Rule 3: An image names a word, not an instruction.

    Finding the instruction means a search backwards through the run.

  4. Rule 4: The step compare needs an exact model and a trace.

    Every value the model cannot know must come from the chip.

  5. Rule 5: Use both when you can.

    Step compare for the core; images for what a model can only follow loosely.

Sources for These Rules

MEHTA-DV, chapter 18: a cache subsystem checked with instruction-set models of its processors. A random program image runs to the end; the model's expected image of external memory is compared with the simulated one. The book notes that a mismatch found this way is hard to trace back. It suggests also comparing the image of the cache nearer the activity, or assertions that stop the run at once.

Our step compare: soc_iss_dpi.c and soc_tb.sv; its cost of about 1 percent at stage E7 (plan 6.2). The memory compare of this page uses the bench's sram field (soc_tb README). It is a checksum of the first 4,096 words of SRAM at the end of the run.

Now Run It: Two Kernels, Both Methods

Both kernels run 1,200 rounds of 64 steps. On the good chip the shift kernel ends at cycle 1,004,426 and the byte kernel at 1,388,426. The model, run alone to the same end, leaves the chip's SRAM checksums: 01a59dfe and 984ac073.

The step compare on the two faulty chips: rule 1.
ISS mismatch cycle=34 pc=8000002c field=rd_wdata rtl=1e3779b9 model=78dde6e4
  shift kernel, model on: checker at cycle 43
ISS mismatch cycle=24 pc=80000038 field=rd_wdata rtl=ffdaa674 model=daa674
  byte kernel, model on: checker at cycle 33
The end-of-test compare on the same chips: rule 2.
shift kernel, model off: pass at cycle 1,004,426, sram 46e4cf93, model 01a59dfe: differs
byte kernel, model off: pass at cycle 1,388,426, sram 984ac073, model 984ac073: equal

Bug 1 was reported 1,004,392 cycles later than the step compare reported it. Bug 2 was never reported: its program passed, and so did its image. At 4 rounds the shift kernel's image differs in 64 of 64 words. The first is 80000400, last written at cycle 2,535 of 3,374: rule 3. The wrong SLL came at cycle 34.

And the price? On the laptop, the shift kernel of 1,200 rounds ran 5 times each way on the good chip. Every run took between 3.868 and 4.425 s, with the step compare or without. The two medians differ by less than the spread between runs: the compare's cost is lost in the noise.

The byte kernel's extraction: srli then andi.
    add  a0, a0, t5                # (keeps the high bit busy)
    srli t1, a0, 8
    andi t1, t1, 0xff              # byte 1
    srli t2, a0, 16
    andi t2, t2, 0xff              # byte 2

Why It Is Built This Way

On this chip the step compare is nearly free. The core is in order and the model is fast C in the same process. Every value it cannot know is in the record. So our bench runs it on every test with the processor, and a mismatch ends the run.

The end-of-test compare earns its place where a model cannot follow the hardware step by step. The book's cache subsystem is one: two processors, caches and memory interleave their transfers in ways an instruction-level model does not time. A final image of memory still has one right answer, whatever the order in between.

This bench's sram field is a checksum, not an image. Two different images can share a checksum, though rarely. A real end-of-test compare dumps the words, as the practice problem does with the model's memory.

The Trap: The Bug That Washed Out

A team checks only final images. Its random programs pass, one after another. The bug in the byte kernel above is in their core too: every value it touched was masked before it was stored. Then a driver uses the full word, and the bug appears on silicon.

An image compare is a sample of the end, not a record of the run. Keep a step compare where you can afford one. Where you cannot, compare intermediate images, or add assertions that stop the run at once. The practice problem writes the end-of-test compare; the worksheet prices both.

At Scale

ap_soc~12 blocks
Phone-class SoChundreds of blocks

This section looks ahead. ap_soc has one core and no cache.

  1. Caches and coherence

    With caches, memory is right only after a flush; images are compared after it, and assertions watch the protocol on the way.

  2. Long runs

    Emulators run billions of cycles. A step compare there streams records off the box, and an image compare is often all there is.

  3. Checkpoints

    Comparing registers and memory at checkpoints splits the difference: latency of one interval, cost of a few compares.

Try It

Run the slice: for each bug and method, the cycle of the report and the last cycle of the run.

Which method reported bug 2, and at which cycle?

The predict question gives it the shorter runs.

RUNIcarus Verilog · in your browser
Edit the code, then run it
Expected: shift left reversed, step compare: reported at cycle 34 of 43 shift left reversed, memory compare: reported at cycle 1004426 of 1004426 logical shift fills from the sign, step compare: reported at cycle 24 of 33 logical shift fills from the sign, memory compare: never reported (1388426 cycles run)

Check Yourself

Predict the outputThe slice now holds the memory compare of the two kernels at 4 rounds. What is the last line it prints?
// Two bugs, two ways of comparing. For each: the cycle at which the method reported it (0: never), and
// the run's last cycle. A step compare names an instruction; a memory compare names a word.
module tb;
  localparam int N = 2;
  string bug [N], method [N];
  int at [N], last [N];
  initial begin
    bug[0] = "shift left reversed"; method[0] = "memory compare"; at[0] = 3374; last[0] = 3374;
    bug[1] = "logical shift fills from the sign"; method[1] = "memory compare"; at[1] = 0; last[1] = 4654;
    for (int i = 0; i < N; i++)
      if (at[i] == 0) $display("%s, %s: never reported (%0d cycles run)", bug[i], method[i], last[i]);
      else $display("%s, %s: reported at cycle %0d of %0d", bug[i], method[i], at[i], last[i]);
  end
endmodule
ConceptWhat does each method compare, and when?
ConceptWhy did the end-of-test compare never report bug 2?
ConceptWhat does an end-of-test compare name when it reports?
ConceptWhen is the end-of-test compare the right choice?

Common Mistakes

Wrong Compare only the final memory image.

A masked fault never reaches memory, and a late report hides its cause.

Fix Keep a step compare where the model can follow the core.

Wrong Debug from the first differing word.

The word may have been written long after the bug, many times.

Fix Find its last writer, then work back, or rerun with the step compare.

Wrong Skip the step compare to save time.

On this chip it costs about a hundredth of the run.

Fix Measure the cost before you drop a check.

Remember

  • The step compare checks every record and reports the first wrong instruction at once.
  • The end-of-test compare checks final images: it reports late, names a word, and misses masked faults.
  • On this chip the step compare costs less than the spread between runs; it runs on every test with the processor.
  • Use images where a model cannot follow the hardware step by step; keep step compares where it can.

Practice

Report a problem with this page