VirtualBox

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

Last change on this file since 99897 was 98103, checked in by vboxsync, 23 months ago

Copyright year updates by scm.

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