Compare commits

...
11 changed files with 638 additions and 9 deletions

No files matched your search

+14
View File
@@ -35,6 +35,20 @@ numeric core and does not move; the heading is the full version — corrected 20
## [Unreleased]
### Added
- **The frames NVIDIA's latency report gives are counted, for the Overlay's own log** (owner decisions D148,
D151; nothing new is stored, shown, asked of the driver or read from its report). The owner's sessions on
0.1.0-beta.48 showed both of the driver's own GPU times in two games — and in Cyberpunk 2077 without frame
generation an *active render* time longer than the span from the card's start on a frame to its end, which the
two averages cannot explain: one is over every frame, one only over the frames that gave a time. While a session
with *Advanced metrics* reads the driver, the Overlay now places each frame by its own two numbers and writes
the counts to `overlay-<pid>-….log` as `LATENCY_FRAMES` lines, in batches that each belong to **one state of
the driver's low-latency status and its frame-generation multiplier** — the counts are read together with
Reflex and frame generation, never apart. About six lines a minute; a game that exits by itself loses the last
batch, under a minute. A bug report carries those logs, as it carried them before. Measured: 65 billionths of a
second more for each reading of the report, once a second; a presented frame costs what it did.
## Releases
Newest first. Each file holds that release's section exactly as it stood here.
+6 -1
View File
@@ -174,7 +174,12 @@ others cannot say.** `fl_reflex_summary` (Catch2) drives `fl_adv_fields.h`'s rea
two newest frames held back, a frame summed once, a span the driver did not report, a span no frame can have, frame
ids that start again, and the ten words of a publication — and since 0.1.0-beta.48 the driver's two own times
(summed over the frames that gave one, each with its own count; zero and more than a second are not counted and
refuse nothing) and the bit a multiplier has. `fl_guard`'s seven `[latency]` cases inject the Overlay
refuse nothing) and the bit a multiplier has — and since 0.1.0-beta.49 the counts for the native log: every place
a summed frame can be in, a span of a microsecond, an active time as long as the span, a refused frame, when a
batch is due, a batch closed by a change of state and the thirty-two such closings a request has, the six lines
and what each carries; a hidden `[.bench]` case is the measurement of one report's cost. `fl_guard`'s eight
`[latency]` cases (the eighth reads the log: the first batch after ten reads, by number, and what is left when a
flush is asked for — against the stand-in's `kModeGpuShapes`) inject the Overlay
into a Direct3D 12 target that has loaded a stand-in `nvapi64.dll`, and read that module's call counts from outside
through its named section (`fl_stub_nvapi_shared.h`) — so "the driver was not called" is a count: not asked → not
even asked for the addresses; asked → about one read a second, sums equal to the stand-in's, every counted read a
+29
View File
@@ -215,6 +215,19 @@ Overlay's flags, a report of 62 summed frames, 2 million reports × 3, twice): 3
— **+36 ns a read**, once a second, and after the call's time has been taken, so it cannot reach the 2 ms latch.
The present path is unchanged: one relaxed load.
**Since 0.1.0-beta.49 each summed frame is also counted for the native log** (owner decisions D148, D151;
§Native logging, `LATENCY_FRAMES`). The owner's ten sessions on beta.48 (HANDOFF, item 46) gave both of the
driver's own times in every frame report of both games — and in Cyberpunk 2077 without frame generation the mean
active time was **longer** than the mean span between the two GPU marks (3.17 against 2.79 ms), which the two
means cannot explain: the span's is over every summed frame, one of no length included, the active time's over
the frames that gave one. So the reader places each summed frame by its own two numbers (`CountGpuTimes`), after
the frame is accepted: which frames are summed does not change, and the seven spans, the two times and their
counts are what they were. **No new call, no further member of the report** — the two GPU marks and
`gpuActiveRenderTimeUs` were read already — and nothing of it leaves the process: the watchdog adds each read's
counts to a batch and writes the batch to the log. **Measured** (the same instrument: 2 million reports × 3,
twice): 424–435 ns before, 490–499 ns after — **+65 ns a read**, once a second, after the call's time has been
taken. `fl_reflex_summary_test "[.bench]"` is that measurement in the tree. The present path is unchanged.
**The gate.** One word, four states — idle, armed, reading, off (`dllmain.cpp`, above `ReadLatencyOnce`). Only the
watchdog arms; a presenting thread takes *armed* to *reading* by compare-exchange and owns the 15.4 KB report
buffer (static storage, never a game thread's stack) and the read's result until it stores *idle* or *off*; the
@@ -932,6 +945,22 @@ No logging in hook bodies. A small fixed-size in-memory ring of structured event
> `FlLatencyState`, the text what it means — and, when the module is found, two more with the end of the path
> `nvapi64.dll` was loaded from and of the image its getters are in. Written by the watchdog; a fault in a getter
> is a `FAULT` line from the presenting thread, as any fault is.
> **`LATENCY_FRAMES` (0.1.0-beta.49, owner decisions D148, D151)**: the frames the driver reads summed, counted
> for this log and nowhere else — nothing of it is published, stored or shown. Each summed frame is placed by its
> own two numbers, the span between its two GPU marks and the driver's active render time: no start mark, a span
> of no length, an active time with no span, a span with no active time, and — where a frame has both — *active
> longer than the span* or *active within the span*, each with its count and both sums in microseconds. No
> threshold: a span of one microsecond is a span. **A batch is six lines and belongs to one state of the driver's
> sleep status** — its low-latency switch, its "the game sleeps" switch and its frame-generation multiplier —
> because the counts mean nothing apart from it: a read in another state closes the batch first (thirty-two such
> closings a request, after which a batch runs to its length and its first line says what it held). A batch is
> also written after a request's tenth read, its thirtieth and every sixtieth from there, when the Agent asks for
> a flush, at a new request and at a stop. `a` is printed in decimal and `b` in hex: *reads* and the switches
> seen on, off (`<<8`) and the multipliers seen (`<<16`); *frames summed* and refused; *GPU span absent* and of no
> length; *active time with no span* and span with no active time; then the two heaps, `a` their frames and `b`
> their span sum (`<<32`) and active sum. **A game that exits by itself takes the batch in hand with it** — under
> a minute of reads. About six lines a minute while a session with *Advanced metrics* reads the driver; none
> otherwise.
> **Three flush points — four since beta.42, the same note —, none on a present path:** the end of `InitThread` (so the
> file exists from the start of the session and a crash mid-session still leaves it), the watchdog when
> `FlControlBlock.logFlushRequested` changes (a counter the Agent bumps at session end; nothing clears it),
+1 -1
View File
@@ -1873,7 +1873,7 @@ Moved verbatim, in this order.
| M12 ❓ | **Advanced metrics — which NVAPI rows answer on real hardware (D101, 2026-11-11).** `18_GPU_VENDOR_APIS` §The inventory lists sixty `nvapi.` rows whose reach is `Agent`. They are declared in the vendored headers; **none has been called on a GPU**, and CI has no driver, so it never takes that branch. Unknown per row: whether the RTX 5080 on the current driver answers or returns `NVAPI_NOT_SUPPORTED` (the memory-temperature target already does not exist on that card). | **The measurement is the bridge's probe on the owner's PC**, then the page itself (the release's owner-only item). Pre-committed: a call that does not answer → that row is N/A with NVAPI's own status as the reason, and nothing is put in its place; a call that hangs or faults twice → the row is off for the session (§Runtime policy); a value that contradicts the vendor's own tool → the row is withheld until it is explained. **Half answered the same day, by the bridge's own test on the dev box** (ctest `fl_nvapi_bridge`, AVAILABLE branch; RTX 5080): every fact answers (`present = 0xFFFFF`), eight of ten live groups answer (`0x33F` — no board and no power-supply temperature sensor on this card: N/A, by the first pre-committed outcome), the display answers its four groups, the global profile lists 24 settings; figures in `18_GPU_VENDOR_APIS` §L3. **Still open**: the same values on the page beside the vendor's own tool, and the session rows (`nvapi.session.*`), which need a game. **And one thing seen once and not explained**: in one test run of about a dozen that day, `FlNvReadLive` came back with no field at all although `FlNvReadFacts`, a moment earlier in the same process, had answered everything; nine further runs did not show it. A handle the driver invalidated is the usual cause of that shape, and nothing here re-enumerates after `FlNvInit`. Pre-committed for the reader that owns the thread: two readings in a row with no field → release and initialise the bridge again, once, and say so in the log; if that does not bring the fields back the layer is off for the session, as any layer that fails twice is. |
| M13 ❓ | **Advanced metrics — LibreHardwareMonitor's CPU, memory, motherboard and storage groups, elevated, with PawnIO (D103, 2026-11-11).** Never opened by any build: §M10's elevated run has not been taken either, and this is a larger surface — a sensor chip on the LPC bus, the embedded controller, SPD over SMBus, SMART. Unknown: whether each group opens on the owner's board, what a refresh costs, whether opening the storage group touches removable drives (this PC once had a failing USB drive), and whether any group enables a privilege (`PrivilegeFootprintTests`). | **One elevated run with the probe verb, before the option exists.** Pre-committed: the storage group cannot be opened without touching removable drives → `lhm.storage.*` stays N/A in beta.39 and its reach reads `Deferred`; a node that throws twice → skipped for the session; the Agent above 1% of one core or 150 MB with the option on (NFR-2) → the slow groups are read less often or dropped before the release; a privilege enabled by a group → that group is not opened, and the owner is asked. **Two of the four answered 2026-11-11, before the option exists.** (1) **Storage: not opened, by the first outcome.** LibreHardwareMonitor 0.9.6's `StorageGroup` lists every drive through DiskInfoToolkit's `ReloadStorages` with no filter by bus and follows drives plugged in later — it cannot be opened without touching removable drives. `lhm.storage.*` reads `Deferred`, and `LhmGroups` has no member for it. (2) **Cost, unelevated, measured with `probe-advanced`** on the dev box: one refresh of the graphics-card group alone is 14 ms of processor time (62 ms elapsed) — 1.4% of one core at one a second, above NFR-2 — and one NVAPI read 0.4 ms. By the third outcome the sensor library is read every fifth tick (0.28%). **Still open, and the owner's**: the same probe as administrator with PawnIO — whether the processor, memory and motherboard groups open on this board, what they cost, and `PrivilegeFootprintTests`' new case on a token that holds the privileges (CI's does; the dev box's unelevated run passes by construction). **The first run was taken on 2026-11-12, by the owner, in ordinary use** (0.1.0-beta.40, the Agent as administrator with PawnIO, an i7-14700KF on a board with an IT8689E chip, an RTX 5080), and read here from a copy of the ledger and the Agent's log, not from a probe. **The groups open and read**: nine of ten sessions stored 119 processor series (a clock and a load per thread, temperatures, powers, voltages), 14 memory series and 21 motherboard series (six fans, six temperatures, nine voltages) beside the card's 41 — 195 from the sensor library in all. **No value was compared with another tool**; that is still the owner's. **Two faults, one cause** (`Infrastructure.Telemetry.LhmLibrary`): the Agent held up to three `Computer`s at once, and the library keeps the driver it reads the processor through and its bus mutexes per process — closing one `Computer` let go of them under the others. After seven sessions the Advanced reader's processor device threw `NullReferenceException` twice and was left alone (the page lost the processor until the reader reopened); once a session's start met another instance's close, the reader's `Open` threw `ObjectDisposedException`, and that session stored 17 series instead of 212. **Fixed 2026-11-12**: opens and closes are serialised and a `Computer` is parked, not closed, while another is in use. The cause is read from the log's timing and was not reproduced — it needs this elevation — so **whether the faults are gone is the owner's next sessions to show**: no `advanced: a device is left alone` and no `did not open` in the Agent's log. **First evidence, 2026-11-12, 0.1.0-beta.41, the same PC:** seven sessions between 06:38 and 07:01 with no `advanced:` line at all, each with the option on storing 212 or 213 series; on beta.40 that morning the processor device faulted out after each of six sessions (04:34–05:07) — thirteen of sixteen over the night. The reader failing to open was seen once in sixteen, so this is not yet enough to call that one gone. Still open: any value beside another tool. |
| M16 ✅ | **The L2 telemetry layer's cost — the first number, and it is above NFR-2 (found 2026-11-11, measuring something else).** `LhmTelemetrySource` refreshes LibreHardwareMonitor's graphics-card group once a second in every recorded session. `probe-advanced` measured that refresh, through the same library and the same group, at **14 ms of processor time** on the dev box (RTX 5080, 41 mapped sensors, about twenty of them the Direct3D engine nodes the library enumerates per card) — 1.4% of one core, where NFR-2 allows the whole Agent 1% during capture and `14_TESTING` §Hook overhead's Agent figure has never been measured. This is a measurement of the call, not yet of a session: L2's own poller was not instrumented. | **Measure L2 in a session** (the Agent's processor time over a ten-minute capture, telemetry at 1000 ms and at 2000 ms). Pre-committed: at or under 1% → this row closes with the number; above → the owner chooses between a slower default for `telemetry.interval_ms`, reading the sensors the layer keeps from NVAPI on NVIDIA cards (L3 already has most, at 0.4 ms), or amending NFR-2 to what is measured. Not decided here, and nothing about L2 changes in the Advanced-metrics train. **Measured in a real Agent, 2026-11-11 (owner decision D110), and answered (D117).** `tools/agent-cost.ps1` runs the shipped `FrameLedger.Agent.exe --console capture` against a copy of hook-harness in a scratch data folder — a session that is not hooked, so the telemetry poller runs as in every session and nothing drains frames — and reads the Agent process's own processor time at exit; the cost per second is the slope between a 45 s and a 165 s session, two runs of each. Dev box (RTX 5080, not elevated, layers `l1+lhm+nvapi`): **19.3 ms of processor time per second of session = 1.93 % of one core with Advanced metrics off** (2,312 and 2,312 ms over 45 s; 4,594 and 4,656 ms over 165 s), **20.4 ms = 2.04 % with it on** (2,984 and 3,000; 5,547 and 5,344); peak working set 113 MiB and 119 MiB. A first pass with 30 s and 90 s sessions gave 1.56 % and 2.21 % — its two short runs differed by 670 ms, which is why the lengths were raised. So the probe's number holds in a session: the Agent's steady cost is about twice NFR-2's 1 %, nearly all of it the layer every session has always used, and the new option adds about a tenth of a percent. **The owner's answer: NFR-2 is amended to ≤ 2.5 % of one core** — the limit had never been measured, the sensors keep their one reading a second, and nothing in the code changes. Not measured: a hooked session (the drain's cost on top), a session with the Agent elevated and PawnIO's groups open, another PC. |
| M14 ❓ | **Reflex latency per frame — is there a route within rules 4 and 5? (Train C, 2026-11-11.)** `17_HOOK_ENGINE` §Memory / latency names hooks on `NvAPI_D3D_SetSleepMode` / `SetLatencyMarker` and a call to `NvAPI_D3D_GetLatency`. NVAPI resolves all three through `nvapi_QueryInterface` by id — they are not exports, so a hook on them is a patch at an address learned at run time, the class refused on 2026-08-09. The route to try first needs no hook: the Overlay's own background thread **calls** `GetLatency` with the device of the swap chain it already hooks, once a second (the call returns the last 64 frames' reports). Unknown: whether calling into the driver from that thread is safe on every device kind, what it costs, what it returns when the game never enabled Reflex, and what it means for the Disclaimer's sentence about that thread. | **A spike on `hook-harness` and a stub first, then one real title.** Pre-committed: no route without a patch at a run-time address or a loader-lock call on the game's thread → Reflex stays N/A and the page says why; overhead above NFR-1 → the same. The owner says go or no on the spike's result. **2026-11-12 — the reading that comes before that spike is `spike-notes` §30** (owner decision D130: a document first, beside 0.1.0-beta.45; nothing was run). It finds: a hook on NVAPI's latency functions is the refused class, and a hook on Streamline's Reflex and PCL functions is train D's wrapper (§M15) — and would miss a game that fetched them before the attach, as `slInit` is missed (D129); the Overlay calling `slReflexGetState` itself breaks the thread contract the vendor's header states; **what remains is the route named in this row**, the Overlay calling two driver getters with the game's device, and a no-injection ETW route that gives the game-side markers only and makes the game post messages to its own window. Corrected there: `nvapi64.dll` exports **two** functions on the dev box (`nvapi_Direct_GetMethod` beside `nvapi_QueryInterface`), not one. The go or no is the owner's, and a go needs the owner's ruling that calling a driver getter with the game's device is inside rule 4. **2026-11-13 — the owner answered (D132, D133).** Route D goes to the spike this row names, on `hook-harness` and a stub `nvapi64.dll`, with the ruling: a driver's read-only getter called with the device of the swap chain the Overlay hooks is inside rule 4 (`CLAUDE.md`, the rule's note of that day). No real game before the owner has seen the result, and nothing shipped changes for the spike (`spike-notes` §31, written after 0.1.0-beta.46). Route C is **refused**; the ETW route **stays closed**, and §G is not reopened. **2026-11-13 — the harness spike is done (`spike-notes` §31), and none of its stop conditions fired.** With a stand-in module: nothing is called or loaded when `nvapi64.dll` is absent, a missing getter is refused whole, an error and a report of nothing read as what they are, and a call the driver holds for seconds stops only the thread that made it — so not the watchdog. With the installed driver (32.0.16.2114, RTX 5080), in the probe's own process and with the probe setting the markers a game would: no fault before `NvAPI_Initialize`, without markers, or across 38 million reads beside a marker-setting thread; a call costs half a microsecond to a microsecond and a half; the report is readable from markers alone, in microseconds; and the Direct3D 12 **device** — the object the Overlay already holds — is what the driver takes. What only a game can say is unanswered: a game's own device, a real report, another driver. **The owner's next word is go or no for one real title**; a go is a plan of its own first. **2026-11-13, the same evening — go (D136)**: a plan for one title, Cyberpunk 2077; no code before the plan is approved, and no release carrying it before a stop while a game runs has been exercised on 0.1.0-beta.46 (owner-only item 44 (d)). **2026-11-13, the plan and four more answers (D138–D141).** The read has **no switch of its own**: it is part of Advanced metrics, so after the release it reaches every Direct3D 12 game that loaded the driver's `nvapi64.dll`, for everyone who switched Advanced metrics on — "one title" is the order of the owner's first runs, not a limit in code (D138). The probe ran a leg with a sleep mode first (D139; `spike-notes` §31, *The leg with a sleep*): **the getters do not wait behind `NvAPI_D3D_Sleep`** — thirty-one million reads beside a thread that slept 97 % of the time, none of a millisecond; a read after a sleeping frame costs about 2.6 µs. An `nvapi64.dll` loaded from the game's own folder is refused with the reason (D140). One call of 2 ms or more switches the read off until the game exits (D141). The plan's design, as reviewed against the source, is in [`handoff/history/0.1.0-beta.46.md`](handoff/history/0.1.0-beta.46.md) §The train after 0.1.0-beta.46. **2026-11-13, night — written; released as 0.1.0Line truncated
| M14 ❓ | **Reflex latency per frame — is there a route within rules 4 and 5? (Train C, 2026-11-11.)** `17_HOOK_ENGINE` §Memory / latency names hooks on `NvAPI_D3D_SetSleepMode` / `SetLatencyMarker` and a call to `NvAPI_D3D_GetLatency`. NVAPI resolves all three through `nvapi_QueryInterface` by id — they are not exports, so a hook on them is a patch at an address learned at run time, the class refused on 2026-08-09. The route to try first needs no hook: the Overlay's own background thread **calls** `GetLatency` with the device of the swap chain it already hooks, once a second (the call returns the last 64 frames' reports). Unknown: whether calling into the driver from that thread is safe on every device kind, what it costs, what it returns when the game never enabled Reflex, and what it means for the Disclaimer's sentence about that thread. | **A spike on `hook-harness` and a stub first, then one real title.** Pre-committed: no route without a patch at a run-time address or a loader-lock call on the game's thread → Reflex stays N/A and the page says why; overhead above NFR-1 → the same. The owner says go or no on the spike's result. **2026-11-12 — the reading that comes before that spike is `spike-notes` §30** (owner decision D130: a document first, beside 0.1.0-beta.45; nothing was run). It finds: a hook on NVAPI's latency functions is the refused class, and a hook on Streamline's Reflex and PCL functions is train D's wrapper (§M15) — and would miss a game that fetched them before the attach, as `slInit` is missed (D129); the Overlay calling `slReflexGetState` itself breaks the thread contract the vendor's header states; **what remains is the route named in this row**, the Overlay calling two driver getters with the game's device, and a no-injection ETW route that gives the game-side markers only and makes the game post messages to its own window. Corrected there: `nvapi64.dll` exports **two** functions on the dev box (`nvapi_Direct_GetMethod` beside `nvapi_QueryInterface`), not one. The go or no is the owner's, and a go needs the owner's ruling that calling a driver getter with the game's device is inside rule 4. **2026-11-13 — the owner answered (D132, D133).** Route D goes to the spike this row names, on `hook-harness` and a stub `nvapi64.dll`, with the ruling: a driver's read-only getter called with the device of the swap chain the Overlay hooks is inside rule 4 (`CLAUDE.md`, the rule's note of that day). No real game before the owner has seen the result, and nothing shipped changes for the spike (`spike-notes` §31, written after 0.1.0-beta.46). Route C is **refused**; the ETW route **stays closed**, and §G is not reopened. **2026-11-13 — the harness spike is done (`spike-notes` §31), and none of its stop conditions fired.** With a stand-in module: nothing is called or loaded when `nvapi64.dll` is absent, a missing getter is refused whole, an error and a report of nothing read as what they are, and a call the driver holds for seconds stops only the thread that made it — so not the watchdog. With the installed driver (32.0.16.2114, RTX 5080), in the probe's own process and with the probe setting the markers a game would: no fault before `NvAPI_Initialize`, without markers, or across 38 million reads beside a marker-setting thread; a call costs half a microsecond to a microsecond and a half; the report is readable from markers alone, in microseconds; and the Direct3D 12 **device** — the object the Overlay already holds — is what the driver takes. What only a game can say is unanswered: a game's own device, a real report, another driver. **The owner's next word is go or no for one real title**; a go is a plan of its own first. **2026-11-13, the same evening — go (D136)**: a plan for one title, Cyberpunk 2077; no code before the plan is approved, and no release carrying it before a stop while a game runs has been exercised on 0.1.0-beta.46 (owner-only item 44 (d)). **2026-11-13, the plan and four more answers (D138–D141).** The read has **no switch of its own**: it is part of Advanced metrics, so after the release it reaches every Direct3D 12 game that loaded the driver's `nvapi64.dll`, for everyone who switched Advanced metrics on — "one title" is the order of the owner's first runs, not a limit in code (D138). The probe ran a leg with a sleep mode first (D139; `spike-notes` §31, *The leg with a sleep*): **the getters do not wait behind `NvAPI_D3D_Sleep`** — thirty-one million reads beside a thread that slept 97 % of the time, none of a millisecond; a read after a sleeping frame costs about 2.6 µs. An `nvapi64.dll` loaded from the game's own folder is refused with the reason (D140). One call of 2 ms or more switches the read off until the game exits (D141). The plan's design, as reviewed against the source, is in [`handoff/history/0.1.0-beta.46.md`](handoff/history/0.1.0-beta.46.md) §The train after 0.1.0-beta.46. **2026-11-13, night — written; released as 0.1.0Line truncated
| M15 ❓ | **The Streamline state behind `slGetFeatureFunction` — re-examined, not reopened (Train D, 2026-11-11).** The owner asked for the refusal in `handoff/history/p0-queue-1-6.md` to be looked at again. `18_GPU_VENDOR_APIS` §The trains states the route to try (hook the export, hand back a wrapper for a fixed list of names) and what it raises: the wrapper is a write to what the game receives, which rule 4 forbids as written; a wrapper must outlive the Overlay's unhook; a game that fetched its functions before the hook existed is never seen. | **A written design against each of the five grounds, then a spike.** Pre-committed: any ground unanswered → the route stays refused, and `sl.dlssg.*`, `sl.reflex.*` and the rest of that block read N/A with "refused" as the reason. Proceeding needs the owner's amendment of rule 4, asked with the rule quoted. |
| M10 ✅ | ~~PDH `\GPU Engine(*)\Utilization Percentage` summed across engines does not reproduce the Task Manager figure the doc invokes. Decide what we actually report and label it accordingly~~ **Decided 2026-09-09 (PR-E1): L1 does not read the engine counters at all.** `LoadPct` is L2's vendor-reported `GPU Core` load (measured ✓ on NVIDIA, §M5 row R1) and is labelled *GPU load (vendor)* wherever it is shown; on a machine without L2 the field is N/A, never a sum that is not the number the user expects. What L1 does read from PDH is one counter, `\GPU Adapter Memory(luid_…_phys_0)\Dedicated Usage`, bound by LUID — the figure Task Manager labels "Dedicated GPU memory", measured 1301 MB at an idle desktop on the RTX 5080. Reopening this needs a measurement of `max(engine)` against Task Manager's own number, not a decision |
+4
View File
@@ -1051,6 +1051,10 @@ Where each owner decision is recorded — the file and its section, and a label
| D145 | [`../legal/ACCURACY.md`](../legal/ACCURACY.md) | the accuracy statement, the README and the guide say two real games were read on one driver (they said none); Privacy Policy 2.21 and Disclaimer 2.17 with it |
| D146 | [`06_DATA_MODEL.md`](06_DATA_MODEL.md) §sensor_blobs | the Agent's samples were 1.32 s apart under a 1 s setting (it waited the whole interval after its work): sample on a fixed period, and store the rate the samples had |
| D147 | [`03_METRICS.md`](03_METRICS.md) | the session summary's latency fields stay N/A: the driver's total is simulation start to GPU end, not input to display |
| D148 | [`17_HOOK_ENGINE.md`](17_HOOK_ENGINE.md) §Native logging | asked on 2026-11-14 with item 46's Cyberpunk 2077 numbers (active render longer than the span between the GPU marks): count the frames, and write the counts **only to the Overlay's native log** — no layout, schema, App or string change |
| D149 | [`17_HOOK_ENGINE.md`](17_HOOK_ENGINE.md) §Native logging | told that a bug report carries the five newest Overlay logs and so these lines: **no change to the legal texts** — the Privacy Policy names the logs of the component loaded into games, and the lines are counts and sums of microseconds |
| D150 | [`07_IPC.md`](07_IPC.md) §Region 5 | the samples that carry no report are mended **on both sides**: the Overlay reads and publishes on a grid of one second, and the Agent no longer overwrites a reading that waits for a sample |
| D151 | [`17_HOOK_ENGINE.md`](17_HOOK_ENGINE.md) §Native logging | the owner's word: Reflex is checked together with frame generation — without it the owner's games do not switch Reflex on, and a low-latency switch that reads on and off is the NVIDIA App's override. A batch of counts belongs to one state of the sleep status |
| D109 | [`../legal/DISCLAIMER.md`](../legal/DISCLAIMER.md) §5, §5A | asked on 2026-11-11 with both sentences quoted: the Disclaimer goes to 2.15 with the Privacy Policy — PawnIO and the admin mode are no longer "for the CPU temperature" alone; with Advanced metrics on they also read the processor's, the memory's and the motherboard's sensors. The admin mode's disclosure follows (`agent-admin-dialog/2`) |
---
@@ -675,12 +675,33 @@ inline void ObserveSlShutdown(Accumulators& a) noexcept {
// ---------------------------------------------------------------------------------------------------------------------
inline constexpr uint32_t kLatSpans =
7u; // simulation, submit, present, driver, OS queue, GPU, total: the region's order
inline constexpr uint32_t kLatGpu = 5u;
inline constexpr uint32_t kLatTotal = 6u;
inline constexpr uint32_t kLatReportFrames = 64u;
inline constexpr uint64_t kLatSpanLimitUs = 1000000u;
static_assert(sizeof(NV_LATENCY_RESULT_PARAMS::frameReport) / sizeof(NV_LATENCY_RESULT_PARAMS::FrameReport) ==
kLatReportFrames);
// HOW A FRAME'S GPU SPAN AND THE DRIVER'S ACTIVE TIME STAND TO EACH OTHER (0.1.0-beta.49, owner decision D148). In one
// real game the mean active time was LONGER than the mean span between the two GPU marks (HANDOFF, item 46), and the
// two means cannot say why: the span's is over every summed frame, one of no length included, the active time's over
// the frames that gave one. So each summed frame is put in one place here, by its own two numbers, and the frames
// that have both are kept in two heaps -- the active time longer than the span, or not -- each with its count and
// both sums. No threshold: a span of one microsecond is a span. FOR THE NATIVE LOG ONLY: nothing of it is published,
// and which frames are summed does not depend on it.
struct LatencyGpuCounts {
uint32_t spanAbsent = 0; // no GPU start mark
uint32_t spanZero = 0; // the two GPU marks are the same instant
uint32_t activeNoSpan = 0; // an active time, and no span with a length
uint32_t spanNoActive = 0; // a span with a length, and no active time
uint32_t longerFrames = 0; // both, and the active time is the LONGER
uint32_t longerSpanUs = 0; // ... their spans
uint32_t longerActiveUs = 0; // ... their active times
uint32_t withinFrames = 0; // both, and the active time is no longer than the span
uint32_t withinSpanUs = 0;
uint32_t withinActiveUs = 0;
};
// What one read of the report added up to.
struct LatencyTally {
uint32_t frames = 0; // frames summed
@@ -688,10 +709,11 @@ struct LatencyTally {
uint32_t sumUs[kLatSpans]{}; // microseconds, over the frames summed
uint32_t lacking = 0; // bit n: a summed frame did not report span n
// The driver's two own times, each over the summed frames that gave one: a count apiece.
uint32_t activeSumUs = 0;
uint32_t activeFrames = 0;
uint32_t frameTimeSumUs = 0;
uint32_t frameTimeFrames = 0;
uint32_t activeSumUs = 0;
uint32_t activeFrames = 0;
uint32_t frameTimeSumUs = 0;
uint32_t frameTimeFrames = 0;
LatencyGpuCounts gpu; // the summed frames, each by its GPU span and its active time: the native log's
};
// Where the reader is in the game's frame ids: the newest one already summed or refused. 0 = none yet.
@@ -728,13 +750,45 @@ inline uint64_t LatencyFrameId(const NV_LATENCY_RESULT_PARAMS::FrameReport& lf)
// (an older driver leaves both zero, and so did the probe's frames, which had no work for the card); more than a
// second is a time no frame can have. Neither is summed, and neither refuses the frame: which frames the spans are
// made of does not depend on these.
inline bool LatencyTimeGiven(uint32_t us) noexcept {
return us != 0u && us <= kLatSpanLimitUs;
}
inline void LatencyAddTime(uint32_t us, uint32_t& sumUs, uint32_t& frames) noexcept {
if (us != 0u && us <= kLatSpanLimitUs) {
if (LatencyTimeGiven(us)) {
sumUs += us;
++frames;
}
}
// One summed frame's place in LatencyGpuCounts: its GPU span as LatencySpan gave it, and the driver's active time
// of the same frame, "given" by the rule LatencyAddTime sums it by. An impossible span never comes here -- its frame
// was refused.
inline void CountGpuTimes(uint32_t spanKind, uint32_t spanUs, uint32_t activeUs, LatencyGpuCounts& counts) noexcept {
const bool span = spanKind == kLatSpanReported && spanUs != 0u;
const bool active = LatencyTimeGiven(activeUs);
if (spanKind == kLatSpanAbsent) {
++counts.spanAbsent;
} else if (spanUs == 0u) {
++counts.spanZero;
}
if (span && active) {
if (activeUs > spanUs) {
++counts.longerFrames;
counts.longerSpanUs += spanUs;
counts.longerActiveUs += activeUs;
} else {
++counts.withinFrames;
counts.withinSpanUs += spanUs;
counts.withinActiveUs += activeUs;
}
} else if (active) {
++counts.activeNoSpan;
} else if (span) {
++counts.spanNoActive;
}
}
inline void ObserveLatencyFrame(const NV_LATENCY_RESULT_PARAMS::FrameReport& lf, LatencyTally& tally) noexcept {
uint32_t us[kLatSpans]{};
const uint32_t kind[kLatSpans] = {
@@ -764,6 +818,7 @@ inline void ObserveLatencyFrame(const NV_LATENCY_RESULT_PARAMS::FrameReport& lf,
}
LatencyAddTime(lf.gpuActiveRenderTimeUs, tally.activeSumUs, tally.activeFrames);
LatencyAddTime(lf.gpuFrameTimeUs, tally.frameTimeSumUs, tally.frameTimeFrames);
CountGpuTimes(kind[kLatGpu], us[kLatGpu], lf.gpuActiveRenderTimeUs, tally.gpu);
}
// One report: the frames newer than the cursor, the two newest left for the next read.
@@ -825,6 +880,143 @@ inline uint32_t LatencyMultiplierBit(uint32_t value) noexcept {
return 1u << (value > 31u ? 31u : value);
}
// ---------------------------------------------------------------------------------------------------------------------
// THE COUNTS, IN BATCHES, FOR THE NATIVE LOG (0.1.0-beta.49, owner decisions D148, D151). The watchdog's.
//
// A BATCH BELONGS TO ONE STATE of the driver's sleep status -- its low-latency switch, its "the game sleeps" switch
// and its frame-generation multiplier -- because the counts mean nothing apart from it: the owner's games switch
// Reflex on only with frame generation, and the low-latency switch may be the NVIDIA App's override and not the
// game's. A read in another state closes the batch before it is added. A state that flickers would write a batch a
// read, so after kLatStateClosures such closings a request's batches run to their length whatever the state, and the
// "seen" words of the batch say what it held.
//
// A batch is also closed after the request's tenth read, its thirtieth, and every sixtieth from there: a game that
// exits takes the watchdog with it, and what was not written by then is lost -- under a minute of it.
// ---------------------------------------------------------------------------------------------------------------------
inline constexpr uint32_t kLatBatchFirst = 10u;
inline constexpr uint32_t kLatBatchSecond = 30u;
inline constexpr uint32_t kLatBatchEvery = 60u;
inline constexpr uint32_t kLatStateClosures = 32u;
inline constexpr uint32_t kLatStateUnknown = 0xFFFFFFFFu; // a read whose sleep status did not come back
inline constexpr uint32_t kLatStateSwitches = 1u | 8u; // bLowLatencyMode, bUseGameSleep (ObserveSleepStatus)
struct LatencyBatch {
uint32_t reads = 0; // reads whose report came back, in this batch
uint32_t frames = 0; // frames they summed
uint32_t refused = 0; // frames they refused
LatencyGpuCounts gpu;
uint32_t sleepOn = 0; // switches the status showed on in this batch
uint32_t sleepOff = 0; // ... and off
uint32_t multipliers = 0; // LatencyMultiplierBit of every multiplier it gave
uint32_t state = kLatStateUnknown; // LatencyStateOf its first read
};
struct LatencyBatchBook {
LatencyBatch batch;
uint32_t okReads = 0; // reads whose report came back, since the request
uint32_t closures = 0; // batches a change of state closed, since the request
};
inline uint32_t LatencyStateOf(bool sleepValid, const LatencySleep& sleep) noexcept {
if (!sleepValid) {
return kLatStateUnknown;
}
return (sleep.on & kLatStateSwitches) | ((sleep.multiplier > 255u ? 255u : sleep.multiplier) << 8);
}
// Whether the batch is to be written BEFORE a read in `state` is added to it.
inline bool LatencyBatchTurns(const LatencyBatchBook& book, uint32_t state) noexcept {
return book.batch.reads != 0u && book.batch.state != state && book.closures < kLatStateClosures;
}
// Whether the batch is to be written AFTER the request's okReads-th read was added.
inline bool LatencyBatchDue(uint32_t okReads) noexcept {
if (okReads <= kLatBatchSecond) {
return okReads == kLatBatchFirst || okReads == kLatBatchSecond;
}
return (okReads - kLatBatchSecond) % kLatBatchEvery == 0u;
}
// A batch is sixty reads of sixty-two frames at most, and a time is a second at most: under 2^32 microseconds. The
// sums stop there all the same, so that a word never wraps into a small number.
inline void LatencyAddStop(uint32_t& sum, uint32_t value) noexcept {
sum = value > 0xFFFFFFFFu - sum ? 0xFFFFFFFFu : sum + value;
}
inline void LatencyBatchAdd(LatencyBatchBook& book, const LatencyTally& tally, bool sleepValid,
const LatencySleep& sleep) noexcept {
LatencyBatch& batch = book.batch;
if (batch.reads == 0u) {
batch.state = LatencyStateOf(sleepValid, sleep);
}
++batch.reads;
++book.okReads;
LatencyAddStop(batch.frames, tally.frames);
LatencyAddStop(batch.refused, tally.refused);
LatencyAddStop(batch.gpu.spanAbsent, tally.gpu.spanAbsent);
LatencyAddStop(batch.gpu.spanZero, tally.gpu.spanZero);
LatencyAddStop(batch.gpu.activeNoSpan, tally.gpu.activeNoSpan);
LatencyAddStop(batch.gpu.spanNoActive, tally.gpu.spanNoActive);
LatencyAddStop(batch.gpu.longerFrames, tally.gpu.longerFrames);
LatencyAddStop(batch.gpu.longerSpanUs, tally.gpu.longerSpanUs);
LatencyAddStop(batch.gpu.longerActiveUs, tally.gpu.longerActiveUs);
LatencyAddStop(batch.gpu.withinFrames, tally.gpu.withinFrames);
LatencyAddStop(batch.gpu.withinSpanUs, tally.gpu.withinSpanUs);
LatencyAddStop(batch.gpu.withinActiveUs, tally.gpu.withinActiveUs);
if (sleepValid) {
batch.sleepOn |= sleep.on & FL_LAT_SLEEP_BITS;
batch.sleepOff |= ~sleep.on & FL_LAT_SLEEP_BITS;
batch.multipliers |= LatencyMultiplierBit(sleep.multiplier);
}
}
// The batch as lines of the native log: a text, the line's `a` (printed in decimal) and its `b` (printed in hex).
inline constexpr uint32_t kLatBatchLines = 6u;
struct LatencyLogLine {
const char* text;
uint32_t a;
uint64_t b;
};
constexpr uint64_t LatencyPair(uint32_t high, uint32_t low) noexcept {
return (static_cast<uint64_t>(high) << 32) | low;
}
constexpr LatencyLogLine LatencyBatchLine(const LatencyBatch& batch, uint32_t line) noexcept {
switch (line) {
case 0u:
return {"reads / sleep switches on | off<<8 | multipliers seen<<16", batch.reads,
batch.sleepOn | (batch.sleepOff << 8) | (static_cast<uint64_t>(batch.multipliers) << 16)};
case 1u:
return {"frames summed / refused", batch.frames, batch.refused};
case 2u:
return {"GPU span absent / of no length", batch.gpu.spanAbsent, batch.gpu.spanZero};
case 3u:
return {"active time with no span / span with no active time", batch.gpu.activeNoSpan, batch.gpu.spanNoActive};
case 4u:
return {"active longer than span: frames / span us<<32 | active us", batch.gpu.longerFrames,
LatencyPair(batch.gpu.longerSpanUs, batch.gpu.longerActiveUs)};
default:
return {"active within span: frames / span us<<32 | active us", batch.gpu.withinFrames,
LatencyPair(batch.gpu.withinSpanUs, batch.gpu.withinActiveUs)};
}
}
// The longest of those texts, for whoever writes them into a line of fixed length.
constexpr uint32_t LatencyBatchLongestText() noexcept {
uint32_t longest = 0u;
for (uint32_t line = 0u; line < kLatBatchLines; ++line) {
const char* text = LatencyBatchLine(LatencyBatch{}, line).text;
uint32_t length = 0u;
while (text[length] != '\0') {
++length;
}
longest = length > longest ? length : longest;
}
return longest;
}
// What the watchdog publishes of it. THE WATCHDOG'S: filled from what a read left behind while nobody is reading.
struct LatencyOut {
uint32_t state = FL_LAT_NONE; // FlLatencyState
+40 -1
View File
@@ -143,7 +143,10 @@ void PublishHandshake() noexcept {
// the log that should have said which hooks went in and what they were handed
// ended before the game had loaded its upscaler. Events are few and bounded
// (installs, a handful of first sights, three faults at most), so this is a few
// appends per session, on the watchdog's own tick.
// appends per session, on the watchdog's own tick -- and, since 0.1.0-beta.49,
// six lines a batch of the driver read's frame counts (LATENCY_FRAMES: a batch
// a minute at most once a session is under way), only while a session asks for
// Advanced metrics and the driver is being read.
// ---------------------------------------------------------------------------
enum FlLogCode : uint32_t {
kLogRingCreated = 1,
@@ -166,6 +169,7 @@ enum FlLogCode : uint32_t {
kLogFfxConfigureType,
kLogPatchBatch,
kLogLatency,
kLogLatencyFrames,
};
const char* LogCodeName(uint32_t code) noexcept {
@@ -210,6 +214,8 @@ const char* LogCodeName(uint32_t code) noexcept {
return "PATCH_BATCH";
case kLogLatency:
return "LATENCY";
case kLogLatencyFrames:
return "LATENCY_FRAMES";
default:
return "?";
}
@@ -227,6 +233,8 @@ struct FlLogEvent {
static_assert(sizeof(FlLogEvent) == 96, "the native log's event: 256 of them are static storage in a game's process");
static_assert(sizeof(fl::inventory::RowName::text) <= sizeof(FlLogEvent::text),
"a row's module!symbol name must fit an event's text, or two rows could log the same truncated name");
static_assert(fl::adv::LatencyBatchLongestText() < sizeof(FlLogEvent::text),
"a line of the driver read's frame counts must fit an event's text: LogNote cuts without saying so");
constexpr uint32_t kLogCapacity = 256;
FlLogEvent g_log[kLogCapacity]{};
@@ -804,6 +812,8 @@ bool g_latStalled = false;
int64_t g_latArmedQpc = 0;
int64_t g_latReadingSinceQpc = 0;
uint32_t g_latLoggedState = FL_LAT_NONE;
// The frame counts of the reads, for the native log only (fl_adv_fields.h; owner decisions D148, D151).
fl::adv::LatencyBatchBook g_latBook;
// One read, on a presenting thread that found the gate armed. Not inlined: RecordPresent stays as small as it was.
__declspec(noinline) void ReadLatencyOnce() noexcept {
@@ -890,9 +900,26 @@ const char* LatencyStateName(uint32_t state) noexcept {
}
}
// The batch of frame counts in hand, as LATENCY_FRAMES lines; nothing when no read is in it. The watchdog's: at the
// batch's end, when the Agent asks for a flush, at a new request and at a stop -- whatever a game that exits by
// itself had not had written by then is lost, under a minute of it.
void WriteLatencyBatch() noexcept {
if (g_latBook.batch.reads == 0u) {
return;
}
for (uint32_t line = 0; line < fl::adv::kLatBatchLines; ++line) {
const fl::adv::LatencyLogLine entry = fl::adv::LatencyBatchLine(g_latBook.batch, line);
LogNote(kLogLatencyFrames, entry.text, entry.a, entry.b);
}
g_latBook.batch = fl::adv::LatencyBatch{};
}
// THE WATCHDOG'S HALF, once a tick while a session asks. `now` is this tick's QPC.
void TickLatency(bool newRequest, int64_t now) noexcept {
if (newRequest) {
// What the session before left of a batch is its own, written before this one's counts begin.
WriteLatencyBatch();
g_latBook = fl::adv::LatencyBatchBook{};
// A session's counts are its own; where the read stands is the process's and stays.
g_latOut.reads = 0u;
g_latOut.worstUs = 0u;
@@ -936,6 +963,16 @@ void TickLatency(bool newRequest, int64_t now) noexcept {
if (g_latRead.ok != 0u) {
g_latOut.tally = g_latRead.tally;
fl::adv::NoteBits(g_adv.validMask, FL_ADV_VALID_LATENCY);
// The same read's frames, counted for the log: a batch is of one state of the sleep status.
const bool sleepValid = g_latRead.sleepValid != 0u;
if (fl::adv::LatencyBatchTurns(g_latBook, fl::adv::LatencyStateOf(sleepValid, g_latRead.sleep))) {
WriteLatencyBatch();
++g_latBook.closures;
}
fl::adv::LatencyBatchAdd(g_latBook, g_latRead.tally, sleepValid, g_latRead.sleep);
if (fl::adv::LatencyBatchDue(g_latBook.okReads)) {
WriteLatencyBatch();
}
}
if (g_latRead.sleepValid != 0u) {
g_latOut.sleepSeenOn |= g_latRead.sleep.on & FL_LAT_SLEEP_BITS;
@@ -3560,6 +3597,7 @@ DWORD WatchdogLoop() noexcept {
std::atomic_ref<uint32_t> flushReq{g_control->logFlushRequested};
if (const uint32_t req = flushReq.load(std::memory_order_acquire); req != g_logFlushSeen) {
g_logFlushSeen = req;
WriteLatencyBatch(); // what is counted of the driver read so far is part of what the Agent asks for
FlushLog();
}
@@ -3698,6 +3736,7 @@ DWORD WINAPI WatchdogThread(LPVOID) noexcept {
}
}
const bool complete = g_stopLogged.load(std::memory_order_acquire) != 0u;
WriteLatencyBatch(); // the watchdog's own book: no presenting thread ever touches it
LogNote(kLogStopFlushed, complete ? "every stop line is above" : "the stop was still writing", complete ? 1u : 0u);
FlushLog(true);
return r;
+92
View File
@@ -7857,6 +7857,98 @@ bool TargetHasModule(HANDLE process, const wchar_t* leaf) {
} // namespace
TEST_CASE("the frames a read summed are counted in the native log, each by its GPU span and the driver's active time: "
"a batch after ten reads, and what is left when the Agent asks",
"[guard][inject][shm][advanced][latency][log]") {
// WHY (0.1.0-beta.49, owner decisions D148, D151). In one real game the mean active time was longer than the mean
// span between the two GPU marks, and the two means cannot say whether that is the driver's doing or the way they
// are taken. The counts that can are written to the log only -- nothing of them is published -- in batches that
// each belong to one state of the sleep status.
LatencyTarget t;
REQUIRE(StartLatencyTarget(t, LatencyArgs(L"--hold-presenting-d3d12 40"), true));
const MappedRing& r = t.r;
fl::stubnv::Shared* stub = t.stub.words;
if (stub == nullptr || r.st == nullptr || r.ctl == nullptr) {
return; // not reached after the REQUIRE; said in the form a static analyser follows (cpp:S2259)
}
REQUIRE(WaitForRecords(r));
SetStubWord(stub->mode, fl::stubnv::kModeGpuShapes); // before the first read: every read is of these frames
SetAdvancedRequest(r, 7u);
// Ten reads sum the frames 5000..5151: sixty-two, then ten a read. By frameID % 5 (fl_stub_nvapi_shared.h) that is
// 31, 31, 30, 30, 30 of the five shapes.
const uint32_t zero = 31u + 30u; // shapes 1 and 4
const uint32_t longer = 30u; // shape 2
const uint32_t within = 31u; // shape 0
char tails[6][64]{};
snprintf(tails[0], sizeof(tails[0]), " a=10 b=0x%x", (1u | 8u) | ((2u | 4u | 16u) << 8) | ((1u << 2) << 16));
snprintf(tails[1], sizeof(tails[1]), " a=152 b=0x0");
snprintf(tails[2], sizeof(tails[2]), " a=0 b=0x%x", zero);
snprintf(tails[3], sizeof(tails[3]), " a=30 b=0x%x", 30u); // shape 4; shape 3
snprintf(tails[4], sizeof(tails[4]), " a=%u b=0x%llx", longer,
(static_cast<unsigned long long>(longer) * fl::stubnv::kGpuUs << 32) |
(static_cast<unsigned long long>(longer) * fl::stubnv::kGpuActiveLongUs));
snprintf(tails[5], sizeof(tails[5]), " a=%u b=0x%llx", within,
(static_cast<unsigned long long>(within) * fl::stubnv::kGpuUs << 32) |
(static_cast<unsigned long long>(within) * fl::stubnv::kGpuActiveUs));
const char* names[6] = {"reads / sleep switches", "frames summed / refused", "GPU span absent / of no length",
"active time with no span", "active longer than span", "active within span"};
std::wstring log;
std::string text;
bool complete = false;
for (int i = 0; i < 500 && !complete; ++i) {
++r.ctl->guardTicks;
Sleep(50);
if (i % 10 != 9 || (log.empty() && !FindOverlayLog(t.child.pi.dwProcessId, t.child.pi.hProcess, log))) {
continue;
}
text = ReadWholeFile(log);
complete = CountOf(text, "LATENCY_FRAMES") >= 6u;
}
INFO("log " << Narrow(log) << ":\n" << text);
REQUIRE(complete);
for (int line = 0; line < 6; ++line) {
INFO("line " << line << ": " << names[line] << " ..." << tails[line]);
CHECK(LogHasLine(text, "LATENCY_FRAMES", names[line], tails[line]));
}
CHECK(CountOf(text, "LATENCY_FRAMES") == 6u); // one batch: the next is twenty reads away
CHECK(r.ctl->logFlushRequested == 0u); // nobody asked for it
// What is published is what it was: these counts are the log's.
fl::FlAdvancedState a{};
REQUIRE(ReadAdvanced(r, 7u, a, 0u, fl::FL_ADV_VALID_LATENCY));
CHECK(LatStateOf(a) == fl::FL_LAT_READING);
for (uint32_t word : a.reservedDlss) {
CHECK(word == 0u);
}
// ---- THE REST, WHEN THE AGENT ASKS. A few reads more, then a flush request: the batch in hand is written with
// the log, six lines whose frames are ten a read.
TickFor(r, 3200);
++r.ctl->logFlushRequested;
complete = false;
for (int i = 0; i < 100 && !complete; ++i) {
++r.ctl->guardTicks;
Sleep(50);
if (i % 10 == 9) {
text = ReadWholeFile(log);
complete = CountOf(text, "LATENCY_FRAMES") >= 12u;
}
}
INFO("log after the flush request:\n" << text);
REQUIRE(complete);
CHECK(CountOf(text, "LATENCY_FRAMES") == 12u);
bool rest = false;
for (uint32_t reads = 1u; reads < 20u && !rest; ++reads) { // the thirtieth read would close it itself
char frames[32]{};
snprintf(frames, sizeof(frames), " a=%u b=0x0", reads * fl::stubnv::kFrameIdStep);
rest = LogHasLine(text, "LATENCY_FRAMES", names[1], frames);
}
CHECK(rest);
CHECK(r.st->faultCount == 0u);
}
TEST_CASE("the driver's latency report is read only while a session asks, once a second, and stops with the request "
"and with the hooks",
"[guard][inject][shm][advanced][latency]") {
+234
View File
@@ -12,7 +12,10 @@
// read as a game that has stopped.
#include <catch2/catch_test_macros.hpp>
#include <chrono>
#include <cstdint>
#include <cstdio>
#include <cstring>
#include <fl_adv_fields.h>
#include <memory>
@@ -310,3 +313,234 @@ TEST_CASE("a publication carries one read, packed as fl_shm.h says, and carries
CHECK(untouched.latGpuCounts == 0u);
CHECK(untouched.latMultipliersSeen == 0u);
}
// ---------------------------------------------------------------------------------------------------------------------
// THE COUNTS FOR THE NATIVE LOG (0.1.0-beta.49, owner decisions D148, D151).
// ---------------------------------------------------------------------------------------------------------------------
TEST_CASE("each summed frame is counted by its GPU span and the driver's active time, and what is summed does not move",
"[latency]") {
fl::adv::LatencyCursor cursor;
fl::adv::LatencyTally tally;
auto report = Report(100u); // 100..163: 100..161 are summed
for (std::uint32_t i = 0; i < 64u; ++i) {
Frame& f = report->frameReport[i];
switch (i % 6u) {
case 0u: // a span of 3700 and an active time that is the shorter
f.gpuActiveRenderTimeUs = 3500u;
break;
case 1u: // the two marks at one instant, and no active time
f.gpuRenderStartTime = f.gpuRenderEndTime;
break;
case 2u: // an active time longer than the span
f.gpuActiveRenderTimeUs = 4000u;
break;
case 3u: // the span, and no active time
break;
case 4u: // the two marks at one instant, and an active time
f.gpuRenderStartTime = f.gpuRenderEndTime;
f.gpuActiveRenderTimeUs = 3500u;
break;
default: // no start mark, and an active time
f.gpuRenderStartTime = 0u;
f.gpuActiveRenderTimeUs = 3500u;
break;
}
}
fl::adv::ObserveLatencyReport(*report, cursor, tally);
// Sixty-two frames: eleven each of the first two shapes, ten each of the other four.
REQUIRE(tally.frames == 62u);
CHECK(tally.refused == 0u);
CHECK(tally.gpu.withinFrames == 11u);
CHECK(tally.gpu.withinSpanUs == 11u * 3700u);
CHECK(tally.gpu.withinActiveUs == 11u * 3500u);
CHECK(tally.gpu.longerFrames == 10u);
CHECK(tally.gpu.longerSpanUs == 10u * 3700u);
CHECK(tally.gpu.longerActiveUs == 10u * 4000u);
CHECK(tally.gpu.spanZero == 11u + 10u);
CHECK(tally.gpu.spanAbsent == 10u);
CHECK(tally.gpu.spanNoActive == 10u);
CHECK(tally.gpu.activeNoSpan == 10u + 10u);
// Every summed frame is in exactly one place: the four counted here, or neither a span nor an active time -- the
// eleven whose two marks are one instant and that gave no time.
const std::uint32_t placed =
tally.gpu.withinFrames + tally.gpu.longerFrames + tally.gpu.spanNoActive + tally.gpu.activeNoSpan;
CHECK(placed + 11u == tally.frames);
// WHAT IS PUBLISHED IS WHAT IT WAS: the span over every frame that reported one, the time over those that gave one.
CHECK(tally.sumUs[fl::adv::kLatGpu] == (11u + 10u + 10u) * 3700u);
CHECK((tally.lacking & (1u << fl::adv::kLatGpu)) != 0u);
CHECK(tally.activeFrames == 11u + 10u + 10u + 10u);
CHECK(tally.activeSumUs == 31u * 3500u + 10u * 4000u);
CHECK(tally.sumUs[fl::adv::kLatTotal] == 62u * 7500u);
}
TEST_CASE(
"an active time as long as the span is not the longer; one of over a second was not given; a refused frame is "
"not counted",
"[latency]") {
fl::adv::LatencyGpuCounts counts;
fl::adv::CountGpuTimes(fl::adv::kLatSpanReported, 3700u, 3700u, counts);
CHECK(counts.withinFrames == 1u);
CHECK(counts.longerFrames == 0u);
fl::adv::CountGpuTimes(fl::adv::kLatSpanReported, 1u, 2u, counts); // a span of a microsecond is a span
CHECK(counts.longerFrames == 1u);
CHECK(counts.longerSpanUs == 1u);
CHECK(counts.longerActiveUs == 2u);
CHECK(counts.spanZero == 0u);
fl::adv::CountGpuTimes(fl::adv::kLatSpanReported, 3700u, 1'000'001u, counts); // no frame has such a time
CHECK(counts.spanNoActive == 1u);
CHECK(counts.longerFrames == 1u);
fl::adv::LatencyCursor cursor;
fl::adv::LatencyTally tally;
auto report = Report(100u);
for (auto& f : report->frameReport) {
f.gpuActiveRenderTimeUs = 3500u;
}
report->frameReport[5].presentEndTime = report->frameReport[5].presentStartTime - 50u; // refused whole
fl::adv::ObserveLatencyReport(*report, cursor, tally);
CHECK(tally.frames == 61u);
CHECK(tally.refused == 1u);
CHECK(tally.gpu.withinFrames == 61u);
CHECK(tally.gpu.withinSpanUs == 61u * 3700u);
}
TEST_CASE("a batch of the log's counts is written after ten reads, after thirty, and every sixty from there",
"[latency]") {
std::uint32_t due = 0u;
for (std::uint32_t reads = 1u; reads <= 400u; ++reads) {
const bool expected = reads == 10u || reads == 30u || reads == 90u || reads == 150u || reads == 210u ||
reads == 270u || reads == 330u || reads == 390u;
CHECK(fl::adv::LatencyBatchDue(reads) == expected);
due += fl::adv::LatencyBatchDue(reads) ? 1u : 0u;
}
CHECK(due == 8u);
CHECK_FALSE(fl::adv::LatencyBatchDue(0u));
}
TEST_CASE("a batch belongs to one state of the sleep status: another state closes it, until a request has closed "
"thirty-two that way",
"[latency]") {
fl::adv::LatencyTally tally;
tally.frames = 10u;
tally.refused = 1u;
tally.gpu.spanZero = 2u;
tally.gpu.longerFrames = 3u;
tally.gpu.longerSpanUs = 300u;
tally.gpu.longerActiveUs = 450u;
tally.gpu.withinFrames = 4u;
tally.gpu.withinSpanUs = 4000u;
tally.gpu.withinActiveUs = 3600u;
// The state: the low-latency switch, "the game sleeps", and the multiplier -- not the other three switches.
const fl::adv::LatencySleep reflexTwo{1u | 8u, 2u};
const fl::adv::LatencySleep reflexTwoVrr{1u | 2u | 8u | 16u, 2u};
const fl::adv::LatencySleep overrideOne{1u, 1u};
const fl::adv::LatencySleep manyFrames{0u, 900u};
CHECK(fl::adv::LatencyStateOf(true, reflexTwo) == ((1u | 8u) | (2u << 8)));
CHECK(fl::adv::LatencyStateOf(true, reflexTwoVrr) == fl::adv::LatencyStateOf(true, reflexTwo));
CHECK(fl::adv::LatencyStateOf(true, overrideOne) != fl::adv::LatencyStateOf(true, reflexTwo));
CHECK(fl::adv::LatencyStateOf(false, reflexTwo) == fl::adv::kLatStateUnknown);
CHECK(fl::adv::LatencyStateOf(true, manyFrames) == (255u << 8));
fl::adv::LatencyBatchBook book;
CHECK_FALSE(fl::adv::LatencyBatchTurns(book, fl::adv::LatencyStateOf(true, reflexTwo))); // nothing to close
fl::adv::LatencyBatchAdd(book, tally, true, reflexTwo);
fl::adv::LatencyBatchAdd(book, tally, true, reflexTwoVrr);
CHECK(book.okReads == 2u);
CHECK(book.batch.reads == 2u);
CHECK(book.batch.frames == 20u);
CHECK(book.batch.refused == 2u);
CHECK(book.batch.gpu.spanZero == 4u);
CHECK(book.batch.gpu.longerFrames == 6u);
CHECK(book.batch.gpu.longerActiveUs == 900u);
CHECK(book.batch.gpu.withinSpanUs == 8000u);
CHECK(book.batch.state == fl::adv::LatencyStateOf(true, reflexTwo));
CHECK(book.batch.sleepOn == (1u | 2u | 8u | 16u));
CHECK(book.batch.sleepOff == (2u | 4u | 16u)); // off in one read or the other
CHECK(book.batch.multipliers == (1u << 2));
CHECK_FALSE(fl::adv::LatencyBatchTurns(book, fl::adv::LatencyStateOf(true, reflexTwoVrr)));
CHECK(fl::adv::LatencyBatchTurns(book, fl::adv::LatencyStateOf(true, overrideOne)));
CHECK(fl::adv::LatencyBatchTurns(book, fl::adv::kLatStateUnknown)); // a read with no status is a state too
// A read with no status adds its frames and nothing to the "seen" words.
fl::adv::LatencyBatchAdd(book, tally, false, overrideOne);
CHECK(book.batch.reads == 3u);
CHECK(book.batch.sleepOn == (1u | 2u | 8u | 16u));
CHECK(book.batch.multipliers == (1u << 2));
// A status that flickers: after thirty-two closings the batch runs on, and says what it held.
book.closures = fl::adv::kLatStateClosures;
CHECK_FALSE(fl::adv::LatencyBatchTurns(book, fl::adv::LatencyStateOf(true, overrideOne)));
fl::adv::LatencyBatchAdd(book, tally, true, overrideOne);
CHECK(book.batch.state == fl::adv::LatencyStateOf(true, reflexTwo)); // its first read's
CHECK(book.batch.multipliers == ((1u << 1) | (1u << 2)));
CHECK(book.batch.sleepOff == (2u | 4u | 8u | 16u));
// A sum stops at the top of its word instead of wrapping into a small number.
std::uint32_t sum = 0xFFFFFFF0u;
fl::adv::LatencyAddStop(sum, 0x20u);
CHECK(sum == 0xFFFFFFFFu);
}
TEST_CASE("a batch is six lines of the log: a text that fits, a count in decimal, and a word in hex", "[latency]") {
fl::adv::LatencyBatch batch;
batch.reads = 10u;
batch.frames = 152u;
batch.refused = 3u;
batch.sleepOn = 1u | 8u;
batch.sleepOff = 2u | 4u | 16u;
batch.multipliers = 1u << 2;
batch.gpu.spanAbsent = 5u;
batch.gpu.spanZero = 61u;
batch.gpu.activeNoSpan = 30u;
batch.gpu.spanNoActive = 31u;
batch.gpu.longerFrames = 30u;
batch.gpu.longerSpanUs = 111000u;
batch.gpu.longerActiveUs = 120000u;
batch.gpu.withinFrames = 26u;
batch.gpu.withinSpanUs = 96200u;
batch.gpu.withinActiveUs = 91000u;
const std::uint64_t expectedB[fl::adv::kLatBatchLines] = {
0x41609ull, 3ull, 61ull, 31ull, (111000ull << 32) | 120000ull, (96200ull << 32) | 91000ull};
const std::uint32_t expectedA[fl::adv::kLatBatchLines] = {10u, 152u, 5u, 30u, 30u, 26u};
for (std::uint32_t line = 0; line < fl::adv::kLatBatchLines; ++line) {
const fl::adv::LatencyLogLine entry = fl::adv::LatencyBatchLine(batch, line);
INFO("line " << line << ": " << entry.text);
CHECK(entry.a == expectedA[line]);
CHECK(entry.b == expectedB[line]);
CHECK(std::strlen(entry.text) <= fl::adv::LatencyBatchLongestText());
CHECK(std::strlen(entry.text) < 72u); // the native log's event has 72 characters of text, the last a zero
for (std::uint32_t other = 0; other < line; ++other) {
CHECK(std::strcmp(entry.text, fl::adv::LatencyBatchLine(batch, other).text) != 0);
}
}
}
// What summing one report costs: the reader runs on a game's presenting thread, once a second. Hidden -- a number
// for a pull request, not a gate: `fl_reflex_summary_test "[.bench]"`.
TEST_CASE("what summing one report of sixty-four frames costs", "[.bench]") {
auto report = Report(5000u);
for (auto& f : report->frameReport) {
f.gpuActiveRenderTimeUs = 3500u;
f.gpuFrameTimeUs = 4200u;
}
constexpr std::uint32_t kRuns = 2'000'000u;
std::uint64_t frames = 0u;
for (int pass = 0; pass < 5; ++pass) {
const auto began = std::chrono::steady_clock::now();
for (std::uint32_t run = 0; run < kRuns; ++run) {
fl::adv::LatencyCursor cursor; // every run sums the report's sixty-two frames anew
fl::adv::LatencyTally tally;
fl::adv::ObserveLatencyReport(*report, cursor, tally);
frames += tally.frames + tally.gpu.withinFrames;
}
const auto nanos =
std::chrono::duration_cast<std::chrono::nanoseconds>(std::chrono::steady_clock::now() - began).count();
std::printf("pass %d: %.1f ns a report\n", pass, static_cast<double>(nanos) / kRuns);
}
CHECK(frames == 5ull * kRuns * (62u + 62u));
}
@@ -25,6 +25,13 @@ enum Mode : std::uint32_t {
kModeFault = 3, // an access violation inside GetLatency
kModeNoDriverSpan = 4, // reports whose driverStartTime is zero: what the driver gives without a sleep mode
kModeImpossible = 5, // reports whose present ends before it starts
// Reports whose frames differ in their GPU span and in the driver's active time, by frameID % 5:
// 0 as kModeReports: a span of kGpuUs and an active time of kGpuActiveUs, which is the shorter
// 1 the two GPU marks at the same instant, and no active time
// 2 an active time of kGpuActiveLongUs, longer than the span
// 3 the span, and no active time
// 4 the two GPU marks at the same instant, and an active time
kModeGpuShapes = 6,
};
// One frame of kModeReports, in microseconds: every frame has these spans.
@@ -38,7 +45,8 @@ inline constexpr std::uint32_t kTotalUs = 7500u;
// The two times a driver works out itself, of every frame: the card at work, and one frame's GPU end to the next's.
inline constexpr std::uint32_t kGpuActiveUs = 3500u;
inline constexpr std::uint32_t kGpuFrameUs = 4200u;
inline constexpr std::uint32_t kFgMultiplier = 2u; // what GetSleepStatus gives while `fgMultiplier` is zero
inline constexpr std::uint32_t kGpuActiveLongUs = 4000u; // kModeGpuShapes: longer than kGpuUs
inline constexpr std::uint32_t kFgMultiplier = 2u; // what GetSleepStatus gives while `fgMultiplier` is zero
inline constexpr std::uint32_t kFirstFrameId = 5000u;
inline constexpr std::uint32_t kFrameIdStep = 10u; // how far the ids move on at each call
@@ -125,6 +125,18 @@ NvAPI_Status __cdecl StubGetLatency(IUnknown* device, NV_LATENCY_RESULT_PARAMS*
if (mode == fl::stubnv::kModeImpossible) {
r.presentEndTime = r.presentStartTime - 50u;
}
if (mode == fl::stubnv::kModeGpuShapes) {
const std::uint64_t shape = id % 5u;
if (shape == 1u || shape == 4u) {
r.gpuRenderStartTime = r.gpuRenderEndTime; // a span of no length; the frame's total is as it was
}
if (shape == 1u || shape == 3u) {
r.gpuActiveRenderTimeUs = 0u;
}
if (shape == 2u) {
r.gpuActiveRenderTimeUs = fl::stubnv::kGpuActiveLongUs;
}
}
}
return NVAPI_OK;
}