1 | /* $Id: tstGIP-2.cpp 22077 2009-08-07 16:01:57Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * SUP Testcase - Global Info Page interface (ring 3).
|
---|
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.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 | * 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 | * Header Files *
|
---|
33 | *******************************************************************************/
|
---|
34 | #include <VBox/sup.h>
|
---|
35 | #include <VBox/err.h>
|
---|
36 | #include <VBox/param.h>
|
---|
37 | #include <iprt/asm.h>
|
---|
38 | #include <iprt/assert.h>
|
---|
39 | #include <iprt/alloc.h>
|
---|
40 | #include <iprt/thread.h>
|
---|
41 | #include <iprt/stream.h>
|
---|
42 | #include <iprt/string.h>
|
---|
43 | #include <iprt/initterm.h>
|
---|
44 | #include <iprt/getopt.h>
|
---|
45 |
|
---|
46 |
|
---|
47 | int main(int argc, char **argv)
|
---|
48 | {
|
---|
49 | RTR3Init();
|
---|
50 |
|
---|
51 | /*
|
---|
52 | * Parse args
|
---|
53 | */
|
---|
54 | static const RTGETOPTDEF g_aOptions[] =
|
---|
55 | {
|
---|
56 | { "--interations", 'i', RTGETOPT_REQ_INT32 },
|
---|
57 | { "--hex", 'h', RTGETOPT_REQ_NOTHING },
|
---|
58 | { "--decimal", 'd', RTGETOPT_REQ_NOTHING },
|
---|
59 | { "--spin", 's', RTGETOPT_REQ_NOTHING }
|
---|
60 | };
|
---|
61 |
|
---|
62 | uint32_t cIterations = 40;
|
---|
63 | bool fHex = true;
|
---|
64 | bool fSpin = false;
|
---|
65 | int ch;
|
---|
66 | RTGETOPTUNION ValueUnion;
|
---|
67 | RTGETOPTSTATE GetState;
|
---|
68 | RTGetOptInit(&GetState, argc, argv, g_aOptions, RT_ELEMENTS(g_aOptions), 1, 0 /* fFlags */);
|
---|
69 | while ((ch = RTGetOpt(&GetState, &ValueUnion)))
|
---|
70 | {
|
---|
71 | switch (ch)
|
---|
72 | {
|
---|
73 | case 'i':
|
---|
74 | cIterations = ValueUnion.u32;
|
---|
75 | break;
|
---|
76 |
|
---|
77 | case 'd':
|
---|
78 | fHex = false;
|
---|
79 | break;
|
---|
80 |
|
---|
81 | case 'h':
|
---|
82 | fHex = true;
|
---|
83 | break;
|
---|
84 |
|
---|
85 | case 's':
|
---|
86 | fSpin = true;
|
---|
87 | break;
|
---|
88 |
|
---|
89 | case VINF_GETOPT_NOT_OPTION:
|
---|
90 | RTPrintf("tstGIP-2: syntax error: %s\n", ValueUnion.psz);
|
---|
91 | return 1;
|
---|
92 |
|
---|
93 | default:
|
---|
94 | if (ch < 0)
|
---|
95 | RTPrintf("tstGIP-2: %Rrc: %s\n", ch, ValueUnion.psz);
|
---|
96 | else
|
---|
97 | RTPrintf("tstGIP-2: syntax error: %s\n", ValueUnion.psz);
|
---|
98 | return 1;
|
---|
99 | }
|
---|
100 | }
|
---|
101 |
|
---|
102 | /*
|
---|
103 | * Init
|
---|
104 | */
|
---|
105 | PSUPDRVSESSION pSession = NIL_RTR0PTR;
|
---|
106 | int rc = SUPR3Init(&pSession);
|
---|
107 | if (RT_SUCCESS(rc))
|
---|
108 | {
|
---|
109 | if (g_pSUPGlobalInfoPage)
|
---|
110 | {
|
---|
111 | RTPrintf("tstGIP-2: u32UpdateHz=%RU32 u32UpdateIntervalNS=%RU32 u64NanoTSLastUpdateHz=%RX64 u32Mode=%d (%s) u32Version=%#x\n",
|
---|
112 | g_pSUPGlobalInfoPage->u32UpdateHz,
|
---|
113 | g_pSUPGlobalInfoPage->u32UpdateIntervalNS,
|
---|
114 | g_pSUPGlobalInfoPage->u64NanoTSLastUpdateHz,
|
---|
115 | g_pSUPGlobalInfoPage->u32Mode,
|
---|
116 | g_pSUPGlobalInfoPage->u32Mode == SUPGIPMODE_SYNC_TSC ? "sync"
|
---|
117 | : g_pSUPGlobalInfoPage->u32Mode == SUPGIPMODE_ASYNC_TSC ? "async"
|
---|
118 | : "???",
|
---|
119 | g_pSUPGlobalInfoPage->u32Version);
|
---|
120 | RTPrintf(fHex
|
---|
121 | ? "tstGIP-2: it: u64NanoTS delta u64TSC UpIntTSC H TransId CpuHz TSC Interval History...\n"
|
---|
122 | : "tstGIP-2: it: u64NanoTS delta u64TSC UpIntTSC H TransId CpuHz TSC Interval History...\n");
|
---|
123 | static SUPGIPCPU s_aaCPUs[2][RT_ELEMENTS(g_pSUPGlobalInfoPage->aCPUs)];
|
---|
124 | for (uint32_t i = 0; i < cIterations; i++)
|
---|
125 | {
|
---|
126 | /* copy the data */
|
---|
127 | memcpy(&s_aaCPUs[i & 1][0], &g_pSUPGlobalInfoPage->aCPUs[0], sizeof(g_pSUPGlobalInfoPage->aCPUs));
|
---|
128 |
|
---|
129 | /* display it & find something to spin on. */
|
---|
130 | uint32_t u32TransactionId = 0;
|
---|
131 | uint32_t volatile *pu32TransactionId = NULL;
|
---|
132 | for (unsigned iCpu = 0; iCpu < RT_ELEMENTS(g_pSUPGlobalInfoPage->aCPUs); iCpu++)
|
---|
133 | if ( g_pSUPGlobalInfoPage->aCPUs[iCpu].u64CpuHz > 0
|
---|
134 | && g_pSUPGlobalInfoPage->aCPUs[iCpu].u64CpuHz != _4G + 1)
|
---|
135 | {
|
---|
136 | PSUPGIPCPU pPrevCpu = &s_aaCPUs[!(i & 1)][iCpu];
|
---|
137 | PSUPGIPCPU pCpu = &s_aaCPUs[i & 1][iCpu];
|
---|
138 | RTPrintf(fHex
|
---|
139 | ? "tstGIP-2: %4d/%d: %016llx %09llx %016llx %08x %d %08x %15llu %08x %08x %08x %08x %08x %08x %08x %08x (%d)\n"
|
---|
140 | : "tstGIP-2: %4d/%d: %016llu %09llu %016llu %010u %d %010u %15llu %08x %08x %08x %08x %08x %08x %08x %08x (%d)\n",
|
---|
141 | i, iCpu,
|
---|
142 | pCpu->u64NanoTS,
|
---|
143 | i ? pCpu->u64NanoTS - pPrevCpu->u64NanoTS : 0,
|
---|
144 | pCpu->u64TSC,
|
---|
145 | pCpu->u32UpdateIntervalTSC,
|
---|
146 | pCpu->iTSCHistoryHead,
|
---|
147 | pCpu->u32TransactionId,
|
---|
148 | pCpu->u64CpuHz,
|
---|
149 | pCpu->au32TSCHistory[0],
|
---|
150 | pCpu->au32TSCHistory[1],
|
---|
151 | pCpu->au32TSCHistory[2],
|
---|
152 | pCpu->au32TSCHistory[3],
|
---|
153 | pCpu->au32TSCHistory[4],
|
---|
154 | pCpu->au32TSCHistory[5],
|
---|
155 | pCpu->au32TSCHistory[6],
|
---|
156 | pCpu->au32TSCHistory[7],
|
---|
157 | pCpu->cErrors);
|
---|
158 | if (!pu32TransactionId)
|
---|
159 | {
|
---|
160 | pu32TransactionId = &g_pSUPGlobalInfoPage->aCPUs[iCpu].u32TransactionId;
|
---|
161 | u32TransactionId = pCpu->u32TransactionId;
|
---|
162 | }
|
---|
163 | }
|
---|
164 |
|
---|
165 | /* wait a bit / spin */
|
---|
166 | if (!fSpin)
|
---|
167 | RTThreadSleep(9);
|
---|
168 | else
|
---|
169 | while (u32TransactionId == *pu32TransactionId)
|
---|
170 | /* nop */;
|
---|
171 | }
|
---|
172 | }
|
---|
173 | else
|
---|
174 | {
|
---|
175 | RTPrintf("tstGIP-2: g_pSUPGlobalInfoPage is NULL\n");
|
---|
176 | rc = -1;
|
---|
177 | }
|
---|
178 |
|
---|
179 | SUPR3Term(false /*fForced*/);
|
---|
180 | }
|
---|
181 | else
|
---|
182 | RTPrintf("tstGIP-2: SUPR3Init failed: %Rrc\n", rc);
|
---|
183 | return !!rc;
|
---|
184 | }
|
---|