VirtualBox

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

Last change on this file since 38321 was 35346, checked in by vboxsync, 14 years ago

VMM reorg: Moving the public include files from include/VBox to include/VBox/vmm.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 7.9 KB
Line 
1/* $Id: tstInt.cpp 35346 2010-12-27 16:13:13Z vboxsync $ */
2/** @file
3 * SUP Testcase - Test the interrupt gate feature of the support library.
4 */
5
6/*
7 * Copyright (C) 2006-2007 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
28/*******************************************************************************
29* Header Files *
30*******************************************************************************/
31#include <VBox/sup.h>
32#include <VBox/vmm/vm.h>
33#include <VBox/vmm/vmm.h>
34#include <VBox/err.h>
35#include <VBox/param.h>
36#include <iprt/asm-amd64-x86.h>
37#include <iprt/initterm.h>
38#include <iprt/stream.h>
39#include <iprt/string.h>
40#include <iprt/alloc.h>
41#include <iprt/time.h>
42
43
44/**
45 * Makes a path to a file in the executable directory.
46 */
47static char *ExeDirFile(char *pszFile, const char *pszArgv0, const char *pszFilename)
48{
49 char *psz;
50 char *psz2;
51
52 strcpy(pszFile, pszArgv0);
53 psz = strrchr(pszFile, '/');
54 psz2 = strrchr(pszFile, '\\');
55 if (psz < psz2)
56 psz = psz2;
57 if (!psz)
58 psz = strrchr(pszFile, ':');
59 if (!psz)
60 {
61 strcpy(pszFile, "./");
62 psz = &pszFile[1];
63 }
64 strcpy(psz + 1, "VMMR0.r0");
65 return pszFile;
66}
67
68int main(int argc, char **argv)
69{
70 int rcRet = 0;
71 int i;
72 int rc;
73 int cIterations = argc > 1 ? RTStrToUInt32(argv[1]) : 32;
74 if (cIterations == 0)
75 cIterations = 64;
76
77 /*
78 * Init.
79 */
80 RTR3Init();
81 PSUPDRVSESSION pSession;
82 rc = SUPR3Init(&pSession);
83 rcRet += rc != 0;
84 RTPrintf("tstInt: SUPR3Init -> rc=%Rrc\n", rc);
85 if (!rc)
86 {
87 /*
88 * Load VMM code.
89 */
90 char szFile[RTPATH_MAX];
91 rc = SUPR3LoadVMM(ExeDirFile(szFile, argv[0], "VMMR0.r0"));
92 if (!rc)
93 {
94 /*
95 * Create a fake 'VM'.
96 */
97 PVMR0 pVMR0 = NIL_RTR0PTR;
98 PVM pVM = NULL;
99 const unsigned cPages = RT_ALIGN_Z(sizeof(*pVM), PAGE_SIZE) >> PAGE_SHIFT;
100 PSUPPAGE paPages = (PSUPPAGE)RTMemAllocZ(cPages * sizeof(SUPPAGE));
101 if (paPages)
102 rc = SUPR3LowAlloc(cPages, (void **)&pVM, &pVMR0, &paPages[0]);
103 else
104 rc = VERR_NO_MEMORY;
105 if (RT_SUCCESS(rc))
106 {
107 pVM->pVMRC = 0;
108 pVM->pVMR3 = pVM;
109 pVM->pVMR0 = pVMR0;
110 pVM->paVMPagesR3 = paPages;
111 pVM->pSession = pSession;
112 pVM->enmVMState = VMSTATE_CREATED;
113
114 rc = SUPR3SetVMForFastIOCtl(pVMR0);
115 if (!rc)
116 {
117
118 /*
119 * Call VMM code with invalid function.
120 */
121 for (i = cIterations; i > 0; i--)
122 {
123 rc = SUPR3CallVMMR0(pVMR0, NIL_VMCPUID, VMMR0_DO_SLOW_NOP, NULL);
124 if (rc != VINF_SUCCESS)
125 {
126 RTPrintf("tstInt: SUPR3CallVMMR0 -> rc=%Rrc i=%d Expected VINF_SUCCESS!\n", rc, i);
127 rcRet++;
128 break;
129 }
130 }
131 RTPrintf("tstInt: Performed SUPR3CallVMMR0 %d times (rc=%Rrc)\n", cIterations, rc);
132
133 /*
134 * The fast path.
135 */
136 if (rc == VINF_SUCCESS)
137 {
138 RTTimeNanoTS();
139 uint64_t StartTS = RTTimeNanoTS();
140 uint64_t StartTick = ASMReadTSC();
141 uint64_t MinTicks = UINT64_MAX;
142 for (i = 0; i < 1000000; i++)
143 {
144 uint64_t OneStartTick = ASMReadTSC();
145 rc = SUPR3CallVMMR0Fast(pVMR0, VMMR0_DO_NOP, 0);
146 uint64_t Ticks = ASMReadTSC() - OneStartTick;
147 if (Ticks < MinTicks)
148 MinTicks = Ticks;
149
150 if (RT_UNLIKELY(rc != VINF_SUCCESS))
151 {
152 RTPrintf("tstInt: SUPR3CallVMMR0Fast -> rc=%Rrc i=%d Expected VINF_SUCCESS!\n", rc, i);
153 rcRet++;
154 break;
155 }
156 }
157 uint64_t Ticks = ASMReadTSC() - StartTick;
158 uint64_t NanoSecs = RTTimeNanoTS() - StartTS;
159
160 RTPrintf("tstInt: SUPR3CallVMMR0Fast - %d iterations in %llu ns / %llu ticks. %llu ns / %#llu ticks per iteration. Min %llu ticks.\n",
161 i, NanoSecs, Ticks, NanoSecs / i, Ticks / i, MinTicks);
162
163 /*
164 * The ordinary path.
165 */
166 RTTimeNanoTS();
167 StartTS = RTTimeNanoTS();
168 StartTick = ASMReadTSC();
169 MinTicks = UINT64_MAX;
170 for (i = 0; i < 1000000; i++)
171 {
172 uint64_t OneStartTick = ASMReadTSC();
173 rc = SUPR3CallVMMR0Ex(pVMR0, NIL_VMCPUID, VMMR0_DO_SLOW_NOP, 0, NULL);
174 uint64_t OneTicks = ASMReadTSC() - OneStartTick;
175 if (OneTicks < MinTicks)
176 MinTicks = OneTicks;
177
178 if (RT_UNLIKELY(rc != VINF_SUCCESS))
179 {
180 RTPrintf("tstInt: SUPR3CallVMMR0Ex -> rc=%Rrc i=%d Expected VINF_SUCCESS!\n", rc, i);
181 rcRet++;
182 break;
183 }
184 }
185 Ticks = ASMReadTSC() - StartTick;
186 NanoSecs = RTTimeNanoTS() - StartTS;
187
188 RTPrintf("tstInt: SUPR3CallVMMR0Ex - %d iterations in %llu ns / %llu ticks. %llu ns / %#llu ticks per iteration. Min %llu ticks.\n",
189 i, NanoSecs, Ticks, NanoSecs / i, Ticks / i, MinTicks);
190 }
191 }
192 else
193 {
194 RTPrintf("tstInt: SUPR3SetVMForFastIOCtl failed: %Rrc\n", rc);
195 rcRet++;
196 }
197 }
198 else
199 {
200 RTPrintf("tstInt: SUPR3ContAlloc(%#zx,,) failed\n", sizeof(*pVM));
201 rcRet++;
202 }
203
204 /*
205 * Unload VMM.
206 */
207 rc = SUPR3UnloadVMM();
208 if (rc)
209 {
210 RTPrintf("tstInt: SUPR3UnloadVMM failed with rc=%Rrc\n", rc);
211 rcRet++;
212 }
213 }
214 else
215 {
216 RTPrintf("tstInt: SUPR3LoadVMM failed with rc=%Rrc\n", rc);
217 rcRet++;
218 }
219
220 /*
221 * Terminate.
222 */
223 rc = SUPR3Term(false /*fForced*/);
224 rcRet += rc != 0;
225 RTPrintf("tstInt: SUPR3Term -> rc=%Rrc\n", rc);
226 }
227
228 return !!rc;
229}
230
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