Re: gettimeofday is at the end of its usefulness?

Tom Lane <tgl@sss.pgh.pa.us>

From: Tom Lane <tgl@sss.pgh.pa.us>
To: Florian Weimer <fw@deneb.enyo.de>
Cc: Haribabu Kommi <kommi.haribabu@gmail.com>, PostgreSQL-development <pgsql-hackers@postgresql.org>
Date: 2016-12-29T21:02:31Z
Lists: pgsql-hackers
Florian Weimer <fw@deneb.enyo.de> writes:
> * Tom Lane:
>> On Linux (RHEL6, 2.4GHz x86_64), I find that gettimeofday(),
>> clock_gettime(CLOCK_MONOTONIC), and clock_gettime(CLOCK_REALTIME)
>> all take about 40ns.  Of course gettimeofday() only has 1us resolution,
>> but the other two have perhaps 10ns resolution (I get no duplicate
>> readings in a tight loop).

> Isn't this very specific to kernel and glibc versions, depending on
> things like CONFIG_HZ settings and what level of vDSO support has been
> backported?

No doubt, but I have yet to find a platform where clock_gettime() exists
but performs worse than gettimeofday().  Do you know of one?

			regards, tom lane


Commits

  1. Use clock_gettime(), if available, in instr_time measurements.