Page MenuHomeFreeBSD

paravirt: Add KVM clock timecounter support
Needs ReviewPublic

Authored by stevek on Jul 17 2018, 7:39 PM.

Details

Reviewers
mmacy
jhb
Summary

This allows a KVM guest to get an accurate cycle counter without having to do a VM exit, which happens when either HPET or ACPI is used.

KVMCLOCK quality is set to 2000 to ensure it is preferred, when it is available. Otherwise, if it was set to 1000, both TSC and KVMCLOCK could be detected and TSC will most likely get selected over KVMCLOCK, based on probe order.

KVM clock also supports getting the wall clock time but that is not implemented yet.

This change is dependent on D16305 being committed first.

Test Plan

Booted on qemu/KVM setup running Junos with these changes.

Diff Detail

Repository
rS FreeBSD src repository
Lint
Lint OK
Unit
No Unit Test Coverage
Build Status
Buildable 20300
Build 19760: arc lint + arc unit

Event Timeline

stevek created this revision.Jul 17 2018, 7:39 PM
stevek edited the summary of this revision. (Show Details)Jul 17 2018, 7:40 PM
bryanv added inline comments.Jul 19 2018, 3:17 PM
sys/x86/x86/kvm_clock.c
65

I don't think we need to do this right now, but we may later want to use this in probe_tsc_freq(), similar to what's done for VMware.

swills added a subscriber: swills.Jul 24 2018, 2:28 PM
araujo added a subscriber: araujo.Aug 9 2018, 9:33 PM
stevek updated this revision to Diff 49325.Oct 19 2018, 11:54 PM

Removed kvm_clock_tsc_freq, per comments, as it is currently not needed.

any update on this?

i have manually patched my FreeBSD 11.2 environment with this patch and the corresponding D16305 patch and the clock on my virtual FreeBSD guests seems to be more correct now.
although i have to mention that i see messages like this from time to time:

Feb 15 11:47:47 kern kernel: calcru: runtime went backwards from 2567676 usec to 2513475 usec for pid 1 (init)
Feb 15 11:47:47 kern kernel: calcru: runtime went backwards from 1658497 usec to 1623487 usec for pid 0 (kernel)

it is a bit unclear to me yet if one is still supposed to use ntp client when using KVMCLOCK or not?

any update on this?

I have some folks in work scheduled to do some stress testing with the patch, but it has not occurred yet.

I don't know yet if anyone else has tested it.

i have manually patched my FreeBSD 11.2 environment with this patch and the corresponding D16305 patch and the clock on my virtual FreeBSD guests seems to be more correct now.
although i have to mention that i see messages like this from time to time:

Feb 15 11:47:47 kern kernel: calcru: runtime went backwards from 2567676 usec to 2513475 usec for pid 1 (init)
Feb 15 11:47:47 kern kernel: calcru: runtime went backwards from 1658497 usec to 1623487 usec for pid 0 (kernel)

Interesting.

it is a bit unclear to me yet if one is still supposed to use ntp client when using KVMCLOCK or not?

I think one is not supposed to be, since the host clock should be the source of truth when using KVMCLOCK. Bryan might have some input on this, since the driver implementation is originally his.