OLD | NEW |
---|---|
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 Loading... | |
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 #if V8_OS_LINUX && !defined(CLOCK_MONOTONIC_COARSE) | |
47 #define CLOCK_MONOTONIC_COARSE 6 // 2.6.32 and up. | |
48 #endif | |
49 | |
46 namespace v8 { | 50 namespace v8 { |
47 namespace internal { | 51 namespace internal { |
48 | 52 |
49 TimeDelta TimeDelta::FromDays(int days) { | 53 TimeDelta TimeDelta::FromDays(int days) { |
50 return TimeDelta(days * Time::kMicrosecondsPerDay); | 54 return TimeDelta(days * Time::kMicrosecondsPerDay); |
51 } | 55 } |
52 | 56 |
53 | 57 |
54 TimeDelta TimeDelta::FromHours(int hours) { | 58 TimeDelta TimeDelta::FromHours(int hours) { |
55 return TimeDelta(hours * Time::kMicrosecondsPerHour); | 59 return TimeDelta(hours * Time::kMicrosecondsPerHour); |
(...skipping 507 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
563 // TODO(bmeurer): This is a temporary hack to support cross-compiling | 567 // TODO(bmeurer): This is a temporary hack to support cross-compiling |
564 // Chrome for Android in AOSP. Remove this once AOSP is fixed, also | 568 // Chrome for Android in AOSP. Remove this once AOSP is fixed, also |
565 // cleanup the tools/gyp/v8.gyp file. | 569 // cleanup the tools/gyp/v8.gyp file. |
566 struct timeval tv; | 570 struct timeval tv; |
567 int result = gettimeofday(&tv, NULL); | 571 int result = gettimeofday(&tv, NULL); |
568 ASSERT_EQ(0, result); | 572 ASSERT_EQ(0, result); |
569 USE(result); | 573 USE(result); |
570 ticks = (tv.tv_sec * Time::kMicrosecondsPerSecond + tv.tv_usec); | 574 ticks = (tv.tv_sec * Time::kMicrosecondsPerSecond + tv.tv_usec); |
571 #elif V8_OS_POSIX | 575 #elif V8_OS_POSIX |
572 struct timespec ts; | 576 struct timespec ts; |
577 #if V8_OS_LINUX | |
578 // Prefer CLOCK_MONOTONIC_COARSE, a high-res clock that's available in | |
579 // 2.6.32 and can be fully serviced from the vDSO, even on virtualized | |
580 // systems. Check that it's not *too* coarse though. | |
581 static clock_t clock_id = -1; | |
Benedikt Meurer
2013/10/31 06:44:50
I think we can safely use zero here, i.e. no expli
bnoordhuis
2013/10/31 12:22:24
I wrote it that way because 0 is a valid clock (CL
Benedikt Meurer
2013/11/04 09:09:57
Please just use 0 here.
| |
582 if (clock_id == -1) { | |
583 if (clock_getres(CLOCK_MONOTONIC_COARSE, &ts) == 0 && | |
Benedikt Meurer
2013/10/31 06:44:50
This won't compile on non-Linux systems that miss
bnoordhuis
2013/10/31 12:22:24
If it weren't for the #if V8_OS_LINUX a few lines
Benedikt Meurer
2013/11/04 09:09:57
Ups, right. Ok, that's fine.
| |
584 ts.tv_nsec <= 1 * 1000 * 1000) { // 1 ms granularity or less. | |
585 clock_id = CLOCK_MONOTONIC_COARSE; | |
586 } else { | |
587 clock_id = CLOCK_MONOTONIC; | |
588 } | |
589 } | |
590 int result = clock_gettime(clock_id, &ts); | |
591 #else | |
573 int result = clock_gettime(CLOCK_MONOTONIC, &ts); | 592 int result = clock_gettime(CLOCK_MONOTONIC, &ts); |
593 #endif // V8_OS_LINUX | |
574 ASSERT_EQ(0, result); | 594 ASSERT_EQ(0, result); |
575 USE(result); | 595 USE(result); |
576 ticks = (ts.tv_sec * Time::kMicrosecondsPerSecond + | 596 ticks = (ts.tv_sec * Time::kMicrosecondsPerSecond + |
577 ts.tv_nsec / Time::kNanosecondsPerMicrosecond); | 597 ts.tv_nsec / Time::kNanosecondsPerMicrosecond); |
578 #endif // V8_OS_MACOSX | 598 #endif // V8_OS_MACOSX |
579 // Make sure we never return 0 here. | 599 // Make sure we never return 0 here. |
580 return TimeTicks(ticks + 1); | 600 return TimeTicks(ticks + 1); |
581 } | 601 } |
582 | 602 |
583 | 603 |
584 // static | 604 // static |
585 bool TimeTicks::IsHighResolutionClockWorking() { | 605 bool TimeTicks::IsHighResolutionClockWorking() { |
586 return true; | 606 return true; |
587 } | 607 } |
588 | 608 |
589 #endif // V8_OS_WIN | 609 #endif // V8_OS_WIN |
590 | 610 |
591 } } // namespace v8::internal | 611 } } // namespace v8::internal |
OLD | NEW |