Commit 3361b7fd authored by bjaideep's avatar bjaideep Committed by Commit bot

AIX: Fix to get more accurate Thread's CPU time

On AIX clock_gettime provides CPU time with a resolution of
10ms, which causes the ThreadTicks testcase to fail since at
the 2 instances the CPU time of the thread outputs to 0.
Using AIX's API thread_cputime instead which provides CPU
time with a resolution of 1ns.
The testcase was added as part of https://codereview.chromium.org/1976603005

R=jochen@chromium.org, lpy@chromium.org, joransiu@ca.ibm.com, jyan@ca.ibm.com, michael_dawson@ca.ibm.com, mbrandy@us.ibm.com

BUG=
LOG=N

Review-Url: https://codereview.chromium.org/2174003002
Cr-Commit-Position: refs/heads/master@{#38029}
parent b1683f05
......@@ -56,6 +56,17 @@ 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;
if (clk_id == CLOCK_THREAD_CPUTIME_ID) {
if (thread_cputime(-1, &tc) != 0) {
UNREACHABLE();
return 0;
}
}
#endif
struct timespec ts;
if (clock_gettime(clk_id, &ts) != 0) {
UNREACHABLE();
......@@ -63,7 +74,15 @@ V8_INLINE int64_t ClockNow(clockid_t clk_id) {
}
v8::base::internal::CheckedNumeric<int64_t> result(ts.tv_sec);
result *= 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.ValueOrDie();
#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