VirtualBox

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

Last change on this file was 108964, checked in by vboxsync, 4 weeks ago

VMM/GVMM: Eliminted IN_GVMM_R0.

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

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette