Commit 1a91971f authored by Vasili Skurydzin's avatar Vasili Skurydzin Committed by V8 LUCI CQ

Aix: Improve clock resolution for ThreadTicks::Now

On Aix, thread_cputime and clock_gettime (with CLOCK_THREAD_CPUTIME_ID)
can both be used to get time consumed by a thread. However,
thread_cputime is preferable, as it is has better resolution
(nanoseconds vs 10ms for clock_gettime).

Change-Id: I8a698f85defa011f6ed1eb5f47a6dbd4e21d1f67
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3036281
Commit-Queue: Vasili Skurydzin <vasili.skurydzin@ibm.com>
Reviewed-by: 's avatarMilad Fa <mfarazma@redhat.com>
Reviewed-by: 's avatarMichael Lippautz <mlippautz@chromium.org>
Cr-Commit-Position: refs/heads/master@{#75793}
parent 04ae4904
......@@ -69,19 +69,22 @@ int64_t ComputeThreadTicks() {
V8_INLINE int64_t ClockNow(clockid_t clk_id) {
#if (defined(_POSIX_MONOTONIC_CLOCK) && _POSIX_MONOTONIC_CLOCK >= 0) || \
defined(V8_OS_BSD) || defined(V8_OS_ANDROID)
// On AIX clock_gettime for CLOCK_THREAD_CPUTIME_ID outputs time with
// resolution of 10ms. thread_cputime API provides the time in ns
#if defined(V8_OS_AIX)
thread_cputime_t tc;
// On AIX clock_gettime for CLOCK_THREAD_CPUTIME_ID outputs time with
// resolution of 10ms. thread_cputime API provides the time in ns.
if (clk_id == CLOCK_THREAD_CPUTIME_ID) {
#if defined(__PASE__) // CLOCK_THREAD_CPUTIME_ID clock not supported on IBMi
return 0;
#endif
#else
thread_cputime_t tc;
if (thread_cputime(-1, &tc) != 0) {
UNREACHABLE();
}
return (tc.stime / v8::base::Time::kNanosecondsPerMicrosecond)
+ (tc.utime / v8::base::Time::kNanosecondsPerMicrosecond);
#endif // defined(__PASE__)
}
#endif
#endif // defined(V8_OS_AIX)
struct timespec ts;
if (clock_gettime(clk_id, &ts) != 0) {
UNREACHABLE();
......@@ -94,15 +97,7 @@ V8_INLINE int64_t ClockNow(clockid_t clk_id) {
1;
CHECK_GT(kSecondsLimit, ts.tv_sec);
int64_t result = int64_t{ts.tv_sec} * v8::base::Time::kMicrosecondsPerSecond;
#if defined(V8_OS_AIX)
if (clk_id == CLOCK_THREAD_CPUTIME_ID) {
result += (tc.stime / v8::base::Time::kNanosecondsPerMicrosecond);
} else {
result += (ts.tv_nsec / v8::base::Time::kNanosecondsPerMicrosecond);
}
#else
result += (ts.tv_nsec / v8::base::Time::kNanosecondsPerMicrosecond);
#endif
return result;
#else // Monotonic clock not supported.
return 0;
......
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