VirtualBox

Changeset 90553 in vbox


Ignore:
Timestamp:
Aug 6, 2021 2:29:11 PM (4 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
146159
Message:

VMM/PGMCritSectRw: Added 'critsectrw' info item. bugref:6695

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/VMM/VMMR3/PDMCritSect.cpp

    r90550 r90553  
    4545static int pdmR3CritSectRwDeleteOne(PVM pVM, PUVM pUVM, PPDMCRITSECTRWINT pCritSect, PPDMCRITSECTRWINT pPrev, bool fFinal);
    4646static FNDBGFINFOARGVINT pdmR3CritSectInfo;
     47static FNDBGFINFOARGVINT pdmR3CritSectRwInfo;
    4748
    4849
     
    7677     */
    7778    DBGFR3InfoRegisterInternalArgv(pVM, "critsect", "Show critical section: critsect [-v] [pattern[...]]", pdmR3CritSectInfo, 0);
     79    DBGFR3InfoRegisterInternalArgv(pVM, "critsectrw", "Show read/write critical section: critsectrw [-v] [pattern[...]]",
     80                                   pdmR3CritSectRwInfo, 0);
    7881
    7982    return VINF_SUCCESS;
     
    10911094            || RTStrSimplePatternMultiMatch(pszPatterns, cchPatterns, pCritSect->pszName, RTSTR_MAX, NULL))
    10921095        {
    1093             pHlp->pfnPrintf(pHlp, "%p: '%s'%s\n", pCritSect, pCritSect->pszName,
     1096            uint32_t fFlags = pCritSect->Core.fFlags;
     1097            pHlp->pfnPrintf(pHlp, "%p: '%s'%s%s%s%s%s\n", pCritSect, pCritSect->pszName,
    10941098                            pCritSect->fAutomaticDefaultCritsect ? " default" : "",
    1095                             pCritSect->fUsedByTimerOrSimilar ? " used-by-timer-or-similar" : "");
     1099                            pCritSect->fUsedByTimerOrSimilar ? " used-by-timer-or-similar" : "",
     1100                            fFlags & RTCRITSECT_FLAGS_NO_NESTING ? " no-testing" : "",
     1101                            fFlags & RTCRITSECT_FLAGS_NO_LOCK_VAL ? " no-lock-val" : "",
     1102                            fFlags & RTCRITSECT_FLAGS_NOP ? " nop" : "");
     1103
    10961104
    10971105            /*
     
    11011109            int32_t        cLockers;
    11021110            int32_t        cNestings;
    1103             uint32_t       fFlags;
    11041111            uint32_t       uMagic;
    11051112            for (uint32_t iTry = 0; iTry < 16; iTry++)
     
    11361143             * If locked, print details
    11371144             */
    1138             if (cLockers != -1 || cNestings != 1 || hOwner != NIL_RTNATIVETHREAD || cVerbosity > 1)
     1145            if (cLockers != -1 || cNestings > 1 || cNestings < 0 || hOwner != NIL_RTNATIVETHREAD || cVerbosity > 1)
    11391146            {
    11401147                /* Translate the owner to a name if we have one and can. */
     
    11581165
    11591166/**
    1160  * @callback_method_impl{FNDBGFINFOARGVINT, critsect}
    1161  */
    1162 static DECLCALLBACK(void) pdmR3CritSectInfo(PVM pVM, PCDBGFINFOHLP pHlp, int cArgs, char **papszArgs)
     1167 * Display matching read/write critical sections.
     1168 */
     1169static void pdmR3CritSectInfoRwWorker(PUVM pUVM, const char *pszPatterns, PCDBGFINFOHLP pHlp, unsigned cVerbosity)
     1170{
     1171    size_t const cchPatterns = pszPatterns ? strlen(pszPatterns) : 0;
     1172    RTCritSectEnter(&pUVM->pdm.s.ListCritSect);
     1173
     1174    for (PPDMCRITSECTRWINT pCritSect = pUVM->pdm.s.pRwCritSects; pCritSect; pCritSect = pCritSect->pNext)
     1175        if (   !pszPatterns
     1176            || RTStrSimplePatternMultiMatch(pszPatterns, cchPatterns, pCritSect->pszName, RTSTR_MAX, NULL))
     1177        {
     1178            uint16_t const fFlags = pCritSect->Core.fFlags;
     1179            pHlp->pfnPrintf(pHlp, "%p: '%s'%s%s%s\n", pCritSect, pCritSect->pszName,
     1180                            pCritSect->Core.fFlags & RTCRITSECT_FLAGS_NO_NESTING ? " no-testing" : "",
     1181                            pCritSect->Core.fFlags & RTCRITSECT_FLAGS_NO_LOCK_VAL ? " no-lock-val" : "",
     1182                            pCritSect->Core.fFlags & RTCRITSECT_FLAGS_NOP ? " nop" : "");
     1183
     1184            /*
     1185             * Get the volatile data:
     1186             */
     1187            RTNATIVETHREAD  hOwner;
     1188            uint64_t        u64State;
     1189            uint32_t        cWriterReads;
     1190            uint32_t        cWriteRecursions;
     1191            bool            fNeedReset;
     1192            uint32_t        uMagic;
     1193            unsigned        cTries = 16;
     1194            do
     1195            {
     1196                u64State         = pCritSect->Core.u64State;
     1197                hOwner           = pCritSect->Core.hNativeWriter;
     1198                cWriterReads     = pCritSect->Core.cWriterReads;
     1199                cWriteRecursions = pCritSect->Core.cWriteRecursions;
     1200                fNeedReset       = pCritSect->Core.fNeedReset;
     1201                uMagic           = pCritSect->Core.u32Magic;
     1202            } while (   cTries-- > 0
     1203                     && (   u64State         != pCritSect->Core.u64State
     1204                         || hOwner           != pCritSect->Core.hNativeWriter
     1205                         || cWriterReads     != pCritSect->Core.cWriterReads
     1206                         || cWriteRecursions != pCritSect->Core.cWriteRecursions
     1207                         || fNeedReset       != pCritSect->Core.fNeedReset
     1208                         || uMagic           != pCritSect->Core.u32Magic));
     1209
     1210            /*
     1211             * Check and resolve the magic to a string, print if not RTCRITSECT_MAGIC.
     1212             */
     1213            const char *pszMagic;
     1214            switch (uMagic)
     1215            {
     1216                case RTCRITSECTRW_MAGIC:            pszMagic = NULL; break;
     1217                case ~RTCRITSECTRW_MAGIC:           pszMagic = " deleted"; break;
     1218                case PDMCRITSECTRW_MAGIC_CORRUPT:   pszMagic = " PDMCRITSECTRW_MAGIC_CORRUPT!"; break;
     1219                default:                            pszMagic = " !unknown!"; break;
     1220            }
     1221            if (pszMagic || cVerbosity > 1)
     1222                pHlp->pfnPrintf(pHlp, "  uMagic=%#x%s\n", uMagic, pszMagic ? pszMagic : "");
     1223
     1224            /*
     1225             * If locked, print details
     1226             */
     1227            if ((u64State & ~RTCSRW_DIR_MASK) || hOwner != NIL_RTNATIVETHREAD || cVerbosity > 1)
     1228            {
     1229                /* Translate the owner to a name if we have one and can. */
     1230                const char *pszOwner = NULL;
     1231                if (hOwner != NIL_RTNATIVETHREAD)
     1232                {
     1233                    RTTHREAD hOwnerThread = RTThreadFromNative(hOwner); /* Note! Does not return a reference (crazy). */
     1234                    if (hOwnerThread != NIL_RTTHREAD)
     1235                        pszOwner = RTThreadGetName(hOwnerThread);
     1236                }
     1237                else
     1238                    pszOwner = "<no-owner>";
     1239
     1240                pHlp->pfnPrintf(pHlp, "  u64State=%#RX64 %s cReads=%u cWrites=%u cWaitingReads=%u\n",
     1241                                u64State, (u64State & RTCSRW_DIR_MASK) == RTCSRW_DIR_WRITE ? "writing" : "reading",
     1242                                (unsigned)((u64State & RTCSRW_CNT_RD_MASK) >> RTCSRW_CNT_RD_SHIFT),
     1243                                (unsigned)((u64State & RTCSRW_CNT_WR_MASK) >> RTCSRW_CNT_RD_SHIFT),
     1244                                (unsigned)((u64State & RTCSRW_WAIT_CNT_RD_MASK) >> RTCSRW_WAIT_CNT_RD_SHIFT));
     1245                if (hOwner != NIL_RTNATIVETHREAD || cVerbosity > 2)
     1246                    pHlp->pfnPrintf(pHlp, "  cNestings=%u cReadNestings=%u hWriter=%p %s\n",
     1247                                    cWriteRecursions, cWriterReads, hOwner, pszOwner ? pszOwner : "???");
     1248            }
     1249        }
     1250    RTCritSectLeave(&pUVM->pdm.s.ListCritSect);
     1251}
     1252
     1253
     1254/**
     1255 * Common worker for critsect and critsectrw info items.
     1256 */
     1257static void pdmR3CritSectInfoCommon(PVM pVM, PCDBGFINFOHLP pHlp, int cArgs, char **papszArgs, bool fReadWrite)
    11631258{
    11641259    PUVM pUVM = pVM->pUVM;
     
    11881283
    11891284            case VINF_GETOPT_NOT_OPTION:
    1190                 pdmR3CritSectInfoWorker(pUVM, ValueUnion.psz, pHlp, cVerbosity);
     1285                if (!fReadWrite)
     1286                    pdmR3CritSectInfoWorker(pUVM, ValueUnion.psz, pHlp, cVerbosity);
     1287                else
     1288                    pdmR3CritSectInfoRwWorker(pUVM, ValueUnion.psz, pHlp, cVerbosity);
    11911289                cProcessed++;
    11921290                break;
     
    12021300     */
    12031301    if (!cProcessed)
    1204         pdmR3CritSectInfoWorker(pUVM, NULL, pHlp, cVerbosity);
    1205 }
    1206 
    1207 
     1302    {
     1303        if (!fReadWrite)
     1304            pdmR3CritSectInfoWorker(pUVM, NULL, pHlp, cVerbosity);
     1305        else
     1306            pdmR3CritSectInfoRwWorker(pUVM, NULL, pHlp, cVerbosity);
     1307    }
     1308}
     1309
     1310
     1311/**
     1312 * @callback_method_impl{FNDBGFINFOARGVINT, critsect}
     1313 */
     1314static DECLCALLBACK(void) pdmR3CritSectInfo(PVM pVM, PCDBGFINFOHLP pHlp, int cArgs, char **papszArgs)
     1315{
     1316    return pdmR3CritSectInfoCommon(pVM, pHlp, cArgs, papszArgs, false);
     1317}
     1318
     1319
     1320/**
     1321 * @callback_method_impl{FNDBGFINFOARGVINT, critsectrw}
     1322 */
     1323static DECLCALLBACK(void) pdmR3CritSectRwInfo(PVM pVM, PCDBGFINFOHLP pHlp, int cArgs, char **papszArgs)
     1324{
     1325    return pdmR3CritSectInfoCommon(pVM, pHlp, cArgs, papszArgs, true);
     1326}
     1327
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