VirtualBox

source: vbox/trunk/src/VBox/HostDrivers/Support/testcase/tstInt.cpp@ 14515

最後變更 在這個檔案從14515是 14515,由 vboxsync 提交於 16 年 前

SUPDrv,SUPLib,VMM: Kicked out the dead VBOX_WITH_IDT_PATCHING code.

  • 屬性 svn:eol-style 設為 native
  • 屬性 svn:keywords 設為 Author Date Id Revision
檔案大小: 7.9 KB
 
1/** $Id: tstInt.cpp 14515 2008-11-24 12:33:00Z vboxsync $ */
2/** @file
3 * Testcase: Test the interrupt gate feature of the support library.
4 */
5
6/*
7 * Copyright (C) 2006-2007 Sun Microsystems, Inc.
8 *
9 * This file is part of VirtualBox Open Source Edition (OSE), as
10 * available from http://www.alldomusa.eu.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 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
27 * Clara, CA 95054 USA or visit http://www.sun.com if you need
28 * additional information or have any questions.
29 */
30
31
32/*******************************************************************************
33* Header Files *
34*******************************************************************************/
35#include <VBox/sup.h>
36#include <VBox/vm.h>
37#include <VBox/vmm.h>
38#include <VBox/err.h>
39#include <VBox/param.h>
40#include <iprt/runtime.h>
41#include <iprt/stream.h>
42#include <iprt/string.h>
43
44
45/**
46 * Makes a path to a file in the executable directory.
47 */
48static char *ExeDirFile(char *pszFile, const char *pszArgv0, const char *pszFilename)
49{
50 char *psz;
51 char *psz2;
52
53 strcpy(pszFile, pszArgv0);
54 psz = strrchr(pszFile, '/');
55 psz2 = strrchr(pszFile, '\\');
56 if (psz < psz2)
57 psz = psz2;
58 if (!psz)
59 psz = strrchr(pszFile, ':');
60 if (!psz)
61 {
62 strcpy(pszFile, "./");
63 psz = &pszFile[1];
64 }
65 strcpy(psz + 1, "VMMR0.r0");
66 return pszFile;
67}
68
69int main(int argc, char **argv)
70{
71 int rcRet = 0;
72 int i;
73 int rc;
74 int cIterations = argc > 1 ? RTStrToUInt32(argv[1]) : 32;
75 if (cIterations == 0)
76 cIterations = 64;
77
78 /*
79 * Init.
80 */
81 RTR3Init();
82 PSUPDRVSESSION pSession;
83 rc = SUPR3Init(&pSession);
84 rcRet += rc != 0;
85 RTPrintf("tstInt: SUPR3Init -> rc=%Rrc\n", rc);
86 if (!rc)
87 {
88 /*
89 * Load VMM code.
90 */
91 char szFile[RTPATH_MAX];
92 rc = SUPLoadVMM(ExeDirFile(szFile, argv[0], "VMMR0.r0"));
93 if (!rc)
94 {
95 /*
96 * Create a fake 'VM'.
97 */
98 PVMR0 pVMR0 = NIL_RTR0PTR;
99 PVM pVM = NULL;
100 const unsigned cPages = RT_ALIGN_Z(sizeof(*pVM), PAGE_SIZE) >> PAGE_SHIFT;
101 PSUPPAGE paPages = (PSUPPAGE)RTMemAllocZ(cPages * sizeof(SUPPAGE));
102 if (paPages)
103 rc = SUPLowAlloc(cPages, (void **)&pVM, &pVMR0, &paPages[0]);
104 else
105 rc = VERR_NO_MEMORY;
106 if (RT_SUCCESS(rc))
107 {
108 pVM->pVMRC = 0;
109 pVM->pVMR3 = pVM;
110 pVM->pVMR0 = pVMR0;
111 pVM->paVMPagesR3 = paPages;
112 pVM->pSession = pSession;
113 pVM->enmVMState = VMSTATE_CREATED;
114
115 rc = SUPSetVMForFastIOCtl(pVMR0);
116 if (!rc)
117 {
118
119 /*
120 * Call VMM code with invalid function.
121 */
122 for (i = cIterations; i > 0; i--)
123 {
124 rc = SUPCallVMMR0(pVMR0, VMMR0_DO_SLOW_NOP, NULL);
125 if (rc != VINF_SUCCESS)
126 {
127 RTPrintf("tstInt: SUPCallVMMR0 -> rc=%Rrc i=%d Expected VINF_SUCCESS!\n", rc, i);
128 rcRet++;
129 break;
130 }
131 }
132 RTPrintf("tstInt: Performed SUPCallVMMR0 %d times (rc=%Rrc)\n", cIterations, rc);
133
134 /*
135 * The fast path.
136 */
137 if (rc == VINF_SUCCESS)
138 {
139 RTTimeNanoTS();
140 uint64_t StartTS = RTTimeNanoTS();
141 uint64_t StartTick = ASMReadTSC();
142 uint64_t MinTicks = UINT64_MAX;
143 for (i = 0; i < 1000000; i++)
144 {
145 uint64_t OneStartTick = ASMReadTSC();
146 rc = SUPCallVMMR0Fast(pVMR0, VMMR0_DO_NOP, 0);
147 uint64_t Ticks = ASMReadTSC() - OneStartTick;
148 if (Ticks < MinTicks)
149 MinTicks = Ticks;
150
151 if (RT_UNLIKELY(rc != VINF_SUCCESS))
152 {
153 RTPrintf("tstInt: SUPCallVMMR0Fast -> rc=%Rrc i=%d Expected VINF_SUCCESS!\n", rc, i);
154 rcRet++;
155 break;
156 }
157 }
158 uint64_t Ticks = ASMReadTSC() - StartTick;
159 uint64_t NanoSecs = RTTimeNanoTS() - StartTS;
160
161 RTPrintf("tstInt: SUPCallVMMR0Fast - %d iterations in %llu ns / %llu ticks. %llu ns / %#llu ticks per iteration. Min %llu ticks.\n",
162 i, NanoSecs, Ticks, NanoSecs / i, Ticks / i, MinTicks);
163
164 /*
165 * The ordinary path.
166 */
167 RTTimeNanoTS();
168 StartTS = RTTimeNanoTS();
169 StartTick = ASMReadTSC();
170 MinTicks = UINT64_MAX;
171 for (i = 0; i < 1000000; i++)
172 {
173 uint64_t OneStartTick = ASMReadTSC();
174 rc = SUPCallVMMR0Ex(pVMR0, VMMR0_DO_SLOW_NOP, 0, NULL);
175 uint64_t Ticks = ASMReadTSC() - OneStartTick;
176 if (Ticks < MinTicks)
177 MinTicks = Ticks;
178
179 if (RT_UNLIKELY(rc != VINF_SUCCESS))
180 {
181 RTPrintf("tstInt: SUPCallVMMR0Ex -> rc=%Rrc i=%d Expected VINF_SUCCESS!\n", rc, i);
182 rcRet++;
183 break;
184 }
185 }
186 Ticks = ASMReadTSC() - StartTick;
187 NanoSecs = RTTimeNanoTS() - StartTS;
188
189 RTPrintf("tstInt: SUPCallVMMR0Ex - %d iterations in %llu ns / %llu ticks. %llu ns / %#llu ticks per iteration. Min %llu ticks.\n",
190 i, NanoSecs, Ticks, NanoSecs / i, Ticks / i, MinTicks);
191 }
192 }
193 else
194 {
195 RTPrintf("tstInt: SUPSetVMForFastIOCtl failed: %Rrc\n", rc);
196 rcRet++;
197 }
198 }
199 else
200 {
201 RTPrintf("tstInt: SUPContAlloc2(%#zx,,) failed\n", sizeof(*pVM));
202 rcRet++;
203 }
204
205 /*
206 * Unload VMM.
207 */
208 rc = SUPUnloadVMM();
209 if (rc)
210 {
211 RTPrintf("tstInt: SUPUnloadVMM failed with rc=%Rrc\n", rc);
212 rcRet++;
213 }
214 }
215 else
216 {
217 RTPrintf("tstInt: SUPLoadVMM failed with rc=%Rrc\n", rc);
218 rcRet++;
219 }
220
221 /*
222 * Terminate.
223 */
224 rc = SUPTerm();
225 rcRet += rc != 0;
226 RTPrintf("tstInt: SUPTerm -> rc=%Rrc\n", rc);
227 }
228
229 return !!rc;
230}
231
注意: 瀏覽 TracBrowser 來幫助您使用儲存庫瀏覽器

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