root / qemu-timer-common.c @ d7582078
History | View | Annotate | Download (2 kB)
1 | c57c846a | Blue Swirl | /*
|
---|---|---|---|
2 | c57c846a | Blue Swirl | * QEMU System Emulator
|
3 | c57c846a | Blue Swirl | *
|
4 | c57c846a | Blue Swirl | * Copyright (c) 2003-2008 Fabrice Bellard
|
5 | c57c846a | Blue Swirl | *
|
6 | c57c846a | Blue Swirl | * Permission is hereby granted, free of charge, to any person obtaining a copy
|
7 | c57c846a | Blue Swirl | * of this software and associated documentation files (the "Software"), to deal
|
8 | c57c846a | Blue Swirl | * in the Software without restriction, including without limitation the rights
|
9 | c57c846a | Blue Swirl | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
10 | c57c846a | Blue Swirl | * copies of the Software, and to permit persons to whom the Software is
|
11 | c57c846a | Blue Swirl | * furnished to do so, subject to the following conditions:
|
12 | c57c846a | Blue Swirl | *
|
13 | c57c846a | Blue Swirl | * The above copyright notice and this permission notice shall be included in
|
14 | c57c846a | Blue Swirl | * all copies or substantial portions of the Software.
|
15 | c57c846a | Blue Swirl | *
|
16 | c57c846a | Blue Swirl | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
17 | c57c846a | Blue Swirl | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
18 | c57c846a | Blue Swirl | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
19 | c57c846a | Blue Swirl | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
20 | c57c846a | Blue Swirl | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
21 | c57c846a | Blue Swirl | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
22 | c57c846a | Blue Swirl | * THE SOFTWARE.
|
23 | c57c846a | Blue Swirl | */
|
24 | c57c846a | Blue Swirl | #include "qemu-timer.h" |
25 | c57c846a | Blue Swirl | |
26 | c57c846a | Blue Swirl | /***********************************************************/
|
27 | c57c846a | Blue Swirl | /* real time host monotonic timer */
|
28 | c57c846a | Blue Swirl | |
29 | c57c846a | Blue Swirl | #ifdef _WIN32
|
30 | c57c846a | Blue Swirl | |
31 | c57c846a | Blue Swirl | int64_t clock_freq; |
32 | c57c846a | Blue Swirl | |
33 | c57c846a | Blue Swirl | static void __attribute__((constructor)) init_get_clock(void) |
34 | c57c846a | Blue Swirl | { |
35 | c57c846a | Blue Swirl | LARGE_INTEGER freq; |
36 | c57c846a | Blue Swirl | int ret;
|
37 | c57c846a | Blue Swirl | ret = QueryPerformanceFrequency(&freq); |
38 | c57c846a | Blue Swirl | if (ret == 0) { |
39 | c57c846a | Blue Swirl | fprintf(stderr, "Could not calibrate ticks\n");
|
40 | c57c846a | Blue Swirl | exit(1);
|
41 | c57c846a | Blue Swirl | } |
42 | c57c846a | Blue Swirl | clock_freq = freq.QuadPart; |
43 | c57c846a | Blue Swirl | } |
44 | c57c846a | Blue Swirl | |
45 | c57c846a | Blue Swirl | #else
|
46 | c57c846a | Blue Swirl | |
47 | c57c846a | Blue Swirl | int use_rt_clock;
|
48 | c57c846a | Blue Swirl | |
49 | c57c846a | Blue Swirl | static void __attribute__((constructor)) init_get_clock(void) |
50 | c57c846a | Blue Swirl | { |
51 | c57c846a | Blue Swirl | use_rt_clock = 0;
|
52 | c57c846a | Blue Swirl | #if defined(__linux__) || (defined(__FreeBSD__) && __FreeBSD_version >= 500000) \ |
53 | 7ae63a51 | Brad | || defined(__DragonFly__) || defined(__FreeBSD_kernel__) \ |
54 | 7ae63a51 | Brad | || defined(__OpenBSD__) |
55 | c57c846a | Blue Swirl | { |
56 | c57c846a | Blue Swirl | struct timespec ts;
|
57 | c57c846a | Blue Swirl | if (clock_gettime(CLOCK_MONOTONIC, &ts) == 0) { |
58 | c57c846a | Blue Swirl | use_rt_clock = 1;
|
59 | c57c846a | Blue Swirl | } |
60 | c57c846a | Blue Swirl | } |
61 | c57c846a | Blue Swirl | #endif
|
62 | c57c846a | Blue Swirl | } |
63 | c57c846a | Blue Swirl | #endif |