Hardware interview practice
Classify ECC counter changes
A monitor compares two AMD-style reliability, availability, and serviceability (RAS) snapshots with monotonic error-correcting code (ECC) counters. Write the C++ function that validates the samples and returns the required severity.
Starting point
Question code
enum Sev { ECC_OK, ECC_WARN, ECC_FATAL, ECC_BAD };
Sev ecc_delta(uint64_t c0,uint64_t u0,uint64_t c1,uint64_t u1,
uint64_t warn_threshold);Reviewed example
Work through one case
Input
c0 = 10, u0 = 0, c1 = 13, u1 = 0, warn_threshold = 3.Expected output
ecc_delta returns ECC_OK.No counter regresses, the uncorrectable delta is zero, and the correctable delta equals rather than exceeds the warning threshold.
What to cover
Requirements
- If either new counter is less than its old counter, return ECC_BAD.
- If u1-u0 is nonzero, return ECC_FATAL regardless of the correctable delta.
- Otherwise return ECC_WARN when c1-c0 is strictly greater than warn_threshold.
- Return ECC_OK for every remaining case, including a correctable delta equal to the threshold.
