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

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

Issue 69933005: Revert "linux: use CLOCK_{REALTIME,MONOTONIC}_COARSE" (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 7 years, 1 month 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 | Annotate | Revision Log
« no previous file with comments | « src/platform/time.h ('k') | 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 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
(...skipping 25 matching lines...) Expand all
36 36
37 #include <cstring> 37 #include <cstring>
38 38
39 #include "checks.h" 39 #include "checks.h"
40 #include "cpu.h" 40 #include "cpu.h"
41 #include "platform.h" 41 #include "platform.h"
42 #if V8_OS_WIN 42 #if V8_OS_WIN
43 #include "win32-headers.h" 43 #include "win32-headers.h"
44 #endif 44 #endif
45 45
46 // Make sure CLOCK_{MONOTONIC,REALTIME}_COARSE is defined on Linux.
47 #if V8_OS_LINUX
48 # if !defined(CLOCK_REALTIME_COARSE)
49 # define CLOCK_REALTIME_COARSE 5 // 2.6.32 and up.
50 # endif
51 # if !defined(CLOCK_MONOTONIC_COARSE)
52 # define CLOCK_MONOTONIC_COARSE 6 // 2.6.32 and up.
53 # endif
54 #endif // V8_OS_LINUX
55
56
57 namespace v8 { 46 namespace v8 {
58 namespace internal { 47 namespace internal {
59 48
60 TimeDelta TimeDelta::FromDays(int days) { 49 TimeDelta TimeDelta::FromDays(int days) {
61 return TimeDelta(days * Time::kMicrosecondsPerDay); 50 return TimeDelta(days * Time::kMicrosecondsPerDay);
62 } 51 }
63 52
64 53
65 TimeDelta TimeDelta::FromHours(int hours) { 54 TimeDelta TimeDelta::FromHours(int hours) {
66 return TimeDelta(hours * Time::kMicrosecondsPerHour); 55 return TimeDelta(hours * Time::kMicrosecondsPerHour);
(...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after
275 } 264 }
276 uint64_t us = static_cast<uint64_t>(us_ + kTimeToEpochInMicroseconds) * 10; 265 uint64_t us = static_cast<uint64_t>(us_ + kTimeToEpochInMicroseconds) * 10;
277 ft.dwLowDateTime = static_cast<DWORD>(us); 266 ft.dwLowDateTime = static_cast<DWORD>(us);
278 ft.dwHighDateTime = static_cast<DWORD>(us >> 32); 267 ft.dwHighDateTime = static_cast<DWORD>(us >> 32);
279 return ft; 268 return ft;
280 } 269 }
281 270
282 #elif V8_OS_POSIX 271 #elif V8_OS_POSIX
283 272
284 Time Time::Now() { 273 Time Time::Now() {
285 #if V8_LIBRT_NOT_AVAILABLE
286 // TODO(bmeurer): This is a temporary hack to support cross-compiling
287 // Chrome for Android in AOSP. Remove this once AOSP is fixed, also
288 // cleanup the tools/gyp/v8.gyp file.
289 struct timeval tv; 274 struct timeval tv;
290 int result = gettimeofday(&tv, NULL); 275 int result = gettimeofday(&tv, NULL);
291 ASSERT_EQ(0, result); 276 ASSERT_EQ(0, result);
292 USE(result); 277 USE(result);
293 return FromTimeval(tv); 278 return FromTimeval(tv);
294 #elif defined(CLOCK_REALTIME_COARSE)
295 struct timespec ts;
296 // Use CLOCK_REALTIME_COARSE if it's available and has a precision of 1ms
297 // or higher. It's serviced from the vDSO with no system call overhead.
298 static clock_t clock_id = static_cast<clock_t>(-1);
299 STATIC_ASSERT(CLOCK_REALTIME != static_cast<clock_t>(-1));
300 STATIC_ASSERT(CLOCK_REALTIME_COARSE != static_cast<clock_t>(-1));
301 if (clock_id == static_cast<clock_t>(-1)) {
302 if (clock_getres(CLOCK_REALTIME_COARSE, &ts) == 0
303 && ts.tv_nsec <= kNanosecondsPerMillisecond)
304 clock_id = CLOCK_REALTIME_COARSE;
305 else
306 clock_id = CLOCK_REALTIME;
307 }
308 int result = clock_gettime(clock_id, &ts);
309 ASSERT_EQ(0, result);
310 USE(result);
311 return FromTimespec(ts);
312 #else
313 struct timeval tv;
314 int result = gettimeofday(&tv, NULL);
315 ASSERT_EQ(0, result);
316 USE(result);
317 return FromTimeval(tv);
318 #endif // V8_LIBRT_NOT_AVAILABLE
319 } 279 }
320 280
321 281
322 Time Time::NowFromSystemTime() { 282 Time Time::NowFromSystemTime() {
323 return Now(); 283 return Now();
324 } 284 }
325 285
326 286
327 Time Time::FromTimespec(struct timespec ts) { 287 Time Time::FromTimespec(struct timespec ts) {
328 ASSERT(ts.tv_nsec >= 0); 288 ASSERT(ts.tv_nsec >= 0);
(...skipping 274 matching lines...) Expand 10 before | Expand all | Expand 10 after
603 // TODO(bmeurer): This is a temporary hack to support cross-compiling 563 // TODO(bmeurer): This is a temporary hack to support cross-compiling
604 // Chrome for Android in AOSP. Remove this once AOSP is fixed, also 564 // Chrome for Android in AOSP. Remove this once AOSP is fixed, also
605 // cleanup the tools/gyp/v8.gyp file. 565 // cleanup the tools/gyp/v8.gyp file.
606 struct timeval tv; 566 struct timeval tv;
607 int result = gettimeofday(&tv, NULL); 567 int result = gettimeofday(&tv, NULL);
608 ASSERT_EQ(0, result); 568 ASSERT_EQ(0, result);
609 USE(result); 569 USE(result);
610 ticks = (tv.tv_sec * Time::kMicrosecondsPerSecond + tv.tv_usec); 570 ticks = (tv.tv_sec * Time::kMicrosecondsPerSecond + tv.tv_usec);
611 #elif V8_OS_POSIX 571 #elif V8_OS_POSIX
612 struct timespec ts; 572 struct timespec ts;
613 #if defined(CLOCK_MONOTONIC_COARSE) 573 int result = clock_gettime(CLOCK_MONOTONIC, &ts);
614 // Use CLOCK_MONOTONIC_COARSE if it's available and has a precision of 1ms
615 // or higher. It's serviced from the vDSO with no system call overhead.
616 static clock_t clock_id = static_cast<clock_t>(-1);
617 STATIC_ASSERT(CLOCK_MONOTONIC != static_cast<clock_t>(-1));
618 STATIC_ASSERT(CLOCK_MONOTONIC_COARSE != static_cast<clock_t>(-1));
619 if (clock_id == static_cast<clock_t>(-1)) {
620 if (clock_getres(CLOCK_MONOTONIC_COARSE, &ts) == 0
621 && ts.tv_nsec <= Time::kNanosecondsPerMillisecond)
622 clock_id = CLOCK_MONOTONIC_COARSE;
623 else
624 clock_id = CLOCK_MONOTONIC;
625 }
626 #else
627 static const clock_t clock_id = CLOCK_MONOTONIC;
628 #endif // defined(CLOCK_MONOTONIC_COARSE)
629 int result = clock_gettime(clock_id, &ts);
630 ASSERT_EQ(0, result); 574 ASSERT_EQ(0, result);
631 USE(result); 575 USE(result);
632 ticks = (ts.tv_sec * Time::kMicrosecondsPerSecond + 576 ticks = (ts.tv_sec * Time::kMicrosecondsPerSecond +
633 ts.tv_nsec / Time::kNanosecondsPerMicrosecond); 577 ts.tv_nsec / Time::kNanosecondsPerMicrosecond);
634 #endif // V8_OS_MACOSX 578 #endif // V8_OS_MACOSX
635 // Make sure we never return 0 here. 579 // Make sure we never return 0 here.
636 return TimeTicks(ticks + 1); 580 return TimeTicks(ticks + 1);
637 } 581 }
638 582
639 583
640 // static 584 // static
641 bool TimeTicks::IsHighResolutionClockWorking() { 585 bool TimeTicks::IsHighResolutionClockWorking() {
642 return true; 586 return true;
643 } 587 }
644 588
645 #endif // V8_OS_WIN 589 #endif // V8_OS_WIN
646 590
647 } } // namespace v8::internal 591 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/platform/time.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698