VirtualBox

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

Last change on this file was 98103, checked in by vboxsync, 17 months ago

Copyright year updates by scm.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id Revision
File size: 11.6 KB
RevLine 
[5456]1/* $Id: timesupref.cpp 98103 2023-01-17 14:15:46Z vboxsync $ */
2/** @file
[8245]3 * IPRT - Time using SUPLib, the C Implementation.
[5456]4 */
5
6/*
[98103]7 * Copyright (C) 2006-2023 Oracle and/or its affiliates.
[5456]8 *
[96407]9 * This file is part of VirtualBox base platform packages, as
10 * available from https://www.virtualbox.org.
[5456]11 *
[96407]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 *
[5999]25 * The contents of this file may alternatively be used under the terms
26 * of the Common Development and Distribution License Version 1.0
[96407]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
[5999]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.
[96407]33 *
34 * SPDX-License-Identifier: GPL-3.0-only OR CDDL-1.0
[5456]35 */
36
[29267]37#if !defined(IN_GUEST) && !defined(RT_NO_GIP)
[5456]38
[57358]39
40/*********************************************************************************************************************************
41* Header Files *
42*********************************************************************************************************************************/
[5456]43#include <iprt/time.h>
[21337]44#include "internal/iprt.h"
45
[5456]46#include <iprt/asm.h>
[29250]47#include <iprt/asm-math.h>
48#include <iprt/asm-amd64-x86.h>
[64281]49#include <iprt/param.h>
[76389]50#include <iprt/string.h>
[5456]51#include <VBox/sup.h>
[54270]52#ifdef IN_RC
53# include <VBox/vmm/vmm.h>
54# include <VBox/vmm/vm.h>
55#endif
[5456]56#include "internal/time.h"
57
58
[54270]59#define TMPL_MODE_SYNC_INVAR_NO_DELTA 1
60#define TMPL_MODE_SYNC_INVAR_WITH_DELTA 2
61#define TMPL_MODE_ASYNC 3
[54202]62
63
[5456]64/*
[54270]65 * Use the XCHG instruction for some kind of serialization.
[5456]66 */
[54270]67#define TMPL_READ_FENCE() ASMReadFence()
[5456]68
[54270]69#undef TMPL_MODE
70#define TMPL_MODE TMPL_MODE_SYNC_INVAR_NO_DELTA
71#undef TMPL_GET_CPU_METHOD
72#define TMPL_GET_CPU_METHOD 0
[54202]73#undef rtTimeNanoTSInternalRef
[54270]74#define rtTimeNanoTSInternalRef RTTimeNanoTSLegacySyncInvarNoDelta
[54202]75#include "timesupref.h"
[54270]76RT_EXPORT_SYMBOL(RTTimeNanoTSLegacySyncInvarNoDelta);
[54202]77
[54270]78#ifdef IN_RING3
79
80# undef TMPL_MODE
81# define TMPL_MODE TMPL_MODE_SYNC_INVAR_WITH_DELTA
82# undef TMPL_GET_CPU_METHOD
83# define TMPL_GET_CPU_METHOD SUPGIPGETCPU_APIC_ID
84# undef rtTimeNanoTSInternalRef
85# define rtTimeNanoTSInternalRef RTTimeNanoTSLegacySyncInvarWithDeltaUseApicId
86# include "timesupref.h"
87RT_EXPORT_SYMBOL(RTTimeNanoTSLegacySyncInvarWithDeltaUseApicId);
88
[81071]89# undef TMPL_MODE
90# define TMPL_MODE TMPL_MODE_SYNC_INVAR_WITH_DELTA
[54270]91# undef TMPL_GET_CPU_METHOD
[81071]92# define TMPL_GET_CPU_METHOD SUPGIPGETCPU_APIC_ID_EXT_0B
93# undef rtTimeNanoTSInternalRef
94# define rtTimeNanoTSInternalRef RTTimeNanoTSLegacySyncInvarWithDeltaUseApicIdExt0B
95# include "timesupref.h"
96RT_EXPORT_SYMBOL(RTTimeNanoTSLegacySyncInvarWithDeltaUseApicIdExt0B);
97
98# undef TMPL_MODE
99# define TMPL_MODE TMPL_MODE_SYNC_INVAR_WITH_DELTA
100# undef TMPL_GET_CPU_METHOD
101# define TMPL_GET_CPU_METHOD SUPGIPGETCPU_APIC_ID_EXT_8000001E
102# undef rtTimeNanoTSInternalRef
103# define rtTimeNanoTSInternalRef RTTimeNanoTSLegacySyncInvarWithDeltaUseApicIdExt8000001E
104# include "timesupref.h"
105RT_EXPORT_SYMBOL(RTTimeNanoTSLegacySyncInvarWithDeltaUseApicIdExt8000001E);
106
107# undef TMPL_GET_CPU_METHOD
[54270]108# define TMPL_GET_CPU_METHOD SUPGIPGETCPU_RDTSCP_MASK_MAX_SET_CPUS
109# undef rtTimeNanoTSInternalRef
110# define rtTimeNanoTSInternalRef RTTimeNanoTSLegacySyncInvarWithDeltaUseRdtscp
111# include "timesupref.h"
112RT_EXPORT_SYMBOL(RTTimeNanoTSLegacySyncInvarWithDeltaUseRdtscp);
113
114# undef TMPL_GET_CPU_METHOD
115# define TMPL_GET_CPU_METHOD SUPGIPGETCPU_IDTR_LIMIT_MASK_MAX_SET_CPUS
116# undef rtTimeNanoTSInternalRef
117# define rtTimeNanoTSInternalRef RTTimeNanoTSLegacySyncInvarWithDeltaUseIdtrLim
118# include "timesupref.h"
119RT_EXPORT_SYMBOL(RTTimeNanoTSLegacySyncInvarWithDeltaUseIdtrLim);
120
121# undef TMPL_MODE
122# define TMPL_MODE TMPL_MODE_ASYNC
123# undef TMPL_GET_CPU_METHOD
124# define TMPL_GET_CPU_METHOD SUPGIPGETCPU_APIC_ID
125# undef rtTimeNanoTSInternalRef
126# define rtTimeNanoTSInternalRef RTTimeNanoTSLegacyAsyncUseApicId
127# include "timesupref.h"
128RT_EXPORT_SYMBOL(RTTimeNanoTSLegacyAsyncUseApicId);
129
[81071]130# undef TMPL_MODE
131# define TMPL_MODE TMPL_MODE_ASYNC
[54270]132# undef TMPL_GET_CPU_METHOD
[81071]133# define TMPL_GET_CPU_METHOD SUPGIPGETCPU_APIC_ID_EXT_0B
134# undef rtTimeNanoTSInternalRef
135# define rtTimeNanoTSInternalRef RTTimeNanoTSLegacyAsyncUseApicIdExt0B
136# include "timesupref.h"
137RT_EXPORT_SYMBOL(RTTimeNanoTSLegacyAsyncUseApicIdExt0B);
138
139# undef TMPL_MODE
140# define TMPL_MODE TMPL_MODE_ASYNC
141# undef TMPL_GET_CPU_METHOD
142# define TMPL_GET_CPU_METHOD SUPGIPGETCPU_APIC_ID_EXT_8000001E
143# undef rtTimeNanoTSInternalRef
144# define rtTimeNanoTSInternalRef RTTimeNanoTSLegacyAsyncUseApicIdExt8000001E
145# include "timesupref.h"
146RT_EXPORT_SYMBOL(RTTimeNanoTSLegacyAsyncUseApicIdExt8000001E);
147
148# undef TMPL_GET_CPU_METHOD
[54270]149# define TMPL_GET_CPU_METHOD SUPGIPGETCPU_RDTSCP_MASK_MAX_SET_CPUS
150# undef rtTimeNanoTSInternalRef
151# define rtTimeNanoTSInternalRef RTTimeNanoTSLegacyAsyncUseRdtscp
152# include "timesupref.h"
153RT_EXPORT_SYMBOL(RTTimeNanoTSLegacyAsyncUseRdtscp);
154
155# undef TMPL_GET_CPU_METHOD
156# define TMPL_GET_CPU_METHOD SUPGIPGETCPU_IDTR_LIMIT_MASK_MAX_SET_CPUS
157# undef rtTimeNanoTSInternalRef
158# define rtTimeNanoTSInternalRef RTTimeNanoTSLegacyAsyncUseIdtrLim
159# include "timesupref.h"
160RT_EXPORT_SYMBOL(RTTimeNanoTSLegacyAsyncUseIdtrLim);
161
[64255]162# undef TMPL_GET_CPU_METHOD
163# define TMPL_GET_CPU_METHOD SUPGIPGETCPU_RDTSCP_GROUP_IN_CH_NUMBER_IN_CL
164# undef rtTimeNanoTSInternalRef
165# define rtTimeNanoTSInternalRef RTTimeNanoTSLegacyAsyncUseRdtscpGroupChNumCl
166# include "timesupref.h"
167RT_EXPORT_SYMBOL(RTTimeNanoTSLegacyAsyncUseRdtscpGroupChNumCl);
168
[54270]169#else /* IN_RC || IN_RING0: Disable interrupts and call getter function. */
170
171# undef TMPL_MODE
172# define TMPL_MODE TMPL_MODE_SYNC_INVAR_WITH_DELTA
173# undef TMPL_GET_CPU_METHOD
174# define TMPL_GET_CPU_METHOD UINT32_MAX
175# undef rtTimeNanoTSInternalRef
176# define rtTimeNanoTSInternalRef RTTimeNanoTSLegacySyncInvarWithDelta
177# include "timesupref.h"
178RT_EXPORT_SYMBOL(RTTimeNanoTSLegacySyncInvarWithDelta);
179
180# undef TMPL_MODE
181# define TMPL_MODE TMPL_MODE_ASYNC
182# undef rtTimeNanoTSInternalRef
183# define rtTimeNanoTSInternalRef RTTimeNanoTSLegacyAsync
184# include "timesupref.h"
[21337]185RT_EXPORT_SYMBOL(RTTimeNanoTSLegacyAsync);
[5456]186
[54270]187#endif
[5456]188
[54202]189
[5456]190/*
191 * Use LFENCE for load serialization.
192 */
[54270]193#undef TMPL_READ_FENCE
194#define TMPL_READ_FENCE() ASMReadFenceSSE2()
[5456]195
[54270]196#undef TMPL_MODE
197#define TMPL_MODE TMPL_MODE_SYNC_INVAR_NO_DELTA
198#undef TMPL_GET_CPU_METHOD
199#define TMPL_GET_CPU_METHOD 0
[54202]200#undef rtTimeNanoTSInternalRef
[54270]201#define rtTimeNanoTSInternalRef RTTimeNanoTSLFenceSyncInvarNoDelta
[54202]202#include "timesupref.h"
[54270]203RT_EXPORT_SYMBOL(RTTimeNanoTSLFenceSyncInvarNoDelta);
[54202]204
[54270]205#ifdef IN_RING3
206
207# undef TMPL_MODE
208# define TMPL_MODE TMPL_MODE_SYNC_INVAR_WITH_DELTA
209# undef TMPL_GET_CPU_METHOD
210# define TMPL_GET_CPU_METHOD SUPGIPGETCPU_APIC_ID
211# undef rtTimeNanoTSInternalRef
212# define rtTimeNanoTSInternalRef RTTimeNanoTSLFenceSyncInvarWithDeltaUseApicId
213# include "timesupref.h"
214RT_EXPORT_SYMBOL(RTTimeNanoTSLFenceSyncInvarWithDeltaUseApicId);
215
[81071]216# undef TMPL_MODE
217# define TMPL_MODE TMPL_MODE_SYNC_INVAR_WITH_DELTA
[54270]218# undef TMPL_GET_CPU_METHOD
[81071]219# define TMPL_GET_CPU_METHOD SUPGIPGETCPU_APIC_ID_EXT_0B
220# undef rtTimeNanoTSInternalRef
221# define rtTimeNanoTSInternalRef RTTimeNanoTSLFenceSyncInvarWithDeltaUseApicIdExt0B
222# include "timesupref.h"
223RT_EXPORT_SYMBOL(RTTimeNanoTSLFenceSyncInvarWithDeltaUseApicIdExt0B);
224
225# undef TMPL_MODE
226# define TMPL_MODE TMPL_MODE_SYNC_INVAR_WITH_DELTA
227# undef TMPL_GET_CPU_METHOD
228# define TMPL_GET_CPU_METHOD SUPGIPGETCPU_APIC_ID_EXT_8000001E
229# undef rtTimeNanoTSInternalRef
230# define rtTimeNanoTSInternalRef RTTimeNanoTSLFenceSyncInvarWithDeltaUseApicIdExt8000001E
231# include "timesupref.h"
232RT_EXPORT_SYMBOL(RTTimeNanoTSLFenceSyncInvarWithDeltaUseApicIdExt8000001E);
233
234# undef TMPL_GET_CPU_METHOD
[54270]235# define TMPL_GET_CPU_METHOD SUPGIPGETCPU_RDTSCP_MASK_MAX_SET_CPUS
236# undef rtTimeNanoTSInternalRef
237# define rtTimeNanoTSInternalRef RTTimeNanoTSLFenceSyncInvarWithDeltaUseRdtscp
238# include "timesupref.h"
239RT_EXPORT_SYMBOL(RTTimeNanoTSLFenceSyncInvarWithDeltaUseRdtscp);
240
241# undef TMPL_GET_CPU_METHOD
242# define TMPL_GET_CPU_METHOD SUPGIPGETCPU_IDTR_LIMIT_MASK_MAX_SET_CPUS
243# undef rtTimeNanoTSInternalRef
244# define rtTimeNanoTSInternalRef RTTimeNanoTSLFenceSyncInvarWithDeltaUseIdtrLim
245# include "timesupref.h"
246RT_EXPORT_SYMBOL(RTTimeNanoTSLFenceSyncInvarWithDeltaUseIdtrLim);
247
248# undef TMPL_MODE
249# define TMPL_MODE TMPL_MODE_ASYNC
250# undef TMPL_GET_CPU_METHOD
251# define TMPL_GET_CPU_METHOD SUPGIPGETCPU_APIC_ID
252# undef rtTimeNanoTSInternalRef
253# define rtTimeNanoTSInternalRef RTTimeNanoTSLFenceAsyncUseApicId
254# include "timesupref.h"
255RT_EXPORT_SYMBOL(RTTimeNanoTSLFenceAsyncUseApicId);
256
[81071]257# undef TMPL_MODE
258# define TMPL_MODE TMPL_MODE_ASYNC
[54270]259# undef TMPL_GET_CPU_METHOD
[81071]260# define TMPL_GET_CPU_METHOD SUPGIPGETCPU_APIC_ID_EXT_0B
261# undef rtTimeNanoTSInternalRef
262# define rtTimeNanoTSInternalRef RTTimeNanoTSLFenceAsyncUseApicIdExt0B
263# include "timesupref.h"
264RT_EXPORT_SYMBOL(RTTimeNanoTSLFenceAsyncUseApicIdExt0B);
265
266# undef TMPL_MODE
267# define TMPL_MODE TMPL_MODE_ASYNC
268# undef TMPL_GET_CPU_METHOD
269# define TMPL_GET_CPU_METHOD SUPGIPGETCPU_APIC_ID_EXT_8000001E
270# undef rtTimeNanoTSInternalRef
271# define rtTimeNanoTSInternalRef RTTimeNanoTSLFenceAsyncUseApicIdExt8000001E
272# include "timesupref.h"
273RT_EXPORT_SYMBOL(RTTimeNanoTSLFenceAsyncUseApicIdExt8000001E);
274
275# undef TMPL_GET_CPU_METHOD
[54270]276# define TMPL_GET_CPU_METHOD SUPGIPGETCPU_RDTSCP_MASK_MAX_SET_CPUS
277# undef rtTimeNanoTSInternalRef
278# define rtTimeNanoTSInternalRef RTTimeNanoTSLFenceAsyncUseRdtscp
279# include "timesupref.h"
280RT_EXPORT_SYMBOL(RTTimeNanoTSLFenceAsyncUseRdtscp);
281
282# undef TMPL_GET_CPU_METHOD
283# define TMPL_GET_CPU_METHOD SUPGIPGETCPU_IDTR_LIMIT_MASK_MAX_SET_CPUS
284# undef rtTimeNanoTSInternalRef
285# define rtTimeNanoTSInternalRef RTTimeNanoTSLFenceAsyncUseIdtrLim
286# include "timesupref.h"
287RT_EXPORT_SYMBOL(RTTimeNanoTSLFenceAsyncUseIdtrLim);
288
[64255]289# undef TMPL_GET_CPU_METHOD
290# define TMPL_GET_CPU_METHOD SUPGIPGETCPU_RDTSCP_GROUP_IN_CH_NUMBER_IN_CL
291# undef rtTimeNanoTSInternalRef
292# define rtTimeNanoTSInternalRef RTTimeNanoTSLFenceAsyncUseRdtscpGroupChNumCl
293# include "timesupref.h"
294RT_EXPORT_SYMBOL(RTTimeNanoTSLFenceAsyncUseRdtscpGroupChNumCl);
295
[54270]296#else /* IN_RC || IN_RING0: Disable interrupts and call getter function. */
297
298# undef TMPL_MODE
299# define TMPL_MODE TMPL_MODE_SYNC_INVAR_WITH_DELTA
300# undef TMPL_GET_CPU_METHOD
301# define TMPL_GET_CPU_METHOD UINT32_MAX
302# undef rtTimeNanoTSInternalRef
303# define rtTimeNanoTSInternalRef RTTimeNanoTSLFenceSyncInvarWithDelta
304# include "timesupref.h"
305RT_EXPORT_SYMBOL(RTTimeNanoTSLFenceSyncInvarWithDelta);
306
307# undef TMPL_MODE
308# define TMPL_MODE TMPL_MODE_ASYNC
309# undef rtTimeNanoTSInternalRef
310# define rtTimeNanoTSInternalRef RTTimeNanoTSLFenceAsync
311# include "timesupref.h"
[21337]312RT_EXPORT_SYMBOL(RTTimeNanoTSLFenceAsync);
[5456]313
[54270]314#endif
[5456]315
[54202]316
[29267]317#endif /* !IN_GUEST && !RT_NO_GIP */
[21337]318
Note: See TracBrowser for help on using the repository browser.

© 2023 Oracle
ContactPrivacy policyTerms of Use