From 58b8023ed532ffcd084ab5d12bee94c479bb954f Mon Sep 17 00:00:00 2001 From: pi-hrx-mem Date: Sun, 15 Nov 2026 12:46:37 -0400 Subject: [PATCH] census: the flags histogram counts the lines it cannot bucket as (absent) #2559 added a per-(boot, device, domain) flags histogram so a one-bucket picture could not hide the rare value again. It left the other axis: a fault line with no flags field -- or with a field the regex cannot parse, which the census cannot tell apart -- is counted in `faults` but invisible in `flags`, and the text report suppressed the whole line when a bucket had none. Measured on the merged tool: 3 fault(s), 3 distinct flags: 0x0007 x2 <- accounts for two of three, and nothing says which is missing Now the absent case is a value like any other: 3 fault(s), 3 distinct flags: 0x0007 x2, (absent) x1 which makes sum(flags) == faults an invariant the self-test can assert, so a parse regression or a dropped field shows up as a broken partition rather than a quiet under-count. Three arms: the no-flags line is COUNTED (not merely parsed), and the partition holds for both a mixed bucket and the device-less fixture. Mutation: re-dropping the absent case fails both new arms by name. --- tools/diag/iommu_fault_census.py | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/tools/diag/iommu_fault_census.py b/tools/diag/iommu_fault_census.py index e1be6c693..0f5ab3dc5 100755 --- a/tools/diag/iommu_fault_census.py +++ b/tools/diag/iommu_fault_census.py @@ -65,8 +65,12 @@ def census(rows): counts, flag_counts = {}, {} for a, fl in pairs: counts[a] = counts.get(a, 0) + 1 - if fl: - flag_counts[fl] = flag_counts.get(fl, 0) + 1 + # A line whose flags field is absent -- or present and unparseable, which this cannot tell apart -- + # is counted in ``faults`` either way, so it must appear in the histogram too: a bucket that only + # holds the lines it could parse under-counts, and an under-count is indistinguishable from a quiet + # device. ``(absent)`` keeps sum(flags) == faults for every bucket (review of engine#2559). + key = fl or "(absent)" + flag_counts[key] = flag_counts.get(key, 0) + 1 top = sorted(counts.items(), key=lambda kv: (-kv[1], kv[0]))[:5] out.append( { @@ -143,10 +147,9 @@ def render(entries, inter, as_json): ) for t in e["top"]: lines.append(" %s x%d" % (t["address"], t["count"])) - if e["flags"]: - lines.append( - " flags: %s" % ", ".join("%s x%d" % (f, n) for f, n in sorted(e["flags"].items(), key=lambda kv: -kv[1])) - ) + lines.append( + " flags: %s" % ", ".join("%s x%d" % (f, n) for f, n in sorted(e["flags"].items(), key=lambda kv: -kv[1])) + ) lines.append(" -> %s" % shape(e)) if inter is None: lines.append("shared across boots: (need two or more labeled journals of the same device)") @@ -281,6 +284,12 @@ def ok(name, got, want): "AMD-Vi: Event logged [IO_PAGE_FAULT domain=0x0001 address=0x1000]\n" ) ok("a fault line without a flags field still parses", census(parse(no_flags, "b"))[0]["faults"], 1) + ok(" ...and it is COUNTED, not dropped from the histogram", + census(parse(no_flags, "b"))[0]["flags"], {"(absent)": 1}) + # engine#2559 review: the histogram must partition the total, or the lines it could not bucket vanish from a + # report that still says how many faults there were -- the same loss the histogram was added to prevent. + for _e in census(parse(two_flags + no_flags, "b")): + ok(" flags partition the fault count (%s)" % _e["device"], sum(_e["flags"].values()), _e["faults"]) print("iommu_fault_census self-test: %d failure(s)" % fails) return 1 if fails else 0