1 | /* $Id: gvmm.h 91287 2021-09-16 21:30:45Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * GVMM - The Global VM Manager.
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2007-2020 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 | #ifndef VBOX_INCLUDED_vmm_gvmm_h
|
---|
28 | #define VBOX_INCLUDED_vmm_gvmm_h
|
---|
29 | #ifndef RT_WITHOUT_PRAGMA_ONCE
|
---|
30 | # pragma once
|
---|
31 | #endif
|
---|
32 |
|
---|
33 | #include <VBox/types.h>
|
---|
34 | #include <VBox/sup.h>
|
---|
35 | #include <iprt/cpuset.h> /* RTCPUSET_MAX_CPUS */
|
---|
36 |
|
---|
37 |
|
---|
38 | RT_C_DECLS_BEGIN
|
---|
39 |
|
---|
40 | /** @defgroup grp_gvmm GVMM - The Global VM Manager.
|
---|
41 | * @ingroup grp_vmm
|
---|
42 | * @{
|
---|
43 | */
|
---|
44 |
|
---|
45 | /** @def IN_GVMM_R0
|
---|
46 | * Used to indicate whether we're inside the same link module as the ring 0
|
---|
47 | * part of the Global VM Manager or not.
|
---|
48 | */
|
---|
49 | #ifdef DOXYGEN_RUNNING
|
---|
50 | # define IN_GVMM_R0
|
---|
51 | #endif
|
---|
52 | /** @def GVMMR0DECL
|
---|
53 | * Ring 0 VM export or import declaration.
|
---|
54 | * @param type The return type of the function declaration.
|
---|
55 | */
|
---|
56 | #ifdef IN_GVMM_R0
|
---|
57 | # define GVMMR0DECL(type) DECLEXPORT(type) VBOXCALL
|
---|
58 | #else
|
---|
59 | # define GVMMR0DECL(type) DECLIMPORT(type) VBOXCALL
|
---|
60 | #endif
|
---|
61 |
|
---|
62 | /** @def NIL_GVM_HANDLE
|
---|
63 | * The nil GVM VM handle value (VM::hSelf).
|
---|
64 | */
|
---|
65 | #define NIL_GVM_HANDLE 0
|
---|
66 |
|
---|
67 |
|
---|
68 | /**
|
---|
69 | * The scheduler statistics
|
---|
70 | */
|
---|
71 | typedef struct GVMMSTATSSCHED
|
---|
72 | {
|
---|
73 | /** The number of calls to GVMMR0SchedHalt. */
|
---|
74 | uint64_t cHaltCalls;
|
---|
75 | /** The number of times we did go to sleep in GVMMR0SchedHalt. */
|
---|
76 | uint64_t cHaltBlocking;
|
---|
77 | /** The number of times we timed out in GVMMR0SchedHalt. */
|
---|
78 | uint64_t cHaltTimeouts;
|
---|
79 | /** The number of times we didn't go to sleep in GVMMR0SchedHalt. */
|
---|
80 | uint64_t cHaltNotBlocking;
|
---|
81 | /** The number of wake ups done during GVMMR0SchedHalt. */
|
---|
82 | uint64_t cHaltWakeUps;
|
---|
83 |
|
---|
84 | /** The number of calls to GVMMR0WakeUp. */
|
---|
85 | uint64_t cWakeUpCalls;
|
---|
86 | /** The number of times the EMT thread wasn't actually halted when GVMMR0WakeUp
|
---|
87 | * was called. */
|
---|
88 | uint64_t cWakeUpNotHalted;
|
---|
89 | /** The number of wake ups done during GVMMR0WakeUp (not counting the explicit
|
---|
90 | * one). */
|
---|
91 | uint64_t cWakeUpWakeUps;
|
---|
92 |
|
---|
93 | /** The number of calls to GVMMR0Poke. */
|
---|
94 | uint64_t cPokeCalls;
|
---|
95 | /** The number of times the EMT thread wasn't actually busy when
|
---|
96 | * GVMMR0Poke was called. */
|
---|
97 | uint64_t cPokeNotBusy;
|
---|
98 |
|
---|
99 | /** The number of calls to GVMMR0SchedPoll. */
|
---|
100 | uint64_t cPollCalls;
|
---|
101 | /** The number of times the EMT has halted in a GVMMR0SchedPoll call. */
|
---|
102 | uint64_t cPollHalts;
|
---|
103 | /** The number of wake ups done during GVMMR0SchedPoll. */
|
---|
104 | uint64_t cPollWakeUps;
|
---|
105 |
|
---|
106 | uint64_t u64Alignment; /**< padding */
|
---|
107 | } GVMMSTATSSCHED;
|
---|
108 | /** Pointer to the GVMM scheduler statistics. */
|
---|
109 | typedef GVMMSTATSSCHED *PGVMMSTATSSCHED;
|
---|
110 |
|
---|
111 | /**
|
---|
112 | * Per host cpu statistics.
|
---|
113 | */
|
---|
114 | typedef struct GVMMSTATSHOSTCPU
|
---|
115 | {
|
---|
116 | /** The CPU ID. */
|
---|
117 | RTCPUID idCpu;
|
---|
118 | /** The CPU's set index. */
|
---|
119 | uint32_t idxCpuSet;
|
---|
120 | /** The desired PPT frequency. */
|
---|
121 | uint32_t uDesiredHz;
|
---|
122 | /** The current PPT timer frequency. */
|
---|
123 | uint32_t uTimerHz;
|
---|
124 | /** The number of times the PPT was changed. */
|
---|
125 | uint32_t cChanges;
|
---|
126 | /** The number of times the PPT was started. */
|
---|
127 | uint32_t cStarts;
|
---|
128 | } GVMMSTATSHOSTCPU;
|
---|
129 | /** Pointer to the GVMM per host CPU statistics. */
|
---|
130 | typedef GVMMSTATSHOSTCPU *PGVMMSTATSHOSTCPU;
|
---|
131 |
|
---|
132 | /**
|
---|
133 | * The GVMM statistics.
|
---|
134 | */
|
---|
135 | typedef struct GVMMSTATS
|
---|
136 | {
|
---|
137 | /** The VM statistics if a VM was specified. */
|
---|
138 | GVMMSTATSSCHED SchedVM;
|
---|
139 | /** The sum statistics of all VMs accessible to the caller. */
|
---|
140 | GVMMSTATSSCHED SchedSum;
|
---|
141 | /** The number of VMs accessible to the caller. */
|
---|
142 | uint32_t cVMs;
|
---|
143 | /** The number of emulation threads in those VMs. */
|
---|
144 | uint32_t cEMTs;
|
---|
145 | /** Padding. */
|
---|
146 | uint32_t u32Padding;
|
---|
147 | /** The number of valid entries in aHostCpus. */
|
---|
148 | uint32_t cHostCpus;
|
---|
149 | /** Per host CPU statistics. */
|
---|
150 | GVMMSTATSHOSTCPU aHostCpus[RTCPUSET_MAX_CPUS];
|
---|
151 | } GVMMSTATS;
|
---|
152 | /** Pointer to the GVMM statistics. */
|
---|
153 | typedef GVMMSTATS *PGVMMSTATS;
|
---|
154 | /** Const pointer to the GVMM statistics. */
|
---|
155 | typedef const GVMMSTATS *PCGVMMSTATS;
|
---|
156 |
|
---|
157 | /**
|
---|
158 | * Per-VM callback for GVMMR0EnumVMs.
|
---|
159 | *
|
---|
160 | * @note This is called while holding the VM used list lock, so only suitable
|
---|
161 | * for quick and simple jobs!
|
---|
162 | *
|
---|
163 | * @returns VINF_SUCCESS to continue the enumeration, anything stops it and
|
---|
164 | * returns the status code.
|
---|
165 | * @param pGVM The VM
|
---|
166 | * @param pvUser The user parameter.
|
---|
167 | * */
|
---|
168 | typedef DECLCALLBACKTYPE(int, FNGVMMR0ENUMCALLBACK,(PGVM pGVM, void *pvUser));
|
---|
169 | /** Pointer to an VM enumeration callback function. */
|
---|
170 | typedef FNGVMMR0ENUMCALLBACK *PFNGVMMR0ENUMCALLBACK;
|
---|
171 |
|
---|
172 |
|
---|
173 | GVMMR0DECL(int) GVMMR0Init(void);
|
---|
174 | GVMMR0DECL(void) GVMMR0Term(void);
|
---|
175 | GVMMR0DECL(int) GVMMR0SetConfig(PSUPDRVSESSION pSession, const char *pszName, uint64_t u64Value);
|
---|
176 | GVMMR0DECL(int) GVMMR0QueryConfig(PSUPDRVSESSION pSession, const char *pszName, uint64_t *pu64Value);
|
---|
177 |
|
---|
178 | GVMMR0DECL(int) GVMMR0CreateVM(PSUPDRVSESSION pSession, uint32_t cCpus, PVMCC *ppVM);
|
---|
179 | GVMMR0DECL(int) GVMMR0InitVM(PGVM pGVM);
|
---|
180 | GVMMR0DECL(void) GVMMR0DoneInitVM(PGVM pGVM);
|
---|
181 | GVMMR0DECL(bool) GVMMR0DoingTermVM(PGVM pGVM);
|
---|
182 | GVMMR0DECL(int) GVMMR0DestroyVM(PGVM pGVM);
|
---|
183 | GVMMR0DECL(int) GVMMR0RegisterVCpu(PGVM pGVM, VMCPUID idCpu);
|
---|
184 | GVMMR0DECL(int) GVMMR0DeregisterVCpu(PGVM pGVM, VMCPUID idCpu);
|
---|
185 | GVMMR0DECL(PGVM) GVMMR0ByHandle(uint32_t hGVM);
|
---|
186 | GVMMR0DECL(int) GVMMR0ValidateGVM(PGVM pGVM);
|
---|
187 | GVMMR0DECL(int) GVMMR0ValidateGVMandEMT(PGVM pGVM, VMCPUID idCpu);
|
---|
188 | GVMMR0DECL(PVMCC) GVMMR0GetVMByEMT(RTNATIVETHREAD hEMT);
|
---|
189 | GVMMR0DECL(PGVMCPU) GVMMR0GetGVCpuByEMT(RTNATIVETHREAD hEMT);
|
---|
190 | GVMMR0DECL(PGVMCPU) GVMMR0GetGVCpuByGVMandEMT(PGVM pGVM, RTNATIVETHREAD hEMT);
|
---|
191 | GVMMR0DECL(RTHCPHYS) GVMMR0ConvertGVMPtr2HCPhys(PGVM pGVM, void *pv);
|
---|
192 | GVMMR0DECL(int) GVMMR0SchedHalt(PGVM pGVM, PGVMCPU pGVCpu, uint64_t u64ExpireGipTime);
|
---|
193 | GVMMR0DECL(int) GVMMR0SchedHaltReq(PGVM pGVM, VMCPUID idCpu, uint64_t u64ExpireGipTime);
|
---|
194 | GVMMR0DECL(int) GVMMR0SchedWakeUp(PGVM pGVM, VMCPUID idCpu);
|
---|
195 | GVMMR0DECL(int) GVMMR0SchedWakeUpEx(PGVM pGVM, VMCPUID idCpu, bool fTakeUsedLock);
|
---|
196 | GVMMR0DECL(int) GVMMR0SchedWakeUpNoGVMNoLock(PGVM pGVM, VMCPUID idCpu);
|
---|
197 | GVMMR0DECL(int) GVMMR0SchedPoke(PGVM pGVM, VMCPUID idCpu);
|
---|
198 | GVMMR0DECL(int) GVMMR0SchedPokeEx(PGVM pGVM, VMCPUID idCpu, bool fTakeUsedLock);
|
---|
199 | GVMMR0DECL(int) GVMMR0SchedPokeNoGVMNoLock(PVMCC pVM, VMCPUID idCpu);
|
---|
200 | GVMMR0DECL(int) GVMMR0SchedWakeUpAndPokeCpus(PGVM pGVM, PCVMCPUSET pSleepSet, PCVMCPUSET pPokeSet);
|
---|
201 | GVMMR0DECL(int) GVMMR0SchedPoll(PGVM pGVM, VMCPUID idCpu, bool fYield);
|
---|
202 | GVMMR0DECL(void) GVMMR0SchedUpdatePeriodicPreemptionTimer(PGVM pGVM, RTCPUID idHostCpu, uint32_t uHz);
|
---|
203 | GVMMR0DECL(int) GVMMR0EnumVMs(PFNGVMMR0ENUMCALLBACK pfnCallback, void *pvUser);
|
---|
204 | GVMMR0DECL(int) GVMMR0QueryStatistics(PGVMMSTATS pStats, PSUPDRVSESSION pSession, PGVM pGVM);
|
---|
205 | GVMMR0DECL(int) GVMMR0ResetStatistics(PCGVMMSTATS pStats, PSUPDRVSESSION pSession, PGVM pGVM);
|
---|
206 |
|
---|
207 |
|
---|
208 | /**
|
---|
209 | * Request packet for calling GVMMR0CreateVM.
|
---|
210 | */
|
---|
211 | typedef struct GVMMCREATEVMREQ
|
---|
212 | {
|
---|
213 | /** The request header. */
|
---|
214 | SUPVMMR0REQHDR Hdr;
|
---|
215 | /** The support driver session. (IN) */
|
---|
216 | PSUPDRVSESSION pSession;
|
---|
217 | /** Number of virtual CPUs for the new VM. (IN) */
|
---|
218 | uint32_t cCpus;
|
---|
219 | /** Pointer to the ring-3 mapping of the shared VM structure on return. (OUT) */
|
---|
220 | PVMR3 pVMR3;
|
---|
221 | /** Pointer to the ring-0 mapping of the shared VM structure on return. (OUT) */
|
---|
222 | PVMR0 pVMR0;
|
---|
223 | } GVMMCREATEVMREQ;
|
---|
224 | /** Pointer to a GVMMR0CreateVM request packet. */
|
---|
225 | typedef GVMMCREATEVMREQ *PGVMMCREATEVMREQ;
|
---|
226 |
|
---|
227 | GVMMR0DECL(int) GVMMR0CreateVMReq(PGVMMCREATEVMREQ pReq, PSUPDRVSESSION pSession);
|
---|
228 |
|
---|
229 |
|
---|
230 | /**
|
---|
231 | * Request buffer for GVMMR0SchedWakeUpAndPokeCpusReq / VMMR0_DO_GVMM_SCHED_WAKE_UP_AND_POKE_CPUS.
|
---|
232 | * @see GVMMR0SchedWakeUpAndPokeCpus.
|
---|
233 | */
|
---|
234 | typedef struct GVMMSCHEDWAKEUPANDPOKECPUSREQ /* nice and unreadable... */
|
---|
235 | {
|
---|
236 | /** The header. */
|
---|
237 | SUPVMMR0REQHDR Hdr;
|
---|
238 | /** The sleeper set. */
|
---|
239 | VMCPUSET SleepSet;
|
---|
240 | /** The set of virtual CPUs to poke. */
|
---|
241 | VMCPUSET PokeSet;
|
---|
242 | } GVMMSCHEDWAKEUPANDPOKECPUSREQ;
|
---|
243 | /** Pointer to a GVMMR0QueryStatisticsReq / VMMR0_DO_GVMM_QUERY_STATISTICS request buffer. */
|
---|
244 | typedef GVMMSCHEDWAKEUPANDPOKECPUSREQ *PGVMMSCHEDWAKEUPANDPOKECPUSREQ;
|
---|
245 |
|
---|
246 | GVMMR0DECL(int) GVMMR0SchedWakeUpAndPokeCpusReq(PGVM pGVM, PGVMMSCHEDWAKEUPANDPOKECPUSREQ pReq);
|
---|
247 |
|
---|
248 |
|
---|
249 | /**
|
---|
250 | * Request buffer for GVMMR0QueryStatisticsReq / VMMR0_DO_GVMM_QUERY_STATISTICS.
|
---|
251 | * @see GVMMR0QueryStatistics.
|
---|
252 | */
|
---|
253 | typedef struct GVMMQUERYSTATISTICSSREQ
|
---|
254 | {
|
---|
255 | /** The header. */
|
---|
256 | SUPVMMR0REQHDR Hdr;
|
---|
257 | /** The support driver session. */
|
---|
258 | PSUPDRVSESSION pSession;
|
---|
259 | /** The statistics. */
|
---|
260 | GVMMSTATS Stats;
|
---|
261 | } GVMMQUERYSTATISTICSSREQ;
|
---|
262 | /** Pointer to a GVMMR0QueryStatisticsReq / VMMR0_DO_GVMM_QUERY_STATISTICS request buffer. */
|
---|
263 | typedef GVMMQUERYSTATISTICSSREQ *PGVMMQUERYSTATISTICSSREQ;
|
---|
264 |
|
---|
265 | GVMMR0DECL(int) GVMMR0QueryStatisticsReq(PGVM pGVM, PGVMMQUERYSTATISTICSSREQ pReq, PSUPDRVSESSION pSession);
|
---|
266 |
|
---|
267 |
|
---|
268 | /**
|
---|
269 | * Request buffer for GVMMR0ResetStatisticsReq / VMMR0_DO_GVMM_RESET_STATISTICS.
|
---|
270 | * @see GVMMR0ResetStatistics.
|
---|
271 | */
|
---|
272 | typedef struct GVMMRESETSTATISTICSSREQ
|
---|
273 | {
|
---|
274 | /** The header. */
|
---|
275 | SUPVMMR0REQHDR Hdr;
|
---|
276 | /** The support driver session. */
|
---|
277 | PSUPDRVSESSION pSession;
|
---|
278 | /** The statistics to reset.
|
---|
279 | * Any non-zero entry will be reset (if permitted). */
|
---|
280 | GVMMSTATS Stats;
|
---|
281 | } GVMMRESETSTATISTICSSREQ;
|
---|
282 | /** Pointer to a GVMMR0ResetStatisticsReq / VMMR0_DO_GVMM_RESET_STATISTICS request buffer. */
|
---|
283 | typedef GVMMRESETSTATISTICSSREQ *PGVMMRESETSTATISTICSSREQ;
|
---|
284 |
|
---|
285 | GVMMR0DECL(int) GVMMR0ResetStatisticsReq(PGVM pGVM, PGVMMRESETSTATISTICSSREQ pReq, PSUPDRVSESSION pSession);
|
---|
286 |
|
---|
287 |
|
---|
288 | /** @} */
|
---|
289 |
|
---|
290 | RT_C_DECLS_END
|
---|
291 |
|
---|
292 | #endif /* !VBOX_INCLUDED_vmm_gvmm_h */
|
---|
293 |
|
---|