Opened 6 years ago

Last modified 3 years ago

#10168 new enhancement

Use monotonic clocks for time as appropriate

Reported by: nickm Owned by:
Priority: Medium Milestone: Tor: unspecified
Component: Core Tor/Tor Version:
Severity: Normal Keywords: tor-relay time monotonic intro large
Cc: Actual Points:
Parent ID: Points: 10
Reviewer: Sponsor:

Description

In some places, like or or, we want to use wall-clock time. But in others, like timers and so forth, we should be using a monotonic timer so we just don't have to worry about time moving backwards.

Libevent 2.1 has a subsystem for this; we could just use it as needed. Or we could snarf the code and adapt it for our uses.

Child Tickets

Change History (18)

comment:1 Changed 6 years ago by andrea

Triage:

ISTR this recently came up in a code review; do we want to try to do something about it for 0.2.5.x?

comment:2 Changed 6 years ago by nickm

Milestone: Tor: 0.2.5.x-finalTor: 0.2.6.x-final

We came up with a simple ratcheted implementation in tor_gettimeofday_cached_monotonic. Doing the right thing here will be a bit tricky, given how we need to cache times here too, so I think we're okay deferring to 0.2.6.

(For an overview of how complicated the right thing is here, peruse Libevent's https://github.com/libevent/libevent/blob/master/evutil_time.c )

comment:3 Changed 6 years ago by nickm

A thought: these should not use timeval or time_t, but rather should use a new set of structs, eg

  typedef monotime_s {
    time_t t;
  } monotime_t;

  typedef monotimeval_s {
    struct timeval tv;
  } monotimeval_t;
  ...

This will help us make the code safe, since the timevals that you get from clock_gettime() do not necessarily correspond to the ones you get from gettimeofday().

comment:4 Changed 5 years ago by nickm

Keywords: tor-relay 026-triaged-1 026-deferrable added

comment:5 Changed 5 years ago by nickm

Milestone: Tor: 0.2.6.x-finalTor: 0.2.7.x-final

comment:6 Changed 5 years ago by nickm

Status: newassigned

comment:7 Changed 5 years ago by nickm

Keywords: 027-triaged-1-out added

Marking triaged-out items from first round of 0.2.7 triage.

comment:8 Changed 5 years ago by nickm

Milestone: Tor: 0.2.7.x-finalTor: 0.2.???

Make all non-needs_review, non-needs_revision, 027-triaged-1-out items belong to 0.2.???

comment:9 Changed 3 years ago by teor

Milestone: Tor: 0.2.???Tor: 0.3.???

Milestone renamed

comment:10 Changed 3 years ago by nickm

Keywords: tor-03-unspecified-201612 added
Milestone: Tor: 0.3.???Tor: unspecified

Finally admitting that 0.3.??? was a euphemism for Tor: unspecified all along.

comment:11 Changed 3 years ago by nickm

Keywords: tor-03-unspecified-201612 removed

Remove an old triaging keyword.

comment:12 Changed 3 years ago by nickm

Keywords: 027-triaged-in added

comment:13 Changed 3 years ago by nickm

Keywords: 027-triaged-in removed

comment:14 Changed 3 years ago by nickm

Keywords: 027-triaged-1-out removed

comment:15 Changed 3 years ago by nickm

Keywords: 026-triaged-1 removed

comment:16 Changed 3 years ago by nickm

Keywords: 026-deferrable removed

comment:17 Changed 3 years ago by nickm

Status: assignednew

Change the status of all assigned/accepted Tor tickets with owner="" to "new".

comment:18 Changed 3 years ago by nickm

Keywords: time monotonic intro large added
Points: 10
Severity: Normal

We have an implementation of monotonic time in Tor, but we aren't using it everywhere we could be.

Note: See TracTickets for help on using tickets.