Skip to content

Fix/stop high precision waits#641

Open
planetchili wants to merge 4 commits into
mainfrom
fix/stop-high-precision-waits
Open

Fix/stop high precision waits#641
planetchili wants to merge 4 commits into
mainfrom
fix/stop-high-precision-waits

Conversation

@planetchili
Copy link
Copy Markdown
Collaborator

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).

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

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 to Sleep) 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);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

CPU utilization relating to high-precision scheduling

2 participants