Changeset 96511 in vbox for trunk/src/VBox/VMM/testcase/NemRawBench-1.cpp
- Timestamp:
- Aug 26, 2022 3:13:16 AM (3 years ago)
- svn:sync-xref-src-repo-rev:
- 153366
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/VMM/testcase/NemRawBench-1.cpp
r96407 r96511 67 67 #endif 68 68 69 #include <stdarg.h> 70 #include <stdint.h> 71 #include <stdio.h> 72 #include <stdlib.h> 73 #include <string.h> 69 #include <iprt/stream.h> 70 #include <iprt/stdarg.h> 71 #include <iprt/types.h> 72 #include <iprt/string.h> 74 73 75 74 … … 137 136 static int error(const char *pszFormat, ...) 138 137 { 139 fprintf(stderr, "error: ");138 RTStrmPrintf(g_pStdErr, "error: "); 140 139 va_list va; 141 140 va_start(va, pszFormat); 142 vfprintf(stderr, pszFormat, va);141 RTStrmPrintfV(g_pStdErr, pszFormat, va); 143 142 va_end(va); 144 143 return 1; … … 184 183 { 185 184 char szTmp[64 + 22]; 186 #ifdef _MSC_VER 187 size_t cchTmp = _snprintf(szTmp, sizeof(szTmp) - 22, "%I64u", uNum); 188 #else 189 size_t cchTmp = snprintf(szTmp, sizeof(szTmp) - 22, "%llu", (unsigned long long)uNum); 190 #endif 185 size_t cchTmp = RTStrPrintf(szTmp, sizeof(szTmp) - 22, "%llu", (unsigned long long)uNum); 191 186 size_t cSeps = (cchTmp - 1) / 3; 192 187 size_t const cchTotal = cchTmp + cSeps; … … 218 213 uint64_t const cInstrPerSec = nsElapsed ? (uint64_t)cInstructions * 1000000000 / nsElapsed : 0; 219 214 char szTmp1[64], szTmp2[64], szTmp3[64]; 220 printf("%s %7s instructions per second (%s exits in %s ns)\n",221 formatNum(cInstrPerSec, 10, szTmp1, sizeof(szTmp1)), pszInstruction,222 formatNum(cExits, 0, szTmp2, sizeof(szTmp2)),223 formatNum(nsElapsed, 0, szTmp3, sizeof(szTmp3)));215 RTPrintf("%s %7s instructions per second (%s exits in %s ns)\n", 216 formatNum(cInstrPerSec, 10, szTmp1, sizeof(szTmp1)), pszInstruction, 217 formatNum(cExits, 0, szTmp2, sizeof(szTmp2)), 218 formatNum(nsElapsed, 0, szTmp3, sizeof(szTmp3))); 224 219 return 0; 225 220 } … … 329 324 static int runtimeError(const char *pszFormat, ...) 330 325 { 331 fprintf(stderr, "runtime error: ");326 RTStrmPrintf(g_pStdErr, "runtime error: "); 332 327 va_list va; 333 328 va_start(va, pszFormat); 334 vfprintf(stderr, pszFormat, va);329 RTStrmPrintfV(g_pStdErr, pszFormat, va); 335 330 va_end(va); 336 331 … … 366 361 { 367 362 if (s_aRegs[i].uType == 32) 368 fprintf(stderr, "%8s=%08x\n", s_aRegs[i].pszName, Value.Reg32);363 RTStrmPrintf(g_pStdErr, "%8s=%08x\n", s_aRegs[i].pszName, Value.Reg32); 369 364 else if (s_aRegs[i].uType == 64) 370 fprintf(stderr, "%8s=%08x'%08x\n", s_aRegs[i].pszName, (unsigned)(Value.Reg64 >> 32), Value.Reg32);365 RTStrmPrintf(g_pStdErr, "%8s=%08x'%08x\n", s_aRegs[i].pszName, (unsigned)(Value.Reg64 >> 32), Value.Reg32); 371 366 else if (s_aRegs[i].uType == 1) 372 fprintf(stderr, "%8s=%04x base=%08x'%08x limit=%08x attr=%04x\n", s_aRegs[i].pszName,373 Value.Segment.Selector, (unsigned)(Value.Segment.Base >> 32), (unsigned)Value.Segment.Base,374 Value.Segment.Limit, Value.Segment.Attributes);367 RTStrmPrintf(g_pStdErr, "%8s=%04x base=%08x'%08x limit=%08x attr=%04x\n", s_aRegs[i].pszName, 368 Value.Segment.Selector, (unsigned)(Value.Segment.Base >> 32), (unsigned)Value.Segment.Base, 369 Value.Segment.Limit, Value.Segment.Attributes); 375 370 } 376 371 else 377 fprintf(stderr, "%8s=<WHvGetVirtualProcessorRegisters failed %#x>\n", s_aRegs[i].pszName, hrc);372 RTStrmPrintf(g_pStdErr, "%8s=<WHvGetVirtualProcessorRegisters failed %#x>\n", s_aRegs[i].pszName, hrc); 378 373 } 379 374 … … 579 574 static void printSReg(const char *pszName, struct kvm_segment const *pSReg) 580 575 { 581 fprintf(stderr, " %5s=%04x base=%016llx limit=%08x type=%#x p=%d dpl=%d db=%d s=%d l=%d g=%d avl=%d un=%d\n",582 pszName, pSReg->selector, pSReg->base, pSReg->limit, pSReg->type, pSReg->present, pSReg->dpl,583 pSReg->db, pSReg->s, pSReg->l, pSReg->g, pSReg->avl, pSReg->unusable);576 RTStrmPrintf(g_pStdErr, " %5s=%04x base=%016llx limit=%08x type=%#x p=%d dpl=%d db=%d s=%d l=%d g=%d avl=%d un=%d\n", 577 pszName, pSReg->selector, pSReg->base, pSReg->limit, pSReg->type, pSReg->present, pSReg->dpl, 578 pSReg->db, pSReg->s, pSReg->l, pSReg->g, pSReg->avl, pSReg->unusable); 584 579 } 585 580 … … 587 582 static int runtimeError(const char *pszFormat, ...) 588 583 { 589 fprintf(stderr, "runtime error: ");584 RTStrmPrintf(g_pStdErr, "runtime error: "); 590 585 va_list va; 591 586 va_start(va, pszFormat); 592 vfprintf(stderr, pszFormat, va);587 RTStrmPrintfV(g_pStdErr, pszFormat, va); 593 588 va_end(va); 594 589 595 fprintf(stderr, " exit_reason=%#010x\n", g_pVCpuRun->exit_reason);596 fprintf(stderr, "ready_for_interrupt_injection=%#x\n", g_pVCpuRun->ready_for_interrupt_injection);597 fprintf(stderr, " if_flag=%#x\n", g_pVCpuRun->if_flag);598 fprintf(stderr, " flags=%#x\n", g_pVCpuRun->flags);599 fprintf(stderr, " kvm_valid_regs=%#018llx\n", g_pVCpuRun->kvm_valid_regs);600 fprintf(stderr, " kvm_dirty_regs=%#018llx\n", g_pVCpuRun->kvm_dirty_regs);590 RTStrmPrintf(g_pStdErr, " exit_reason=%#010x\n", g_pVCpuRun->exit_reason); 591 RTStrmPrintf(g_pStdErr, "ready_for_interrupt_injection=%#x\n", g_pVCpuRun->ready_for_interrupt_injection); 592 RTStrmPrintf(g_pStdErr, " if_flag=%#x\n", g_pVCpuRun->if_flag); 593 RTStrmPrintf(g_pStdErr, " flags=%#x\n", g_pVCpuRun->flags); 594 RTStrmPrintf(g_pStdErr, " kvm_valid_regs=%#018llx\n", g_pVCpuRun->kvm_valid_regs); 595 RTStrmPrintf(g_pStdErr, " kvm_dirty_regs=%#018llx\n", g_pVCpuRun->kvm_dirty_regs); 601 596 602 597 struct kvm_regs Regs; … … 607 602 && ioctl(g_fdVCpu, KVM_GET_SREGS, &SRegs) != -1) 608 603 { 609 fprintf(stderr, " rip=%016llx\n", Regs.rip);604 RTStrmPrintf(g_pStdErr, " rip=%016llx\n", Regs.rip); 610 605 printSReg("cs", &SRegs.cs); 611 fprintf(stderr, " rflags=%08llx\n", Regs.rflags);612 fprintf(stderr, " rax=%016llx\n", Regs.rax);613 fprintf(stderr, " rbx=%016llx\n", Regs.rcx);614 fprintf(stderr, " rdx=%016llx\n", Regs.rdx);615 fprintf(stderr, " rcx=%016llx\n", Regs.rbx);616 fprintf(stderr, " rsp=%016llx\n", Regs.rsp);617 fprintf(stderr, " rbp=%016llx\n", Regs.rbp);618 fprintf(stderr, " rsi=%016llx\n", Regs.rsi);619 fprintf(stderr, " rdi=%016llx\n", Regs.rdi);606 RTStrmPrintf(g_pStdErr, " rflags=%08llx\n", Regs.rflags); 607 RTStrmPrintf(g_pStdErr, " rax=%016llx\n", Regs.rax); 608 RTStrmPrintf(g_pStdErr, " rbx=%016llx\n", Regs.rcx); 609 RTStrmPrintf(g_pStdErr, " rdx=%016llx\n", Regs.rdx); 610 RTStrmPrintf(g_pStdErr, " rcx=%016llx\n", Regs.rbx); 611 RTStrmPrintf(g_pStdErr, " rsp=%016llx\n", Regs.rsp); 612 RTStrmPrintf(g_pStdErr, " rbp=%016llx\n", Regs.rbp); 613 RTStrmPrintf(g_pStdErr, " rsi=%016llx\n", Regs.rsi); 614 RTStrmPrintf(g_pStdErr, " rdi=%016llx\n", Regs.rdi); 620 615 printSReg("ss", &SRegs.ss); 621 616 printSReg("ds", &SRegs.ds); … … 628 623 uint64_t const offMem = Regs.rip + SRegs.cs.base - MY_MEM_BASE; 629 624 if (offMem < g_cbMem - 10) 630 fprintf(stderr, " bytes at PC (%#zx): %02x %02x %02x %02x %02x %02x %02x %02x\n", (size_t)(offMem + MY_MEM_BASE),631 g_pbMem[offMem ], g_pbMem[offMem + 1], g_pbMem[offMem + 2], g_pbMem[offMem + 3],632 g_pbMem[offMem + 4], g_pbMem[offMem + 5], g_pbMem[offMem + 6], g_pbMem[offMem + 7]);625 RTStrmPrintf(g_pStdErr, " bytes at PC (%#zx): %02x %02x %02x %02x %02x %02x %02x %02x\n", (size_t)(offMem + MY_MEM_BASE), 626 g_pbMem[offMem ], g_pbMem[offMem + 1], g_pbMem[offMem + 2], g_pbMem[offMem + 3], 627 g_pbMem[offMem + 4], g_pbMem[offMem + 5], g_pbMem[offMem + 6], g_pbMem[offMem + 7]); 633 628 } 634 629 … … 771 766 static int runtimeError(const char *pszFormat, ...) 772 767 { 773 fprintf(stderr, "runtime error: ");768 RTStrmPrintf(g_pStdErr, "runtime error: "); 774 769 va_list va; 775 770 va_start(va, pszFormat); 776 vfprintf(stderr, pszFormat, va);771 RTStrmPrintfV(g_pStdErr, pszFormat, va); 777 772 va_end(va); 778 773 … … 868 863 { 869 864 if (s_aFields[i].uFmt == 16) 870 fprintf(stderr, "%28s=%04llx\n", s_aFields[i].pszName, uValue);865 RTStrmPrintf(g_pStdErr, "%28s=%04llx\n", s_aFields[i].pszName, uValue); 871 866 else if (s_aFields[i].uFmt == 32) 872 fprintf(stderr, "%28s=%08llx\n", s_aFields[i].pszName, uValue);867 RTStrmPrintf(g_pStdErr, "%28s=%08llx\n", s_aFields[i].pszName, uValue); 873 868 else 874 fprintf(stderr, "%28s=%08x'%08x\n", s_aFields[i].pszName, (uint32_t)(uValue >> 32), (uint32_t)uValue);869 RTStrmPrintf(g_pStdErr, "%28s=%08x'%08x\n", s_aFields[i].pszName, (uint32_t)(uValue >> 32), (uint32_t)uValue); 875 870 } 876 871 else 877 fprintf(stderr, "%28s=<%s failed %#x>\n", s_aFields[i].pszName,878 s_aFields[i].fIsReg ? "hv_vcpu_read_register" : "hv_vmx_vcpu_read_vmcs", rcHv);872 RTStrmPrintf(g_pStdErr, "%28s=<%s failed %#x>\n", s_aFields[i].pszName, 873 s_aFields[i].fIsReg ? "hv_vcpu_read_register" : "hv_vmx_vcpu_read_vmcs", rcHv); 879 874 } 880 875 return 1; … … 1098 1093 void dumpCode(uint8_t const *pb, uint8_t *pbEnd) 1099 1094 { 1100 printf("testing:");1095 RTPrintf("testing:"); 1101 1096 for (; pb != pbEnd; pb++) 1102 printf(" %02x", *pb);1103 printf("\n");1097 RTPrintf(" %02x", *pb); 1098 RTPrintf("\n"); 1104 1099 } 1105 1100 … … 1232 1227 || strcmp(pszArg, "/?") == 0) 1233 1228 { 1234 printf("Does some benchmarking of the native NEM engine.\n"1235 "\n"1236 "Usage: NemRawBench-1 --factor <factor>\n"1237 "\n"1238 "Options\n"1239 " --factor <factor>\n"1240 " Iteration count factor. Default is %u.\n"1241 " Lower it if execution is slow, increase if quick.\n",1242 cFactorDefault);1229 RTPrintf("Does some benchmarking of the native NEM engine.\n" 1230 "\n" 1231 "Usage: NemRawBench-1 --factor <factor>\n" 1232 "\n" 1233 "Options\n" 1234 " --factor <factor>\n" 1235 " Iteration count factor. Default is %u.\n" 1236 " Lower it if execution is slow, increase if quick.\n", 1237 cFactorDefault); 1243 1238 return 0; 1244 1239 } … … 1247 1242 i++; 1248 1243 if (i < argc) 1249 cFactor = atoi(argv[i]);1244 cFactor = RTStrToUInt32(argv[i]); 1250 1245 else 1251 1246 { 1252 fprintf(stderr, "syntax error: Option %s is takes a value!\n", pszArg);1247 RTStrmPrintf(g_pStdErr, "syntax error: Option %s is takes a value!\n", pszArg); 1253 1248 return 2; 1254 1249 } … … 1256 1251 else 1257 1252 { 1258 fprintf(stderr, "syntax error: Unknown option: %s\n", pszArg);1253 RTStrmPrintf(g_pStdErr, "syntax error: Unknown option: %s\n", pszArg); 1259 1254 return 2; 1260 1255 } … … 1268 1263 if (rcExit == 0) 1269 1264 { 1270 printf("tstNemBench-1: Successfully created test VM...\n");1265 RTPrintf("tstNemBench-1: Successfully created test VM...\n"); 1271 1266 1272 1267 /* … … 1277 1272 mmioTest(cFactor); 1278 1273 1279 printf("tstNemBench-1: done\n");1274 RTPrintf("tstNemBench-1: done\n"); 1280 1275 } 1281 1276 return rcExit;
Note:
See TracChangeset
for help on using the changeset viewer.