Page MenuHomeFreeBSD

Add/enable option to allow tsc as timecounter for VM
Needs ReviewPublic

Authored by lprylli_netflix.com on Mar 19 2019, 9:00 PM.
Tags
None
Referenced Files
Unknown Object (File)
Sun, Nov 3, 7:22 AM
Unknown Object (File)
Sat, Nov 2, 9:09 AM
Unknown Object (File)
Sat, Nov 2, 7:45 AM
Unknown Object (File)
Fri, Nov 1, 10:19 PM
Unknown Object (File)
Tue, Oct 29, 8:39 AM
Unknown Object (File)
Fri, Oct 18, 12:39 PM
Unknown Object (File)
Oct 4 2024, 10:44 PM
Unknown Object (File)
Sep 28 2024, 8:49 PM
Subscribers

Details

Reviewers
gallatin
imp
jhb
Summary
Instead of systematically disabling use of tsc as timecounter for
VM, a new option is introduced to allow overriding default
behavior and still enable tsc. The major reason to previously
systematically disallow tsc as timecounter in the VM case is to
allow for VM migration, but in many contexts this is not a restriction.

Some systems rely on efficient and low granularity timecounter, even
when running as VM.  While timecounter choice can be overwritten after
boot, allowing it from kernel boot additionally allows to test the
full boot procedure in a VM with tsc timecounter which can be useful
to diagnose timecounter related issues during that time.

Tested: ran Freebsd native and under VM, checked tsc choices and
behavior.
Test Plan

tested with kernel running on baremetal or VM

Diff Detail

Lint
Lint Passed
Unit
No Test Coverage
Build Status
Buildable 23313
Build 22343: arc lint + arc unit

Event Timeline

I'm curious which hypervisor you have tested this under and did you consider using one of the virtualized clocks if one was available? I know that there are some early patches to add kvmclock support to bhyve for example.

sys/x86/x86/tsc.c
57

For FreeBSD we probably want to leave the default setting as-is by setting this to zero. I would perhaps rename the knob/variable as well to be something like 'tsc_vm_enable' and 'hw.tsc.vm_enable'. Finally, I would maybe make this a CTLFLAG_RDTUN sysctl and call it 'machdep.tsc_vm_enable'. Then it is documented via sysctl -d and you can inspect the current value on existing systems, etc. The reason for machdep is that the other existing TSC sysctl is 'machdep.tsc_freq'.

Updating D19648: Add/enable option to allow tsc as timecounter for VM

  • change tunable to machdep.tsc_vm_enable
  • make it a sysctl
  • don't modify default (initial value must be zero).
In D19648#420593, @jhb wrote:

I'm curious which hypervisor you have tested this under and did you consider using one of the virtualized clocks if one was available? I know that there are some early patches to add kvmclock support to bhyve for example.

I have ran experiments with hypervizor either linux/qemu/kvm or freebsd/bhyve and had the same behavior for both. kvmclock could solve the issue in long-term, but it seems some additional parts would be needed in both bhyve and in freebsd kernel (as guest).

I updated the patch. But if you have a pointer to kvmclock patches, I'll be glad to try them.

Tiny style nits can be fixed when this is committed.

sys/x86/x86/tsc.c
89

I would move tsc_vm_enable declaration here and just leave off the ' = 0' (see the tsc_skip_calibration node above for an example of this style).

125

style(9) would want a single tab indent, a blank line before the indent, and parentheses around the return value.

This revision is now accepted and ready to land.Mar 26 2019, 4:24 PM
This revision now requires review to proceed.Mar 26 2019, 10:02 PM

Just pushed style fixes.