Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1057)

Side by Side Diff: src/base/platform/time.cc

Issue 2174003002: AIX: Fix to get more accurate Thread's CPU time (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: fixed incorrect indentation Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 the V8 project authors. All rights reserved. 1 // Copyright 2013 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "src/base/platform/time.h" 5 #include "src/base/platform/time.h"
6 6
7 #if V8_OS_POSIX 7 #if V8_OS_POSIX
8 #include <fcntl.h> // for O_RDONLY 8 #include <fcntl.h> // for O_RDONLY
9 #include <sys/time.h> 9 #include <sys/time.h>
10 #include <unistd.h> 10 #include <unistd.h>
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
49 return absolute_micros.ValueOrDie(); 49 return absolute_micros.ValueOrDie();
50 } 50 }
51 #elif V8_OS_POSIX 51 #elif V8_OS_POSIX
52 // Helper function to get results from clock_gettime() and convert to a 52 // Helper function to get results from clock_gettime() and convert to a
53 // microsecond timebase. Minimum requirement is MONOTONIC_CLOCK to be supported 53 // microsecond timebase. Minimum requirement is MONOTONIC_CLOCK to be supported
54 // on the system. FreeBSD 6 has CLOCK_MONOTONIC but defines 54 // on the system. FreeBSD 6 has CLOCK_MONOTONIC but defines
55 // _POSIX_MONOTONIC_CLOCK to -1. 55 // _POSIX_MONOTONIC_CLOCK to -1.
56 V8_INLINE int64_t ClockNow(clockid_t clk_id) { 56 V8_INLINE int64_t ClockNow(clockid_t clk_id) {
57 #if (defined(_POSIX_MONOTONIC_CLOCK) && _POSIX_MONOTONIC_CLOCK >= 0) || \ 57 #if (defined(_POSIX_MONOTONIC_CLOCK) && _POSIX_MONOTONIC_CLOCK >= 0) || \
58 defined(V8_OS_BSD) || defined(V8_OS_ANDROID) 58 defined(V8_OS_BSD) || defined(V8_OS_ANDROID)
59 // On AIX clock_gettime for CLOCK_THREAD_CPUTIME_ID outputs time with
60 // resolution of 10ms. thread_cputime API provides the time in ns
61 #if defined(V8_OS_AIX)
62 thread_cputime_t tc;
63 if (clk_id == CLOCK_THREAD_CPUTIME_ID) {
64 if (thread_cputime(-1, &tc) != 0) {
65 UNREACHABLE();
66 return 0;
67 }
68 }
69 #endif
59 struct timespec ts; 70 struct timespec ts;
60 if (clock_gettime(clk_id, &ts) != 0) { 71 if (clock_gettime(clk_id, &ts) != 0) {
61 UNREACHABLE(); 72 UNREACHABLE();
62 return 0; 73 return 0;
63 } 74 }
64 v8::base::internal::CheckedNumeric<int64_t> result(ts.tv_sec); 75 v8::base::internal::CheckedNumeric<int64_t> result(ts.tv_sec);
65 result *= v8::base::Time::kMicrosecondsPerSecond; 76 result *= v8::base::Time::kMicrosecondsPerSecond;
77 #if defined(V8_OS_AIX)
78 if (clk_id == CLOCK_THREAD_CPUTIME_ID) {
79 result += (tc.stime / v8::base::Time::kNanosecondsPerMicrosecond);
80 } else {
81 result += (ts.tv_nsec / v8::base::Time::kNanosecondsPerMicrosecond);
82 }
83 #else
66 result += (ts.tv_nsec / v8::base::Time::kNanosecondsPerMicrosecond); 84 result += (ts.tv_nsec / v8::base::Time::kNanosecondsPerMicrosecond);
85 #endif
67 return result.ValueOrDie(); 86 return result.ValueOrDie();
68 #else // Monotonic clock not supported. 87 #else // Monotonic clock not supported.
69 return 0; 88 return 0;
70 #endif 89 #endif
71 } 90 }
72 #elif V8_OS_WIN 91 #elif V8_OS_WIN
73 V8_INLINE bool IsQPCReliable() { 92 V8_INLINE bool IsQPCReliable() {
74 v8::base::CPU cpu; 93 v8::base::CPU cpu;
75 // On Athlon X2 CPUs (e.g. model 15) QueryPerformanceCounter is unreliable. 94 // On Athlon X2 CPUs (e.g. model 15) QueryPerformanceCounter is unreliable.
76 return strcmp(cpu.vendor(), "AuthenticAMD") == 0 && cpu.family() == 15; 95 return strcmp(cpu.vendor(), "AuthenticAMD") == 0 && cpu.family() == 15;
(...skipping 655 matching lines...) Expand 10 before | Expand all | Expand 10 after
732 DCHECK_GE(tsc_now, tsc_initial); 751 DCHECK_GE(tsc_now, tsc_initial);
733 uint64_t tsc_ticks = tsc_now - tsc_initial; 752 uint64_t tsc_ticks = tsc_now - tsc_initial;
734 tsc_ticks_per_second = tsc_ticks / elapsed_time_seconds; 753 tsc_ticks_per_second = tsc_ticks / elapsed_time_seconds;
735 754
736 return tsc_ticks_per_second; 755 return tsc_ticks_per_second;
737 } 756 }
738 #endif // V8_OS_WIN 757 #endif // V8_OS_WIN
739 758
740 } // namespace base 759 } // namespace base
741 } // namespace v8 760 } // namespace v8
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698