Changeset 96506 in vbox
- Timestamp:
- Aug 25, 2022 10:44:36 PM (2 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/ValidationKit/utils/cpu/rdtsc.cpp
r96407 r96506 39 39 * Header Files * 40 40 *********************************************************************************************************************************/ 41 #include <iprt/types.h> 42 #include <stdlib.h> 43 #include <stdio.h> 44 #include <time.h> 41 #include <iprt/errcore.h> 42 #include <iprt/initterm.h> 43 #include <iprt/message.h> 44 #include <iprt/stream.h> 45 #include <iprt/string.h> 46 #include <iprt/time.h> 45 47 46 48 … … 79 81 int main(int argc, char **argv) 80 82 { 83 int rc = RTR3InitExe(argc, &argv, 0); 84 if (RT_FAILURE(rc)) 85 return RTMsgInitFailure(rc); 81 86 82 87 /* … … 99 104 /* Option value. */ 100 105 const char *pszValue = NULL; 101 u nsigned longuValue = 0;106 uint64_t uValue = 0; 102 107 switch (chOpt) 103 108 { … … 108 113 { 109 114 if (i + 1 >= argc) 110 { 111 printf("syntax error: The %c option requires a value\n", chOpt); 112 return RTEXITCODE_SYNTAX; 113 } 115 return RTMsgSyntax("The %c option requires a value", chOpt); 114 116 pszValue = argv[++i]; 115 117 } … … 123 125 { 124 126 char *pszNext = NULL; 125 uValue = strtoul(pszValue, &pszNext, 0); 127 rc = RTStrToUInt64Ex(pszValue, &pszNext, 0, &uValue); 128 if (RT_FAILURE(rc)) 129 return RTMsgSyntax("Bad number: %s (%Rrc)", pszValue, rc); 126 130 if (pszNext && *pszNext != '\0') 127 131 { … … 133 137 uValue *= _1G; 134 138 else 135 { 136 printf("syntax error: Bad value format for option %c: %s\n", chOpt, pszValue); 137 return RTEXITCODE_SYNTAX; 138 } 139 return RTMsgSyntax("Bad value format for option %c: %s", chOpt, pszValue); 139 140 } 140 141 break; … … 161 162 case 'h': 162 163 case '?': 163 printf("usage: rdtsc [-l <loops>] [-s <loops-between-status>]\n"164 " [-m <minimum-seconds-to-run>]\n");164 RTPrintf("usage: rdtsc [-l <loops>] [-s <loops-between-status>]\n" 165 " [-m <minimum-seconds-to-run>]\n"); 165 166 return RTEXITCODE_SUCCESS; 166 167 167 168 default: 168 printf("syntax error: Unknown option %c (argument %d)\n", chOpt, i); 169 return RTEXITCODE_SYNTAX; 169 return RTMsgSyntax("Unknown option %c (argument %d)\n", chOpt, i); 170 170 } 171 171 } 172 172 } 173 173 else 174 { 175 printf("synatx error: argument %d (%s): not an option\n", i, psz); 176 return RTEXITCODE_SYNTAX; 177 } 174 return RTMsgSyntax("argument %d (%s): not an option\n", i, psz); 178 175 } 179 176 … … 181 178 * Do the job. 182 179 */ 183 time_t uSecStart; 184 time(&uSecStart); 180 uint64_t const nsTsStart = RTTimeNanoTS(); 185 181 unsigned cOuterLoops = 0; 186 182 unsigned cLoopsToNextStatus = cStatusEvery; … … 224 220 if ((uint64_t)offDelta > offMaxJump) 225 221 offMaxJump = offDelta; 226 printf("%u/%u: Jump: %#010x`%08x -> %#010x`%08x\n", cOuterLoops, iLoop,227 (unsigned)g_aRdTscResults[i].uHigh, (unsigned)g_aRdTscResults[i].uLow,228 (unsigned)g_aRdTscResults[i + 1].uHigh, (unsigned)g_aRdTscResults[i + 1].uLow);222 RTPrintf("%u/%u: Jump: %#010x`%08x -> %#010x`%08x\n", cOuterLoops, iLoop, 223 (unsigned)g_aRdTscResults[i].uHigh, (unsigned)g_aRdTscResults[i].uLow, 224 (unsigned)g_aRdTscResults[i + 1].uHigh, (unsigned)g_aRdTscResults[i + 1].uLow); 229 225 } 230 226 } … … 232 228 { 233 229 cBackwards++; 234 printf("%u/%u: Back: %#010x`%08x -> %#010x`%08x\n", cOuterLoops, iLoop,235 (unsigned)g_aRdTscResults[i].uHigh, (unsigned)g_aRdTscResults[i].uLow,236 (unsigned)g_aRdTscResults[i + 1].uHigh, (unsigned)g_aRdTscResults[i + 1].uLow);230 RTPrintf("%u/%u: Back: %#010x`%08x -> %#010x`%08x\n", cOuterLoops, iLoop, 231 (unsigned)g_aRdTscResults[i].uHigh, (unsigned)g_aRdTscResults[i].uLow, 232 (unsigned)g_aRdTscResults[i + 1].uHigh, (unsigned)g_aRdTscResults[i + 1].uLow); 237 233 } 238 234 } … … 240 236 { 241 237 cSame++; 242 printf("%u/%u: Same: %#010x`%08x -> %#010x`%08x\n", cOuterLoops, iLoop,243 (unsigned)g_aRdTscResults[i].uHigh, (unsigned)g_aRdTscResults[i].uLow,244 (unsigned)g_aRdTscResults[i + 1].uHigh, (unsigned)g_aRdTscResults[i + 1].uLow);238 RTPrintf("%u/%u: Same: %#010x`%08x -> %#010x`%08x\n", cOuterLoops, iLoop, 239 (unsigned)g_aRdTscResults[i].uHigh, (unsigned)g_aRdTscResults[i].uLow, 240 (unsigned)g_aRdTscResults[i + 1].uHigh, (unsigned)g_aRdTscResults[i + 1].uLow); 245 241 } 246 242 #if ARCH_BITS == 64 … … 259 255 { 260 256 cLoopsToNextStatus = cStatusEvery; 261 printf("%u/%u: %#010x`%08x\n", cOuterLoops, iLoop,262 (unsigned)g_aRdTscResults[cResults].uHigh, (unsigned)g_aRdTscResults[cResults].uLow);257 RTPrintf("%u/%u: %#010x`%08x\n", cOuterLoops, iLoop, 258 (unsigned)g_aRdTscResults[cResults].uHigh, (unsigned)g_aRdTscResults[cResults].uLow); 263 259 } 264 260 } … … 270 266 if (!cMinSeconds) 271 267 break; 272 time_t uSecNow; 273 if ( time(&uSecNow) == (time_t)-1 274 || uSecNow == (time_t)-1 275 || uSecStart == (time_t)-1 276 || uSecNow - uSecStart >= (time_t)cMinSeconds) 268 uint64_t nsElapsed = RTTimeNanoTS() - nsTsStart; 269 if (nsElapsed >= cMinSeconds * RT_NS_1SEC_64) 277 270 break; 278 271 } … … 283 276 if (cBackwards == 0 && cSame == 0 && cJumps == 0 && cBadValues == 0) 284 277 { 285 printf("rdtsc: Success (%u RDTSC over %u*%u loops, deltas: %#x`%08x..%#x`%08x)\n",286 cRdTscInstructions, cOuterLoops, cMaxLoops,287 (unsigned)(offMinIncr >> 32), (unsigned)offMinIncr, (unsigned)(offMaxIncr >> 32), (unsigned)offMaxIncr);278 RTPrintf("rdtsc: Success (%u RDTSC over %u*%u loops, deltas: %#x`%08x..%#x`%08x)\n", 279 cRdTscInstructions, cOuterLoops, cMaxLoops, 280 (unsigned)(offMinIncr >> 32), (unsigned)offMinIncr, (unsigned)(offMaxIncr >> 32), (unsigned)offMaxIncr); 288 281 return RTEXITCODE_SUCCESS; 289 282 } 290 printf("RDTSC instructions: %u\n", cRdTscInstructions);291 printf("Loops: %u * %u => %u\n", cMaxLoops, cOuterLoops, cOuterLoops * cMaxLoops);292 printf("Backwards: %u\n", cBackwards);293 printf("Jumps: %u\n", cJumps);294 printf("Max jumps: %#010x`%08x\n", (unsigned)(offMaxJump >> 32), (unsigned)offMaxJump);295 printf("Same value: %u\n", cSame);296 printf("Bad values: %u\n", cBadValues);297 printf("Min increment: %#010x`%08x\n", (unsigned)(offMinIncr >> 32), (unsigned)offMinIncr);298 printf("Max increment: %#010x`%08x\n", (unsigned)(offMaxIncr >> 32), (unsigned)offMaxIncr);283 RTPrintf("RDTSC instructions: %u\n", cRdTscInstructions); 284 RTPrintf("Loops: %u * %u => %u\n", cMaxLoops, cOuterLoops, cOuterLoops * cMaxLoops); 285 RTPrintf("Backwards: %u\n", cBackwards); 286 RTPrintf("Jumps: %u\n", cJumps); 287 RTPrintf("Max jumps: %#010x`%08x\n", (unsigned)(offMaxJump >> 32), (unsigned)offMaxJump); 288 RTPrintf("Same value: %u\n", cSame); 289 RTPrintf("Bad values: %u\n", cBadValues); 290 RTPrintf("Min increment: %#010x`%08x\n", (unsigned)(offMinIncr >> 32), (unsigned)offMinIncr); 291 RTPrintf("Max increment: %#010x`%08x\n", (unsigned)(offMaxIncr >> 32), (unsigned)offMaxIncr); 299 292 return RTEXITCODE_FAILURE; 300 293 }
Note:
See TracChangeset
for help on using the changeset viewer.