VirtualBox

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

Last change on this file since 57944 was 57358, checked in by vboxsync, 9 years ago

*: scm cleanup run.

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