VirtualBox

source: vbox/trunk/include/VBox/vmm/gvmm.h@ 93593

Last change on this file since 93593 was 93115, checked in by vboxsync, 3 years ago

scm --update-copyright-year

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