VirtualBox

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

Last change on this file since 76389 was 76389, checked in by vboxsync, 6 years ago

VBox/sup.h: Don't include VBox/err.h for no good reason. bugref:9344

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id Revision
File size: 8.4 KB
Line 
1/* $Id: timesupref.cpp 76389 2018-12-23 01:39:48Z 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 <iprt/string.h>
41#include <VBox/sup.h>
42#ifdef IN_RC
43# include <VBox/vmm/vmm.h>
44# include <VBox/vmm/vm.h>
45#endif
46#include "internal/time.h"
47
48
49#define TMPL_MODE_SYNC_INVAR_NO_DELTA 1
50#define TMPL_MODE_SYNC_INVAR_WITH_DELTA 2
51#define TMPL_MODE_ASYNC 3
52
53
54/*
55 * Use the XCHG instruction for some kind of serialization.
56 */
57#define TMPL_READ_FENCE() ASMReadFence()
58
59#undef TMPL_MODE
60#define TMPL_MODE TMPL_MODE_SYNC_INVAR_NO_DELTA
61#undef TMPL_GET_CPU_METHOD
62#define TMPL_GET_CPU_METHOD 0
63#undef rtTimeNanoTSInternalRef
64#define rtTimeNanoTSInternalRef RTTimeNanoTSLegacySyncInvarNoDelta
65#include "timesupref.h"
66RT_EXPORT_SYMBOL(RTTimeNanoTSLegacySyncInvarNoDelta);
67
68#ifdef IN_RING3
69
70# undef TMPL_MODE
71# define TMPL_MODE TMPL_MODE_SYNC_INVAR_WITH_DELTA
72# undef TMPL_GET_CPU_METHOD
73# define TMPL_GET_CPU_METHOD SUPGIPGETCPU_APIC_ID
74# undef rtTimeNanoTSInternalRef
75# define rtTimeNanoTSInternalRef RTTimeNanoTSLegacySyncInvarWithDeltaUseApicId
76# include "timesupref.h"
77RT_EXPORT_SYMBOL(RTTimeNanoTSLegacySyncInvarWithDeltaUseApicId);
78
79# undef TMPL_GET_CPU_METHOD
80# define TMPL_GET_CPU_METHOD SUPGIPGETCPU_RDTSCP_MASK_MAX_SET_CPUS
81# undef rtTimeNanoTSInternalRef
82# define rtTimeNanoTSInternalRef RTTimeNanoTSLegacySyncInvarWithDeltaUseRdtscp
83# include "timesupref.h"
84RT_EXPORT_SYMBOL(RTTimeNanoTSLegacySyncInvarWithDeltaUseRdtscp);
85
86# undef TMPL_GET_CPU_METHOD
87# define TMPL_GET_CPU_METHOD SUPGIPGETCPU_IDTR_LIMIT_MASK_MAX_SET_CPUS
88# undef rtTimeNanoTSInternalRef
89# define rtTimeNanoTSInternalRef RTTimeNanoTSLegacySyncInvarWithDeltaUseIdtrLim
90# include "timesupref.h"
91RT_EXPORT_SYMBOL(RTTimeNanoTSLegacySyncInvarWithDeltaUseIdtrLim);
92
93# undef TMPL_MODE
94# define TMPL_MODE TMPL_MODE_ASYNC
95# undef TMPL_GET_CPU_METHOD
96# define TMPL_GET_CPU_METHOD SUPGIPGETCPU_APIC_ID
97# undef rtTimeNanoTSInternalRef
98# define rtTimeNanoTSInternalRef RTTimeNanoTSLegacyAsyncUseApicId
99# include "timesupref.h"
100RT_EXPORT_SYMBOL(RTTimeNanoTSLegacyAsyncUseApicId);
101
102# undef TMPL_GET_CPU_METHOD
103# define TMPL_GET_CPU_METHOD SUPGIPGETCPU_RDTSCP_MASK_MAX_SET_CPUS
104# undef rtTimeNanoTSInternalRef
105# define rtTimeNanoTSInternalRef RTTimeNanoTSLegacyAsyncUseRdtscp
106# include "timesupref.h"
107RT_EXPORT_SYMBOL(RTTimeNanoTSLegacyAsyncUseRdtscp);
108
109# undef TMPL_GET_CPU_METHOD
110# define TMPL_GET_CPU_METHOD SUPGIPGETCPU_IDTR_LIMIT_MASK_MAX_SET_CPUS
111# undef rtTimeNanoTSInternalRef
112# define rtTimeNanoTSInternalRef RTTimeNanoTSLegacyAsyncUseIdtrLim
113# include "timesupref.h"
114RT_EXPORT_SYMBOL(RTTimeNanoTSLegacyAsyncUseIdtrLim);
115
116# undef TMPL_GET_CPU_METHOD
117# define TMPL_GET_CPU_METHOD SUPGIPGETCPU_RDTSCP_GROUP_IN_CH_NUMBER_IN_CL
118# undef rtTimeNanoTSInternalRef
119# define rtTimeNanoTSInternalRef RTTimeNanoTSLegacyAsyncUseRdtscpGroupChNumCl
120# include "timesupref.h"
121RT_EXPORT_SYMBOL(RTTimeNanoTSLegacyAsyncUseRdtscpGroupChNumCl);
122
123#else /* IN_RC || IN_RING0: Disable interrupts and call getter function. */
124
125# undef TMPL_MODE
126# define TMPL_MODE TMPL_MODE_SYNC_INVAR_WITH_DELTA
127# undef TMPL_GET_CPU_METHOD
128# define TMPL_GET_CPU_METHOD UINT32_MAX
129# undef rtTimeNanoTSInternalRef
130# define rtTimeNanoTSInternalRef RTTimeNanoTSLegacySyncInvarWithDelta
131# include "timesupref.h"
132RT_EXPORT_SYMBOL(RTTimeNanoTSLegacySyncInvarWithDelta);
133
134# undef TMPL_MODE
135# define TMPL_MODE TMPL_MODE_ASYNC
136# undef rtTimeNanoTSInternalRef
137# define rtTimeNanoTSInternalRef RTTimeNanoTSLegacyAsync
138# include "timesupref.h"
139RT_EXPORT_SYMBOL(RTTimeNanoTSLegacyAsync);
140
141#endif
142
143
144/*
145 * Use LFENCE for load serialization.
146 */
147#undef TMPL_READ_FENCE
148#define TMPL_READ_FENCE() ASMReadFenceSSE2()
149
150#undef TMPL_MODE
151#define TMPL_MODE TMPL_MODE_SYNC_INVAR_NO_DELTA
152#undef TMPL_GET_CPU_METHOD
153#define TMPL_GET_CPU_METHOD 0
154#undef rtTimeNanoTSInternalRef
155#define rtTimeNanoTSInternalRef RTTimeNanoTSLFenceSyncInvarNoDelta
156#include "timesupref.h"
157RT_EXPORT_SYMBOL(RTTimeNanoTSLFenceSyncInvarNoDelta);
158
159#ifdef IN_RING3
160
161# undef TMPL_MODE
162# define TMPL_MODE TMPL_MODE_SYNC_INVAR_WITH_DELTA
163# undef TMPL_GET_CPU_METHOD
164# define TMPL_GET_CPU_METHOD SUPGIPGETCPU_APIC_ID
165# undef rtTimeNanoTSInternalRef
166# define rtTimeNanoTSInternalRef RTTimeNanoTSLFenceSyncInvarWithDeltaUseApicId
167# include "timesupref.h"
168RT_EXPORT_SYMBOL(RTTimeNanoTSLFenceSyncInvarWithDeltaUseApicId);
169
170# undef TMPL_GET_CPU_METHOD
171# define TMPL_GET_CPU_METHOD SUPGIPGETCPU_RDTSCP_MASK_MAX_SET_CPUS
172# undef rtTimeNanoTSInternalRef
173# define rtTimeNanoTSInternalRef RTTimeNanoTSLFenceSyncInvarWithDeltaUseRdtscp
174# include "timesupref.h"
175RT_EXPORT_SYMBOL(RTTimeNanoTSLFenceSyncInvarWithDeltaUseRdtscp);
176
177# undef TMPL_GET_CPU_METHOD
178# define TMPL_GET_CPU_METHOD SUPGIPGETCPU_IDTR_LIMIT_MASK_MAX_SET_CPUS
179# undef rtTimeNanoTSInternalRef
180# define rtTimeNanoTSInternalRef RTTimeNanoTSLFenceSyncInvarWithDeltaUseIdtrLim
181# include "timesupref.h"
182RT_EXPORT_SYMBOL(RTTimeNanoTSLFenceSyncInvarWithDeltaUseIdtrLim);
183
184# undef TMPL_MODE
185# define TMPL_MODE TMPL_MODE_ASYNC
186# undef TMPL_GET_CPU_METHOD
187# define TMPL_GET_CPU_METHOD SUPGIPGETCPU_APIC_ID
188# undef rtTimeNanoTSInternalRef
189# define rtTimeNanoTSInternalRef RTTimeNanoTSLFenceAsyncUseApicId
190# include "timesupref.h"
191RT_EXPORT_SYMBOL(RTTimeNanoTSLFenceAsyncUseApicId);
192
193# undef TMPL_GET_CPU_METHOD
194# define TMPL_GET_CPU_METHOD SUPGIPGETCPU_RDTSCP_MASK_MAX_SET_CPUS
195# undef rtTimeNanoTSInternalRef
196# define rtTimeNanoTSInternalRef RTTimeNanoTSLFenceAsyncUseRdtscp
197# include "timesupref.h"
198RT_EXPORT_SYMBOL(RTTimeNanoTSLFenceAsyncUseRdtscp);
199
200# undef TMPL_GET_CPU_METHOD
201# define TMPL_GET_CPU_METHOD SUPGIPGETCPU_IDTR_LIMIT_MASK_MAX_SET_CPUS
202# undef rtTimeNanoTSInternalRef
203# define rtTimeNanoTSInternalRef RTTimeNanoTSLFenceAsyncUseIdtrLim
204# include "timesupref.h"
205RT_EXPORT_SYMBOL(RTTimeNanoTSLFenceAsyncUseIdtrLim);
206
207# undef TMPL_GET_CPU_METHOD
208# define TMPL_GET_CPU_METHOD SUPGIPGETCPU_RDTSCP_GROUP_IN_CH_NUMBER_IN_CL
209# undef rtTimeNanoTSInternalRef
210# define rtTimeNanoTSInternalRef RTTimeNanoTSLFenceAsyncUseRdtscpGroupChNumCl
211# include "timesupref.h"
212RT_EXPORT_SYMBOL(RTTimeNanoTSLFenceAsyncUseRdtscpGroupChNumCl);
213
214#else /* IN_RC || IN_RING0: Disable interrupts and call getter function. */
215
216# undef TMPL_MODE
217# define TMPL_MODE TMPL_MODE_SYNC_INVAR_WITH_DELTA
218# undef TMPL_GET_CPU_METHOD
219# define TMPL_GET_CPU_METHOD UINT32_MAX
220# undef rtTimeNanoTSInternalRef
221# define rtTimeNanoTSInternalRef RTTimeNanoTSLFenceSyncInvarWithDelta
222# include "timesupref.h"
223RT_EXPORT_SYMBOL(RTTimeNanoTSLFenceSyncInvarWithDelta);
224
225# undef TMPL_MODE
226# define TMPL_MODE TMPL_MODE_ASYNC
227# undef rtTimeNanoTSInternalRef
228# define rtTimeNanoTSInternalRef RTTimeNanoTSLFenceAsync
229# include "timesupref.h"
230RT_EXPORT_SYMBOL(RTTimeNanoTSLFenceAsync);
231
232#endif
233
234
235#endif /* !IN_GUEST && !RT_NO_GIP */
236
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