VirtualBox

source: vbox/trunk/include/VBox/vmm/gvm.h@ 90828

Last change on this file since 90828 was 90597, checked in by vboxsync, 3 years ago

VMM: Speed up VMMGetCpu in ring-0 by using hash table (via new GVMMR0GetGVCpuByGVMandEMT call). bugref:6695

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id Revision
File size: 9.3 KB
Line 
1/* $Id: gvm.h 90597 2021-08-10 13:08:35Z vboxsync $ */
2/** @file
3 * GVM - The Global VM Data.
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_gvm_h
28#define VBOX_INCLUDED_vmm_gvm_h
29#ifndef RT_WITHOUT_PRAGMA_ONCE
30# pragma once
31#endif
32
33#ifndef USING_VMM_COMMON_DEFS
34# error "Compile job does not include VMM_COMMON_DEFS from src/VBox/Config.kmk - make sure you really need to include this file!"
35#endif
36#include <VBox/types.h>
37#include <VBox/vmm/vm.h>
38#include <VBox/param.h>
39#include <iprt/thread.h>
40#include <iprt/assertcompile.h>
41
42
43/** @defgroup grp_gvmcpu GVMCPU - The Global VMCPU Data
44 * @ingroup grp_vmm
45 * @{
46 */
47
48#if defined(__cplusplus) && !defined(GVM_C_STYLE_STRUCTURES)
49typedef struct GVMCPU : public VMCPU
50#else
51typedef struct GVMCPU
52#endif
53{
54#if !defined(__cplusplus) || defined(GVM_C_STYLE_STRUCTURES)
55 VMCPU s;
56#endif
57
58 /** VCPU id (0 - (pVM->cCpus - 1). */
59 VMCPUID idCpu;
60 /** Padding. */
61 uint32_t uPadding0;
62
63 /** Handle to the EMT thread. */
64 RTNATIVETHREAD hEMT;
65
66 /** Pointer to the global (ring-0) VM structure this CPU belongs to. */
67 R0PTRTYPE(PGVM) pGVM;
68 /** Pointer to the GVM structure, for CTX_SUFF use in VMMAll code. */
69 PGVM pVMR0;
70 /** The ring-3 address of this structure (only VMCPU part). */
71 PVMCPUR3 pVCpuR3;
72
73 /** Padding so the noisy stuff on a 64 byte boundrary.
74 * @note Keeping this working for 32-bit header syntax checking. */
75 uint8_t abPadding1[HC_ARCH_BITS == 32 ? 40 : 24];
76
77 /** Which host CPU ID is this EMT running on.
78 * Only valid when in RC or HMR0 with scheduling disabled. */
79 RTCPUID volatile idHostCpu;
80 /** The CPU set index corresponding to idHostCpu, UINT32_MAX if not valid.
81 * @remarks Best to make sure iHostCpuSet shares cache line with idHostCpu! */
82 uint32_t volatile iHostCpuSet;
83
84 /** Padding so gvmm starts on a 64 byte boundrary.
85 * @note Keeping this working for 32-bit header syntax checking. */
86 uint8_t abPadding2[56];
87
88 /** The GVMM per vcpu data. */
89 union
90 {
91#ifdef VMM_INCLUDED_SRC_VMMR0_GVMMR0Internal_h
92 struct GVMMPERVCPU s;
93#endif
94 uint8_t padding[64];
95 } gvmm;
96
97 /** The HM per vcpu data. */
98 union
99 {
100#if defined(VMM_INCLUDED_SRC_include_HMInternal_h) && defined(IN_RING0)
101 struct HMR0PERVCPU s;
102#endif
103 uint8_t padding[1024];
104 } hmr0;
105
106#ifdef VBOX_WITH_NEM_R0
107 /** The NEM per vcpu data. */
108 union
109 {
110# if defined(VMM_INCLUDED_SRC_include_NEMInternal_h) && defined(IN_RING0)
111 struct NEMR0PERVCPU s;
112# endif
113 uint8_t padding[64];
114 } nemr0;
115#endif
116
117 union
118 {
119#if defined(VMM_INCLUDED_SRC_include_VMMInternal_h) && defined(IN_RING0)
120 struct VMMR0PERVCPU s;
121#endif
122 uint8_t padding[64];
123 } vmmr0;
124
125 /** Padding the structure size to page boundrary. */
126#ifdef VBOX_WITH_NEM_R0
127 uint8_t abPadding3[4096 - 64*2 - 64 - 1024 - 64 - 64];
128#else
129 uint8_t abPadding3[4096 - 64*2 - 64 - 1024 - 64];
130#endif
131} GVMCPU;
132#if RT_GNUC_PREREQ(4, 6) && defined(__cplusplus)
133# pragma GCC diagnostic push
134#endif
135#if RT_GNUC_PREREQ(4, 3) && defined(__cplusplus)
136# pragma GCC diagnostic ignored "-Winvalid-offsetof"
137#endif
138AssertCompileMemberAlignment(GVMCPU, idCpu, 4096);
139AssertCompileMemberAlignment(GVMCPU, gvmm, 64);
140#ifdef VBOX_WITH_NEM_R0
141AssertCompileMemberAlignment(GVMCPU, nemr0, 64);
142#endif
143AssertCompileSizeAlignment(GVMCPU, 4096);
144#if RT_GNUC_PREREQ(4, 6) && defined(__cplusplus)
145# pragma GCC diagnostic pop
146#endif
147
148/** @} */
149
150/** @defgroup grp_gvm GVM - The Global VM Data
151 * @ingroup grp_vmm
152 * @{
153 */
154
155/**
156 * The Global VM Data.
157 *
158 * This is a ring-0 only structure where we put items we don't need to
159 * share with ring-3 or GC, like for instance various RTR0MEMOBJ handles.
160 *
161 * Unlike VM, there are no special alignment restrictions here. The
162 * paddings are checked by compile time assertions.
163 */
164#if defined(__cplusplus) && !defined(GVM_C_STYLE_STRUCTURES)
165typedef struct GVM : public VM
166#else
167typedef struct GVM
168#endif
169{
170#if !defined(__cplusplus) || defined(GVM_C_STYLE_STRUCTURES)
171 VM s;
172#endif
173 /** Magic / eye-catcher (GVM_MAGIC). */
174 uint32_t u32Magic;
175 /** The global VM handle for this VM. */
176 uint32_t hSelf;
177 /** Pointer to this structure (for validation purposes). */
178 PGVM pSelf;
179 /** The ring-3 mapping of the VM structure. */
180 PVMR3 pVMR3;
181 /** The support driver session the VM is associated with. */
182 PSUPDRVSESSION pSession;
183 /** Number of Virtual CPUs, i.e. how many entries there are in aCpus.
184 * Same same as VM::cCpus. */
185 uint32_t cCpus;
186 /** Padding so gvmm starts on a 64 byte boundrary. */
187 uint8_t abPadding[HC_ARCH_BITS == 32 ? 12 + 28 : 28];
188
189 /** The GVMM per vm data. */
190 union
191 {
192#ifdef VMM_INCLUDED_SRC_VMMR0_GVMMR0Internal_h
193 struct GVMMPERVM s;
194#endif
195 uint8_t padding[4352];
196 } gvmm;
197
198 /** The GMM per vm data. */
199 union
200 {
201#ifdef VMM_INCLUDED_SRC_VMMR0_GMMR0Internal_h
202 struct GMMPERVM s;
203#endif
204 uint8_t padding[1024];
205 } gmm;
206
207 /** The HM per vm data. */
208 union
209 {
210#if defined(VMM_INCLUDED_SRC_include_HMInternal_h) && defined(IN_RING0)
211 struct HMR0PERVM s;
212#endif
213 uint8_t padding[256];
214 } hmr0;
215
216#ifdef VBOX_WITH_NEM_R0
217 /** The NEM per vcpu data. */
218 union
219 {
220# if defined(VMM_INCLUDED_SRC_include_NEMInternal_h) && defined(IN_RING0)
221 struct NEMR0PERVM s;
222# endif
223 uint8_t padding[256];
224 } nemr0;
225#endif
226
227 /** The RAWPCIVM per vm data. */
228 union
229 {
230#ifdef VBOX_INCLUDED_rawpci_h
231 struct RAWPCIPERVM s;
232#endif
233 uint8_t padding[64];
234 } rawpci;
235
236 union
237 {
238#if defined(VMM_INCLUDED_SRC_include_PDMInternal_h) && defined(IN_RING0)
239 struct PDMR0PERVM s;
240#endif
241 uint8_t padding[2176];
242 } pdmr0;
243
244 union
245 {
246#if defined(VMM_INCLUDED_SRC_include_PGMInternal_h) && defined(IN_RING0)
247 struct PGMR0PERVM s;
248#endif
249 uint8_t padding[640];
250 } pgmr0;
251
252 union
253 {
254#if defined(VMM_INCLUDED_SRC_include_IOMInternal_h) && defined(IN_RING0)
255 struct IOMR0PERVM s;
256#endif
257 uint8_t padding[512];
258 } iomr0;
259
260 union
261 {
262#if defined(VMM_INCLUDED_SRC_include_APICInternal_h) && defined(IN_RING0)
263 struct APICR0PERVM s;
264#endif
265 uint8_t padding[64];
266 } apicr0;
267
268 union
269 {
270#if defined(VMM_INCLUDED_SRC_include_DBGFInternal_h) && defined(IN_RING0)
271 struct DBGFR0PERVM s;
272#endif
273 uint8_t padding[1024];
274 } dbgfr0;
275
276 union
277 {
278#if defined(VMM_INCLUDED_SRC_include_TMInternal_h) && defined(IN_RING0)
279 TMR0PERVM s;
280#endif
281 uint8_t padding[128];
282 } tmr0;
283
284 /** Padding so aCpus starts on a page boundrary. */
285#ifdef VBOX_WITH_NEM_R0
286 uint8_t abPadding2[4096*2 - 64 - 256 - 256 - 1024 - 256 - 64 - 2176 - 640 - 512 - 64 - 1024 - 128 - sizeof(PGVMCPU) * VMM_MAX_CPU_COUNT];
287#else
288 uint8_t abPadding2[4096*2 - 64 - 256 - 256 - 1024 - 64 - 2176 - 640 - 512 - 64 - 1024 - 128 - sizeof(PGVMCPU) * VMM_MAX_CPU_COUNT];
289#endif
290
291 /** For simplifying CPU enumeration in VMMAll code. */
292 PGVMCPU apCpusR0[VMM_MAX_CPU_COUNT];
293
294 /** GVMCPU array for the configured number of virtual CPUs. */
295 GVMCPU aCpus[1];
296} GVM;
297#if 0
298#if RT_GNUC_PREREQ(4, 6) && defined(__cplusplus)
299# pragma GCC diagnostic push
300#endif
301#if RT_GNUC_PREREQ(4, 3) && defined(__cplusplus)
302# pragma GCC diagnostic ignored "-Winvalid-offsetof"
303#endif
304AssertCompileMemberAlignment(GVM, u32Magic, 64);
305AssertCompileMemberAlignment(GVM, gvmm, 64);
306AssertCompileMemberAlignment(GVM, gmm, 64);
307#ifdef VBOX_WITH_NEM_R0
308AssertCompileMemberAlignment(GVM, nemr0, 64);
309#endif
310AssertCompileMemberAlignment(GVM, rawpci, 64);
311AssertCompileMemberAlignment(GVM, pdmr0, 64);
312AssertCompileMemberAlignment(GVM, aCpus, 4096);
313AssertCompileSizeAlignment(GVM, 4096);
314#if RT_GNUC_PREREQ(4, 6) && defined(__cplusplus)
315# pragma GCC diagnostic pop
316#endif
317#endif
318
319/** The GVM::u32Magic value (Wayne Shorter). */
320#define GVM_MAGIC 0x19330825
321
322/** @} */
323
324#endif /* !VBOX_INCLUDED_vmm_gvm_h */
325
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