VirtualBox

source: vbox/trunk/src/VBox/HostDrivers/Support/testcase/tstSupTscDelta.cpp@ 54320

Last change on this file since 54320 was 54320, checked in by vboxsync, 10 years ago

tstSupTscDelta.cpp: min/max fix.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 8.5 KB
Line 
1/* $Id: tstSupTscDelta.cpp 54320 2015-02-19 23:05:20Z vboxsync $ */
2/** @file
3 * SUP Testcase - Global Info Page TSC Delta Measurement Utility.
4 */
5
6/*
7 * Copyright (C) 2015 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* Header Files *
29*******************************************************************************/
30#include <VBox/sup.h>
31#include <VBox/err.h>
32#include <iprt/assert.h>
33#include <iprt/stream.h>
34#include <iprt/string.h>
35#include <iprt/getopt.h>
36#include <iprt/test.h>
37#include <iprt/thread.h>
38
39
40
41int main(int argc, char **argv)
42{
43 RTTEST hTest;
44 RTEXITCODE rcExit = RTTestInitExAndCreate(argc, &argv, 0 /*fRtInit*/, "tstSupTscDelta", &hTest);
45 if (rcExit != RTEXITCODE_SUCCESS)
46 return rcExit;
47
48 /*
49 * Parse args
50 */
51 static const RTGETOPTDEF g_aOptions[] =
52 {
53 { "--iterations", 'i', RTGETOPT_REQ_INT32 },
54 };
55
56 uint32_t cIterations = 0; /* Currently 0 so that it doesn't upset testing. */
57 uint32_t cMsSleepBetweenIterations = 10;
58
59 int ch;
60 RTGETOPTUNION ValueUnion;
61 RTGETOPTSTATE GetState;
62 RTGetOptInit(&GetState, argc, argv, g_aOptions, RT_ELEMENTS(g_aOptions), 1, RTGETOPTINIT_FLAGS_NO_STD_OPTS);
63 while ((ch = RTGetOpt(&GetState, &ValueUnion)))
64 {
65 switch (ch)
66 {
67 case 'i':
68 cIterations = ValueUnion.u32;
69 break;
70
71 default:
72 return RTGetOptPrintError(ch, &ValueUnion);
73 }
74 }
75 if (!cIterations)
76 return RTTestSkipAndDestroy(hTest, "Nothing to do. The --iterations argument is 0 or not given.");
77
78 /*
79 * Init
80 */
81 PSUPDRVSESSION pSession = NIL_RTR0PTR;
82 int rc = SUPR3Init(&pSession);
83 if (RT_SUCCESS(rc))
84 {
85 PSUPGLOBALINFOPAGE pGip = g_pSUPGlobalInfoPage;
86 if (pGip)
87 {
88 if (pGip->enmUseTscDelta < SUPGIPUSETSCDELTA_PRACTICALLY_ZERO)
89 return RTTestSkipAndDestroy(hTest, "No deltas to play with: enmUseTscDelta=%d\n", pGip->enmUseTscDelta);
90
91 /*
92 * Init stats.
93 */
94 struct
95 {
96 int64_t iLowest;
97 int64_t iHighest;
98 int64_t iTotal;
99 uint64_t uAbsMin;
100 uint64_t uAbsMax;
101 uint64_t uAbsTotal;
102 } aCpuStats[RTCPUSET_MAX_CPUS];
103 RT_ZERO(aCpuStats);
104 for (uint32_t i = 0; i < pGip->cCpus; i++)
105 {
106 aCpuStats[i].iLowest = INT64_MAX;
107 aCpuStats[i].iHighest = INT64_MIN;
108 aCpuStats[i].uAbsMin = UINT64_MAX;
109 }
110
111 /*
112 * Do the work.
113 */
114 for (uint32_t iIteration = 0; ; iIteration++)
115 {
116 /*
117 * Display the current deltas and gather statistics.
118 */
119 RTPrintf("tstSupTscDelta: Iteration #%u results:", iIteration);
120 for (uint32_t iCpu = 0; iCpu < pGip->cCpus; iCpu++)
121 {
122 int64_t iTscDelta = pGip->aCPUs[iCpu].i64TSCDelta;
123
124 /* print */
125 if ((iCpu % 4) == 0)
126 RTPrintf("\ntstSupTscDelta:");
127 if (pGip->aCPUs[iCpu].enmState != SUPGIPCPUSTATE_ONLINE)
128 RTPrintf(" %02x: offline ", iCpu, iTscDelta);
129 else if (iTscDelta != INT64_MAX)
130 RTPrintf(" %02x: %-12lld", iCpu, iTscDelta);
131 else
132 RTPrintf(" %02x: INT64_MAX ", iCpu);
133
134 /* stats */
135 if ( iTscDelta != INT64_MAX
136 && pGip->aCPUs[iCpu].enmState == SUPGIPCPUSTATE_ONLINE)
137 {
138 if (aCpuStats[iCpu].iLowest > iTscDelta)
139 aCpuStats[iCpu].iLowest = iTscDelta;
140 if (aCpuStats[iCpu].iHighest < iTscDelta)
141 aCpuStats[iCpu].iHighest = iTscDelta;
142 aCpuStats[iCpu].iTotal += iTscDelta;
143
144 uint64_t uAbsTscDelta = iTscDelta >= 0 ? (uint64_t)iTscDelta : (uint64_t)-iTscDelta;
145 if (aCpuStats[iCpu].uAbsMin > uAbsTscDelta)
146 aCpuStats[iCpu].uAbsMin = uAbsTscDelta;
147 if (aCpuStats[iCpu].uAbsMax < uAbsTscDelta)
148 aCpuStats[iCpu].uAbsMax = uAbsTscDelta;
149 aCpuStats[iCpu].uAbsTotal += uAbsTscDelta;
150 }
151 }
152 if (((pGip->cCpus - 1) % 4) != 0)
153 RTPrintf("\n");
154
155 /*
156 * Done?
157 */
158 if (iIteration + 1 >= cIterations)
159 break;
160
161 /*
162 * Force a new measurement.
163 */
164 RTThreadSleep(cMsSleepBetweenIterations);
165 for (uint32_t iCpu = 0; iCpu < pGip->cCpus; iCpu++)
166 if (pGip->aCPUs[iCpu].enmState == SUPGIPCPUSTATE_ONLINE)
167 {
168 rc = SUPR3TscDeltaMeasure(pGip->aCPUs[iCpu].idCpu, false /*fAsync*/, true /*fForce*/, 64, 16 /*ms*/);
169 if (RT_FAILURE(rc))
170 RTTestFailed(hTest, "SUPR3TscDeltaMeasure failed on %#x: %Rrc", pGip->aCPUs[iCpu].idCpu, rc);
171 }
172 }
173
174 /*
175 * Display statistics that we've gathered.
176 */
177 RTPrintf("tstSupTscDelta: Results:\n");
178 int64_t iLowest = INT64_MAX;
179 int64_t iHighest = INT64_MIN;
180 int64_t iTotal = 0;
181 uint32_t cTotal = 0;
182 for (uint32_t iCpu = 0; iCpu < pGip->cCpus; iCpu++)
183 {
184 if (pGip->aCPUs[iCpu].enmState != SUPGIPCPUSTATE_ONLINE)
185 RTPrintf("tstSupTscDelta: %02x: offline\n", iCpu);
186 else
187 {
188 RTPrintf("tstSupTscDelta: %02x: lowest=%-12lld highest=%-12lld average=%-12lld spread=%-12lld\n",
189 iCpu,
190 aCpuStats[iCpu].iLowest,
191 aCpuStats[iCpu].iHighest,
192 aCpuStats[iCpu].iTotal / cIterations,
193 aCpuStats[iCpu].iHighest - aCpuStats[iCpu].iLowest);
194 RTPrintf( "tstSupTscDelta: absmin=%-12llu absmax=%-12llu absavg=%-12llu idCpu=%#4x idApic=%#4x\n",
195 aCpuStats[iCpu].uAbsMin,
196 aCpuStats[iCpu].uAbsMax,
197 aCpuStats[iCpu].uAbsTotal / cIterations,
198 pGip->aCPUs[iCpu].idCpu,
199 pGip->aCPUs[iCpu].idApic);
200 if (iLowest > aCpuStats[iCpu].iLowest)
201 iLowest = aCpuStats[iCpu].iLowest;
202 if (iHighest < aCpuStats[iCpu].iHighest)
203 iHighest = aCpuStats[iCpu].iHighest;
204 iTotal += aCpuStats[iCpu].iHighest;
205 cTotal += cIterations;
206 }
207 }
208 RTPrintf("tstSupTscDelta: all: lowest=%-12lld highest=%-12lld average=%-12lld spread=%-12lld\n",
209 iLowest, iHighest, iTotal / cTotal, iHighest - iLowest);
210 }
211 else
212 RTTestFailed(hTest, "g_pSUPGlobalInfoPage is NULL");
213
214 SUPR3Term(false /*fForced*/);
215 }
216 else
217 RTTestFailed(hTest, "SUPR3Init failed: %Rrc", rc);
218 return RTTestSummaryAndDestroy(hTest);
219}
220
221
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