Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 29 Oct 2017 14:54:55 -0600
From:      Ian Lepore <ian@freebsd.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   Re: svn commit: r325108 - head/sys/amd64/vmm/io
Message-ID:  <1509310495.21609.60.camel@freebsd.org>
In-Reply-To: <201710292050.v9TKo3j5058456@repo.freebsd.org>
References:  <201710292050.v9TKo3j5058456@repo.freebsd.org>

next in thread | previous in thread | raw e-mail | index | archive | help
On Sun, 2017-10-29 at 20:50 +0000, Ian Lepore wrote:
> Author: ian
> Date: Sun Oct 29 20:50:03 2017
> New Revision: 325108
> URL: https://svnweb.freebsd.org/changeset/base/325108
> 
> Log:
>   Improve the performance of the hpet timer in bhyve guests by making the
>   timer frequency a power of two.  This changes the frequency from 10 to
>   16.7 MHz (2 ^ 24 HZ).  Using a power of two avoids roundoff errors when
>   doing arithmetic in sbintime_t units.
>   
>   Testing shows this can fix erratic ntpd behavior in guests using the
>   hpet timer (which is the default for multicore guests).
>   
>   Reported by:	bsam@
> 
> Modified:
>   head/sys/amd64/vmm/io/vhpet.c
> 
> Modified: head/sys/amd64/vmm/io/vhpet.c
> ==============================================================================
> --- head/sys/amd64/vmm/io/vhpet.c	Sun Oct 29 20:40:56 2017	(r325107)
> +++ head/sys/amd64/vmm/io/vhpet.c	Sun Oct 29 20:50:03 2017	(r325108)
> @@ -51,7 +51,7 @@ __FBSDID("$FreeBSD$");
>  
>  static MALLOC_DEFINE(M_VHPET, "vhpet", "bhyve virtual hpet");
>  
> -#define	HPET_FREQ	10000000		/* 10.0 Mhz */
> +#define	HPET_FREQ	16777216		/* 16.7 (2^24) Mhz */
>  #define	FS_PER_S	1000000000000000ul
>  
>  /* Timer N Configuration and Capabilities Register */
> 

It should be noted that this is really more of a workaround than a fix.
 I think the right fix might be to use bintime rather than sbintime to
avoid the rounding errors.  I also suspect this problem affects other
emulated timers such as atpit/8254 where there is less freedom to wish
away the problem with a power-of-two frequency change.

Still, I committed this as-is because it was shown to fix a real-world
problem and it doesn't prevent doing a better fix later.

-- Ian




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?1509310495.21609.60.camel>