Skip to question
asic.fyi
DesignVerificationSystemVerilogFirmwareArchitectureInterviews
asic.fyi/Interview questions/Measure dependent L1-cache load latency

Hardware interview practice

Measure dependent L1-cache load latency

HardMemory SystemsC

Design a C microbenchmark that estimates dependent-load latency for a 32 KiB L1 data cache. Explain how you prevent the compiler, prefetching, migration, and timer overhead from invalidating the result.

Try it in the question bankReason first. Then compare.

Keep this exact question selected while you check your answer and review the full solution.

Practice this question →
Starting point

Question code

double measure_l1_cycles_per_load(
    uintptr_t **pointer_chain,
    size_t chain_bytes,
    size_t iterations);
Reviewed example

Work through one case

Input
100000 dependent loads; serialized elapsed time 402000 cycles; matched empty-loop/timer overhead 2000 cycles; start/end CPU IDs match
Expected output
(402000-2000)/100000 = 4.0 cycles per dependent L1 load; accept the trial

Dependency prevents parallel loads from hiding latency, and subtracting matched overhead isolates the approximate per-load cost.

What to cover

Requirements

  1. Use an L1-sized randomized dependent pointer chain so each load supplies the address of the next load.
  2. Warm the chain, keep the final pointer observable, and prevent compiler removal or reordering of the measured loop.
  3. Use architecture-supported serialized cycle reads, subtract measured loop/timer overhead, and divide by accepted dependent loads.
  4. Repeat trials, reject migration or non-L1 working sets, pin the thread when supported, and report a robust statistic such as the median.
asic.fyi · Learn silicon end to end.info@asic.fyi