VirtualBox

source: vbox/trunk/src/VBox/HostDrivers/Support/testcase/tstGIP-2.cpp@ 26943

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

*: RTGetOpt cleanup related to --help and --version (now standard option). Use RTGetOptPrintError.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 6.9 KB
Line 
1/* $Id: tstGIP-2.cpp 26517 2010-02-14 21:39:00Z 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
47int 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, RTGETOPTINIT_FLAGS_NO_STD_OPTS);
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 default:
90 return RTGetOptPrintError(ch, &ValueUnion);
91 }
92 }
93
94 /*
95 * Init
96 */
97 PSUPDRVSESSION pSession = NIL_RTR0PTR;
98 int rc = SUPR3Init(&pSession);
99 if (RT_SUCCESS(rc))
100 {
101 if (g_pSUPGlobalInfoPage)
102 {
103 RTPrintf("tstGIP-2: u32UpdateHz=%RU32 u32UpdateIntervalNS=%RU32 u64NanoTSLastUpdateHz=%RX64 u32Mode=%d (%s) u32Version=%#x\n",
104 g_pSUPGlobalInfoPage->u32UpdateHz,
105 g_pSUPGlobalInfoPage->u32UpdateIntervalNS,
106 g_pSUPGlobalInfoPage->u64NanoTSLastUpdateHz,
107 g_pSUPGlobalInfoPage->u32Mode,
108 g_pSUPGlobalInfoPage->u32Mode == SUPGIPMODE_SYNC_TSC ? "sync"
109 : g_pSUPGlobalInfoPage->u32Mode == SUPGIPMODE_ASYNC_TSC ? "async"
110 : "???",
111 g_pSUPGlobalInfoPage->u32Version);
112 RTPrintf(fHex
113 ? "tstGIP-2: it: u64NanoTS delta u64TSC UpIntTSC H TransId CpuHz TSC Interval History...\n"
114 : "tstGIP-2: it: u64NanoTS delta u64TSC UpIntTSC H TransId CpuHz TSC Interval History...\n");
115 static SUPGIPCPU s_aaCPUs[2][RT_ELEMENTS(g_pSUPGlobalInfoPage->aCPUs)];
116 for (uint32_t i = 0; i < cIterations; i++)
117 {
118 /* copy the data */
119 memcpy(&s_aaCPUs[i & 1][0], &g_pSUPGlobalInfoPage->aCPUs[0], sizeof(g_pSUPGlobalInfoPage->aCPUs));
120
121 /* display it & find something to spin on. */
122 uint32_t u32TransactionId = 0;
123 uint32_t volatile *pu32TransactionId = NULL;
124 for (unsigned iCpu = 0; iCpu < RT_ELEMENTS(g_pSUPGlobalInfoPage->aCPUs); iCpu++)
125 if ( g_pSUPGlobalInfoPage->aCPUs[iCpu].u64CpuHz > 0
126 && g_pSUPGlobalInfoPage->aCPUs[iCpu].u64CpuHz != _4G + 1)
127 {
128 PSUPGIPCPU pPrevCpu = &s_aaCPUs[!(i & 1)][iCpu];
129 PSUPGIPCPU pCpu = &s_aaCPUs[i & 1][iCpu];
130 RTPrintf(fHex
131 ? "tstGIP-2: %4d/%d: %016llx %09llx %016llx %08x %d %08x %15llu %08x %08x %08x %08x %08x %08x %08x %08x (%d)\n"
132 : "tstGIP-2: %4d/%d: %016llu %09llu %016llu %010u %d %010u %15llu %08x %08x %08x %08x %08x %08x %08x %08x (%d)\n",
133 i, iCpu,
134 pCpu->u64NanoTS,
135 i ? pCpu->u64NanoTS - pPrevCpu->u64NanoTS : 0,
136 pCpu->u64TSC,
137 pCpu->u32UpdateIntervalTSC,
138 pCpu->iTSCHistoryHead,
139 pCpu->u32TransactionId,
140 pCpu->u64CpuHz,
141 pCpu->au32TSCHistory[0],
142 pCpu->au32TSCHistory[1],
143 pCpu->au32TSCHistory[2],
144 pCpu->au32TSCHistory[3],
145 pCpu->au32TSCHistory[4],
146 pCpu->au32TSCHistory[5],
147 pCpu->au32TSCHistory[6],
148 pCpu->au32TSCHistory[7],
149 pCpu->cErrors);
150 if (!pu32TransactionId)
151 {
152 pu32TransactionId = &g_pSUPGlobalInfoPage->aCPUs[iCpu].u32TransactionId;
153 u32TransactionId = pCpu->u32TransactionId;
154 }
155 }
156
157 /* wait a bit / spin */
158 if (!fSpin)
159 RTThreadSleep(9);
160 else
161 while (u32TransactionId == *pu32TransactionId)
162 /* nop */;
163 }
164 }
165 else
166 {
167 RTPrintf("tstGIP-2: g_pSUPGlobalInfoPage is NULL\n");
168 rc = -1;
169 }
170
171 SUPR3Term(false /*fForced*/);
172 }
173 else
174 RTPrintf("tstGIP-2: SUPR3Init failed: %Rrc\n", rc);
175 return !!rc;
176}
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