Skip to content

Commit f0401ae

Browse files
authored
fix(vm): kernel incorrectly believes that tsc is unreliable in amd64 (#21)
When a Mac wakes up from sleep, the hardware clock in the guest will lag for a while. This causes the kernel to think that the `TSC` is unstable, and thus switches to `HPET`. However, the `HPET` is much slower than the `TSC`, causing any program involved with time-related code to experience a drop in performance. Don't worry about any side effects of this option. In PR #19, we forced an update of the system time and hardware time in the guest. In arm64, the `clocksource` is fixed as `arch_sys_counter`, so this issue does not exist. Signed-off-by: Black-Hole1 <bh@bugs.cc>
1 parent a1db9b1 commit f0401ae

File tree

4 files changed

+17
-0
lines changed

4 files changed

+17
-0
lines changed

cspell.config.yml

+2
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ words:
2929
- pidlock
3030
- gopsutil
3131
- shirou
32+
- clocksource
33+
- hpet
3234
dictionaries:
3335
- companies
3436
- softwareTerms

internal/consts/consts_amd64.go

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
package consts
2+
3+
const IsAMD64 = true

internal/consts/consts_arm64.go

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
package consts
2+
3+
const IsAMD64 = false

pkg/vfkit/kernel_cmd.go

+9
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ package vfkit
66
import (
77
"strings"
88

9+
"github.com/oomol-lab/ovm/internal/consts"
910
"github.com/oomol-lab/ovm/pkg/cli"
1011
)
1112

@@ -21,6 +22,14 @@ func kernelCMD(opt *cli.Context) string {
2122
// see: https://github.com/oomol-lab/ovm-js/pull/23
2223
sb.WriteString("fb_tunnels=none ")
2324

25+
// When a Mac wakes up from sleep, the hardware clock in the guest will lag for a while. This causes the kernel to think that the TSC is unstable, and thus switches to HPET.
26+
// However, the HPET is much slower than the TSC, causing any program involved with time-related code to experience a drop in performance.
27+
// Don't worry about any side effects of this option. In PR #19, we forced an update of the system time and hardware time in the guest.
28+
// In arm64, the clocksource is fixed as arch_sys_counter, so this issue does not exist.
29+
if consts.IsAMD64 {
30+
sb.WriteString("clocksource=tsc tsc=reliable ")
31+
}
32+
2433
// systemd configuration
2534
// see: https://www.freedesktop.org/software/systemd/man/latest/systemd.html#Options%20that%20duplicate%20kernel%20command%20line%20settings
2635
{

0 commit comments

Comments
 (0)