From 657db692b2241d89a324acc246b3c5230d8bd6ac Mon Sep 17 00:00:00 2001 From: Jamie Liu Date: Thu, 14 Jun 2018 11:34:15 -0700 Subject: [PATCH] Ignore expiration count in kernelCPUClockListener.Notify. PiperOrigin-RevId: 200590832 Change-Id: I35b817ecccc9414a742dee4815dfc67d0c7d0496 --- pkg/sentry/kernel/kernel.go | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/pkg/sentry/kernel/kernel.go b/pkg/sentry/kernel/kernel.go index 536461bbd..a17148af1 100644 --- a/pkg/sentry/kernel/kernel.go +++ b/pkg/sentry/kernel/kernel.go @@ -960,7 +960,13 @@ type kernelCPUClockListener struct { // Notify implements ktime.TimerListener.Notify. func (l kernelCPUClockListener) Notify(exp uint64) { - atomic.AddUint64(&l.k.cpuClock, exp) + // Only increment cpuClock by 1 regardless of the number of expirations. + // This approximately compensates for cases where thread throttling or bad + // Go runtime scheduling prevents the cpuClockTicker goroutine, and + // presumably task goroutines as well, from executing for a long period of + // time. It's also necessary to prevent CPU clocks from seeing large + // discontinuous jumps. + atomic.AddUint64(&l.k.cpuClock, 1) } // Destroy implements ktime.TimerListener.Destroy.