All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Adam C. Emerson" <aemerson@redhat.com>
To: The Sacred Order of the Squid Cybernetic <ceph-devel@vger.kernel.org>
Subject: Re: About ceph_clock_now()
Date: Tue, 12 Jan 2016 12:32:48 -0500	[thread overview]
Message-ID: <20160112173248.GA8218@ultraspiritum.redhat.com> (raw)
In-Reply-To: <892700092.10054838.1452614393452.JavaMail.zimbra@redhat.com>

[-- Attachment #1: Type: text/plain, Size: 2922 bytes --]

On 12/01/2016, Erwan Velu wrote:
> Hi folks,

Hello!

> When reading the code I noticed that ceph_clock_now() is mostly used to compute a local difference of time.
> I do see you are using "clock_gettime(CLOCK_REALTIME, &tp)" but was wondering if CLOCK_MONOTONIC_RAW isn't more accurate.
> 
> I mean if the local system time is readujsted by NTP (or similar) some computation could be wrong leading to some possible mis-interpretation or wrong scheduling.

I have done some work starting in that direction currently in master. In
common/ceph_time.h I define coarse and fine versions of the real clock
and monotonic clock and I've switched the osdc subsystem over to use them.

We use the std::chrono C++ time library, but we define our own clocks
(so we can pick the right one for performance/resolution tradeoffs) and an
in-memory timespan representation (so not every function taking a duration has
to be a template.)

The real_clock and mono_clock classes correspond to CLOCK_REALTIME and CLOCK_MONOTONIC, and coarse_real_clock and coarse_mono_clock correspond to CLOCK_REALTIME_COARSE and CLOCK_MONOTONIC_COARSE. If you require millisecond resolution but nothing finer, you should prefer the coarse variants.

The std::chrono library lets us integrate with other C++ libraries (and use the
standard concurrency features) and has the advantage of stronger typing; we
can't use a duration where a time point is required or subtract a monotonic
time point from a real time point.

As I understand it, CLOCK_MONOTONIC_RAW is generally the wrong choice.
The raw hardware clock is prone to drift, and NTP synchronization (or other
corrective) makes the elapsed time measurements more accurate.

However, I am not a Time Lord. If someone knows better, please correct me here.

One concern with monotonic clocks, even for elapsed time, is that their epoch is
unspecified. You cannot send a monotonic time over the network to another
machine nor can you save it to a file and re-read it later. Anything to be
serialized must be a real time.

This is unfortunate. If I were a Time Lord I'd travel back in time and make the
POSIX committee adopt CLOCK_UTC and CLOCK_TAI so we could have serializable
monotonic time values.

> I could work on a PR is you find this interesting.

I find it interesting. If you want to change more subsystems to use ceph_time
and use monotonic and coarse clocks in appropriate places I think that would be
wonderful. It might be worthwhile to focus on the places where we use double to
represent a time value.

Please read through ceph_time.h and osdc to get a feel for it. If you think it
could use improvement, I'd be happy to hear your ideas.

Thank you.

-- 
Senior Software Engineer           Red Hat Storage, Ann Arbor, MI, US
IRC: Aemerson@{RedHat, OFTC, Freenode}
0x80F7544B90EDBFB9 E707 86BA 0C1B 62CC 152C  7C12 80F7 544B 90ED BFB9

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 603 bytes --]

  reply	other threads:[~2016-01-12 17:32 UTC|newest]

Thread overview: 29+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <177186823.10053087.1452614184109.JavaMail.zimbra@redhat.com>
2016-01-12 15:59 ` About ceph_clock_now() Erwan Velu
2016-01-12 17:32   ` Adam C. Emerson [this message]
2016-01-13 10:41     ` Erwan Velu
2016-01-13 13:48       ` Sage Weil
2016-01-13 14:52         ` Matt Benjamin
2016-01-14 16:10         ` Erwan Velu
2016-01-14 16:14           ` Adam C. Emerson
2016-01-19 16:17         ` Erwan Velu
2016-01-19 16:29           ` Adam C. Emerson
2016-01-19 16:57             ` Erwan Velu
2016-01-21 19:22             ` Erwan Velu
2016-01-22 16:00               ` Erwan Velu
2016-01-22 17:35                 ` Adam C. Emerson
2016-01-26 14:12                   ` Erwan Velu
2016-01-23 11:49                 ` Willem Jan Withagen
2016-01-23 20:20                   ` Matt Benjamin
2016-01-23 21:55                     ` Adam C. Emerson
2016-01-24 11:53                       ` Willem Jan Withagen
2016-01-24 12:51                         ` Willem Jan Withagen
2016-01-25  0:03                           ` Adam C. Emerson
2016-01-25  9:08                             ` Willem Jan Withagen
2016-01-25  9:58                               ` Erwan Velu
2016-01-25 10:57                                 ` Willem Jan Withagen
2016-01-25 17:22                                   ` Adam C. Emerson
     [not found]                                     ` <56A66099.4030501@digiware.nl>
     [not found]                                       ` <1523354716.24670379.1453744826329.JavaMail.zimbra@redhat.com>
2016-01-25 19:38                                         ` Willem Jan Withagen
2016-01-25 20:14                                           ` Adam C. Emerson
2016-01-25 20:18                                             ` Matt Benjamin
2016-01-25 20:22                                             ` Willem Jan Withagen
2016-01-13 15:28       ` Adam C. Emerson

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20160112173248.GA8218@ultraspiritum.redhat.com \
    --to=aemerson@redhat.com \
    --cc=ceph-devel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.