Timers and timing, was: MySQL Performance 6.0rc1
Robert Watson
rwatson at FreeBSD.org
Fri Oct 28 14:32:32 PDT 2005
On Fri, 28 Oct 2005, David Xu wrote:
>>> On the other hand, a lower risk change might be to simply add a new
>>> CLOCK_ type for lower resolution, and have a timer synchronize a
>>> variable to the system clock once every 1/10 of a second. This avoids
>>> having to muck with VM layout, etc.
>>
>> Is the CLOCK_* namespace ours to muck about with in the first place ?
>>
> I prefer this way, can you implement it? The global page idea is a
> complex, someone can slowly work on it, there are many things can be
> done, for example, fast syscall using sysenter/sysexit.
Just as an experiment, I added two new time counters:
CLOCK_POOR - use a cached time returned by getnanotime(), which may be out
of date by up to 10/hz (see phk's e-mail for the correct
number).
CLOCK_SECOND - Same as CLOCK_POOR, only truncate the nanoseconds field to
0, and return 1 second as the resolution via
clock_getres().
Patch is attached.
Performance measurements on a P4 Xeon, dual processor with UP and SMP
kernel configurations, no debugging. Measured using 10,000 loops of each
system call, 12 samples per clock type. Measurements are in nanoseconds,
measured using CLOCK_REALTIME, which has a resolution of 280ns reported
via clock_getres(). Not surprisingly, the two above clocks measure about
the same (they should do), and are a lot faster than real time
measurements (they should be). As currently implemented, gettimeofday()
appears to cost the same as CLOCK_REALTIME.
It would be interesting to distribution of clock wrongness was, but I'm
not set up to measure that currently.
Robert N M Watson
x 7UP/gettimeofday
+ 7UP/clock_gettime_poor
* 7UP/clock_gettime_realtime
% 7UP/clock_gettime_second
+--------------------------------------------------------------------------+
| @ * |
| @ * |
| @ * |
| @ * |
|+ @ * |
|@ @ x* |
|@%@ @@ x* *** *|
| |__A_M| |_AA|_| |
+--------------------------------------------------------------------------+
N Min Max Median Avg Stddev
x 12 1410 1507 1502 1493.75 26.574509
+ 12 523 634 624 595.58333 47.586206
Difference at 95.0% confidence
-898.167 +/- 32.632
-60.1283% +/- 2.18457%
(Student's t, pooled s = 38.5399)
* 12 1437 1627 1503 1507.6667 42.401401
No difference proven at 95.0% confidence
% 12 524 631 623 595 45.696628
Difference at 95.0% confidence
-898.75 +/- 31.6491
-60.1674% +/- 2.11877%
(Student's t, pooled s = 37.379)
x 7SMP/gettimeofday
+ 7SMP/clock_gettime_poor
* 7SMP/clock_gettime_realtime
% 7SMP/clock_gettime_second
+--------------------------------------------------------------------------+
|@ @ * x*|
|@ @ * x*|
|@% @% * x*|
|@@ @@ **x**|
||MA_M |AMM|
+--------------------------------------------------------------------------+
N Min Max Median Avg Stddev
x 12 1406 1443 1436 1425.4167 16.527984
+ 12 503 566 517 527.08333 26.352362
Difference at 95.0% confidence
-898.333 +/- 18.6239
-63.0225% +/- 1.30656%
(Student's t, pooled s = 21.9957)
* 12 1404 1450 1444 1430.0833 19.327128
No difference proven at 95.0% confidence
% 12 505 562 549 531.5 26.182923
Difference at 95.0% confidence
-893.917 +/- 18.538
-62.7127% +/- 1.30054%
(Student's t, pooled s = 21.8943)
-------------- next part --------------
--- //depot/vendor/freebsd/src/sys/kern/kern_time.c 2005/10/23 23:00:53
+++ //depot/user/rwatson/clock/src/sys/kern/kern_time.c 2005/10/28 17:42:44
@@ -225,6 +225,14 @@
case CLOCK_MONOTONIC:
nanouptime(ats);
break;
+ case CLOCK_SECOND:
+ getnanotime(ats);
+ ats->tv_nsec = 0;
+ break;
+ case CLOCK_POOR:
+ getnanotime(ats);
+ ats->tv_nsec = 0;
+ break;
default:
return (EINVAL);
}
@@ -306,6 +314,7 @@
switch (clock_id) {
case CLOCK_REALTIME:
case CLOCK_MONOTONIC:
+ case CLOCK_POOR:
/*
* Round up the result of the division cheaply by adding 1.
* Rounding up is especially important if rounding down
@@ -318,6 +327,10 @@
/* Accurately round up here because we can do so cheaply. */
ts->tv_nsec = (1000000000 + hz - 1) / hz;
break;
+ case CLOCK_SECOND:
+ ts->tv_sec = 1;
+ ts->tv_nsec = 0;
+ break;
default:
return (EINVAL);
}
--- //depot/vendor/freebsd/src/sys/sys/time.h 2005/04/02 12:35:19
+++ //depot/user/rwatson/clock/src/sys/sys/time.h 2005/10/28 17:42:44
@@ -238,6 +238,8 @@
#define CLOCK_VIRTUAL 1
#define CLOCK_PROF 2
#define CLOCK_MONOTONIC 4
+#define CLOCK_SECOND 5
+#define CLOCK_POOR 6
#endif
#ifndef TIMER_ABSTIME
More information about the freebsd-current
mailing list