svn commit: r245123 - projects/bhyve/usr.sbin/bhyve
Peter Grehan
grehan at svn.freebsd.org
Mon Jan 7 04:51:44 UTC 2013
Author: grehan
Date: Mon Jan 7 04:51:43 2013
New Revision: 245123
URL: http://svnweb.freebsd.org/changeset/base/245123
Log:
Use 64-bit arithmetic throughout, and lock accesses to globals.
With this change, dbench with >= 4 processes runs without getting
weird jumps forward in time when the APCI pmtimer is the default
timecounter.
Obtained from: NetApp
Modified:
projects/bhyve/usr.sbin/bhyve/pmtmr.c
Modified: projects/bhyve/usr.sbin/bhyve/pmtmr.c
==============================================================================
--- projects/bhyve/usr.sbin/bhyve/pmtmr.c Mon Jan 7 03:47:59 2013 (r245122)
+++ projects/bhyve/usr.sbin/bhyve/pmtmr.c Mon Jan 7 04:51:43 2013 (r245123)
@@ -37,6 +37,7 @@ __FBSDID("$FreeBSD$");
#include <stdio.h>
#include <time.h>
#include <assert.h>
+#include <pthread.h>
#include "inout.h"
@@ -51,36 +52,42 @@ __FBSDID("$FreeBSD$");
#define PMTMR_FREQ 3579545 /* 3.579545MHz */
-static uint32_t pmtmr_tscf;
-static uint32_t pmtmr_old;
+static pthread_mutex_t pmtmr_mtx;
+static uint64_t pmtmr_tscf;
+static uint64_t pmtmr_old;
static uint64_t pmtmr_tsc_old;
static uint32_t
pmtmr_val(void)
{
uint64_t pmtmr_tsc_new;
- uint32_t pmtmr_new;
+ uint64_t pmtmr_new;
static int inited = 0;
if (!inited) {
size_t len;
+ uint32_t tmpf;
inited = 1;
- len = sizeof(pmtmr_tscf);
- sysctlbyname("machdep.tsc_freq", &pmtmr_tscf, &len,
+ pthread_mutex_init(&pmtmr_mtx, NULL);
+ len = sizeof(tmpf);
+ sysctlbyname("machdep.tsc_freq", &tmpf, &len,
NULL, 0);
+ pmtmr_tscf = tmpf;
pmtmr_tsc_old = rdtsc();
pmtmr_old = pmtmr_tsc_old / pmtmr_tscf * PMTMR_FREQ;
return (pmtmr_old);
}
+ pthread_mutex_lock(&pmtmr_mtx);
pmtmr_tsc_new = rdtsc();
pmtmr_new = (pmtmr_tsc_new - pmtmr_tsc_old) * PMTMR_FREQ / pmtmr_tscf +
pmtmr_old;
pmtmr_old = pmtmr_new;
pmtmr_tsc_old = pmtmr_tsc_new;
+ pthread_mutex_unlock(&pmtmr_mtx);
- return (pmtmr_old);
+ return (pmtmr_new);
}
static int
More information about the svn-src-projects
mailing list