Lines Matching refs:csam

25 #include <VBox/vmm/csam.h>
242 rc = MMR3HyperAllocOnceNoRel(pVM, CSAM_PGDIRBMP_CHUNKS*sizeof(RTHCPTR), 0, MM_TAG_CSAM, (void **)&pVM->csam.s.pPDBitmapHC);
244 rc = MMR3HyperAllocOnceNoRel(pVM, CSAM_PGDIRBMP_CHUNKS*sizeof(RTRCPTR), 0, MM_TAG_CSAM, (void **)&pVM->csam.s.pPDGCBitmapHC);
246 pVM->csam.s.pPDBitmapGC = MMHyperR3ToRC(pVM, pVM->csam.s.pPDGCBitmapHC);
247 pVM->csam.s.pPDHCBitmapGC = MMHyperR3ToRC(pVM, pVM->csam.s.pPDBitmapHC);
255 rc = SSMR3RegisterInternal(pVM, "CSAM", 0, CSAM_SAVED_STATE_VERSION, sizeof(pVM->csam.s) + PAGE_SIZE*16,
261 STAM_REG(pVM, &pVM->csam.s.StatNrTraps, STAMTYPE_COUNTER, "/CSAM/PageTraps", STAMUNIT_OCCURENCES, "The number of CSAM page traps.");
262 STAM_REG(pVM, &pVM->csam.s.StatDangerousWrite, STAMTYPE_COUNTER, "/CSAM/DangerousWrites", STAMUNIT_OCCURENCES, "The number of dangerous writes that cause a context switch.");
264 STAM_REG(pVM, &pVM->csam.s.StatNrPageNPHC, STAMTYPE_COUNTER, "/CSAM/HC/PageNotPresent", STAMUNIT_OCCURENCES, "The number of CSAM pages marked not present.");
265 STAM_REG(pVM, &pVM->csam.s.StatNrPageNPGC, STAMTYPE_COUNTER, "/CSAM/GC/PageNotPresent", STAMUNIT_OCCURENCES, "The number of CSAM pages marked not present.");
266 STAM_REG(pVM, &pVM->csam.s.StatNrPages, STAMTYPE_COUNTER, "/CSAM/PageRec/AddedRW", STAMUNIT_OCCURENCES, "The number of CSAM page records (RW monitoring).");
267 STAM_REG(pVM, &pVM->csam.s.StatNrPagesInv, STAMTYPE_COUNTER, "/CSAM/PageRec/AddedRWI", STAMUNIT_OCCURENCES, "The number of CSAM page records (RW & invalidation monitoring).");
268 STAM_REG(pVM, &pVM->csam.s.StatNrRemovedPages, STAMTYPE_COUNTER, "/CSAM/PageRec/Removed", STAMUNIT_OCCURENCES, "The number of removed CSAM page records.");
269 STAM_REG(pVM, &pVM->csam.s.StatPageRemoveREMFlush,STAMTYPE_COUNTER, "/CSAM/PageRec/Removed/REMFlush", STAMUNIT_OCCURENCES, "The number of removed CSAM page records that caused a REM flush.");
271 STAM_REG(pVM, &pVM->csam.s.StatNrPatchPages, STAMTYPE_COUNTER, "/CSAM/PageRec/Patch", STAMUNIT_OCCURENCES, "The number of CSAM patch page records.");
272 STAM_REG(pVM, &pVM->csam.s.StatNrUserPages, STAMTYPE_COUNTER, "/CSAM/PageRec/Ignore/User", STAMUNIT_OCCURENCES, "The number of CSAM user page records (ignored).");
273 STAM_REG(pVM, &pVM->csam.s.StatPagePATM, STAMTYPE_COUNTER, "/CSAM/PageRec/Type/PATM", STAMUNIT_OCCURENCES, "The number of PATM page records.");
274 STAM_REG(pVM, &pVM->csam.s.StatPageCSAM, STAMTYPE_COUNTER, "/CSAM/PageRec/Type/CSAM", STAMUNIT_OCCURENCES, "The number of CSAM page records.");
275 STAM_REG(pVM, &pVM->csam.s.StatPageREM, STAMTYPE_COUNTER, "/CSAM/PageRec/Type/REM", STAMUNIT_OCCURENCES, "The number of REM page records.");
276 STAM_REG(pVM, &pVM->csam.s.StatPageMonitor, STAMTYPE_COUNTER, "/CSAM/PageRec/Monitored", STAMUNIT_OCCURENCES, "The number of monitored pages.");
278 STAM_REG(pVM, &pVM->csam.s.StatCodePageModified, STAMTYPE_COUNTER, "/CSAM/Monitor/DirtyPage", STAMUNIT_OCCURENCES, "The number of code page modifications.");
280 STAM_REG(pVM, &pVM->csam.s.StatNrFlushes, STAMTYPE_COUNTER, "/CSAM/PageFlushes", STAMUNIT_OCCURENCES, "The number of CSAM page flushes.");
281 STAM_REG(pVM, &pVM->csam.s.StatNrFlushesSkipped, STAMTYPE_COUNTER, "/CSAM/PageFlushesSkipped", STAMUNIT_OCCURENCES, "The number of CSAM page flushes that were skipped.");
282 STAM_REG(pVM, &pVM->csam.s.StatNrKnownPagesHC, STAMTYPE_COUNTER, "/CSAM/HC/KnownPageRecords", STAMUNIT_OCCURENCES, "The number of known CSAM page records.");
283 STAM_REG(pVM, &pVM->csam.s.StatNrKnownPagesGC, STAMTYPE_COUNTER, "/CSAM/GC/KnownPageRecords", STAMUNIT_OCCURENCES, "The number of known CSAM page records.");
284 STAM_REG(pVM, &pVM->csam.s.StatNrInstr, STAMTYPE_COUNTER, "/CSAM/ScannedInstr", STAMUNIT_OCCURENCES, "The number of scanned instructions.");
285 STAM_REG(pVM, &pVM->csam.s.StatNrBytesRead, STAMTYPE_COUNTER, "/CSAM/BytesRead", STAMUNIT_OCCURENCES, "The number of bytes read for scanning.");
286 STAM_REG(pVM, &pVM->csam.s.StatNrOpcodeRead, STAMTYPE_COUNTER, "/CSAM/OpcodeBytesRead", STAMUNIT_OCCURENCES, "The number of opcode bytes read by the recompiler.");
288 STAM_REG(pVM, &pVM->csam.s.StatBitmapAlloc, STAMTYPE_COUNTER, "/CSAM/Alloc/PageBitmap", STAMUNIT_OCCURENCES, "The number of page bitmap allocations.");
290 STAM_REG(pVM, &pVM->csam.s.StatInstrCacheHit, STAMTYPE_COUNTER, "/CSAM/Cache/Hit", STAMUNIT_OCCURENCES, "The number of dangerous instruction cache hits.");
291 STAM_REG(pVM, &pVM->csam.s.StatInstrCacheMiss, STAMTYPE_COUNTER, "/CSAM/Cache/Miss", STAMUNIT_OCCURENCES, "The number of dangerous instruction cache misses.");
293 STAM_REG(pVM, &pVM->csam.s.StatScanNextFunction, STAMTYPE_COUNTER, "/CSAM/Function/Scan/Success", STAMUNIT_OCCURENCES, "The number of found functions beyond the ret border.");
294 STAM_REG(pVM, &pVM->csam.s.StatScanNextFunctionFailed, STAMTYPE_COUNTER, "/CSAM/Function/Scan/Failed", STAMUNIT_OCCURENCES, "The number of refused functions beyond the ret border.");
296 STAM_REG(pVM, &pVM->csam.s.StatTime, STAMTYPE_PROFILE, "/PROF/CSAM/Scan", STAMUNIT_TICKS_PER_CALL, "Scanning overhead.");
297 STAM_REG(pVM, &pVM->csam.s.StatTimeCheckAddr, STAMTYPE_PROFILE, "/PROF/CSAM/CheckAddr", STAMUNIT_TICKS_PER_CALL, "Address check overhead.");
298 STAM_REG(pVM, &pVM->csam.s.StatTimeAddrConv, STAMTYPE_PROFILE, "/PROF/CSAM/AddrConv", STAMUNIT_TICKS_PER_CALL, "Address conversion overhead.");
299 STAM_REG(pVM, &pVM->csam.s.StatTimeFlushPage, STAMTYPE_PROFILE, "/PROF/CSAM/FlushPage", STAMUNIT_TICKS_PER_CALL, "Page flushing overhead.");
300 STAM_REG(pVM, &pVM->csam.s.StatTimeDisasm, STAMTYPE_PROFILE, "/PROF/CSAM/Disasm", STAMUNIT_TICKS_PER_CALL, "Disassembly overhead.");
301 STAM_REG(pVM, &pVM->csam.s.StatFlushDirtyPages, STAMTYPE_PROFILE, "/PROF/CSAM/FlushDirtyPage", STAMUNIT_TICKS_PER_CALL, "Dirty page flushing overhead.");
302 STAM_REG(pVM, &pVM->csam.s.StatCheckGates, STAMTYPE_PROFILE, "/PROF/CSAM/CheckGates", STAMUNIT_TICKS_PER_CALL, "CSAMR3CheckGates overhead.");
344 AssertRelease(!(RT_OFFSETOF(VM, csam.s) & 31));
345 AssertRelease(sizeof(pVM->csam.s) <= sizeof(pVM->csam.padding));
351 pVM->csam.s.offVM = RT_OFFSETOF(VM, patm);
353 pVM->csam.s.fGatesChecked = false;
354 pVM->csam.s.fScanningStarted = false;
358 pVM->csam.s.cDirtyPages = 0;
360 memset(pVM->csam.s.pvDirtyBasePage, 0, sizeof(pVM->csam.s.pvDirtyBasePage));
361 memset(pVM->csam.s.pvDirtyFaultPage, 0, sizeof(pVM->csam.s.pvDirtyFaultPage));
363 memset(&pVM->csam.s.aDangerousInstr, 0, sizeof(pVM->csam.s.aDangerousInstr));
364 pVM->csam.s.cDangerousInstr = 0;
365 pVM->csam.s.iDangerousInstr = 0;
367 memset(pVM->csam.s.pvCallInstruction, 0, sizeof(pVM->csam.s.pvCallInstruction));
368 pVM->csam.s.iCallInstruction = 0;
379 * The csam will update the addresses used by the switcher.
389 pVM->csam.s.pPDBitmapGC = MMHyperR3ToRC(pVM, pVM->csam.s.pPDGCBitmapHC);
390 pVM->csam.s.pPDHCBitmapGC = MMHyperR3ToRC(pVM, pVM->csam.s.pPDBitmapHC);
394 if (pVM->csam.s.pPDGCBitmapHC[i])
396 pVM->csam.s.pPDGCBitmapHC[i] += offDelta;
404 * Terminates the csam.
426 if (pVM->csam.s.pPDBitmapHC[i])
427 MMHyperFree(pVM, pVM->csam.s.pPDBitmapHC[i]);
448 if (pVM->csam.s.pPDBitmapHC[i])
451 ASMMemZero32(pVM->csam.s.pPDBitmapHC[i], CSAM_PAGE_BITMAP_SIZE);
458 PCSAMPAGEREC pPageRec = (PCSAMPAGEREC)RTAvlPVGetBestFit(&pVM->csam.s.pPageTree, 0, true);
463 Assert(!pVM->csam.s.pPageTree);
501 PSSMHANDLE pSSM = pVM->csam.s.savedstate.pSSM;
526 CSAM csamInfo = pVM->csam.s;
533 RTAvlPVDoWithAll(&pVM->csam.s.pPageTree, true, CountRecord, &csamInfo.savedstate.cPageRecords);
538 pVM->csam.s.savedstate.pSSM = pSSM;
559 rc = RTAvlPVDoWithAll(&pVM->csam.s.pPageTree, true, SavePageState, pVM);
588 pVM->csam.s.savedstate.pSSM = pSSM;
597 pVM->csam.s.fGatesChecked = csamInfo.fGatesChecked;
598 pVM->csam.s.fScanningStarted = csamInfo.fScanningStarted;
601 pVM->csam.s.cDirtyPages = csamInfo.cDirtyPages;
602 memcpy(pVM->csam.s.pvDirtyBasePage, csamInfo.pvDirtyBasePage, sizeof(pVM->csam.s.pvDirtyBasePage));
603 memcpy(pVM->csam.s.pvDirtyFaultPage, csamInfo.pvDirtyFaultPage, sizeof(pVM->csam.s.pvDirtyFaultPage));
606 pVM->csam.s.cPossibleCodePages = csamInfo.cPossibleCodePages;
607 memcpy(pVM->csam.s.pvPossibleCodePage, csamInfo.pvPossibleCodePage, sizeof(pVM->csam.s.pvPossibleCodePage));
610 rc = SSMR3GetStructEx(pSSM, pVM->csam.s.pPDBitmapHC, sizeof(uint8_t *) * CSAM_PGDIRBMP_CHUNKS,
619 if(pVM->csam.s.pPDBitmapHC[i])
621 rc = MMHyperAlloc(pVM, CSAM_PAGE_BITMAP_SIZE, 0, MM_TAG_CSAM, (void **)&pVM->csam.s.pPDBitmapHC[i]);
628 pVM->csam.s.pPDGCBitmapHC[i] = MMHyperR3ToRC(pVM, pVM->csam.s.pPDBitmapHC[i]);
629 Assert(pVM->csam.s.pPDGCBitmapHC[i]);
632 rc = SSMR3GetMem(pSSM, pVM->csam.s.pPDBitmapHC[i], CSAM_PAGE_BITMAP_SIZE);
637 Assert(!pVM->csam.s.pPDGCBitmapHC[i]);
638 pVM->csam.s.pPDGCBitmapHC[i] = 0;
677 memset(&pVM->csam.s.aDangerousInstr, 0, sizeof(pVM->csam.s.aDangerousInstr));
678 pVM->csam.s.cDangerousInstr = 0;
679 pVM->csam.s.iDangerousInstr = 0;
701 STAM_PROFILE_START(&pVM->csam.s.StatTimeAddrConv, a);
712 STAM_PROFILE_STOP(&pVM->csam.s.StatTimeAddrConv, a);
728 STAM_PROFILE_STOP(&pVM->csam.s.StatTimeAddrConv, a);
734 STAM_PROFILE_STOP(&pVM->csam.s.StatTimeAddrConv, a);
1127 STAM_PROFILE_START(&pVM->csam.s.StatTimeDisasm, a);
1136 STAM_PROFILE_STOP(&pVM->csam.s.StatTimeDisasm, a);
1143 STAM_COUNTER_ADD(&pVM->csam.s.StatNrBytesRead, cbInstr);
1183 STAM_COUNTER_INC(&pVM->csam.s.StatScanNextFunctionFailed);
1195 STAM_COUNTER_INC(&pVM->csam.s.StatScanNextFunctionFailed);
1208 STAM_COUNTER_INC(&pVM->csam.s.StatScanNextFunction);
1221 STAM_COUNTER_INC(&pVM->csam.s.StatScanNextFunctionFailed);
1234 STAM_COUNTER_INC(&pVM->csam.s.StatScanNextFunction);
1241 STAM_COUNTER_INC(&pVM->csam.s.StatScanNextFunctionFailed);
1289 pVM->csam.s.fScanningStarted = true;
1340 STAM_PROFILE_START(&pVM->csam.s.StatTimeDisasm, a);
1349 STAM_PROFILE_STOP(&pVM->csam.s.StatTimeDisasm, a);
1358 STAM_COUNTER_ADD(&pVM->csam.s.StatNrBytesRead, cbInstr);
1635 STAM_PROFILE_START(&pVM->csam.s.StatTimeFlushPage, a);
1642 if (pVM->csam.s.pPageTree == NULL)
1644 STAM_PROFILE_STOP(&pVM->csam.s.StatTimeFlushPage, a);
1652 STAM_PROFILE_STOP(&pVM->csam.s.StatTimeFlushPage, a);
1663 STAM_COUNTER_ADD(&pVM->csam.s.StatNrFlushesSkipped, 1);
1664 STAM_PROFILE_STOP(&pVM->csam.s.StatTimeFlushPage, a);
1672 pPageRec = (PCSAMPAGEREC)RTAvlPVGet(&pVM->csam.s.pPageTree, (AVLPVKEY)(uintptr_t)addr);
1678 STAM_COUNTER_ADD(&pVM->csam.s.StatNrFlushesSkipped, 1);
1679 STAM_PROFILE_STOP(&pVM->csam.s.StatTimeFlushPage, a);
1685 STAM_COUNTER_ADD(&pVM->csam.s.StatNrFlushes, 1);
1715 STAM_PROFILE_STOP(&pVM->csam.s.StatTimeFlushPage, a);
1720 STAM_PROFILE_STOP(&pVM->csam.s.StatTimeFlushPage, a);
1753 pPageRec = (PCSAMPAGEREC)RTAvlPVGet(&pVM->csam.s.pPageTree, (AVLPVKEY)(uintptr_t)addr);
1778 pPageRec = (PCSAMPAGEREC)RTAvlPVGet(&pVM->csam.s.pPageTree, (AVLPVKEY)(uintptr_t)pInstrGC);
1847 ret = RTAvlPVInsert(&pVM->csam.s.pPageTree, &pPage->Core);
1878 STAM_COUNTER_INC(&pVM->csam.s.StatPageMonitor);
1891 STAM_COUNTER_INC(&pVM->csam.s.StatPageCSAM);
1894 STAM_COUNTER_INC(&pVM->csam.s.StatPagePATM);
1897 STAM_COUNTER_INC(&pVM->csam.s.StatPageREM);
1906 STAM_COUNTER_INC(&pVM->csam.s.StatNrPages);
1908 STAM_COUNTER_INC(&pVM->csam.s.StatNrPagesInv);
1931 Assert(!pVM->csam.s.cDirtyPages);
1933 if (pVM->csam.s.fScanningStarted == false)
1943 pPageRec = (PCSAMPAGEREC)RTAvlPVGet(&pVM->csam.s.pPageTree, (AVLPVKEY)(uintptr_t)pPageAddrGC);
1954 STAM_COUNTER_INC(&pVM->csam.s.StatNrUserPages);
1960 pPageRec = (PCSAMPAGEREC)RTAvlPVGet(&pVM->csam.s.pPageTree, (AVLPVKEY)(uintptr_t)pPageAddrGC);
1990 STAM_COUNTER_INC(&pVM->csam.s.StatPageMonitor);
2002 STAM_COUNTER_INC(&pVM->csam.s.StatNrPagesInv);
2059 pPageRec = (PCSAMPAGEREC)RTAvlPVGet(&pVM->csam.s.pPageTree, (AVLPVKEY)(uintptr_t)pPageAddrGC);
2079 pPageRec = (PCSAMPAGEREC)RTAvlPVRemove(&pVM->csam.s.pPageTree, (AVLPVKEY)(uintptr_t)GCPtr);
2083 STAM_COUNTER_INC(&pVM->csam.s.StatNrRemovedPages);
2092 STAM_COUNTER_DEC(&pVM->csam.s.StatPageMonitor);
2098 STAM_COUNTER_INC(&pVM->csam.s.StatPageRemoveREMFlush);
2107 STAM_COUNTER_DEC(&pVM->csam.s.StatPageCSAM);
2110 STAM_COUNTER_DEC(&pVM->csam.s.StatPagePATM);
2113 STAM_COUNTER_DEC(&pVM->csam.s.StatPageREM);
2219 STAM_PROFILE_START(&pVM->csam.s.StatTimeCheckAddr, a);
2230 STAM_COUNTER_ADD(&pVM->csam.s.StatNrKnownPagesHC, 1);
2231 STAM_PROFILE_STOP(&pVM->csam.s.StatTimeCheckAddr, a);
2234 STAM_PROFILE_STOP(&pVM->csam.s.StatTimeCheckAddr, a);
2238 pPageRec = (PCSAMPAGEREC)RTAvlPVGet(&pVM->csam.s.pPageTree, (AVLPVKEY)(uintptr_t)pInstr);
2244 STAM_COUNTER_ADD(&pVM->csam.s.StatNrKnownPagesHC, 1);
2245 STAM_PROFILE_STOP(&pVM->csam.s.StatTimeCheckAddr, a);
2253 STAM_PROFILE_STOP(&pVM->csam.s.StatTimeCheckAddr, a);
2281 STAM_COUNTER_ADD(&pVM->csam.s.StatNrInstr, 1);
2379 STAM_PROFILE_START(&pVM->csam.s.StatTime, a);
2381 STAM_PROFILE_STOP(&pVM->csam.s.StatTime, a);
2405 STAM_PROFILE_START(&pVM->csam.s.StatFlushDirtyPages, a);
2407 for (uint32_t i=0;i<pVM->csam.s.cDirtyPages;i++)
2411 RTRCPTR GCPtr = pVM->csam.s.pvDirtyBasePage[i];
2421 rc = PGMShwMakePageReadonly(pVCpu, pVM->csam.s.pvDirtyFaultPage[i], 0 /*fFlags*/);
2424 Log(("CSAMR3FlushDirtyPages: flush %RRv (modifypage rc=%Rrc)\n", pVM->csam.s.pvDirtyBasePage[i], rc));
2426 pPageRec = (PCSAMPAGEREC)RTAvlPVGet(&pVM->csam.s.pPageTree, (AVLPVKEY)(uintptr_t)GCPtr);
2438 STAM_COUNTER_INC(&pVM->csam.s.StatNrUserPages);
2442 pVM->csam.s.cDirtyPages = 0;
2443 STAM_PROFILE_STOP(&pVM->csam.s.StatFlushDirtyPages, a);
2458 for (uint32_t i=0;i<pVM->csam.s.cPossibleCodePages;i++)
2460 RTRCPTR GCPtr = pVM->csam.s.pvPossibleCodePage[i];
2469 pVM->csam.s.cPossibleCodePages = 0;
2521 if ( !pVM->csam.s.fGatesChecked
2526 if ( pVM->csam.s.fGatesChecked
2536 pVM->csam.s.fGatesChecked = true;
2537 for (unsigned i=0;i<RT_ELEMENTS(pVM->csam.s.pvCallInstruction);i++)
2539 RTRCPTR pHandler = pVM->csam.s.pvCallInstruction[i];
2548 STAM_PROFILE_START(&pVM->csam.s.StatTime, a);
2550 STAM_PROFILE_STOP(&pVM->csam.s.StatTime, a);
2575 STAM_PROFILE_START(&pVM->csam.s.StatCheckGates, a);
2584 STAM_PROFILE_STOP(&pVM->csam.s.StatCheckGates, a);
2629 STAM_PROFILE_START(&pVM->csam.s.StatTime, b);
2631 STAM_PROFILE_STOP(&pVM->csam.s.StatTime, b);
2706 STAM_PROFILE_STOP(&pVM->csam.s.StatCheckGates, a);
2721 for (unsigned i=0;i<RT_ELEMENTS(pVM->csam.s.pvCallInstruction);i++)
2723 if (pVM->csam.s.pvCallInstruction[i] == GCPtrCall)
2729 pVM->csam.s.pvCallInstruction[pVM->csam.s.iCallInstruction++] = GCPtrCall;
2730 if (pVM->csam.s.iCallInstruction >= RT_ELEMENTS(pVM->csam.s.pvCallInstruction))
2731 pVM->csam.s.iCallInstruction = 0;