Repository navigation
Conversation
…biased interrupt time (#962) spored on Windows counted running time through Go's monotonic clock, which on Windows is the biased interrupt time and keeps counting through sleep and hibernation. sysKernelClocks now reads QueryUnbiasedInterruptTime (Monotonic role, excludes sleep/hibernation) and QueryInterruptTime (Boottime role), so the shared #945 kernel-clock logic measures the daemon's own count, and so spawn:compute-seconds and --cost-limit, without the hibernation. Windows still has no boot id, so the readings are not published or checkpointed. Unverified against a real EC2 hibernation of a Windows instance. (#962)
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
Windows CI showed sysKernelClocks unreadable: QueryInterruptTime is not a kernel32 export, so Find failed on every Windows version and the clocks were silently disabled.
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.
Fixes #962
Stacked on #965 (→ #947 → #916). Review and merge those first; this diff is against
fix/945.This is unverified on a real Windows hibernation. No Windows instance was launched. The fix follows Microsoft's documentation of the two APIs and is tested through the stub hooks; whether the unbiased interrupt time really stops across an EC2 hibernation of a Windows instance has not been observed.
What changed
sysKernelClocksinpkg/agent/sys_windows.gono longer reports "not available". It reads, through lazy kernel32 procs (golang.org/x/sys/windows, already a dependency):QueryUnbiasedInterruptTime→ Monotonic role. Microsoft: "does not include time the system spends in sleep or hibernation"; "reflects only the time that the system is in the working state". Windows 7 / Server 2008 R2+.QueryInterruptTime→ Boottime role. The biased count, which keeps counting through sleep and hibernation. The unbiased page contrasts the two: the system uses biased time so that "relative timers that would have expired during sleep expire immediately upon waking". This is also what Go's monotonic clock reads on Windows, which is the cause of the bug. Windows 10 / Server 2016+.Both are 100ns units that "begin at zero when the system starts", so they fit the
{0,0}boot origin from #945. The docs are cited in the code comment. The unbiased count is read first, so the pair can only overstate the suspended time. If either proc is missing (before Server 2016), the clocks report false and compute is counted as before. I didn't useGetTickCount64: it does include sleep, but it is in milliseconds and comes from the tick count, so subtracting the unbiased interrupt time from it is not exact.The units and the role mapping are in a platform-neutral
interruptTimeClocksinkernelclock.go, so they are tested on every OS. It rejects pairs no system produces (biased behind unbiased, or values past thetime.Durationrange).Scope: spored's own count only. Windows still has no boot id and no boot-scoped location, so nothing is published or checkpointed (
ComputeClockneeds a boot id before it publishes kernel readings). What changes is the daemon's in-processTotalComputeSeconds, which feedsspawn:compute-seconds, the stopped-instance compute inspawn status, and--cost-limit.spored statuson Windows still reads the checkpoint and shows no hibernated time.Tests
TestInterruptTimeClocks_MapsUnbiasedToMonotonicandTestInterruptTimeClocks_RejectsImpossiblePairs: platform-neutral.TestWindowsDaemon_HibernationIsNotCountedAsCompute: platform-neutral, throughSetKernelClocksForTest. It sets up a Windows-shaped daemon (no boot id, no boot time, no checkpoint, tag 70s) on fake interrupt-time counters, runs it for 10 minutes, then hibernates for 8 hours. It expects 670s, 8h hibernated, and no kernel readings published.interruptTimeClocksalways returning false (as on Windows before this fix), both tests fail.TestSysKernelClocks_ReadsBothInterruptTimes(//go:build windows) reads the real APIs. This repo's CI has no Windows runner, so it will not run in CI. It has only been compiled (GOOS=windows go test -c).GOOS=windows go build ./...passes.GOOS=windows go vetpasses for./pkg/agent ./cmd/sporedon amd64 and arm64. A repo-wideGOOS=windows go vet ./...stops on existing Unix-only test files inpkg/serviceandpkg/taskproto, which this PR does not touch.make checkpasses apart from the known Docker-onlyTestGenerateWrapper_ChownFixesCrossUIDStickyUnlink_Docker, which fails because no Docker daemon is running.make check-nestedpasses.Caveats
QueryInterruptTime, so behaviour there is unchanged.