Fix/stop high precision waits#641
Open
planetchili wants to merge 4 commits into
Open
Conversation
There was a problem hiding this comment.
Pull request overview
This PR reduces background CPU usage by switching periodic loops from high-precision timer waits to Sleep()-based waiting, and adjusts related timing defaults/limits to accommodate the coarser Windows timer resolution.
Changes:
- Introduces a selectable wait mechanism in
IntervalWaiter(defaulting toSleep) while keeping unit tests on high-precision timing. - Clamps (instead of errors) out-of-range ETW flush / telemetry periods, and updates API min constants (telemetry min now 50ms; ETW flush min now 8ms).
- Adjusts overlay timing behavior (poll timestamping) and UI defaults/migrations for increased metrics offset.
Reviewed changes
Copilot reviewed 16 out of 16 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| IntelPresentMon/UnitTests/Timing.cpp | Forces high-precision mechanism for timing-accuracy tests. |
| IntelPresentMon/PresentMonService/PMMainThread.cpp | Reduces telemetry idle wait cadence and relies on Sleep-based waiting via IntervalWaiter. |
| IntelPresentMon/PresentMonService/acts/SetTelemetryPeriod.h | Changes telemetry period handling to clamp and warn (instead of error). |
| IntelPresentMon/PresentMonService/acts/SetEtwFlushPeriod.h | Changes ETW flush period handling to clamp and warn (instead of error). |
| IntelPresentMon/PresentMonAPI2Tests/MultiClientTests.cpp | Updates tests to match new min/clamping behavior. |
| IntelPresentMon/PresentMonAPI2Tests/InterimBroadcasterTests.cpp | Updates tests to use new telemetry minimum baseline. |
| IntelPresentMon/PresentMonAPI2/PresentMonAPI.h | Updates public min constants for telemetry/ETW flush periods. |
| IntelPresentMon/Core/source/pmon/DynamicQuery.h | Adds PollWithTimestamp() to support explicit “now” timestamps. |
| IntelPresentMon/Core/source/pmon/DynamicQuery.cpp | Implements DynamicQuery::PollWithTimestamp(). |
| IntelPresentMon/Core/source/kernel/Overlay.h | Updates overlay graph update signature to take a QPC timestamp. |
| IntelPresentMon/Core/source/kernel/Overlay.cpp | Uses interval-wait target timestamps for polling cadence. |
| IntelPresentMon/Core/source/kernel/MetricPackMapper.h | Polls dynamic query with explicit timestamps and converts to epoch-relative time for graph data. |
| IntelPresentMon/CommonUtilities/PrecisionWaiter.cpp | Fixes buffer/short-wait handling and avoids negative/invalid timer intervals. |
| IntelPresentMon/CommonUtilities/IntervalWaiter.h | Adds WaitMechanism + Options to choose between Sleep and high-precision timer waiting. |
| IntelPresentMon/CommonUtilities/IntervalWaiter.cpp | Implements mechanism selection and Sleep() waiting path. |
| IntelPresentMon/AppCef/ipm-ui-vue/src/core/preferences.ts | Raises default metrics offset and adds prefs migration for the new default. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| throw util::Except<ActionExecutionError>(sta); | ||
| } | ||
| auto telemetrySamplePeriodMs = in.telemetrySamplePeriodMs; | ||
| if (telemetrySamplePeriodMs && telemetrySamplePeriodMs < PM_TELEMETRY_PERIOD_MIN) { |
Comment on lines
+432
to
+433
| const auto waitResult = samplingWaiter.Wait(); | ||
| const auto targetTimestamp = samplingWaiter.TargetTimeToTimestamp(waitResult.targetSec); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
closes #640
Stop using high precision waiting for interval timer everywhere. Main offenders are ETW flush thread, followed distantly by telemetry poll thread. This change can bring us from 0.4% utilization to under 0.2% utilization on test system.
Using Sleep() means we can be off by as much as 15.6 ms (and can never schedule faster than that rate). Increased overlay window offset to match increased event processing lag (now 150ms). Telemetry will experience 15.6 ms jitter in sample cadence, but 15.6/100 is likely tolerable. Overlay polling client-side also changed, but with manual window placement we can guarantee perfect polling cadence even without timer precision (some jitter for graph update is likely tolerable, especially if we use standard update rate of 10 Hz). Set minimum ETW flush period to 8 ms and minimum telemetry period to 50 ms to match these changes (requesting out of range no longer errors, just output warning to log/diagnostic).