- Timestamp:
- Mar 30, 2009 12:01:20 PM (16 years ago)
- svn:sync-xref-src-repo-rev:
- 45397
- Location:
- trunk/src/VBox/VMM
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/VMM/PDMCritSect.cpp
r14657 r18532 35 35 #include <iprt/assert.h> 36 36 #include <iprt/thread.h> 37 #include <iprt/string.h> 37 38 38 39 … … 114 115 if (RT_SUCCESS(rc)) 115 116 { 116 pCritSect->pVMR3 = pVM;117 pCritSect->pVMR0 = pVM->pVMR0;118 pCritSect->pVMRC = pVM->pVMRC;119 pCritSect->pvKey = pvKey;117 pCritSect->pVMR3 = pVM; 118 pCritSect->pVMR0 = pVM->pVMR0; 119 pCritSect->pVMRC = pVM->pVMRC; 120 pCritSect->pvKey = pvKey; 120 121 pCritSect->EventToSignal = NIL_RTSEMEVENT; 121 pCritSect->pNext = pVM->pdm.s.pCritSects; 122 pCritSect->pNext = pVM->pdm.s.pCritSects; 123 pCritSect->pszName = RTStrDup(pszName); 122 124 pVM->pdm.s.pCritSects = pCritSect; 123 #ifdef VBOX_WITH_STATISTICS124 125 STAMR3RegisterF(pVM, &pCritSect->StatContentionRZLock, STAMTYPE_COUNTER, STAMVISIBILITY_ALWAYS, STAMUNIT_OCCURENCES, NULL, "/PDM/CritSects/%s/ContentionRZLock", pszName); 125 126 STAMR3RegisterF(pVM, &pCritSect->StatContentionRZUnlock,STAMTYPE_COUNTER, STAMVISIBILITY_ALWAYS, STAMUNIT_OCCURENCES, NULL, "/PDM/CritSects/%s/ContentionRZUnlock", pszName); 126 127 STAMR3RegisterF(pVM, &pCritSect->StatContentionR3, STAMTYPE_COUNTER, STAMVISIBILITY_ALWAYS, STAMUNIT_OCCURENCES, NULL, "/PDM/CritSects/%s/ContentionR3", pszName); 128 #ifdef VBOX_WITH_STATISTICS 127 129 STAMR3RegisterF(pVM, &pCritSect->StatLocked, STAMTYPE_PROFILE_ADV, STAMVISIBILITY_ALWAYS, STAMUNIT_TICKS_PER_OCCURENCE, NULL, "/PDM/CritSects/%s/Locked", pszName); 128 130 #endif … … 189 191 190 192 /* delete */ 191 pCritSect->pNext = NULL; 192 pCritSect->pvKey = NULL; 193 pCritSect->pVMR3 = NULL; 194 pCritSect->pVMR0 = NIL_RTR0PTR; 195 pCritSect->pVMRC = NIL_RTRCPTR; 196 #ifdef VBOX_WITH_STATISTICS 193 pCritSect->pNext = NULL; 194 pCritSect->pvKey = NULL; 195 pCritSect->pVMR3 = NULL; 196 pCritSect->pVMR0 = NIL_RTR0PTR; 197 pCritSect->pVMRC = NIL_RTRCPTR; 198 RTStrFree((char *)pCritSect->pszName); 199 pCritSect->pszName = NULL; 197 200 if (!fFinal) 198 201 { … … 200 203 STAMR3Deregister(pVM, &pCritSect->StatContentionRZUnlock); 201 204 STAMR3Deregister(pVM, &pCritSect->StatContentionR3); 205 #ifdef VBOX_WITH_STATISTICS 202 206 STAMR3Deregister(pVM, &pCritSect->StatLocked); 203 }204 207 #endif 208 } 205 209 return RTCritSectDelete(&pCritSect->Core); 206 210 } … … 334 338 * @returns VERR_SEM_DESTROYED if RTCritSectDelete was called while waiting. 335 339 * @param pCritSect The critical section. 336 * @param EventToSignal 340 * @param EventToSignal The semapore that should be signalled. 337 341 */ 338 342 VMMR3DECL(int) PDMR3CritSectScheduleExitEvent(PPDMCRITSECT pCritSect, RTSEMEVENT EventToSignal) … … 350 354 } 351 355 356 357 /** 358 * Counts the critical sections owned by the calling thread, optionally 359 * returning a comma separated list naming them. 360 * 361 * This is for diagnostic purposes only. 362 * 363 * @returns Lock count. 364 * 365 * @param pVM The VM handle. 366 * @param pszNames Where to return the critical section names. 367 * @param cbNames The size of the buffer. 368 */ 369 VMMR3DECL(uint32_t) PDMR3CritSectCountOwned(PVM pVM, char *pszNames, size_t cbNames) 370 { 371 /* 372 * Init the name buffer. 373 */ 374 size_t cchLeft = cbNames; 375 if (cchLeft) 376 { 377 cchLeft--; 378 pszNames[0] = pszNames[cchLeft] = '\0'; 379 } 380 381 /* 382 * Iterate the critical sections. 383 */ 384 /* This is unsafe, but wtf. */ 385 RTNATIVETHREAD const hNativeThread = RTThreadNativeSelf(); 386 uint32_t cCritSects = 0; 387 for (PPDMCRITSECTINT pCur = pVM->pdm.s.pCritSects; 388 pCur; 389 pCur = pCur->pNext) 390 { 391 /* Same as RTCritSectIsOwner(). */ 392 if (pCur->Core.NativeThreadOwner == hNativeThread) 393 { 394 cCritSects++; 395 396 /* 397 * Copy the name if there is space. Fun stuff. 398 */ 399 if (cchLeft) 400 { 401 /* try add comma. */ 402 if (cCritSects != 1) 403 { 404 *pszNames++ = ','; 405 if (--cchLeft) 406 { 407 *pszNames++ = ' '; 408 cchLeft--; 409 } 410 } 411 412 /* try copy the name. */ 413 if (cchLeft) 414 { 415 size_t const cchName = strlen(pCur->pszName); 416 if (cchName < cchLeft) 417 { 418 memcpy(pszNames, pCur->pszName, cchName); 419 pszNames += cchName; 420 cchLeft -= cchName; 421 } 422 else 423 { 424 if (cchLeft > 2) 425 { 426 memcpy(pszNames, pCur->pszName, cchLeft - 2); 427 pszNames += cchLeft - 2; 428 cchLeft = 2; 429 } 430 while (cchLeft-- > 0) 431 *pszNames++ = '+'; 432 } 433 } 434 *pszNames = '\0'; 435 } 436 } 437 } 438 439 return cCritSects; 440 } -
trunk/src/VBox/VMM/VMMAll/PDMAllCritSect.cpp
r13898 r18532 57 57 NOREF(rcBusy); 58 58 59 STAM_STATS({ if (pCritSect->s.Core.cLockers >= 0 && !RTCritSectIsOwner(&pCritSect->s.Core)) STAM_COUNTER_INC(&pCritSect->s.StatContentionR3); }); 59 STAM_REL_STATS({if (pCritSect->s.Core.cLockers >= 0 && !RTCritSectIsOwner(&pCritSect->s.Core)) 60 STAM_COUNTER_INC(&pCritSect->s.StatContentionR3); }); 60 61 int rc = RTCritSectEnter(&pCritSect->s.Core); 61 62 STAM_STATS({ if (pCritSect->s.Core.cNestings == 1) STAM_PROFILE_ADV_START(&pCritSect->s.StatLocked, l); }); … … 95 96 */ 96 97 LogFlow(("PDMCritSectEnter: locked => R3 (%Rrc)\n", rcBusy)); 97 STAM_ COUNTER_INC(&pCritSect->s.StatContentionRZLock);98 STAM_REL_COUNTER_INC(&pCritSect->s.StatContentionRZLock); 98 99 return rcBusy; 99 100 #endif /* !IN_RING3 */ … … 203 204 VM_FF_SET(pVM, VM_FF_PDM_CRITSECT); 204 205 VM_FF_SET(pVM, VM_FF_TO_R3); 205 STAM_ COUNTER_INC(&pVM->pdm.s.StatQueuedCritSectLeaves);206 STAM_ COUNTER_INC(&pCritSect->s.StatContentionRZUnlock);206 STAM_REL_COUNTER_INC(&pVM->pdm.s.StatQueuedCritSectLeaves); 207 STAM_REL_COUNTER_INC(&pCritSect->s.StatContentionRZUnlock); 207 208 #endif /* !IN_RING3 */ 208 209 }
Note:
See TracChangeset
for help on using the changeset viewer.