[PATCH 6/6] vmd: preserve i8253 counter load timestamp

ssnf <[email protected]>
Newsgroups gmane.os.openbsd.tech
Message-ID <[email protected]>
The counter timestamp is recorded when the guest completes the PIT
write, but i8253_reset() records it again when the event is
processed.

This moves the counter epoch forward by the event processing delay
and makes the emulated count jump backwards.

Keep the guest write timestamp for counter programming, and
establish a new epoch explicitly when restarting active timers.
---
 usr.sbin/vmd/i8253.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/usr.sbin/vmd/i8253.c b/usr.sbin/vmd/i8253.c
index d769b6d8e69..f6e2fc929f1 100644
--- a/usr.sbin/vmd/i8253.c
+++ b/usr.sbin/vmd/i8253.c
@@ -353,7 +353,6 @@ i8253_reset(uint8_t chn)
 	i8253_channel[chn].in_use = 1;
 	i8253_channel[chn].state = 0;
 	tv.tv_usec = (i8253_channel[chn].start * NS_PER_TICK) / 1000;
-	clock_gettime(CLOCK_MONOTONIC, &i8253_channel[chn].ts);
 	evtimer_add(&i8253_channel[chn].timer, &tv);
 }
 
@@ -398,8 +397,11 @@ void
 i8253_start(void)
 {
 	int i;
-	for (i = 0; i < 3; i++)
-		if (i8253_channel[i].in_use)
+	for (i = 0; i < 3; i++) {
+		if (i8253_channel[i].in_use) {
+			clock_gettime(CLOCK_MONOTONIC, &i8253_channel[i].ts);
 			i8253_reset(i);
+		}
+	}
 	event_add(&dev_pipe.read_ev, NULL);
 }
-- 
2.51.0
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.