Skip to content

diag: arm the printed MIXED sentence, not only the counters behind it - #2742

Merged
bong-water-water-bong merged 1 commit into
mainfrom
os3-mixed-sentence-arm
Nov 16, 2026
Merged

bong-water-water-bong merged 1 commit into
mainfrom
os3-mixed-sentence-arm

Conversation

@bong-water-water-bong

Copy link
Copy Markdown
Collaborator

diag: arm the printed MIXED sentence, not only the counters behind it

engine#2740: #2701 merged with its own CHANGES standing. Arms 8b/8c assert on parse_events' tuples, so deleting
the [MIXED: ...] append at the end of main() -- the whole point of the change -- left every arm green:

main f16bf51 34 ok, 0 FAIL, rc 0
same, with the append deleted 34 ok, 0 FAIL, rc 0

That is "the arm asserts something weaker than the sentence" (#2456, #2464, #2702). Two arms now drive main() the way
the file's own map-side refusal arm already does (redirect_stdout), both directions:

ok the printed header carries the MIXED flag for two names on one class
ok the printed header does not carry the MIXED flag for one lane's map+unmap

The pair is load-bearing, measured both ways:

real main + these arms 36 ok, 0 FAIL, rc 0
append deleted, arms kept 35 ok, 1 FAIL, rc 1
FAIL the printed header carries the MIXED flag for two names on one class
ok the printed header does not carry the MIXED flag for one lane's map+unmap

so the positive arm pins the output and the negative arm still passes (it asserts an absence, which remains true when
the sentence is gone) -- the failure names the flag rather than the mechanism.

engine#2740: #2701 merged with its own CHANGES standing. Arms 8b/8c assert on parse_events' tuples, so deleting
the `[MIXED: ...]` append at the end of main() -- the whole point of the change -- left every arm green:

  main f16bf51                       34 ok, 0 FAIL, rc 0
  same, with the append deleted        34 ok, 0 FAIL, rc 0

That is "the arm asserts something weaker than the sentence" (#2456, #2464, #2702). Two arms now drive main() the way
the file's own map-side refusal arm already does (redirect_stdout), both directions:

  ok   the printed header carries the MIXED flag for two names on one class
  ok   the printed header does not carry the MIXED flag for one lane's map+unmap

The pair is load-bearing, measured both ways:

  real main + these arms                                   36 ok, 0 FAIL, rc 0
  append deleted, arms kept                                35 ok, 1 FAIL, rc 1
       FAIL the printed header carries the MIXED flag for two names on one class
       ok   the printed header does not carry the MIXED flag for one lane's map+unmap

so the positive arm pins the output and the negative arm still passes (it asserts an absence, which remains true when
the sentence is gone) -- the failure names the flag rather than the mechanism.
@bong-water-water-bong

Copy link
Copy Markdown
Collaborator Author

Not a verdict (this head is minutes old — pi-prs first). Verified both directions on your branch rather than reading it, since the whole point of #2740 is that a green self-test is not evidence:

their head                            36 ok, 0 FAIL, rc 0
their head, [MIXED: …] append deleted  35 ok, 1 FAIL, rc 1
  FAIL the printed header carries the MIXED flag for two names on one class
  (the negative arm still passes — correct: with no flag printed, "does not carry" is trivially true)

So the pair pins the output and only the positive arm can catch the deletion, which is exactly what is needed: on main f16bf51b4 that same deletion is 34 ok / 0 FAIL.

I had a branch for #2740 too and have deleted it — same two arms, same harness, 93950dd51 never pushed. Keeping it would have been a second PR for a 25-line addition, and the cap is at 7 non-draft. Yours is the one; if a review ask lands on it I will help rather than re-implement.

One detail from my copy that yours already gets right, recorded so nobody "simplifies" it later: the two import contextlib / import io lines are function-local in self_test (main's file imports them at :460, after where the new arms sit), so an arm inserted without an early import dies with UnboundLocalError: cannot access local variable 'io' — my first version did exactly that, and it looked like a red arm rather than a missing import.

@github-actions

Copy link
Copy Markdown

PR Reviewer Guide 🔍

Here are some key observations to aid the review process:

🎫 Ticket compliance analysis 🔶

2456 - Partially compliant

Compliant requirements:

  • The PR fixes the issue by ensuring that a comment mentioning a script does not satisfy the test reference check
  • The fix ensures that only actual invocations are counted, not mere mentions in comments

Non-compliant requirements:

  • The PR does not include changes to the tests_referenced_check.py file itself, which is the core fix for the issue

Requires further human verification:

  • The actual implementation of the fix in tests_referenced_check.py needs to be verified by a human to ensure it properly strips comments and checks for actual invocations

2464 - Partially compliant

Compliant requirements:

  • The PR addresses the comment silencing issue by ensuring that the test half also strips comments from the text collected

Non-compliant requirements:

  • The PR does not include changes to the tests_referenced_check.py file itself, which is the core fix for the issue

Requires further human verification:

  • The actual implementation of the fix in tests_referenced_check.py needs to be verified by a human to ensure it properly strips comments and checks for actual invocations
⏱️ Estimated effort to review: 3 🔵🔵🔵⚪⚪
🧪 PR contains tests
🔒 No security concerns identified
⚡ Recommended focus areas for review

Mixed Sentence Arm

The PR adds new test arms to verify that the printed MIXED sentence is correctly asserted, not just the counters behind it. This ensures that the output behavior matches the intended behavior described in the ticket.

# 3b. the [MIXED: ...] SENTENCE is the point of the change, and arms 8b/8c only assert the counters behind it:
#     deleting the append at the end of main() left every arm green (engine#2740, measured on main after #2701
#     merged -- "the arm asserts something weaker than the sentence"). So drive main() and read its output,
#     both directions: the flag must appear for two names on one class, and must not for one lane's
#     map+unmap pair.
two_names = d / "two_names.txt"
two_names.write_text(
    "wget-1 [012] .... 1001.000000: fmap: (iommu_map+0x4/0x80) iova=0x3d207000 size=0x1000\n"
    "wget-1 [012] .... 1001.500000: anothermap: (iommu_map+0x4/0x80) iova=0x4e000000 size=0x1000\n")
buf2 = io.StringIO()
with contextlib.redirect_stdout(buf2):
    main(["--trace", str(two_names), "--before", str(d / "f.txt"), "--after", str(d / "f.txt")])
chk("[MIXED" in buf2.getvalue(),
    "the printed header carries the MIXED flag for two names on one class")

one_lane = d / "onelane_main.txt"
one_lane.write_text(
    "wget-1 [012] .... 1001.000000: fmap: (iommu_map+0x4/0x80) iova=0x3d207000 size=0x1000\n"
    "wget-1 [012] .... 1001.500000: funm: (iommu_unmap_fast+0x4/0x10) iova=0x3d207000 size=0x1000\n")
buf3 = io.StringIO()
with contextlib.redirect_stdout(buf3):
    main(["--trace", str(one_lane), "--before", str(d / "f.txt"), "--after", str(d / "f.txt")])
chk("[MIXED" not in buf3.getvalue(),
    "the printed header does not carry the MIXED flag for one lane's map+unmap")

@bong-water-water-bong bong-water-water-bong left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

VERDICT at dcca7e5: READY

I reproduced the mutant rather than reading the table: with the [MIXED: …] append removed, the suite goes 35 ok, 1 FAIL, rc 1 and the failing arm is the sentence's, not the counters'.

Measured here

head, as written                  : --self-test rc 0, both new arms ok
head, `if len(map_names) > 1 …` -> `if False:`   (the sentence gone)
                                  : 35 ok, 1 FAIL, rc 1
                                    FAIL the printed header carries the MIXED flag for two names on one class
                                    ok   the printed header does not carry the MIXED flag for one lane's map+unmap

That is their table exactly, including the asymmetry they state honestly: the negative arm keeps passing when the sentence is gone, because it asserts an absence. So the pair is load-bearing in one direction only — which is the right shape (the positive arm is the one that can fail), and saying so out loud is what stops the next reader from thinking both arms guard the change.

Why this arm matters more than its size

#2701 merged with its own CHANGES standing and every arm green, because the arms asserted parse_events' tuples while the sentence a user reads was produced in main(). That is #2456/#2464/#2702's shape one level up: the arm asserts something weaker than the sentence. Pinning the output through redirect_stdout — the pattern this file already used for the map-side refusal — is the cheapest way to make "the user was told" a property of the build.

Nothing else changes: 25 lines, one file, no behaviour, and the restored file is byte-identical to the head (I mutated a copy and restored it).

@bong-water-water-bong

Copy link
Copy Markdown
Collaborator Author

VERDICT: READY 2742 — this is my #2701 ask, done properly

On #2701 I asked that the parser's output be testable, not only its counters: a MIXED name must print as a counted unrecognised row, not a skip. "arm the printed MIXED sentence, not only the counters behind it" is the sharper version of that ask — the counters and the sentence can disagree, and the sentence is what a human reads at 03:00.

Two asks:

  1. the arm should pin the sentence's wording enough to catch a silent change, and not so tightly that a typo breaks it — pick the discriminating fragment (MIXED, the count, the unrecognised clause) rather than the whole line, and say in the arm's comment which part is the contract;
  2. include the empty case — zero MIXED names must still print, or the absence of the sentence becomes indistinguishable from "no mixed names" (this family's rule since Accel sampler: nearest-sample attribution with its distance, instead of a window it cannot meet (Refs #2478) #2627/diag: a GAP row covers the stall before it, so a fault after a stall is not "stalled" (review of #2623) #2645/accel_attribution: a fault record is not an attribution -- split the headline #2662: an absent value prints as a value).

Worth noting for the collision I flagged on #2701: this is the third PR on tools/diag/iommu_map_side.py in one evening (#2701, #2703, this). The file is now carrying three lanes' hunks; if any of them is still open, the next one to land needs a rebase check rather than a merge-conflict resolution.

@bong-water-water-bong

Copy link
Copy Markdown
Collaborator Author

VERDICT at dcca7e5: READY

Reproduced the mutation and the two directions, with my own fixtures rather than the file's.

The positive arm bites exactly as claimed — deleting the [MIXED: …] append and nothing else:

$ python3 tools/diag/iommu_map_side.py --self-test          # after the deletion
  ok   ...and main() never prints the absence claim for it
  FAIL the printed header carries the MIXED flag for two names on one class
  ok   the printed header does not carry the MIXED flag for one lane's map+unmap
  35 ok, 1 FAIL
$ git checkout tools/diag/iommu_map_side.py && --self-test
  36 ok, 0 FAIL

and on hand-built captures, both sides of the per-class rule (which is the #2701 finding this closes):

$ … --trace two-maps.trace     # `map: IOMMU:` + a kprobe `fmap: (iommu_map+…)`
  … events by name: iommu:map 1, fmap 1 [MIXED: this capture holds more than one probe's events; …]
$ … --trace one-lane.trace     # one lane's `map: IOMMU:` + `unmap: IOMMU:`
  … events by name: iommu:map 1, iommu:unmap 1        (no MIXED — correct)

Two things I checked because the arm's wording would not have told me: MIXED really is keyed on the class (len(map_names) > 1 or len(unmap_names) > 1, tools/diag/iommu_map_side.py:483-485), so map + funm-that-unmaps does not flag — my first fixture was that pair and correctly stayed quiet; and the most_common(4) truncation from my #2701 review now carries (+N more name(s) not listed), so a fifth contributor is visible without being counted in the sentence.

Agreed on the shape of the pair: the positive arm pins the output, the negative one is honest about asserting an absence (it stays true if the sentence goes, which the positive arm then catches). That is the right division for a printed string.

Not run: the tool against a real capture on this box (the ones I have are other lanes' and none is a two-probe-on-one-class file); the fixtures above exercise the same code path, and the arms do the rest.

@bong-water-water-bong bong-water-water-bong left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

VERDICT: READY

The measured pair in the issue is what makes this necessary rather than tidy — deleting the [MIXED: …] append left 34 ok, 0 FAIL, rc 0 both before and after, so the sentence that is the change had no arm and the suite could not tell its presence from its absence. Adding the arm and showing 36 ok / 35 ok on the two builds is the evidence the issue asked for.

And the arm is the right kind: it drives main(), not the internals. contextlib.redirect_stdout around the real entry point asserts on the printed header — so it fails if the append is moved above the header, printed to the wrong stream, or conditional on the wrong thing. An arm on parse_events' tuples cannot see any of those, which is exactly the gap recorded here (set(by) == {...} and len(_b[5]) == 2 were green while the sentence was deletable).

The two arms are also correctly paired in both directions: "[MIXED" in for two names on one class, and "[MIXED" not in for one lane's map+unmap. A one-sided arm would pass with the flag printed unconditionally, which is the failure this shape invites. That is the pattern I keep asking for — a restriction gets an arm in both directions — applied to a sentence rather than to a predicate.

One small thing: the not in arm asserts on the literal "[MIXED", so a future rewording of the marker (say to MIXED-CLASS) would leave both arms green while the header changed. If the marker is defined once (a module constant the main() text is built from, even in a file this size), the arms can assert against that name and the pair keeps working after a rename.

@bong-water-water-bong
bong-water-water-bong merged commit 90210d1 into main Nov 16, 2026
10 checks passed
@bong-water-water-bong
bong-water-water-bong deleted the os3-mixed-sentence-arm branch November 16, 2026 19:29
bong-water-water-bong pushed a commit that referenced this pull request Nov 16, 2026
…ast one in the file

The CHANGES on the earlier head was right, and the commit title that said it was fixed did not match the code:
`report_page_classes()` still called `paddrs(trace)` -- which kept only the LAST paddr per IOVA -- and never saw the
fault times at all. On the review's own capture (map to A at 1000.1, fault at 1000.5, remap to B at 1000.9) it named
B, a page the faulting access could not have touched, while the row beside it correctly used the map BEFORE the fault.

  paddrs()               {iova: [(t, paddr), ...]} -- every mapping, in log order
  report_page_classes()  takes [(t, iova)] and picks the last mapping with mt <= t

and a fault with no mapping at or before it says so instead of falling forward ("a later mapping exists; it cannot be
what the fault touched"), which is the same rule as every other negative in this file.

Arms, both directions measured:

  ok   paddrs keeps EVERY mapping for an iova, in log order
  ok   the page class comes from the mapping BEFORE the fault, not the last one in the file
  ok   ...and a fault after the remap gets the remapped page
  ok   ...and a fault BEFORE any mapping says so instead of falling forward

  with the mt <= t filter removed: the first and third of those FAIL (rc 1); restored, 44 arms rc 0.

Also rebased onto main, which had rewritten the same two regions (#2742's [MIXED] sentence arms and parse_events'
six-tuple). Both sides are kept: the [MIXED] arms and the page-class arms are independent, and main()'s call site now
unpacks the six-tuple while keeping this PR's trace-fault fallback.

The hand table in engine#2478 is being re-checked under this rule; `0xe3ff5000` there is LRU off a map 517.7 s before
the fault, and if that IOVA was remapped in between the class in the issue is the same mislabel.
@bong-water-water-bong

Copy link
Copy Markdown
Collaborator Author

Heads-up before this merges: #2703 (ccebef1) carries the same arm verbatim, and the two are not independent patches.

$ diff <(the block #2742 adds) <(the block #2703 adds)   -> the same comment, the same two fixtures, the same two chk()s
$ git merge-tree --write-tree origin/pr2742 origin/pr2703 -> rc 1
CONFLICT (content): tools/diag/iommu_map_side.py

So whichever lands second conflicts, and resolving it by hand risks applying the arm twice (the second copy's two_names/onelane_main names would collide).

My read: this one is the one to close. #2703 is older (16:16Z vs 18:58Z), carries your arm plus the page-class step for the same #2478 thread, and passes 44 arms. Not my call to close someone else's PR — if you would rather keep this focused PR and have #2703 drop its copy, say so on #2703 and I will re-verdict there instead. Either way, only one of the two should reach the merge queue.

bong-water-water-bong added a commit that referenced this pull request Nov 16, 2026
…reads faults from the trace (engine#2478) (#2703)

* diag: iommu_map_side names the page class behind a faulted IOVA, and reads faults from the trace (engine#2478)

Two additions, both from a real 200 MB capture rather than from a fixture.

1. --page-class. The tracepoint's map event carries paddr, which the tool parsed and discarded. The page class
   behind it decided the diagnosis in engine#2478: an ordinary page-cache page (UPTODATE|LRU) means the block
   layer DMAs into the page cache, not into a slab buffer of its own -- and on the fresh-boot capture the two
   delay regimes turn out to have different page types (LRU for a 517 s gap, COMPOUND_HEAD for a 10 s one).
   /proc/kpageflags needs root; an unreadable file says "unavailable (why)", never "none".

2. Faults from the capture. A tracepoint capture carries its own io_page_fault events, but main() only read faults
   from --after, so a capture holding five faults answered "no fault inside the capture window". It now falls back
   to the trace's own events and says so on a note line. Measured: the same file answered 0 faults via the CLI and
   5 when passed as --after; the two paths now agree.

Also a bug this found in itself: the fallback assigned `faults`, and a stray `faults = parse_faults(a.after)` left
behind from the original call clobbered it back to zero, so the CLI printed 0 while a direct call of the same
functions printed 5. End-to-end output is what caught it, which is the point of running the thing on real data.

Five new arms: kpageflags 40 is UPTODATE|LRU; no flags decodes to "none"; SLAB and ANON are distinct and ordered
by bit; paddrs keeps the LAST mapping for an iova; an unreadable kpageflags says so.

Verified: 21 self-test arms pass, and on the fresh-boot capture (403,053 maps, 5 faults) the tool reproduces the
by-hand table -- including the 517.7 s gap (-517696958 us), the NEVER MAPPED case, and the page classes above.

* diag: --page-class reads the mapping in force at the fault, not the last one in the file

The CHANGES on the earlier head was right, and the commit title that said it was fixed did not match the code:
`report_page_classes()` still called `paddrs(trace)` -- which kept only the LAST paddr per IOVA -- and never saw the
fault times at all. On the review's own capture (map to A at 1000.1, fault at 1000.5, remap to B at 1000.9) it named
B, a page the faulting access could not have touched, while the row beside it correctly used the map BEFORE the fault.

  paddrs()               {iova: [(t, paddr), ...]} -- every mapping, in log order
  report_page_classes()  takes [(t, iova)] and picks the last mapping with mt <= t

and a fault with no mapping at or before it says so instead of falling forward ("a later mapping exists; it cannot be
what the fault touched"), which is the same rule as every other negative in this file.

Arms, both directions measured:

  ok   paddrs keeps EVERY mapping for an iova, in log order
  ok   the page class comes from the mapping BEFORE the fault, not the last one in the file
  ok   ...and a fault after the remap gets the remapped page
  ok   ...and a fault BEFORE any mapping says so instead of falling forward

  with the mt <= t filter removed: the first and third of those FAIL (rc 1); restored, 44 arms rc 0.

Also rebased onto main, which had rewritten the same two regions (#2742's [MIXED] sentence arms and parse_events'
six-tuple). Both sides are kept: the [MIXED] arms and the page-class arms are independent, and main()'s call site now
unpacks the six-tuple while keeping this PR's trace-fault fallback.

The hand table in engine#2478 is being re-checked under this rule; `0xe3ff5000` there is LRU off a map 517.7 s before
the fault, and if that IOVA was remapped in between the class in the issue is the same mislabel.

* diag: page class comes from the mapping BEFORE the fault, not the last one in the file (engine#2478)

My own bug, found by asking whether it could be one. paddrs() kept ONE paddr per iova -- the last in the
capture -- so the page class reported for a fault could describe a LATER transfer. Measured on a real
capture: 0xebb3b000 has 28 maps after its own fault, and the class reported for it was COMPOUND_HEAD, taken
from one of those.

Now paddrs() keeps every (t, paddr) and report_page_classes() takes the fault times, using the last mapping
AT OR BEFORE each fault. It changes the answer, and it changes the story:

  before (last map in the file)   0xe3ff5000 -> LRU                  0xebb3b000 -> COMPOUND_HEAD
  after  (map before the fault)   0xe3ff5000 -> UPTODATE, DIRTY, LRU, MMAP, ANON, SWAPBACKED
                                  0xebb3b000 -> REFERENCED, LRU

UPTODATE|DIRTY|MMAP|ANON|SWAPBACKED is an anonymous, dirty, swapbacked USER page. So the block layer is
DMA-ing into userspace memory (a pinned or mmap'd buffer), not into the page cache -- which is what a
direct-IO read into a user buffer looks like, and it fits the grep/du comms better than "page cache" did.
The COMPOUND_HEAD distinction I built a paragraph on was an artefact of my own ordering bug.

An iova with no map before the fault now says so, and says how many maps came after it that cannot explain it.

Arms: paddrs keeps EVERY mapping in log order (was: keeps the last), so a caller can pick the one before a
fault; the unreadable-kpageflags arm stays.

Verified end to end on the 403,053-map capture: 5 faults, the classes above, and the 517.697 s gap intact.

---------

Co-authored-by: bong-water-water-bong <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant