VirtualBox

Changeset 23460 in vbox for trunk/src


Ignore:
Timestamp:
Oct 1, 2009 2:02:51 AM (15 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
53057
Message:

PGM: Page lock counters. (disabled)

Location:
trunk/src/VBox/VMM
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/VMM/PGMInternal.h

    r23459 r23460  
    11141114#define PGM_PAGE_GET_TD_IDX(pPage) \
    11151115    ((PGM_PAGE_GET_TRACKING(pPage) >> PGMPOOL_TD_IDX_SHIFT)   & PGMPOOL_TD_IDX_MASK)
     1116
     1117
     1118// /** Enables page lock accounting. */
     1119// #define PGM_PAGE_WITH_LOCKS
     1120
     1121#ifdef PGM_PAGE_WITH_LOCKS
     1122/** Max number of locks on a page. */
     1123# ifdef PGM_PAGE_WITH_PAGEID_IN_HCPHYS
     1124#  define PGM_PAGE_MAX_LOCKS    256
     1125# else
     1126#  define PGM_PAGE_MAX_LOCKS    16
     1127# endif
     1128/** Get the read lock count.
     1129 * @returns count.
     1130 * @param   pPage               Pointer to the physical guest page tracking structure.
     1131 */
     1132# define PGM_PAGE_GET_READ_LOCKS(pPage)     ( (pPage)->cReadLocksY )
     1133/** Get the write lock count.
     1134 * @returns count.
     1135 * @param   pPage               Pointer to the physical guest page tracking structure.
     1136 */
     1137# define PGM_PAGE_GET_WRITE_LOCKS(pPage)    ( (pPage)->cWriteLocksY )
     1138/** Decrement the read lock counter.
     1139 * @param   pPage               Pointer to the physical guest page tracking structure.
     1140 */
     1141# define PGM_PAGE_DEC_READ_LOCKS(pPage)     do { --(pPage)->cReadLocksY; } while (0)
     1142/** Decrement the write lock counter.
     1143 * @param   pPage               Pointer to the physical guest page tracking structure.
     1144 */
     1145# define PGM_PAGE_DEC_WRITE_LOCKS(pPage)    do { --(pPage)->cWriteLocksY; } while (0)
     1146/** Increment the read lock counter.
     1147 * @param   pPage               Pointer to the physical guest page tracking structure.
     1148 */
     1149# define PGM_PAGE_INC_READ_LOCKS(pPage)     do { ++(pPage)->cReadLocksY; } while (0)
     1150/** Increment the write lock counter.
     1151 * @param   pPage               Pointer to the physical guest page tracking structure.
     1152 */
     1153# define PGM_PAGE_INC_WRITE_LOCKS(pPage)    do { ++(pPage)->cWriteLocksY; } while (0)
     1154#endif
    11161155
    11171156
  • trunk/src/VBox/VMM/PGMPhys.cpp

    r23457 r23460  
    451451             */
    452452            PPGMPAGEMAP pMap = pTlbe->pMap;
    453             pMap->cRefs++;
    454 #if 0 /** @todo implement locking properly */
    455             if (RT_LIKELY(pPage->cLocks != PGM_PAGE_MAX_LOCKS))
    456                 if (RT_UNLIKELY(++pPage->cLocks == PGM_PAGE_MAX_LOCKS))
    457                 {
    458                     AssertMsgFailed(("%RGp is entering permanent locked state!\n", GCPhys));
     453            if (pMap)
     454                pMap->cRefs++;
     455
     456# ifdef PGM_PAGE_WITH_LOCKS
     457            unsigned cLocks = PGM_PAGE_GET_WRITE_LOCKS(pPage);
     458            if (RT_LIKELY(cLocks < PGM_PAGE_MAX_LOCKS - 1))
     459                PGM_PAGE_INC_WRITE_LOCKS(pPage);
     460            else if (cLocks != PGM_PAGE_GET_WRITE_LOCKS(pPage))
     461            {
     462                PGM_PAGE_INC_WRITE_LOCKS(pPage);
     463                AssertMsgFailed(("%RGp / %R[pgmpage] is entering permanent write locked state!\n", GCPhys, pPage));
     464                if (pMap)
    459465                    pMap->cRefs++; /* Extra ref to prevent it from going away. */
    460                 }
    461 #endif
     466            }
     467# endif
     468
    462469            *ppv = (void *)((uintptr_t)pTlbe->pv | (GCPhys & PAGE_OFFSET_MASK));
    463             pLock->pvPage = pPage;
     470            pLock->uPageAndType = (uintptr_t)pPage | PGMPAGEMAPLOCK_TYPE_WRITE;
    464471            pLock->pvMap = pMap;
    465472        }
     
    520527             */
    521528            PPGMPAGEMAP pMap = pTlbe->pMap;
    522             pMap->cRefs++;
    523 #if 0 /** @todo implement locking properly */
    524             if (RT_LIKELY(pPage->cLocks != PGM_PAGE_MAX_LOCKS))
    525                 if (RT_UNLIKELY(++pPage->cLocks == PGM_PAGE_MAX_LOCKS))
    526                 {
    527                     AssertMsgFailed(("%RGp is entering permanent locked state!\n", GCPhys));
     529            if (pMap)
     530                pMap->cRefs++;
     531
     532# ifdef PGM_PAGE_WITH_LOCKS
     533            unsigned cLocks = PGM_PAGE_GET_READ_LOCKS(pPage);
     534            if (RT_LIKELY(cLocks < PGM_PAGE_MAX_LOCKS - 1))
     535                PGM_PAGE_INC_READ_LOCKS(pPage);
     536            else if (cLocks != PGM_PAGE_GET_READ_LOCKS(pPage))
     537            {
     538                PGM_PAGE_INC_READ_LOCKS(pPage);
     539                AssertMsgFailed(("%RGp / %R[pgmpage] is entering permanent readonly locked state!\n", GCPhys, pPage));
     540                if (pMap)
    528541                    pMap->cRefs++; /* Extra ref to prevent it from going away. */
    529                 }
    530 #endif
     542            }
     543# endif
     544
    531545            *ppv = (void *)((uintptr_t)pTlbe->pv | (GCPhys & PAGE_OFFSET_MASK));
    532             pLock->pvPage = pPage;
     546            pLock->uPageAndType = (uintptr_t)pPage | PGMPAGEMAPLOCK_TYPE_READ;
    533547            pLock->pvMap = pMap;
    534548        }
  • trunk/src/VBox/VMM/VMMAll/PGMAllPhys.cpp

    r23453 r23460  
    10691069            if (pMap)
    10701070                pMap->cRefs++;
    1071 # if 0 /** @todo implement locking properly */
    1072             if (RT_LIKELY(pPage->cLocks != PGM_PAGE_MAX_LOCKS))
    1073                 if (RT_UNLIKELY(++pPage->cLocks == PGM_PAGE_MAX_LOCKS))
    1074                 {
    1075                     AssertMsgFailed(("%RGp is entering permanent locked state!\n", GCPhys));
    1076                     if (pMap)
    1077                         pMap->cRefs++; /* Extra ref to prevent it from going away. */
    1078                 }
     1071
     1072# ifdef PGM_PAGE_WITH_LOCKS
     1073            unsigned cLocks = PGM_PAGE_GET_WRITE_LOCKS(pPage);
     1074            if (RT_LIKELY(cLocks < PGM_PAGE_MAX_LOCKS - 1))
     1075                PGM_PAGE_INC_WRITE_LOCKS(pPage);
     1076            else if (cLocks != PGM_PAGE_GET_WRITE_LOCKS(pPage))
     1077            {
     1078                PGM_PAGE_INC_WRITE_LOCKS(pPage);
     1079                AssertMsgFailed(("%RGp / %R[pgmpage] is entering permanent write locked state!\n", GCPhys, pPage));
     1080                if (pMap)
     1081                    pMap->cRefs++; /* Extra ref to prevent it from going away. */
     1082            }
    10791083# endif
     1084
    10801085            *ppv = (void *)((uintptr_t)pTlbe->pv | (GCPhys & PAGE_OFFSET_MASK));
    1081             pLock->pvPage = pPage;
     1086            pLock->uPageAndType = (uintptr_t)pPage | PGMPAGEMAPLOCK_TYPE_WRITE;
    10821087            pLock->pvMap = pMap;
    10831088        }
     
    11641169            if (pMap)
    11651170                pMap->cRefs++;
    1166 # if 0 /** @todo implement locking properly */
    1167             if (RT_LIKELY(pPage->cLocks != PGM_PAGE_MAX_LOCKS))
    1168                 if (RT_UNLIKELY(++pPage->cLocks == PGM_PAGE_MAX_LOCKS))
    1169                 {
    1170                     AssertMsgFailed(("%RGp is entering permanent locked state!\n", GCPhys));
    1171                     if (pMap)
    1172                         pMap->cRefs++; /* Extra ref to prevent it from going away. */
    1173                 }
     1171
     1172# ifdef PGM_PAGE_WITH_LOCKS
     1173            unsigned cLocks = PGM_PAGE_GET_READ_LOCKS(pPage);
     1174            if (RT_LIKELY(cLocks < PGM_PAGE_MAX_LOCKS - 1))
     1175                PGM_PAGE_INC_READ_LOCKS(pPage);
     1176            else if (cLocks != PGM_PAGE_GET_READ_LOCKS(pPage))
     1177            {
     1178                PGM_PAGE_INC_READ_LOCKS(pPage);
     1179                AssertMsgFailed(("%RGp / %R[pgmpage] is entering permanent readonly locked state!\n", GCPhys, pPage));
     1180                if (pMap)
     1181                    pMap->cRefs++; /* Extra ref to prevent it from going away. */
     1182            }
    11741183# endif
     1184
    11751185            *ppv = (void *)((uintptr_t)pTlbe->pv | (GCPhys & PAGE_OFFSET_MASK));
    1176             pLock->pvPage = pPage;
     1186            pLock->uPageAndType = (uintptr_t)pPage | PGMPAGEMAPLOCK_TYPE_READ;
    11771187            pLock->pvMap = pMap;
    11781188        }
     
    12741284
    12751285#else   /* IN_RING3 */
    1276     PPGMPAGEMAP pMap = (PPGMPAGEMAP)pLock->pvMap;
    1277     if (!pMap)
    1278     {
    1279         /* The ZERO page and MMIO2 ends up here. */
    1280         Assert(pLock->pvPage);
    1281         pLock->pvPage = NULL;
     1286    PPGMPAGEMAP pMap       = (PPGMPAGEMAP)pLock->pvMap;
     1287    PPGMPAGE    pPage      = (PPGMPAGE)(pLock->uPageAndType & ~PGMPAGEMAPLOCK_TYPE_MASK);
     1288    bool        fWriteLock = (pLock->uPageAndType & PGMPAGEMAPLOCK_TYPE_MASK) == PGMPAGEMAPLOCK_TYPE_WRITE;
     1289
     1290    pLock->uPageAndType = 0;
     1291    pLock->pvMap = NULL;
     1292
     1293    pgmLock(pVM);
     1294# ifdef PGM_PAGE_WITH_LOCKS
     1295    if (fWriteLock)
     1296    {
     1297        unsigned cLocks = PGM_PAGE_GET_WRITE_LOCKS(pPage);
     1298        Assert(cLocks > 0);
     1299        if (RT_LIKELY(cLocks > 0 && cLocks < PGM_PAGE_MAX_LOCKS))
     1300            PGM_PAGE_DEC_WRITE_LOCKS(pPage);
     1301
     1302        if (PGM_PAGE_GET_STATE(pPage) == PGM_PAGE_STATE_WRITE_MONITORED)
     1303        {
     1304            PGM_PAGE_SET_WRITTEN_TO(pPage);
     1305            PGM_PAGE_SET_STATE(pPage, PGM_PAGE_STATE_ALLOCATED);
     1306            Assert(pVM->pgm.s.cMonitoredPages > 0);
     1307            pVM->pgm.s.cMonitoredPages--;
     1308            pVM->pgm.s.cWrittenToPages++;
     1309        }
    12821310    }
    12831311    else
    12841312    {
    1285         pgmLock(pVM);
    1286 
    1287 # if 0 /** @todo implement page locking */
    1288         PPGMPAGE pPage = (PPGMPAGE)pLock->pvPage;
    1289         Assert(pPage->cLocks >= 1);
    1290         if (pPage->cLocks != PGM_PAGE_MAX_LOCKS)
    1291             pPage->cLocks--;
    1292 # endif
    1293 
     1313        unsigned cLocks = PGM_PAGE_GET_READ_LOCKS(pPage);
     1314        Assert(cLocks > 0);
     1315        if (RT_LIKELY(cLocks > 0 && cLocks < PGM_PAGE_MAX_LOCKS))
     1316            PGM_PAGE_DEC_READ_LOCKS(pPage);
     1317    }
     1318#endif
     1319
     1320    if (pMap)
     1321    {
    12941322        Assert(pMap->cRefs >= 1);
    12951323        pMap->cRefs--;
    12961324        pMap->iAge = 0;
    1297 
    1298         pgmUnlock(pVM);
    1299     }
     1325    }
     1326    pgmUnlock(pVM);
    13001327#endif /* IN_RING3 */
    13011328}
Note: See TracChangeset for help on using the changeset viewer.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette