VirtualBox

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

Last change on this file since 28800 was 28800, checked in by vboxsync, 15 years ago

Automated rebranding to Oracle copyright/license strings via filemuncher

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