Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/external/bsd/libevent/dist/test Calibrate the amount of time...
details: https://anonhg.NetBSD.org/src/rev/62be3a2e7543
branches: trunk
changeset: 758612:62be3a2e7543
user: pgoyette <pgoyette%NetBSD.org@localhost>
date: Thu Nov 11 14:11:26 2010 +0000
description:
Calibrate the amount of time that a sleep() requires, and use that
interval instead of assuming that there are exactly 1000 real-time-clock
milliseconds per second! On some ports when running under qemu, there
can be twice as many RTC milliseconds as expected.
This is part 2 of the changes required to make the libevent tests work
on port-amd64 under qemu.
diffstat:
external/bsd/libevent/dist/test/regress.c | 34 ++++++++++++++++++++++++++++--
1 files changed, 31 insertions(+), 3 deletions(-)
diffs (76 lines):
diff -r 469e2f4e8713 -r 62be3a2e7543 external/bsd/libevent/dist/test/regress.c
--- a/external/bsd/libevent/dist/test/regress.c Thu Nov 11 14:08:45 2010 +0000
+++ b/external/bsd/libevent/dist/test/regress.c Thu Nov 11 14:11:26 2010 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: regress.c,v 1.1.1.1 2009/11/02 10:01:03 plunky Exp $ */
+/* $NetBSD: regress.c,v 1.2 2010/11/11 14:11:26 pgoyette Exp $ */
/*
* Copyright (c) 2003, 2004 Niels Provos <provos%citi.umich.edu@localhost>
* All rights reserved.
@@ -78,6 +78,8 @@
static struct timeval tcalled;
static struct event_base *global_base;
+static int interval;
+
#define TEST1 "this is a test"
#define SECONDS 1
@@ -183,6 +185,27 @@
}
static void
+calibrate(void)
+{
+ struct timeval start, end, diff;
+ int delta;
+
+ gettimeofday(&start, NULL);
+ sleep(SECONDS);
+ gettimeofday(&end, NULL);
+
+ timersub(&end, &start, &diff);
+
+ delta = diff.tv_sec * 1000 + diff.tv_usec / 1000;
+ if (delta < 0)
+ delta = -delta;
+
+ interval = delta;
+ fprintf(stdout, "Calibrated interval: %d sec = %d msec\n", SECONDS,
+ interval);
+}
+
+static void
timeout_cb(int fd, short event, void *arg)
{
struct timeval tv;
@@ -194,7 +217,7 @@
else
evutil_timersub(&tset, &tcalled, &tv);
- diff = tv.tv_sec*1000 + tv.tv_usec/1000 - SECONDS * 1000;
+ diff = tv.tv_sec*1000 + tv.tv_usec/1000 - interval;
if (diff < 0)
diff = -diff;
@@ -924,7 +947,7 @@
evtimer_add(&ev, &tv);
tv.tv_usec = 0;
- tv.tv_sec = 1;
+ tv.tv_sec = SECONDS;
event_loopexit(&tv);
evutil_gettimeofday(&tv_start, NULL);
@@ -1625,6 +1648,11 @@
if (signal(SIGPIPE, SIG_IGN) == SIG_ERR)
return (1);
#endif
+ /*
+ * Calibrate sleep() vs elapsed real-time
+ */
+ calibrate();
+
setvbuf(stdout, NULL, _IONBF, 0);
/* Initalize the event library */
Home |
Main Index |
Thread Index |
Old Index