Commit 10a8e20f authored by Sergey Ulanov's avatar Sergey Ulanov Committed by V8 LUCI CQ

[Fuchsia] Add Fuchsia-specific implementation of TimeTicks::Now()

Previously the POSIX version of TimeTicks::Now() was used on Fuchsia.
It's more efficient to call zx_clock_get_monotonic() directly.

Bug: chromium:1317914
Change-Id: I56da954a2567bcb866100c157878176bcb7cf319
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3595601
Auto-Submit: Sergey Ulanov <sergeyu@chromium.org>
Commit-Queue: Hannes Payer <hpayer@chromium.org>
Reviewed-by: 's avatarHannes Payer <hpayer@chromium.org>
Cr-Commit-Position: refs/heads/main@{#80224}
parent b4165a35
......@@ -9,12 +9,19 @@
#include <sys/time.h>
#include <unistd.h>
#endif
#if V8_OS_DARWIN
#include <mach/mach.h>
#include <mach/mach_time.h>
#include <pthread.h>
#endif
#if V8_OS_FUCHSIA
#include <threads.h>
#include <zircon/syscalls.h>
#include <zircon/threads.h>
#endif
#include <cstring>
#include <ostream>
......@@ -68,6 +75,15 @@ int64_t ComputeThreadTicks() {
thread_info_data.system_time.microseconds);
return micros;
}
#elif V8_OS_FUCHSIA
V8_INLINE int64_t GetFuchsiaThreadTicks() {
zx_info_thread_stats_t info;
zx_status_t status = zx_object_get_info(thrd_get_zx_handle(thrd_current()),
ZX_INFO_THREAD_STATS, &info,
sizeof(info), nullptr, nullptr);
CHECK_EQ(status, ZX_OK);
return info.total_runtime / v8::base::Time::kNanosecondsPerMicrosecond;
}
#elif V8_OS_POSIX
// Helper function to get results from clock_gettime() and convert to a
// microsecond timebase. Minimum requirement is MONOTONIC_CLOCK to be supported
......@@ -721,6 +737,8 @@ TimeTicks TimeTicks::Now() {
info.numer / info.denom);
#elif V8_OS_SOLARIS
ticks = (gethrtime() / Time::kNanosecondsPerMicrosecond);
#elif V8_OS_FUCHSIA
ticks = zx_clock_get_monotonic() / Time::kNanosecondsPerMicrosecond;
#elif V8_OS_POSIX
ticks = ClockNow(CLOCK_MONOTONIC);
#elif V8_OS_STARBOARD
......@@ -736,6 +754,8 @@ TimeTicks TimeTicks::Now() {
bool TimeTicks::IsHighResolution() {
#if V8_OS_DARWIN
return true;
#elif V8_OS_FUCHSIA
return true;
#elif V8_OS_POSIX
static const bool is_high_resolution = IsHighResolutionTimer(CLOCK_MONOTONIC);
return is_high_resolution;
......@@ -783,6 +803,8 @@ ThreadTicks ThreadTicks::Now() {
#endif
#elif V8_OS_DARWIN
return ThreadTicks(ComputeThreadTicks());
#elif V8_OS_FUCHSIA
return ThreadTicks(GetFuchsiaThreadTicks());
#elif(defined(_POSIX_THREAD_CPUTIME) && (_POSIX_THREAD_CPUTIME >= 0)) || \
defined(V8_OS_ANDROID)
return ThreadTicks(ClockNow(CLOCK_THREAD_CPUTIME_ID));
......
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