Re: [patch] Auto-setting hz to 100 inside QEMU/VMWare

From: Robert Watson <rwatson_at_FreeBSD.org>
Date: Fri, 28 Dec 2007 10:00:58 +0000 (GMT)
On Fri, 28 Dec 2007, Mike Silbersack wrote:

> When running FreeBSD inside QEMU / VMWare, one of my pet peeves is that time 
> is completely inaccurate.  This seems to be cured by setting kern.hz=100 
> (down from the default of 1000) in /boot/loader.conf, but I'm getting sick 
> of doing that every time I set up a virtual box.
>
> So, here's a patch to have the kernel auto-detect that it's running inside 
> one of those two environments and automatically make that adjustment.
>
> If you're running FreeBSD inside any other virtual environments (Parallels? 
> Microsoft Virtual PC?) and can detect them via data in kenv, I'll be happy 
> to add them to the patch as well.
>
> I have only tested this patch in QEMU so far, I will test inside VMWare 
> tomorrow.
>
> If anyone could review and/or test this, it would be appreciated.

I like the general idea, but one thing that does worry me is that this 
prevents me from using config to set HZ at all, I have to set it at runtime 
using the tunable.  Could we add an:

options VIRTUAL_HZ=100	# alternative default HZ to use with virtualization

Or something along these lines?  kern.hz as a tunable could still override it, 
but this would put the default in the config rather than in the code.  So the 
new logic would be something along the lines of

{

 	if (detect_virtualmachine())
 		hz = VIRTUAL_HZ;	/* A big HZ hurts. */
 	else
 		hz = HZ;
}

I also wonder if detect_virtualmachine(), or whatever the most appropriate 
name is, should be an MD routine shared by amd64, but also available on sun4v 
in the form of int detect_virtualmachine(void) { return (1); }.

FYI, the vendor for Parallels is:

   smbios.bios.vendor="Parallels Software International Inc."

In any case, having something along these lines in the tree would make my life 
with Parallels and VMWare a lot easier "out of the box".

Robert N M Watson
Computer Laboratory
University of Cambridge
Received on Fri Dec 28 2007 - 09:00:58 UTC

This archive was generated by hypermail 2.4.0 : Wed May 19 2021 - 11:39:24 UTC