VirtualBox

source: vbox/trunk/src/VBox/Runtime/common/time/timesupref.cpp@ 107192

Last change on this file since 107192 was 107192, checked in by vboxsync, 7 weeks ago

IPRT,VMM/TM: Support for GIP time on win.arm64. jiraref:VBP-1266

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id Revision
File size: 13.8 KB
Line 
1/* $Id: timesupref.cpp 107192 2024-11-29 14:42:15Z vboxsync $ */
2/** @file
3 * IPRT - Time using SUPLib, the C Implementation.
4 */
5
6/*
7 * Copyright (C) 2006-2024 Oracle and/or its affiliates.
8 *
9 * This file is part of VirtualBox base platform packages, as
10 * available from https://www.virtualbox.org.
11 *
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation, in version 3 of the
15 * License.
16 *
17 * This program is distributed in the hope that it will be useful, but
18 * WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 * General Public License for more details.
21 *
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, see <https://www.gnu.org/licenses>.
24 *
25 * The contents of this file may alternatively be used under the terms
26 * of the Common Development and Distribution License Version 1.0
27 * (CDDL), a copy of it is provided in the "COPYING.CDDL" file included
28 * in the VirtualBox distribution, in which case the provisions of the
29 * CDDL are applicable instead of those of the GPL.
30 *
31 * You may elect to license modified versions of this file under the
32 * terms and conditions of either the GPL or the CDDL or both.
33 *
34 * SPDX-License-Identifier: GPL-3.0-only OR CDDL-1.0
35 */
36
37#if !defined(IN_GUEST) && !defined(RT_NO_GIP) /* rest of the file */
38
39
40/*********************************************************************************************************************************
41* Header Files *
42*********************************************************************************************************************************/
43#include <iprt/time.h>
44#include "internal/iprt.h"
45
46#include <iprt/asm.h>
47#include <iprt/asm-math.h>
48#if defined(RT_ARCH_AMD64) || defined(RT_ARCH_x86)
49# include <iprt/asm-amd64-x86.h>
50#elif defined(RT_ARCH_ARM64)
51# include <iprt/asm-arm.h>
52#else
53# error "port me"
54#endif
55#include <iprt/param.h>
56#include <iprt/string.h>
57#include <VBox/sup.h>
58#ifdef IN_RC
59# include <VBox/vmm/vmm.h>
60# include <VBox/vmm/vm.h>
61#endif
62#include "internal/time.h"
63
64
65#define TMPL_MODE_SYNC_INVAR_NO_DELTA 1
66#define TMPL_MODE_SYNC_INVAR_WITH_DELTA 2
67#define TMPL_MODE_ASYNC 3
68
69
70#if defined(RT_ARCH_AMD64) || defined(RT_ARCH_x86)
71/*
72 * AMD64 & x86.
73 * AMD64 & x86.
74 * AMD64 & x86.
75 */
76
77/*
78 * Use the XCHG instruction for some kind of serialization.
79 */
80# define TMPL_READ_FENCE() ASMReadFence()
81
82# undef TMPL_MODE
83# define TMPL_MODE TMPL_MODE_SYNC_INVAR_NO_DELTA
84# undef TMPL_GET_CPU_METHOD
85# define TMPL_GET_CPU_METHOD 0
86# undef rtTimeNanoTSInternalRef
87# define rtTimeNanoTSInternalRef RTTimeNanoTSLegacySyncInvarNoDelta
88# include "timesupref.h"
89RT_EXPORT_SYMBOL(RTTimeNanoTSLegacySyncInvarNoDelta);
90
91# ifdef IN_RING3
92
93# undef TMPL_MODE
94# define TMPL_MODE TMPL_MODE_SYNC_INVAR_WITH_DELTA
95# undef TMPL_GET_CPU_METHOD
96# define TMPL_GET_CPU_METHOD SUPGIPGETCPU_APIC_ID
97# undef rtTimeNanoTSInternalRef
98# define rtTimeNanoTSInternalRef RTTimeNanoTSLegacySyncInvarWithDeltaUseApicId
99# include "timesupref.h"
100RT_EXPORT_SYMBOL(RTTimeNanoTSLegacySyncInvarWithDeltaUseApicId);
101
102# undef TMPL_MODE
103# define TMPL_MODE TMPL_MODE_SYNC_INVAR_WITH_DELTA
104# undef TMPL_GET_CPU_METHOD
105# define TMPL_GET_CPU_METHOD SUPGIPGETCPU_APIC_ID_EXT_0B
106# undef rtTimeNanoTSInternalRef
107# define rtTimeNanoTSInternalRef RTTimeNanoTSLegacySyncInvarWithDeltaUseApicIdExt0B
108# include "timesupref.h"
109RT_EXPORT_SYMBOL(RTTimeNanoTSLegacySyncInvarWithDeltaUseApicIdExt0B);
110
111# undef TMPL_MODE
112# define TMPL_MODE TMPL_MODE_SYNC_INVAR_WITH_DELTA
113# undef TMPL_GET_CPU_METHOD
114# define TMPL_GET_CPU_METHOD SUPGIPGETCPU_APIC_ID_EXT_8000001E
115# undef rtTimeNanoTSInternalRef
116# define rtTimeNanoTSInternalRef RTTimeNanoTSLegacySyncInvarWithDeltaUseApicIdExt8000001E
117# include "timesupref.h"
118RT_EXPORT_SYMBOL(RTTimeNanoTSLegacySyncInvarWithDeltaUseApicIdExt8000001E);
119
120# undef TMPL_GET_CPU_METHOD
121# define TMPL_GET_CPU_METHOD SUPGIPGETCPU_RDTSCP_MASK_MAX_SET_CPUS
122# undef rtTimeNanoTSInternalRef
123# define rtTimeNanoTSInternalRef RTTimeNanoTSLegacySyncInvarWithDeltaUseRdtscp
124# include "timesupref.h"
125RT_EXPORT_SYMBOL(RTTimeNanoTSLegacySyncInvarWithDeltaUseRdtscp);
126
127# undef TMPL_GET_CPU_METHOD
128# define TMPL_GET_CPU_METHOD SUPGIPGETCPU_IDTR_LIMIT_MASK_MAX_SET_CPUS
129# undef rtTimeNanoTSInternalRef
130# define rtTimeNanoTSInternalRef RTTimeNanoTSLegacySyncInvarWithDeltaUseIdtrLim
131# include "timesupref.h"
132RT_EXPORT_SYMBOL(RTTimeNanoTSLegacySyncInvarWithDeltaUseIdtrLim);
133
134# undef TMPL_MODE
135# define TMPL_MODE TMPL_MODE_ASYNC
136# undef TMPL_GET_CPU_METHOD
137# define TMPL_GET_CPU_METHOD SUPGIPGETCPU_APIC_ID
138# undef rtTimeNanoTSInternalRef
139# define rtTimeNanoTSInternalRef RTTimeNanoTSLegacyAsyncUseApicId
140# include "timesupref.h"
141RT_EXPORT_SYMBOL(RTTimeNanoTSLegacyAsyncUseApicId);
142
143# undef TMPL_MODE
144# define TMPL_MODE TMPL_MODE_ASYNC
145# undef TMPL_GET_CPU_METHOD
146# define TMPL_GET_CPU_METHOD SUPGIPGETCPU_APIC_ID_EXT_0B
147# undef rtTimeNanoTSInternalRef
148# define rtTimeNanoTSInternalRef RTTimeNanoTSLegacyAsyncUseApicIdExt0B
149# include "timesupref.h"
150RT_EXPORT_SYMBOL(RTTimeNanoTSLegacyAsyncUseApicIdExt0B);
151
152# undef TMPL_MODE
153# define TMPL_MODE TMPL_MODE_ASYNC
154# undef TMPL_GET_CPU_METHOD
155# define TMPL_GET_CPU_METHOD SUPGIPGETCPU_APIC_ID_EXT_8000001E
156# undef rtTimeNanoTSInternalRef
157# define rtTimeNanoTSInternalRef RTTimeNanoTSLegacyAsyncUseApicIdExt8000001E
158# include "timesupref.h"
159RT_EXPORT_SYMBOL(RTTimeNanoTSLegacyAsyncUseApicIdExt8000001E);
160
161# undef TMPL_GET_CPU_METHOD
162# define TMPL_GET_CPU_METHOD SUPGIPGETCPU_RDTSCP_MASK_MAX_SET_CPUS
163# undef rtTimeNanoTSInternalRef
164# define rtTimeNanoTSInternalRef RTTimeNanoTSLegacyAsyncUseRdtscp
165# include "timesupref.h"
166RT_EXPORT_SYMBOL(RTTimeNanoTSLegacyAsyncUseRdtscp);
167
168# undef TMPL_GET_CPU_METHOD
169# define TMPL_GET_CPU_METHOD SUPGIPGETCPU_IDTR_LIMIT_MASK_MAX_SET_CPUS
170# undef rtTimeNanoTSInternalRef
171# define rtTimeNanoTSInternalRef RTTimeNanoTSLegacyAsyncUseIdtrLim
172# include "timesupref.h"
173RT_EXPORT_SYMBOL(RTTimeNanoTSLegacyAsyncUseIdtrLim);
174
175# undef TMPL_GET_CPU_METHOD
176# define TMPL_GET_CPU_METHOD SUPGIPGETCPU_RDTSCP_GROUP_IN_CH_NUMBER_IN_CL
177# undef rtTimeNanoTSInternalRef
178# define rtTimeNanoTSInternalRef RTTimeNanoTSLegacyAsyncUseRdtscpGroupChNumCl
179# include "timesupref.h"
180RT_EXPORT_SYMBOL(RTTimeNanoTSLegacyAsyncUseRdtscpGroupChNumCl);
181
182# else /* IN_RC || IN_RING0: Disable interrupts and call getter function. */
183
184# undef TMPL_MODE
185# define TMPL_MODE TMPL_MODE_SYNC_INVAR_WITH_DELTA
186# undef TMPL_GET_CPU_METHOD
187# define TMPL_GET_CPU_METHOD UINT32_MAX
188# undef rtTimeNanoTSInternalRef
189# define rtTimeNanoTSInternalRef RTTimeNanoTSLegacySyncInvarWithDelta
190# include "timesupref.h"
191RT_EXPORT_SYMBOL(RTTimeNanoTSLegacySyncInvarWithDelta);
192
193# undef TMPL_MODE
194# define TMPL_MODE TMPL_MODE_ASYNC
195# undef rtTimeNanoTSInternalRef
196# define rtTimeNanoTSInternalRef RTTimeNanoTSLegacyAsync
197# include "timesupref.h"
198RT_EXPORT_SYMBOL(RTTimeNanoTSLegacyAsync);
199
200# endif
201
202
203/*
204 * Use LFENCE for load serialization.
205 */
206# undef TMPL_READ_FENCE
207# define TMPL_READ_FENCE() ASMReadFenceSSE2()
208
209# undef TMPL_MODE
210# define TMPL_MODE TMPL_MODE_SYNC_INVAR_NO_DELTA
211# undef TMPL_GET_CPU_METHOD
212# define TMPL_GET_CPU_METHOD 0
213# undef rtTimeNanoTSInternalRef
214# define rtTimeNanoTSInternalRef RTTimeNanoTSLFenceSyncInvarNoDelta
215# include "timesupref.h"
216RT_EXPORT_SYMBOL(RTTimeNanoTSLFenceSyncInvarNoDelta);
217
218# ifdef IN_RING3
219
220# undef TMPL_MODE
221# define TMPL_MODE TMPL_MODE_SYNC_INVAR_WITH_DELTA
222# undef TMPL_GET_CPU_METHOD
223# define TMPL_GET_CPU_METHOD SUPGIPGETCPU_APIC_ID
224# undef rtTimeNanoTSInternalRef
225# define rtTimeNanoTSInternalRef RTTimeNanoTSLFenceSyncInvarWithDeltaUseApicId
226# include "timesupref.h"
227RT_EXPORT_SYMBOL(RTTimeNanoTSLFenceSyncInvarWithDeltaUseApicId);
228
229# undef TMPL_MODE
230# define TMPL_MODE TMPL_MODE_SYNC_INVAR_WITH_DELTA
231# undef TMPL_GET_CPU_METHOD
232# define TMPL_GET_CPU_METHOD SUPGIPGETCPU_APIC_ID_EXT_0B
233# undef rtTimeNanoTSInternalRef
234# define rtTimeNanoTSInternalRef RTTimeNanoTSLFenceSyncInvarWithDeltaUseApicIdExt0B
235# include "timesupref.h"
236RT_EXPORT_SYMBOL(RTTimeNanoTSLFenceSyncInvarWithDeltaUseApicIdExt0B);
237
238# undef TMPL_MODE
239# define TMPL_MODE TMPL_MODE_SYNC_INVAR_WITH_DELTA
240# undef TMPL_GET_CPU_METHOD
241# define TMPL_GET_CPU_METHOD SUPGIPGETCPU_APIC_ID_EXT_8000001E
242# undef rtTimeNanoTSInternalRef
243# define rtTimeNanoTSInternalRef RTTimeNanoTSLFenceSyncInvarWithDeltaUseApicIdExt8000001E
244# include "timesupref.h"
245RT_EXPORT_SYMBOL(RTTimeNanoTSLFenceSyncInvarWithDeltaUseApicIdExt8000001E);
246
247# undef TMPL_GET_CPU_METHOD
248# define TMPL_GET_CPU_METHOD SUPGIPGETCPU_RDTSCP_MASK_MAX_SET_CPUS
249# undef rtTimeNanoTSInternalRef
250# define rtTimeNanoTSInternalRef RTTimeNanoTSLFenceSyncInvarWithDeltaUseRdtscp
251# include "timesupref.h"
252RT_EXPORT_SYMBOL(RTTimeNanoTSLFenceSyncInvarWithDeltaUseRdtscp);
253
254# undef TMPL_GET_CPU_METHOD
255# define TMPL_GET_CPU_METHOD SUPGIPGETCPU_IDTR_LIMIT_MASK_MAX_SET_CPUS
256# undef rtTimeNanoTSInternalRef
257# define rtTimeNanoTSInternalRef RTTimeNanoTSLFenceSyncInvarWithDeltaUseIdtrLim
258# include "timesupref.h"
259RT_EXPORT_SYMBOL(RTTimeNanoTSLFenceSyncInvarWithDeltaUseIdtrLim);
260
261# undef TMPL_MODE
262# define TMPL_MODE TMPL_MODE_ASYNC
263# undef TMPL_GET_CPU_METHOD
264# define TMPL_GET_CPU_METHOD SUPGIPGETCPU_APIC_ID
265# undef rtTimeNanoTSInternalRef
266# define rtTimeNanoTSInternalRef RTTimeNanoTSLFenceAsyncUseApicId
267# include "timesupref.h"
268RT_EXPORT_SYMBOL(RTTimeNanoTSLFenceAsyncUseApicId);
269
270# undef TMPL_MODE
271# define TMPL_MODE TMPL_MODE_ASYNC
272# undef TMPL_GET_CPU_METHOD
273# define TMPL_GET_CPU_METHOD SUPGIPGETCPU_APIC_ID_EXT_0B
274# undef rtTimeNanoTSInternalRef
275# define rtTimeNanoTSInternalRef RTTimeNanoTSLFenceAsyncUseApicIdExt0B
276# include "timesupref.h"
277RT_EXPORT_SYMBOL(RTTimeNanoTSLFenceAsyncUseApicIdExt0B);
278
279# undef TMPL_MODE
280# define TMPL_MODE TMPL_MODE_ASYNC
281# undef TMPL_GET_CPU_METHOD
282# define TMPL_GET_CPU_METHOD SUPGIPGETCPU_APIC_ID_EXT_8000001E
283# undef rtTimeNanoTSInternalRef
284# define rtTimeNanoTSInternalRef RTTimeNanoTSLFenceAsyncUseApicIdExt8000001E
285# include "timesupref.h"
286RT_EXPORT_SYMBOL(RTTimeNanoTSLFenceAsyncUseApicIdExt8000001E);
287
288# undef TMPL_GET_CPU_METHOD
289# define TMPL_GET_CPU_METHOD SUPGIPGETCPU_RDTSCP_MASK_MAX_SET_CPUS
290# undef rtTimeNanoTSInternalRef
291# define rtTimeNanoTSInternalRef RTTimeNanoTSLFenceAsyncUseRdtscp
292# include "timesupref.h"
293RT_EXPORT_SYMBOL(RTTimeNanoTSLFenceAsyncUseRdtscp);
294
295# undef TMPL_GET_CPU_METHOD
296# define TMPL_GET_CPU_METHOD SUPGIPGETCPU_IDTR_LIMIT_MASK_MAX_SET_CPUS
297# undef rtTimeNanoTSInternalRef
298# define rtTimeNanoTSInternalRef RTTimeNanoTSLFenceAsyncUseIdtrLim
299# include "timesupref.h"
300RT_EXPORT_SYMBOL(RTTimeNanoTSLFenceAsyncUseIdtrLim);
301
302# undef TMPL_GET_CPU_METHOD
303# define TMPL_GET_CPU_METHOD SUPGIPGETCPU_RDTSCP_GROUP_IN_CH_NUMBER_IN_CL
304# undef rtTimeNanoTSInternalRef
305# define rtTimeNanoTSInternalRef RTTimeNanoTSLFenceAsyncUseRdtscpGroupChNumCl
306# include "timesupref.h"
307RT_EXPORT_SYMBOL(RTTimeNanoTSLFenceAsyncUseRdtscpGroupChNumCl);
308
309# else /* IN_RC || IN_RING0: Disable interrupts and call getter function. */
310
311# undef TMPL_MODE
312# define TMPL_MODE TMPL_MODE_SYNC_INVAR_WITH_DELTA
313# undef TMPL_GET_CPU_METHOD
314# define TMPL_GET_CPU_METHOD UINT32_MAX
315# undef rtTimeNanoTSInternalRef
316# define rtTimeNanoTSInternalRef RTTimeNanoTSLFenceSyncInvarWithDelta
317# include "timesupref.h"
318RT_EXPORT_SYMBOL(RTTimeNanoTSLFenceSyncInvarWithDelta);
319
320# undef TMPL_MODE
321# define TMPL_MODE TMPL_MODE_ASYNC
322# undef rtTimeNanoTSInternalRef
323# define rtTimeNanoTSInternalRef RTTimeNanoTSLFenceAsync
324# include "timesupref.h"
325RT_EXPORT_SYMBOL(RTTimeNanoTSLFenceAsync);
326
327# endif
328
329#else /* !AMD64 && !X86 */
330/*
331 * Generic.
332 */
333# define TMPL_READ_FENCE() ASMReadFence()
334
335# undef TMPL_MODE
336# define TMPL_MODE TMPL_MODE_SYNC_INVAR_NO_DELTA
337# undef TMPL_GET_CPU_METHOD
338# define TMPL_GET_CPU_METHOD 0
339# undef rtTimeNanoTSInternalRef
340# define rtTimeNanoTSInternalRef RTTimeNanoTSSyncInvarNoDelta
341# include "timesupref.h"
342RT_EXPORT_SYMBOL(RTTimeNanoTSSyncInvarNoDelta);
343
344# ifdef IN_RING0
345
346# undef TMPL_MODE
347# define TMPL_MODE TMPL_MODE_SYNC_INVAR_WITH_DELTA
348# undef TMPL_GET_CPU_METHOD
349# define TMPL_GET_CPU_METHOD UINT32_MAX
350# undef rtTimeNanoTSInternalRef
351# define rtTimeNanoTSInternalRef RTTimeNanoTSSyncInvarWithDelta
352# include "timesupref.h"
353RT_EXPORT_SYMBOL(RTTimeNanoTSSyncInvarWithDelta);
354
355# undef TMPL_MODE
356# define TMPL_MODE TMPL_MODE_ASYNC
357# undef rtTimeNanoTSInternalRef
358# define rtTimeNanoTSInternalRef RTTimeNanoTSAsync
359# include "timesupref.h"
360RT_EXPORT_SYMBOL(RTTimeNanoTSAsync);
361
362# elif defined(IN_RING3) && defined(RT_ARCH_ARM64)
363
364# undef TMPL_MODE
365# define TMPL_MODE TMPL_MODE_SYNC_INVAR_WITH_DELTA
366# undef TMPL_GET_CPU_METHOD
367# define TMPL_GET_CPU_METHOD SUPGIPGETCPU_TPIDRRO_EL0
368# undef rtTimeNanoTSInternalRef
369# define rtTimeNanoTSInternalRef RTTimeNanoTSSyncInvarWithDeltaUseTpIdRRo
370# include "timesupref.h"
371RT_EXPORT_SYMBOL(RTTimeNanoTSSyncInvarWithDeltaUseTpIdRRo);
372
373# undef TMPL_MODE
374# define TMPL_MODE TMPL_MODE_ASYNC
375# undef TMPL_GET_CPU_METHOD
376# define TMPL_GET_CPU_METHOD SUPGIPGETCPU_TPIDRRO_EL0
377# undef rtTimeNanoTSInternalRef
378# define rtTimeNanoTSInternalRef RTTimeNanoTSAsyncUseTpIdRRo
379# include "timesupref.h"
380RT_EXPORT_SYMBOL(RTTimeNanoTSAsyncUseTpIdRRo);
381
382# endif
383
384#endif /* !AMD64 && !X86 */
385
386#endif /* !IN_GUEST && !RT_NO_GIP */
387
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette