Commit 9cc183d8 authored by machenbach's avatar machenbach Committed by Commit bot

Revert of Use CLOCK_REALTIME_COARSE when available. (patchset #1 id:1 of...

Revert of Use CLOCK_REALTIME_COARSE when available. (patchset #1 id:1 of https://codereview.chromium.org/1151283005/)

Reason for revert:
[Sheriff] This leads to several failures in chromium and blocks our roll:
https://codereview.chromium.org/1154363002/

Bisect (https://codereview.chromium.org/1152553004/) points to this CL.

Please add the failing chromium trybot on a reland of this CL.

Original issue's description:
> Use CLOCK_REALTIME_COARSE when available.
>
> On systems that have CLOCK_REALTIME_COARSE with good enough resolution,
> we can avoid making a system call to get the current time; it's serviced
> from the vDSO.
>
> This is v2 of the patch.  v1 can be found at [0] but was reverted in [1]
> because of Chromium sandbox restrictions.  The necessary changes have
> been applied upstream in [2].
>
> [0] https://codereview.chromium.org/1125003002
> [1] https://codereview.chromium.org/1130083003
> [2] https://codereview.chromium.org/1133653002
>
> BUG=
> LOG=N
>
> Committed: https://crrev.com/28cea2b749f24ba33e6e0c8e343dd0d6258ee302
> Cr-Commit-Position: refs/heads/master@{#28639}

TBR=jochen@chromium.org,bmeurer@chromium.org,ben@strongloop.com
NOPRESUBMIT=true
NOTREECHECKS=true
NOTRY=true
BUG=

Review URL: https://codereview.chromium.org/1154783003

Cr-Commit-Position: refs/heads/master@{#28656}
parent 092acb2b
......@@ -20,16 +20,10 @@
#include "src/base/lazy-instance.h"
#include "src/base/win32-headers.h"
#endif
#include "src/base/atomicops.h"
#include "src/base/cpu.h"
#include "src/base/logging.h"
#include "src/base/platform/platform.h"
// CLOCK_REALTIME_COARSE was added in Linux 2.6.32.
#if V8_OS_LINUX && !defined(CLOCK_REALTIME_COARSE)
#define CLOCK_REALTIME_COARSE 5
#endif
namespace v8 {
namespace base {
......@@ -258,40 +252,11 @@ FILETIME Time::ToFiletime() const {
#elif V8_OS_POSIX
Time Time::Now() {
#ifdef CLOCK_REALTIME_COARSE
struct timespec ts;
static const clockid_t kInvalidClockId = static_cast<clockid_t>(-1);
static clockid_t cached_clock_id = kInvalidClockId;
clockid_t clock_id = NoBarrier_Load(&cached_clock_id);
if (V8_UNLIKELY(clock_id == kInvalidClockId)) {
// Use CLOCK_REALTIME_COARSE when available (linux >= 2.6.32) and precise
// enough. Unlike CLOCK_REALTIME, its coarse cousin is normally serviced
// from the vDSO, without making an actual system call.
//
// CLOCK_REALTIME_COARSE precision is determined by CONFIG_HZ, the number
// of ticks per second that the kernel runs at. Granularity can be as low
// as one update every few hundred milliseconds so we need to ensure it is
// not _too_ coarse. Most kernels are built with CONFIG_HZ=1000, providing
// a one millisecond precision that is good enough for our purposes.
if (clock_getres(CLOCK_REALTIME_COARSE, &ts) < 0 || ts.tv_sec > 0 ||
ts.tv_nsec > 1000 * 1000) {
clock_id = CLOCK_REALTIME; // Not available or not suitable.
} else {
clock_id = CLOCK_REALTIME_COARSE;
}
NoBarrier_Store(&cached_clock_id, clock_id);
}
int result = clock_gettime(clock_id, &ts);
DCHECK_EQ(0, result);
USE(result);
return FromTimespec(ts);
#else
struct timeval tv;
int result = gettimeofday(&tv, NULL);
DCHECK_EQ(0, result);
USE(result);
return FromTimeval(tv);
#endif
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment