VTIM_real vs VTIM_mono / double vs uint64_t

Nils Goroll slink at schokola.de
Thu Apr 7 08:50:20 CEST 2016


On 04/04/16 23:37, Nils Goroll wrote:
> I once optimized a CLOCK_REALTIME bound app by caching real time and offsetting
> it with the TSC

Long story short, glibc does this ifdef HP_TIMING_AVAIL and my age-old wisdom
regarding mono vs. real does not hold any more - at least not on my own machine.

- Linux 3.16.0-4-amd64 #1 SMP Debian 3.16.7-ckt25-1 (2016-03-06) x86_64
- i7-4600M

In particular, glibc doesn't syscall (!), which I was complete unware of.

I expect this may look completely different on other platforms.


On 04/04/16 21:21, Devon H. O'Dell wrote:
> using 64-bit counters that represent the number of nanoseconds since the
> epoch.

insights from a trivial benchmark (patch attached) on my machine:

* real/mono overhead is <= ~5%

* ignoring the VTIM value, the double/uint64 overhead is negligible
  (as expected)

* with two arith ops per call (addition, division by 2), the double/uint64
  overhead is ~10 - ~15%

Please consider the usual disclaimers for synthetic benchmarks in a tight loop.

So this basically confirms dhos more realistic benchmarks:
- on this platform, optimizing for mono time does not make any sense
- the main potential is avoiding FP ops by representing time as an integer

Nils

	-

# default optimizer

varnish-cache/lib/libvarnish (master)$ cc -Wall -o foo -DTEST_DRIVER -I../..
-I../../include vtim.c vas.c -lm

varnish-cache/lib/libvarnish (master)$ ./foo bench
bench noop test value 0.000000
bench noop took 2.051ns per call

bench warmup test value 0.000000
bench warmup took 19.128ns per call

bench VTIM_mono test value 0.000000
bench VTIM_mono took 19.116ns per call
bench VTIM_mono_i test value 0.000000
bench VTIM_mono_i took 19.034ns per call
bench VTIM_real test value 0.000000
bench VTIM_real took 20.007ns per call
bench VTIM_real_i test value 0.000000
bench VTIM_real_i took 19.995ns per call

bench VTIM_mono test value 7008.426196
bench VTIM_mono took 25.131ns per call
bench VTIM_mono_i test value 7008644393743.000000
bench VTIM_mono_i took 21.817ns per call
bench VTIM_real test value 1460010972.766325
bench VTIM_real took 26.303ns per call
bench VTIM_real_i test value 1460010972992060672.000000
bench VTIM_real_i took 22.570ns per call

# -O6

varnish-cache/lib/libvarnish (master)$ cc -O6 -Wall -o foo -DTEST_DRIVER -I../..
-I../../include vtim.c vas.c -lm

varnish-cache/lib/libvarnish (master)$ ./foo bench
bench noop test value 0.000000
bench noop took 0.000ns per call

bench warmup test value 0.000000
bench warmup took 15.500ns per call

bench VTIM_mono test value 0.000000
bench VTIM_mono took 15.533ns per call
bench VTIM_mono_i test value 0.000000
bench VTIM_mono_i took 15.552ns per call
bench VTIM_real test value 0.000000
bench VTIM_real took 15.861ns per call
bench VTIM_real_i test value 0.000000
bench VTIM_real_i took 15.899ns per call

bench VTIM_mono test value 7624.422416
bench VTIM_mono took 20.277ns per call
bench VTIM_mono_i test value 7624605637622.000000
bench VTIM_mono_i took 18.319ns per call
bench VTIM_real test value 1460011588.673950
bench VTIM_real took 20.942ns per call
bench VTIM_real_i test value 1460011588860285696.000000
bench VTIM_real_i took 18.630ns per call
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0001-uint64_t-VTIM-functions-and-a-trivial-benchmark.patch
Type: text/x-patch
Size: 3295 bytes
Desc: not available
URL: <https://www.varnish-cache.org/lists/pipermail/varnish-dev/attachments/20160407/6c4652cd/attachment-0001.bin>


More information about the varnish-dev mailing list