Changeset 75537 in vbox
- Timestamp:
- Nov 17, 2018 1:26:43 AM (6 years ago)
- Location:
- trunk/src/VBox/Devices/VMMDev
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Devices/VMMDev/VMMDev.cpp
r75532 r75537 2946 2946 { 2947 2947 Assert(iCpu != NIL_VMCPUID); 2948 STAM_REL_COUNTER_INC(&pThis->Stat HgcmReqBufAllocs);2948 STAM_REL_COUNTER_INC(&pThis->StatReqBufAllocs); 2949 2949 pRequestHeaderFree = pRequestHeader = (VMMDevRequestHeader *)RTMemAlloc(RT_MAX(requestHeader.size, 512)); 2950 2950 } … … 4123 4123 4124 4124 #ifdef VBOX_WITH_HGCM 4125 /* 4126 * Everything HGCM. 4127 */ 4125 4128 vmmdevHGCMDestroy(pThis); 4126 RTCritSectDelete(&pThis->critsectHGCMCmdList); 4129 #endif 4130 4131 /* 4132 * Free the request buffers. 4133 */ 4127 4134 for (uint32_t iCpu = 0; iCpu < RT_ELEMENTS(pThis->apReqBufs); iCpu++) 4128 4135 { … … 4130 4137 RTMemPageFree(pThis->apReqBufs[iCpu], _4K); 4131 4138 } 4132 #endif4133 4139 4134 4140 #ifndef VBOX_WITHOUT_TESTING_FEATURES … … 4464 4470 4465 4471 #ifdef VBOX_WITH_HGCM 4466 RTListInit(&pThis->listHGCMCmd); 4467 rc = RTCritSectInit(&pThis->critsectHGCMCmdList); 4472 rc = vmmdevHGCMInit(pThis); 4468 4473 AssertRCReturn(rc, rc); 4469 pThis->u32HGCMEnabled = 0; 4470 #endif /* VBOX_WITH_HGCM */ 4474 #endif 4471 4475 4472 4476 /* … … 4476 4480 pThis->mouseCapabilities |= VMMDEV_MOUSE_HOST_RECHECKS_NEEDS_HOST_CURSOR; 4477 4481 4482 /* 4483 * Statistics. 4484 */ 4478 4485 PDMDevHlpSTAMRegisterF(pDevIns, &pThis->StatMemBalloonChunks, STAMTYPE_U32, STAMVISIBILITY_ALWAYS, STAMUNIT_COUNT, "Memory balloon size", "/Devices/VMMDev/BalloonChunks"); 4479 4486 #ifdef VBOX_WITH_HGCM … … 4484 4491 PDMDevHlpSTAMRegisterF(pDevIns, &pThis->StatHgcmCmdTotal, STAMTYPE_PROFILE, STAMVISIBILITY_ALWAYS, STAMUNIT_TICKS_PER_CALL, 4485 4492 "Profiling whole HGCM call.", "/HGCM/MsgTotal"); 4486 PDMDevHlpSTAMRegisterF(pDevIns, &pThis->StatHgcmReqBufAllocs, STAMTYPE_COUNTER, STAMVISIBILITY_ALWAYS, STAMUNIT_COUNT, 4493 PDMDevHlpSTAMRegisterF(pDevIns, &pThis->StatHgcmLargeCmdAllocs,STAMTYPE_COUNTER, STAMVISIBILITY_ALWAYS, STAMUNIT_COUNT, 4494 "Times the allocation cache could not be used.", "/HGCM/LargeCmdAllocs"); 4495 #endif 4496 PDMDevHlpSTAMRegisterF(pDevIns, &pThis->StatReqBufAllocs, STAMTYPE_COUNTER, STAMVISIBILITY_ALWAYS, STAMUNIT_COUNT, 4487 4497 "Times a larger request buffer was required.", "/HGCM/LargeReqBufAllocs"); 4488 #endif4489 4498 4490 4499 /* -
trunk/src/VBox/Devices/VMMDev/VMMDevHGCM.cpp
r75532 r75537 133 133 bool fRestored; 134 134 135 /** Set if allocated from the memory cache, clear if heap. */ 136 bool fMemCache; 137 135 138 /** GC physical address of the guest request. */ 136 139 RTGCPHYS GCPhys; … … 157 160 { 158 161 uint32_t u32ClientID; 159 HGCMServiceLocation loc;162 HGCMServiceLocation *pLoc; /**< Allocated after this structure. */ 160 163 } connect; 161 164 … … 191 194 192 195 196 /** 197 * Version for the memory cache. 198 */ 199 typedef struct VBOXHGCMCMDCACHED 200 { 201 VBOXHGCMCMD Core; /**< 112 */ 202 VBOXHGCMGUESTPARM aGuestParms[6]; /**< 40 * 6 = 240 */ 203 VBOXHGCMSVCPARM aHostParms[6]; /**< 24 * 6 = 144 */ 204 } VBOXHGCMCMDCACHED; /**< 112+240+144 = 496 */ 205 AssertCompile(sizeof(VBOXHGCMCMD) <= 112); 206 AssertCompile(sizeof(VBOXHGCMGUESTPARM) <= 40); 207 AssertCompile(sizeof(VBOXHGCMSVCPARM) <= 24); 208 AssertCompile(sizeof(VBOXHGCMCMDCACHED) <= 512); 209 AssertCompile(sizeof(VBOXHGCMCMDCACHED) > sizeof(VBOXHGCMCMD) + sizeof(HGCMServiceLocation)); 210 211 193 212 static int vmmdevHGCMCmdListLock(PVMMDEV pThis) 194 213 { … … 212 231 * @param cParms Number of HGCM parameters for VBOXHGCMCMDTYPE_CALL command. 213 232 */ 214 static PVBOXHGCMCMD vmmdevHGCMCmdAlloc(VBOXHGCMCMDTYPE enmCmdType, RTGCPHYS GCPhys, uint32_t cbRequest, uint32_t cParms) 215 { 233 static PVBOXHGCMCMD vmmdevHGCMCmdAlloc(PVMMDEV pThis, VBOXHGCMCMDTYPE enmCmdType, RTGCPHYS GCPhys, uint32_t cbRequest, uint32_t cParms) 234 { 235 #if 1 236 /* 237 * Try use the cache. 238 */ 239 VBOXHGCMCMDCACHED *pCmdCached; 240 AssertCompile(sizeof(*pCmdCached) >= sizeof(VBOXHGCMCMD) + sizeof(HGCMServiceLocation)); 241 if (cParms <= RT_ELEMENTS(pCmdCached->aGuestParms)) 242 { 243 int rc = RTMemCacheAllocEx(pThis->hHgcmCmdCache, (void **)&pCmdCached); 244 if (RT_SUCCESS(rc)) 245 { 246 RT_ZERO(*pCmdCached); 247 pCmdCached->Core.fMemCache = true; 248 pCmdCached->Core.GCPhys = GCPhys; 249 pCmdCached->Core.cbRequest = cbRequest; 250 pCmdCached->Core.enmCmdType = enmCmdType; 251 if (enmCmdType == VBOXHGCMCMDTYPE_CALL) 252 { 253 pCmdCached->Core.u.call.cParms = cParms; 254 pCmdCached->Core.u.call.paGuestParms = pCmdCached->aGuestParms; 255 pCmdCached->Core.u.call.paHostParms = pCmdCached->aHostParms; 256 } 257 else if (enmCmdType == VBOXHGCMCMDTYPE_CONNECT) 258 pCmdCached->Core.u.connect.pLoc = (HGCMServiceLocation *)(&pCmdCached->Core + 1); 259 260 return &pCmdCached->Core; 261 } 262 return NULL; 263 } 264 STAM_REL_COUNTER_INC(&pThis->StatHgcmLargeCmdAllocs); 265 266 #else 267 RT_NOREF(pThis); 268 #endif 269 216 270 /* Size of required memory buffer. */ 217 const uint32_t cbCmd = sizeof(struct VBOXHGCMCMD) 218 + cParms * sizeof(VBOXHGCMGUESTPARM) 219 + cParms * sizeof(VBOXHGCMSVCPARM); 271 const uint32_t cbCmd = sizeof(VBOXHGCMCMD) + cParms * (sizeof(VBOXHGCMGUESTPARM) + sizeof(VBOXHGCMSVCPARM)) 272 + (enmCmdType == VBOXHGCMCMDTYPE_CONNECT ? sizeof(HGCMServiceLocation) : 0); 220 273 221 274 PVBOXHGCMCMD pCmd = (PVBOXHGCMCMD)RTMemAllocZ(cbCmd); … … 237 290 } 238 291 } 292 else if (enmCmdType == VBOXHGCMCMDTYPE_CONNECT) 293 pCmd->u.connect.pLoc = (HGCMServiceLocation *)(pCmd + 1); 239 294 } 240 295 return pCmd; … … 276 331 } 277 332 278 RTMemFree(pCmd); 333 #if 1 334 if (pCmd->fMemCache) 335 RTMemCacheFree(pThis->hHgcmCmdCache, pCmd); 336 else 337 #endif 338 RTMemFree(pCmd); 279 339 } 280 340 } … … 358 418 pCmd->enmRequestType = pHGCMConnect->header.header.requestType; 359 419 pCmd->u.connect.u32ClientID = pHGCMConnect->u32ClientID; 360 pCmd->u.connect.loc= pHGCMConnect->loc;420 *pCmd->u.connect.pLoc = pHGCMConnect->loc; 361 421 } 362 422 … … 371 431 int rc = VINF_SUCCESS; 372 432 373 PVBOXHGCMCMD pCmd = vmmdevHGCMCmdAlloc( VBOXHGCMCMDTYPE_CONNECT, GCPhys, pHGCMConnect->header.header.size, 0);433 PVBOXHGCMCMD pCmd = vmmdevHGCMCmdAlloc(pThis, VBOXHGCMCMDTYPE_CONNECT, GCPhys, pHGCMConnect->header.header.size, 0); 374 434 if (pCmd) 375 435 { … … 377 437 378 438 /* Only allow the guest to use existing services! */ 379 ASSERT_GUEST(p Cmd->u.connect.loc.type == VMMDevHGCMLoc_LocalHost_Existing);380 pCmd->u.connect. loc.type = VMMDevHGCMLoc_LocalHost_Existing;439 ASSERT_GUEST(pHGCMConnect->loc.type == VMMDevHGCMLoc_LocalHost_Existing); 440 pCmd->u.connect.pLoc->type = VMMDevHGCMLoc_LocalHost_Existing; 381 441 382 442 vmmdevHGCMAddCommand(pThis, pCmd); 383 rc = pThis->pHGCMDrv->pfnConnect(pThis->pHGCMDrv, pCmd, &pCmd->u.connect.loc, &pCmd->u.connect.u32ClientID);443 rc = pThis->pHGCMDrv->pfnConnect(pThis->pHGCMDrv, pCmd, pCmd->u.connect.pLoc, &pCmd->u.connect.u32ClientID); 384 444 if (RT_FAILURE(rc)) 385 445 vmmdevHGCMRemoveCommand(pThis, pCmd); … … 414 474 int rc = VINF_SUCCESS; 415 475 416 PVBOXHGCMCMD pCmd = vmmdevHGCMCmdAlloc( VBOXHGCMCMDTYPE_DISCONNECT, GCPhys, pHGCMDisconnect->header.header.size, 0);476 PVBOXHGCMCMD pCmd = vmmdevHGCMCmdAlloc(pThis, VBOXHGCMCMDTYPE_DISCONNECT, GCPhys, pHGCMDisconnect->header.header.size, 0); 417 477 if (pCmd) 418 478 { … … 640 700 * @param pcbHGCMParmStruct Where to store size of used HGCM parameter structure. 641 701 */ 642 static int vmmdevHGCMCallAlloc( const VMMDevHGCMCall *pHGCMCall, uint32_t cbHGCMCall, RTGCPHYS GCPhys,702 static int vmmdevHGCMCallAlloc(PVMMDEV pThis, const VMMDevHGCMCall *pHGCMCall, uint32_t cbHGCMCall, RTGCPHYS GCPhys, 643 703 VMMDevRequestType enmRequestType, PVBOXHGCMCMD *ppCmd, uint32_t *pcbHGCMParmStruct) 644 704 { … … 660 720 RT_UNTRUSTED_VALIDATED_FENCE(); 661 721 662 PVBOXHGCMCMD pCmd = vmmdevHGCMCmdAlloc( VBOXHGCMCMDTYPE_CALL, GCPhys, cbHGCMCall, cParms);722 PVBOXHGCMCMD pCmd = vmmdevHGCMCmdAlloc(pThis, VBOXHGCMCMDTYPE_CALL, GCPhys, cbHGCMCall, cParms); 663 723 if (pCmd == NULL) 664 724 return VERR_NO_MEMORY; … … 919 979 PVBOXHGCMCMD pCmd; 920 980 uint32_t cbHGCMParmStruct; 921 int rc = vmmdevHGCMCallAlloc(p HGCMCall, cbHGCMCall, GCPhys, enmRequestType, &pCmd, &cbHGCMParmStruct);981 int rc = vmmdevHGCMCallAlloc(pThis, pHGCMCall, cbHGCMCall, GCPhys, enmRequestType, &pCmd, &cbHGCMParmStruct); 922 982 if (RT_SUCCESS(rc)) 923 983 { … … 1449 1509 { 1450 1510 SSMR3PutU32(pSSM, pCmd->u.connect.u32ClientID); 1451 SSMR3PutMem(pSSM, &pCmd->u.connect.loc, sizeof(pCmd->u.connect.loc));1511 SSMR3PutMem(pSSM, pCmd->u.connect.pLoc, sizeof(*pCmd->u.connect.pLoc)); 1452 1512 } 1453 1513 else if (pCmd->enmCmdType == VBOXHGCMCMDTYPE_DISCONNECT) … … 1524 1584 AssertRCReturn(rc, rc); 1525 1585 1526 PVBOXHGCMCMD pCmd = vmmdevHGCMCmdAlloc( enmCmdType, GCPhys, cbRequest, cParms);1586 PVBOXHGCMCMD pCmd = vmmdevHGCMCmdAlloc(pThis, enmCmdType, GCPhys, cbRequest, cParms); 1527 1587 AssertReturn(pCmd, VERR_NO_MEMORY); 1528 1588 … … 1589 1649 { 1590 1650 SSMR3GetU32(pSSM, &pCmd->u.connect.u32ClientID); 1591 rc = SSMR3GetMem(pSSM, &pCmd->u.connect.loc, sizeof(pCmd->u.connect.loc));1651 rc = SSMR3GetMem(pSSM, pCmd->u.connect.pLoc, sizeof(*pCmd->u.connect.pLoc)); 1592 1652 AssertRCReturn(rc, rc); 1593 1653 } … … 1646 1706 AssertRCReturn(rc, rc); 1647 1707 1648 PVBOXHGCMCMD pCmd = vmmdevHGCMCmdAlloc( enmCmdType, GCPhys, cbRequest, cLinAddrs);1708 PVBOXHGCMCMD pCmd = vmmdevHGCMCmdAlloc(pThis, enmCmdType, GCPhys, cbRequest, cLinAddrs); 1649 1709 AssertReturn(pCmd, VERR_NO_MEMORY); 1650 1710 … … 1704 1764 LogFlowFunc(("Restoring %RGp size %x bytes\n", GCPhys, cbRequest)); 1705 1765 1706 PVBOXHGCMCMD pCmd = vmmdevHGCMCmdAlloc( VBOXHGCMCMDTYPE_LOADSTATE, GCPhys, cbRequest, 0);1766 PVBOXHGCMCMD pCmd = vmmdevHGCMCmdAlloc(pThis, VBOXHGCMCMDTYPE_LOADSTATE, GCPhys, cbRequest, 0); 1707 1767 AssertReturn(pCmd, VERR_NO_MEMORY); 1708 1768 … … 1740 1800 } 1741 1801 1742 PVBOXHGCMCMD pCmd = vmmdevHGCMCmdAlloc( VBOXHGCMCMDTYPE_CONNECT, pLoadedCmd->GCPhys, cbReq, 0);1802 PVBOXHGCMCMD pCmd = vmmdevHGCMCmdAlloc(pThis, VBOXHGCMCMDTYPE_CONNECT, pLoadedCmd->GCPhys, cbReq, 0); 1743 1803 AssertReturn(pCmd, VERR_NO_MEMORY); 1744 1804 … … 1784 1844 } 1785 1845 1786 PVBOXHGCMCMD pCmd = vmmdevHGCMCmdAlloc( VBOXHGCMCMDTYPE_DISCONNECT, pLoadedCmd->GCPhys, cbReq, 0);1846 PVBOXHGCMCMD pCmd = vmmdevHGCMCmdAlloc(pThis, VBOXHGCMCMDTYPE_DISCONNECT, pLoadedCmd->GCPhys, cbReq, 0); 1787 1847 AssertReturn(pCmd, VERR_NO_MEMORY); 1788 1848 … … 1828 1888 PVBOXHGCMCMD pCmd; 1829 1889 uint32_t cbHGCMParmStruct; 1830 rc = vmmdevHGCMCallAlloc(p Req, cbReq, pLoadedCmd->GCPhys, enmRequestType, &pCmd, &cbHGCMParmStruct);1890 rc = vmmdevHGCMCallAlloc(pThis, pReq, cbReq, pLoadedCmd->GCPhys, enmRequestType, &pCmd, &cbHGCMParmStruct); 1831 1891 if (RT_FAILURE(rc)) 1832 1892 return rc; … … 2014 2074 { 2015 2075 vmmdevHGCMAddCommand(pThis, pCmd); 2016 rcCmd = pThis->pHGCMDrv->pfnConnect(pThis->pHGCMDrv, pCmd, &pCmd->u.connect.loc, &pCmd->u.connect.u32ClientID); 2076 rcCmd = pThis->pHGCMDrv->pfnConnect(pThis->pHGCMDrv, pCmd, pCmd->u.connect.pLoc, 2077 &pCmd->u.connect.u32ClientID); 2017 2078 if (RT_FAILURE(rcCmd)) 2018 2079 vmmdevHGCMRemoveCommand(pThis, pCmd); … … 2092 2153 } 2093 2154 2094 /** Deallocate HGCM commands. 2155 2156 /** 2157 * Counterpart to vmmdevHGCMInit(). 2095 2158 * 2096 2159 * @param pThis The VMMDev instance data. … … 2099 2162 { 2100 2163 LogFlowFunc(("\n")); 2164 2165 RTCritSectDelete(&pThis->critsectHGCMCmdList); 2101 2166 2102 2167 PVBOXHGCMCMD pCmd, pNext; … … 2106 2171 vmmdevHGCMCmdFree(pThis, pCmd); 2107 2172 } 2108 } 2173 2174 AssertCompile((uintptr_t)NIL_RTMEMCACHE == 0); 2175 if (pThis->hHgcmCmdCache != NIL_RTMEMCACHE) 2176 { 2177 RTMemCacheDestroy(pThis->hHgcmCmdCache); 2178 pThis->hHgcmCmdCache = NIL_RTMEMCACHE; 2179 } 2180 } 2181 2182 2183 /** 2184 * Initializes the HGCM specific state. 2185 * 2186 * Keeps VBOXHGCMCMDCACHED and friends local. 2187 * 2188 * @returns VBox status code. 2189 * @param pThis The VMMDev instance data. 2190 */ 2191 int vmmdevHGCMInit(PVMMDEV pThis) 2192 { 2193 RTListInit(&pThis->listHGCMCmd); 2194 2195 int rc = RTCritSectInit(&pThis->critsectHGCMCmdList); 2196 AssertLogRelRCReturn(rc, rc); 2197 2198 rc = RTMemCacheCreate(&pThis->hHgcmCmdCache, sizeof(VBOXHGCMCMDCACHED), 64, _1M, NULL, NULL, NULL, 0); 2199 AssertLogRelRCReturn(rc, rc); 2200 2201 pThis->u32HGCMEnabled = 0; 2202 2203 return VINF_SUCCESS; 2204 } 2205 -
trunk/src/VBox/Devices/VMMDev/VMMDevHGCM.h
r75532 r75537 37 37 38 38 void vmmdevHGCMDestroy(PVMMDEV pThis); 39 int vmmdevHGCMInit(PVMMDEV pThis); 39 40 RT_C_DECLS_END 40 41 -
trunk/src/VBox/Devices/VMMDev/VMMDevState.h
r75532 r75537 29 29 30 30 #include <iprt/list.h> 31 #include <iprt/memcache.h> 32 31 33 32 34 #define VMMDEV_WITH_ALT_TIMESYNC … … 283 285 /** Saved state version of restored commands. */ 284 286 uint32_t u32SSMVersion; 285 # if HC_ARCH_BITS == 32 286 /** Alignment padding. */ 287 uint32_t u32Alignment7; 288 # endif 287 RTMEMCACHE hHgcmCmdCache; 289 288 STAMPROFILE StatHgcmCmdArrival; 290 289 STAMPROFILE StatHgcmCmdCompletion; 291 290 STAMPROFILE StatHgcmCmdTotal; 292 STAMCOUNTER StatHgcm ReqBufAllocs;291 STAMCOUNTER StatHgcmLargeCmdAllocs; 293 292 #endif /* VBOX_WITH_HGCM */ 293 STAMCOUNTER StatReqBufAllocs; 294 294 295 295 /** Per CPU request 4K sized buffers, allocated as needed. */ … … 406 406 void VMMDevCtlSetGuestFilterMask(VMMDEV *pVMMDevState, uint32_t u32OrMask, uint32_t u32NotMask); 407 407 408 408 409 /** The saved state version. */ 409 410 #define VMMDEV_SAVED_STATE_VERSION VMMDEV_SAVED_STATE_VERSION_HGCM_PARAMS
Note:
See TracChangeset
for help on using the changeset viewer.