1 | /* $Id: timesupref.cpp 69111 2017-10-17 14:26:02Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * IPRT - Time using SUPLib, the C Implementation.
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2006-2017 Oracle Corporation
|
---|
8 | *
|
---|
9 | * This file is part of VirtualBox Open Source Edition (OSE), as
|
---|
10 | * available from http://www.virtualbox.org. This file is free software;
|
---|
11 | * you can redistribute it and/or modify it under the terms of the GNU
|
---|
12 | * General Public License (GPL) as published by the Free Software
|
---|
13 | * Foundation, in version 2 as it comes in the "COPYING" file of the
|
---|
14 | * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
|
---|
15 | * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
16 | *
|
---|
17 | * The contents of this file may alternatively be used under the terms
|
---|
18 | * of the Common Development and Distribution License Version 1.0
|
---|
19 | * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
|
---|
20 | * VirtualBox OSE distribution, in which case the provisions of the
|
---|
21 | * CDDL are applicable instead of those of the GPL.
|
---|
22 | *
|
---|
23 | * You may elect to license modified versions of this file under the
|
---|
24 | * terms and conditions of either the GPL or the CDDL or both.
|
---|
25 | */
|
---|
26 |
|
---|
27 | #if !defined(IN_GUEST) && !defined(RT_NO_GIP)
|
---|
28 |
|
---|
29 |
|
---|
30 | /*********************************************************************************************************************************
|
---|
31 | * Header Files *
|
---|
32 | *********************************************************************************************************************************/
|
---|
33 | #include <iprt/time.h>
|
---|
34 | #include "internal/iprt.h"
|
---|
35 |
|
---|
36 | #include <iprt/asm.h>
|
---|
37 | #include <iprt/asm-math.h>
|
---|
38 | #include <iprt/asm-amd64-x86.h>
|
---|
39 | #include <iprt/param.h>
|
---|
40 | #include <VBox/sup.h>
|
---|
41 | #ifdef IN_RC
|
---|
42 | # include <VBox/vmm/vmm.h>
|
---|
43 | # include <VBox/vmm/vm.h>
|
---|
44 | #endif
|
---|
45 | #include "internal/time.h"
|
---|
46 |
|
---|
47 |
|
---|
48 | #define TMPL_MODE_SYNC_INVAR_NO_DELTA 1
|
---|
49 | #define TMPL_MODE_SYNC_INVAR_WITH_DELTA 2
|
---|
50 | #define TMPL_MODE_ASYNC 3
|
---|
51 |
|
---|
52 |
|
---|
53 | /*
|
---|
54 | * Use the XCHG instruction for some kind of serialization.
|
---|
55 | */
|
---|
56 | #define TMPL_READ_FENCE() ASMReadFence()
|
---|
57 |
|
---|
58 | #undef TMPL_MODE
|
---|
59 | #define TMPL_MODE TMPL_MODE_SYNC_INVAR_NO_DELTA
|
---|
60 | #undef TMPL_GET_CPU_METHOD
|
---|
61 | #define TMPL_GET_CPU_METHOD 0
|
---|
62 | #undef rtTimeNanoTSInternalRef
|
---|
63 | #define rtTimeNanoTSInternalRef RTTimeNanoTSLegacySyncInvarNoDelta
|
---|
64 | #include "timesupref.h"
|
---|
65 | RT_EXPORT_SYMBOL(RTTimeNanoTSLegacySyncInvarNoDelta);
|
---|
66 |
|
---|
67 | #ifdef IN_RING3
|
---|
68 |
|
---|
69 | # undef TMPL_MODE
|
---|
70 | # define TMPL_MODE TMPL_MODE_SYNC_INVAR_WITH_DELTA
|
---|
71 | # undef TMPL_GET_CPU_METHOD
|
---|
72 | # define TMPL_GET_CPU_METHOD SUPGIPGETCPU_APIC_ID
|
---|
73 | # undef rtTimeNanoTSInternalRef
|
---|
74 | # define rtTimeNanoTSInternalRef RTTimeNanoTSLegacySyncInvarWithDeltaUseApicId
|
---|
75 | # include "timesupref.h"
|
---|
76 | RT_EXPORT_SYMBOL(RTTimeNanoTSLegacySyncInvarWithDeltaUseApicId);
|
---|
77 |
|
---|
78 | # undef TMPL_GET_CPU_METHOD
|
---|
79 | # define TMPL_GET_CPU_METHOD SUPGIPGETCPU_RDTSCP_MASK_MAX_SET_CPUS
|
---|
80 | # undef rtTimeNanoTSInternalRef
|
---|
81 | # define rtTimeNanoTSInternalRef RTTimeNanoTSLegacySyncInvarWithDeltaUseRdtscp
|
---|
82 | # include "timesupref.h"
|
---|
83 | RT_EXPORT_SYMBOL(RTTimeNanoTSLegacySyncInvarWithDeltaUseRdtscp);
|
---|
84 |
|
---|
85 | # undef TMPL_GET_CPU_METHOD
|
---|
86 | # define TMPL_GET_CPU_METHOD SUPGIPGETCPU_IDTR_LIMIT_MASK_MAX_SET_CPUS
|
---|
87 | # undef rtTimeNanoTSInternalRef
|
---|
88 | # define rtTimeNanoTSInternalRef RTTimeNanoTSLegacySyncInvarWithDeltaUseIdtrLim
|
---|
89 | # include "timesupref.h"
|
---|
90 | RT_EXPORT_SYMBOL(RTTimeNanoTSLegacySyncInvarWithDeltaUseIdtrLim);
|
---|
91 |
|
---|
92 | # undef TMPL_MODE
|
---|
93 | # define TMPL_MODE TMPL_MODE_ASYNC
|
---|
94 | # undef TMPL_GET_CPU_METHOD
|
---|
95 | # define TMPL_GET_CPU_METHOD SUPGIPGETCPU_APIC_ID
|
---|
96 | # undef rtTimeNanoTSInternalRef
|
---|
97 | # define rtTimeNanoTSInternalRef RTTimeNanoTSLegacyAsyncUseApicId
|
---|
98 | # include "timesupref.h"
|
---|
99 | RT_EXPORT_SYMBOL(RTTimeNanoTSLegacyAsyncUseApicId);
|
---|
100 |
|
---|
101 | # undef TMPL_GET_CPU_METHOD
|
---|
102 | # define TMPL_GET_CPU_METHOD SUPGIPGETCPU_RDTSCP_MASK_MAX_SET_CPUS
|
---|
103 | # undef rtTimeNanoTSInternalRef
|
---|
104 | # define rtTimeNanoTSInternalRef RTTimeNanoTSLegacyAsyncUseRdtscp
|
---|
105 | # include "timesupref.h"
|
---|
106 | RT_EXPORT_SYMBOL(RTTimeNanoTSLegacyAsyncUseRdtscp);
|
---|
107 |
|
---|
108 | # undef TMPL_GET_CPU_METHOD
|
---|
109 | # define TMPL_GET_CPU_METHOD SUPGIPGETCPU_IDTR_LIMIT_MASK_MAX_SET_CPUS
|
---|
110 | # undef rtTimeNanoTSInternalRef
|
---|
111 | # define rtTimeNanoTSInternalRef RTTimeNanoTSLegacyAsyncUseIdtrLim
|
---|
112 | # include "timesupref.h"
|
---|
113 | RT_EXPORT_SYMBOL(RTTimeNanoTSLegacyAsyncUseIdtrLim);
|
---|
114 |
|
---|
115 | # undef TMPL_GET_CPU_METHOD
|
---|
116 | # define TMPL_GET_CPU_METHOD SUPGIPGETCPU_RDTSCP_GROUP_IN_CH_NUMBER_IN_CL
|
---|
117 | # undef rtTimeNanoTSInternalRef
|
---|
118 | # define rtTimeNanoTSInternalRef RTTimeNanoTSLegacyAsyncUseRdtscpGroupChNumCl
|
---|
119 | # include "timesupref.h"
|
---|
120 | RT_EXPORT_SYMBOL(RTTimeNanoTSLegacyAsyncUseRdtscpGroupChNumCl);
|
---|
121 |
|
---|
122 | #else /* IN_RC || IN_RING0: Disable interrupts and call getter function. */
|
---|
123 |
|
---|
124 | # undef TMPL_MODE
|
---|
125 | # define TMPL_MODE TMPL_MODE_SYNC_INVAR_WITH_DELTA
|
---|
126 | # undef TMPL_GET_CPU_METHOD
|
---|
127 | # define TMPL_GET_CPU_METHOD UINT32_MAX
|
---|
128 | # undef rtTimeNanoTSInternalRef
|
---|
129 | # define rtTimeNanoTSInternalRef RTTimeNanoTSLegacySyncInvarWithDelta
|
---|
130 | # include "timesupref.h"
|
---|
131 | RT_EXPORT_SYMBOL(RTTimeNanoTSLegacySyncInvarWithDelta);
|
---|
132 |
|
---|
133 | # undef TMPL_MODE
|
---|
134 | # define TMPL_MODE TMPL_MODE_ASYNC
|
---|
135 | # undef rtTimeNanoTSInternalRef
|
---|
136 | # define rtTimeNanoTSInternalRef RTTimeNanoTSLegacyAsync
|
---|
137 | # include "timesupref.h"
|
---|
138 | RT_EXPORT_SYMBOL(RTTimeNanoTSLegacyAsync);
|
---|
139 |
|
---|
140 | #endif
|
---|
141 |
|
---|
142 |
|
---|
143 | /*
|
---|
144 | * Use LFENCE for load serialization.
|
---|
145 | */
|
---|
146 | #undef TMPL_READ_FENCE
|
---|
147 | #define TMPL_READ_FENCE() ASMReadFenceSSE2()
|
---|
148 |
|
---|
149 | #undef TMPL_MODE
|
---|
150 | #define TMPL_MODE TMPL_MODE_SYNC_INVAR_NO_DELTA
|
---|
151 | #undef TMPL_GET_CPU_METHOD
|
---|
152 | #define TMPL_GET_CPU_METHOD 0
|
---|
153 | #undef rtTimeNanoTSInternalRef
|
---|
154 | #define rtTimeNanoTSInternalRef RTTimeNanoTSLFenceSyncInvarNoDelta
|
---|
155 | #include "timesupref.h"
|
---|
156 | RT_EXPORT_SYMBOL(RTTimeNanoTSLFenceSyncInvarNoDelta);
|
---|
157 |
|
---|
158 | #ifdef IN_RING3
|
---|
159 |
|
---|
160 | # undef TMPL_MODE
|
---|
161 | # define TMPL_MODE TMPL_MODE_SYNC_INVAR_WITH_DELTA
|
---|
162 | # undef TMPL_GET_CPU_METHOD
|
---|
163 | # define TMPL_GET_CPU_METHOD SUPGIPGETCPU_APIC_ID
|
---|
164 | # undef rtTimeNanoTSInternalRef
|
---|
165 | # define rtTimeNanoTSInternalRef RTTimeNanoTSLFenceSyncInvarWithDeltaUseApicId
|
---|
166 | # include "timesupref.h"
|
---|
167 | RT_EXPORT_SYMBOL(RTTimeNanoTSLFenceSyncInvarWithDeltaUseApicId);
|
---|
168 |
|
---|
169 | # undef TMPL_GET_CPU_METHOD
|
---|
170 | # define TMPL_GET_CPU_METHOD SUPGIPGETCPU_RDTSCP_MASK_MAX_SET_CPUS
|
---|
171 | # undef rtTimeNanoTSInternalRef
|
---|
172 | # define rtTimeNanoTSInternalRef RTTimeNanoTSLFenceSyncInvarWithDeltaUseRdtscp
|
---|
173 | # include "timesupref.h"
|
---|
174 | RT_EXPORT_SYMBOL(RTTimeNanoTSLFenceSyncInvarWithDeltaUseRdtscp);
|
---|
175 |
|
---|
176 | # undef TMPL_GET_CPU_METHOD
|
---|
177 | # define TMPL_GET_CPU_METHOD SUPGIPGETCPU_IDTR_LIMIT_MASK_MAX_SET_CPUS
|
---|
178 | # undef rtTimeNanoTSInternalRef
|
---|
179 | # define rtTimeNanoTSInternalRef RTTimeNanoTSLFenceSyncInvarWithDeltaUseIdtrLim
|
---|
180 | # include "timesupref.h"
|
---|
181 | RT_EXPORT_SYMBOL(RTTimeNanoTSLFenceSyncInvarWithDeltaUseIdtrLim);
|
---|
182 |
|
---|
183 | # undef TMPL_MODE
|
---|
184 | # define TMPL_MODE TMPL_MODE_ASYNC
|
---|
185 | # undef TMPL_GET_CPU_METHOD
|
---|
186 | # define TMPL_GET_CPU_METHOD SUPGIPGETCPU_APIC_ID
|
---|
187 | # undef rtTimeNanoTSInternalRef
|
---|
188 | # define rtTimeNanoTSInternalRef RTTimeNanoTSLFenceAsyncUseApicId
|
---|
189 | # include "timesupref.h"
|
---|
190 | RT_EXPORT_SYMBOL(RTTimeNanoTSLFenceAsyncUseApicId);
|
---|
191 |
|
---|
192 | # undef TMPL_GET_CPU_METHOD
|
---|
193 | # define TMPL_GET_CPU_METHOD SUPGIPGETCPU_RDTSCP_MASK_MAX_SET_CPUS
|
---|
194 | # undef rtTimeNanoTSInternalRef
|
---|
195 | # define rtTimeNanoTSInternalRef RTTimeNanoTSLFenceAsyncUseRdtscp
|
---|
196 | # include "timesupref.h"
|
---|
197 | RT_EXPORT_SYMBOL(RTTimeNanoTSLFenceAsyncUseRdtscp);
|
---|
198 |
|
---|
199 | # undef TMPL_GET_CPU_METHOD
|
---|
200 | # define TMPL_GET_CPU_METHOD SUPGIPGETCPU_IDTR_LIMIT_MASK_MAX_SET_CPUS
|
---|
201 | # undef rtTimeNanoTSInternalRef
|
---|
202 | # define rtTimeNanoTSInternalRef RTTimeNanoTSLFenceAsyncUseIdtrLim
|
---|
203 | # include "timesupref.h"
|
---|
204 | RT_EXPORT_SYMBOL(RTTimeNanoTSLFenceAsyncUseIdtrLim);
|
---|
205 |
|
---|
206 | # undef TMPL_GET_CPU_METHOD
|
---|
207 | # define TMPL_GET_CPU_METHOD SUPGIPGETCPU_RDTSCP_GROUP_IN_CH_NUMBER_IN_CL
|
---|
208 | # undef rtTimeNanoTSInternalRef
|
---|
209 | # define rtTimeNanoTSInternalRef RTTimeNanoTSLFenceAsyncUseRdtscpGroupChNumCl
|
---|
210 | # include "timesupref.h"
|
---|
211 | RT_EXPORT_SYMBOL(RTTimeNanoTSLFenceAsyncUseRdtscpGroupChNumCl);
|
---|
212 |
|
---|
213 | #else /* IN_RC || IN_RING0: Disable interrupts and call getter function. */
|
---|
214 |
|
---|
215 | # undef TMPL_MODE
|
---|
216 | # define TMPL_MODE TMPL_MODE_SYNC_INVAR_WITH_DELTA
|
---|
217 | # undef TMPL_GET_CPU_METHOD
|
---|
218 | # define TMPL_GET_CPU_METHOD UINT32_MAX
|
---|
219 | # undef rtTimeNanoTSInternalRef
|
---|
220 | # define rtTimeNanoTSInternalRef RTTimeNanoTSLFenceSyncInvarWithDelta
|
---|
221 | # include "timesupref.h"
|
---|
222 | RT_EXPORT_SYMBOL(RTTimeNanoTSLFenceSyncInvarWithDelta);
|
---|
223 |
|
---|
224 | # undef TMPL_MODE
|
---|
225 | # define TMPL_MODE TMPL_MODE_ASYNC
|
---|
226 | # undef rtTimeNanoTSInternalRef
|
---|
227 | # define rtTimeNanoTSInternalRef RTTimeNanoTSLFenceAsync
|
---|
228 | # include "timesupref.h"
|
---|
229 | RT_EXPORT_SYMBOL(RTTimeNanoTSLFenceAsync);
|
---|
230 |
|
---|
231 | #endif
|
---|
232 |
|
---|
233 |
|
---|
234 | #endif /* !IN_GUEST && !RT_NO_GIP */
|
---|
235 |
|
---|