VirtualBox

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

Last change on this file since 57181 was 54270, checked in by vboxsync, 10 years ago

IPRT,TM: Implemented the get-cpu-number optimizations for the RTTimeNanoTS code.

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