Changeset 33306 in vbox for trunk/src/VBox/GuestHost/OpenGL/util
- Timestamp:
- Oct 21, 2010 12:52:37 PM (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/GuestHost/OpenGL/util/vboxhgsmi.c
r33241 r33306 60 60 #endif 61 61 62 #define VBOX_WITH_CRHGSMIPROFILE 63 #ifdef VBOX_WITH_CRHGSMIPROFILE 64 #include <iprt/time.h> 65 #include <stdio.h> 66 67 typedef struct VBOXCRHGSMIPROFILE 68 { 69 uint64_t cStartTime; 70 uint64_t cStepsTime; 71 uint64_t cSteps; 72 } VBOXCRHGSMIPROFILE, *PVBOXCRHGSMIPROFILE; 73 74 #define VBOXCRHGSMIPROFILE_GET_TIME_NANO() RTTimeNanoTS() 75 #define VBOXCRHGSMIPROFILE_GET_TIME_MILLI() RTTimeMilliTS() 76 77 /* 10 sec */ 78 #define VBOXCRHGSMIPROFILE_LOG_STEP_TIME (10000000000.) 79 80 DECLINLINE(void) vboxCrHgsmiProfileStart(PVBOXCRHGSMIPROFILE pProfile) 81 { 82 pProfile->cStepsTime = 0; 83 pProfile->cSteps = 0; 84 pProfile->cStartTime = VBOXCRHGSMIPROFILE_GET_TIME_NANO(); 85 } 86 87 DECLINLINE(void) vboxCrHgsmiProfileStep(PVBOXCRHGSMIPROFILE pProfile, uint64_t cStepTime) 88 { 89 pProfile->cStepsTime += cStepTime; 90 ++pProfile->cSteps; 91 } 92 93 typedef struct VBOXCRHGSMIPROFILE_SCOPE 94 { 95 uint64_t cStartTime; 96 // bool bDisable; 97 } VBOXCRHGSMIPROFILE_SCOPE, *PVBOXCRHGSMIPROFILE_SCOPE; 98 99 static VBOXCRHGSMIPROFILE g_VBoxProfile; 100 101 static void vboxCrHgsmiLog(char * szString, ...) 102 { 103 char szBuffer[4096] = {0}; 104 va_list pArgList; 105 va_start(pArgList, szString); 106 _vsnprintf(szBuffer, sizeof(szBuffer) / sizeof(szBuffer[0]), szString, pArgList); 107 va_end(pArgList); 108 109 VBoxCrHgsmiLog(szBuffer); 110 } 111 112 DECLINLINE(void) vboxCrHgsmiProfileLog(PVBOXCRHGSMIPROFILE pProfile, uint64_t cTime) 113 { 114 uint64_t profileTime = cTime - pProfile->cStartTime; 115 double percent = ((double)100.0) * pProfile->cStepsTime / profileTime; 116 double cps = ((double)1000000000.) * pProfile->cSteps / profileTime; 117 vboxCrHgsmiLog("hgsmi: cps: %.1f, host %.1f%%\n", cps, percent); 118 } 119 120 DECLINLINE(void) vboxCrHgsmiProfileScopeEnter(PVBOXCRHGSMIPROFILE_SCOPE pScope) 121 { 122 // pScope->bDisable = false; 123 pScope->cStartTime = VBOXCRHGSMIPROFILE_GET_TIME_NANO(); 124 } 125 126 DECLINLINE(void) vboxCrHgsmiProfileScopeExit(PVBOXCRHGSMIPROFILE_SCOPE pScope) 127 { 128 // if (!pScope->bDisable) 129 { 130 uint64_t cTime = VBOXCRHGSMIPROFILE_GET_TIME_NANO(); 131 vboxCrHgsmiProfileStep(&g_VBoxProfile, cTime - pScope->cStartTime); 132 if (VBOXCRHGSMIPROFILE_LOG_STEP_TIME < cTime - g_VBoxProfile.cStartTime) 133 { 134 vboxCrHgsmiProfileLog(&g_VBoxProfile, cTime); 135 vboxCrHgsmiProfileStart(&g_VBoxProfile); 136 } 137 } 138 } 139 140 141 #define VBOXCRHGSMIPROFILE_INIT() vboxCrHgsmiProfileStart(&g_VBoxProfile) 142 #define VBOXCRHGSMIPROFILE_TERM() do {} while (0) 143 144 #define VBOXCRHGSMIPROFILE_FUNC_PROLOGUE() \ 145 VBOXCRHGSMIPROFILE_SCOPE __vboxCrHgsmiProfileScope; \ 146 vboxCrHgsmiProfileScopeEnter(&__vboxCrHgsmiProfileScope); 147 148 #define VBOXCRHGSMIPROFILE_FUNC_EPILOGUE() \ 149 vboxCrHgsmiProfileScopeExit(&__vboxCrHgsmiProfileScope); \ 150 151 152 #else 153 #define VBOXCRHGSMIPROFILE_INIT() do {} while (0) 154 #define VBOXCRHGSMIPROFILE_TERM() do {} while (0) 155 #define VBOXCRHGSMIPROFILE_FUNC_PROLOGUE() do {} while (0) 156 #define VBOXCRHGSMIPROFILE_FUNC_EPILOGUE() do {} while (0) 157 #endif 158 159 62 160 typedef struct { 63 161 int initialized; … … 443 541 static void *crVBoxHGSMIAlloc(CRConnection *conn) 444 542 { 445 PCRVBOXHGSMI_CLIENT pClient = _crVBoxHGSMIClientGet(); 446 void *pvBuf = _crVBoxHGSMIDoAlloc(pClient, conn->buffer_size); 543 PCRVBOXHGSMI_CLIENT pClient; 544 void *pvBuf; 545 546 VBOXCRHGSMIPROFILE_FUNC_PROLOGUE(); 547 548 pClient = _crVBoxHGSMIClientGet(); 549 pvBuf = _crVBoxHGSMIDoAlloc(pClient, conn->buffer_size); 447 550 Assert(pvBuf); 551 552 VBOXCRHGSMIPROFILE_FUNC_EPILOGUE(); 553 448 554 return pvBuf; 449 555 } … … 456 562 pSubm->fFlags.Value = 0; 457 563 pSubm->fFlags.bDoNotRetire = 1; 458 pSubm->fFlags.bDoNotSignalCompletion = 1; /* <- we do not need that actually since459 * in case we want completion,460 * we will block in _crVBoxHGSMICmdBufferGetRc (when locking the buffer)461 * which is needed for getting the result */564 // pSubm->fFlags.bDoNotSignalCompletion = 1; /* <- we do not need that actually since 565 // * in case we want completion, 566 // * we will block in _crVBoxHGSMICmdBufferGetRc (when locking the buffer) 567 // * which is needed for getting the result */ 462 568 } 463 569 … … 467 573 # error "Port Me!!" 468 574 #endif 575 576 DECLINLINE(void) _crVBoxHGSMIWaitCmd(PCRVBOXHGSMI_CLIENT pClient) 577 { 578 int rc = CRVBOXHGSMI_BUF_WAIT(pClient->pCmdBuffer); 579 Assert(rc == 0); 580 } 469 581 470 582 static void _crVBoxHGSMIWriteExact(CRConnection *conn, PCRVBOXHGSMI_CLIENT pClient, PVBOXUHGSMI_BUFFER pBuf, uint32_t offStart, unsigned int len) … … 506 618 if (RT_SUCCESS(rc)) 507 619 { 620 _crVBoxHGSMIWaitCmd(pClient); 508 621 /* @todo: do we need to wait for completion actually? 509 622 * NOTE: in case we do not need completion, … … 539 652 if (RT_SUCCESS(rc)) 540 653 { 654 _crVBoxHGSMIWaitCmd(pClient); 541 655 /* @todo: do we need to wait for completion actually? 542 656 * NOTE: in case we do not need completion, … … 556 670 static void crVBoxHGSMIWriteExact(CRConnection *conn, const void *buf, unsigned int len) 557 671 { 672 VBOXCRHGSMIPROFILE_FUNC_PROLOGUE(); 558 673 Assert(0); 559 674 … … 566 681 // _crVBoxHGSMIWriteExact(conn, pClient, pBuf, 0, len); 567 682 // _crVBoxHGSMIBufFree(pClient, pBuf); 683 VBOXCRHGSMIPROFILE_FUNC_EPILOGUE(); 568 684 } 569 685 … … 609 725 return; 610 726 } 727 728 _crVBoxHGSMIWaitCmd(pClient); 611 729 612 730 parms = (CRVBOXHGSMIREAD *)_crVBoxHGSMICmdBufferLockRo(pClient, sizeof (*parms)); … … 733 851 break; 734 852 } 853 854 _crVBoxHGSMIWaitCmd(pClient); 735 855 736 856 parms = (CRVBOXHGSMIWRITEREAD *)_crVBoxHGSMICmdBufferLockRo(pClient, sizeof (*parms)); … … 799 919 PVBOXUHGSMI_BUFFER pBuf; 800 920 921 VBOXCRHGSMIPROFILE_FUNC_PROLOGUE(); 922 801 923 if (!bufp) /* We're sending a user-allocated buffer. */ 802 924 { … … 811 933 _crVBoxHGSMIWriteReadExact(conn, pClient, (void*)start, 0, len, false); 812 934 #endif 935 VBOXCRHGSMIPROFILE_FUNC_EPILOGUE(); 813 936 return; 814 937 } … … 822 945 Assert(pBuf); 823 946 if (!pBuf) 947 { 948 VBOXCRHGSMIPROFILE_FUNC_EPILOGUE(); 824 949 return; 950 } 825 951 826 952 pClient = (PCRVBOXHGSMI_CLIENT)pBuf->pvUserData; … … 847 973 */ 848 974 *bufp = NULL; 975 976 VBOXCRHGSMIPROFILE_FUNC_EPILOGUE(); 849 977 } 850 978 … … 852 980 { 853 981 PCRVBOXHGSMI_CLIENT pClient; 854 PVBOXUHGSMI_BUFFER pBuf = _crVBoxHGSMIBufFromMemPtr(buf); 982 PVBOXUHGSMI_BUFFER pBuf; 983 VBOXCRHGSMIPROFILE_FUNC_PROLOGUE(); 984 pBuf = _crVBoxHGSMIBufFromMemPtr(buf); 855 985 Assert(pBuf); 856 986 Assert(0); 857 987 CRASSERT(0); 858 988 if (!pBuf) 989 { 990 VBOXCRHGSMIPROFILE_FUNC_EPILOGUE(); 859 991 return; 992 } 860 993 pClient = (PCRVBOXHGSMI_CLIENT)pBuf->pvUserData; 861 994 _crVBoxHGSMIReadExact(conn, pClient); 862 } 863 864 static void crVBoxHGSMIFree(CRConnection *conn, void *buf) 995 VBOXCRHGSMIPROFILE_FUNC_EPILOGUE(); 996 } 997 998 static void _crVBoxHGSMIFree(CRConnection *conn, void *buf) 865 999 { 866 1000 CRVBOXHGSMIBUFFER *hgsmi_buffer = (CRVBOXHGSMIBUFFER *) buf - 1; … … 888 1022 #endif 889 1023 } 1024 } 1025 static void crVBoxHGSMIFree(CRConnection *conn, void *buf) 1026 { 1027 VBOXCRHGSMIPROFILE_FUNC_PROLOGUE(); 1028 _crVBoxHGSMIFree(conn, buf); 1029 VBOXCRHGSMIPROFILE_FUNC_EPILOGUE(); 890 1030 } 891 1031 … … 967 1107 && cached_type != CR_MESSAGE_GATHER) 968 1108 { 969 crVBoxHGSMIFree(conn, msg);1109 _crVBoxHGSMIFree(conn, msg); 970 1110 } 971 1111 } … … 973 1113 static void crVBoxHGSMIReceiveMessage(CRConnection *conn) 974 1114 { 975 PCRVBOXHGSMI_CLIENT pClient = _crVBoxHGSMIClientGet(); 1115 PCRVBOXHGSMI_CLIENT pClient; 1116 VBOXCRHGSMIPROFILE_FUNC_PROLOGUE(); 1117 1118 pClient = _crVBoxHGSMIClientGet(); 976 1119 977 1120 Assert(pClient); … … 979 1122 980 1123 _crVBoxHGSMIReceiveMessage(conn, pClient); 1124 VBOXCRHGSMIPROFILE_FUNC_EPILOGUE(); 981 1125 } 982 1126 /* … … 985 1129 static void crVBoxHGSMIAccept( CRConnection *conn, const char *hostname, unsigned short port ) 986 1130 { 1131 VBOXCRHGSMIPROFILE_FUNC_PROLOGUE(); 987 1132 Assert(0); 988 1133 … … 991 1136 CRASSERT(FALSE); 992 1137 #endif 1138 VBOXCRHGSMIPROFILE_FUNC_EPILOGUE(); 993 1139 } 994 1140 … … 1038 1184 #ifdef RT_OS_WINDOWS 1039 1185 DWORD cbReturned; 1186 VBOXCRHGSMIPROFILE_FUNC_PROLOGUE(); 1040 1187 1041 1188 if (g_crvboxhgsmi.hGuestDrv == INVALID_HANDLE_VALUE) … … 1055 1202 Assert(0); 1056 1203 crDebug("could not open VBox Guest Additions driver! rc = %d\n", GetLastError()); 1204 VBOXCRHGSMIPROFILE_FUNC_EPILOGUE(); 1057 1205 return FALSE; 1058 1206 } 1059 1207 } 1060 1208 #else 1209 VBOXCRHGSMIPROFILE_FUNC_PROLOGUE(); 1210 1061 1211 if (g_crvboxhgsmi.iGuestDrv == INVALID_HANDLE_VALUE) 1062 1212 { … … 1065 1215 { 1066 1216 crDebug("could not open Guest Additions kernel module! rc = %d\n", errno); 1217 VBOXCRHGSMIPROFILE_FUNC_EPILOGUE(); 1067 1218 return FALSE; 1068 1219 } … … 1097 1248 if (info.result == VINF_SUCCESS) 1098 1249 { 1250 int rc; 1099 1251 conn->u32ClientID = info.u32ClientID; 1100 1252 crDebug("HGCM connect was successful: client id =0x%x\n", conn->u32ClientID); 1101 1253 1102 return crVBoxHGSMISetVersion(conn, CR_PROTOCOL_VERSION_MAJOR, CR_PROTOCOL_VERSION_MINOR); 1254 rc = crVBoxHGSMISetVersion(conn, CR_PROTOCOL_VERSION_MAJOR, CR_PROTOCOL_VERSION_MINOR); 1255 VBOXCRHGSMIPROFILE_FUNC_EPILOGUE(); 1256 return rc; 1103 1257 } 1104 1258 else … … 1116 1270 #endif 1117 1271 } 1272 1273 VBOXCRHGSMIPROFILE_FUNC_EPILOGUE(); 1118 1274 1119 1275 return FALSE; … … 1135 1291 int i; 1136 1292 #endif 1293 VBOXCRHGSMIPROFILE_FUNC_PROLOGUE(); 1137 1294 1138 1295 if (conn->pHostBuffer) … … 1214 1371 # endif 1215 1372 } 1373 VBOXCRHGSMIPROFILE_FUNC_EPILOGUE(); 1216 1374 #endif /* IN_GUEST */ 1217 1375 } … … 1219 1377 static void crVBoxHGSMIInstantReclaim(CRConnection *conn, CRMessage *mess) 1220 1378 { 1379 VBOXCRHGSMIPROFILE_FUNC_PROLOGUE(); 1221 1380 Assert(0); 1222 1381 1223 crVBoxHGSMIFree(conn, mess);1382 _crVBoxHGSMIFree(conn, mess); 1224 1383 CRASSERT(FALSE); 1384 1385 VBOXCRHGSMIPROFILE_FUNC_EPILOGUE(); 1225 1386 } 1226 1387 1227 1388 static void crVBoxHGSMIHandleNewMessage( CRConnection *conn, CRMessage *msg, unsigned int len ) 1228 1389 { 1390 VBOXCRHGSMIPROFILE_FUNC_PROLOGUE(); 1229 1391 Assert(0); 1230 1392 1231 1393 CRASSERT(FALSE); 1394 VBOXCRHGSMIPROFILE_FUNC_EPILOGUE(); 1232 1395 } 1233 1396 … … 1241 1404 pClient->pHgsmi = pHgsmi; 1242 1405 rc = pHgsmi->pfnBufferCreate(pHgsmi, CRVBOXHGSMI_PAGE_ALIGN(1), 1243 VBOXUHGSMI_SYNCHOBJECT_TYPE_SEMAPHORE, NULL, 1406 VBOXUHGSMI_SYNCHOBJECT_TYPE_EVENT, 1407 NULL, 1244 1408 &pClient->pCmdBuffer); 1245 1409 AssertRC(rc); … … 1247 1411 { 1248 1412 rc = pHgsmi->pfnBufferCreate(pHgsmi, CRVBOXHGSMI_PAGE_ALIGN(0x800000), 1249 VBOXUHGSMI_SYNCHOBJECT_TYPE_SEMAPHORE, NULL, 1413 VBOXUHGSMI_SYNCHOBJECT_TYPE_EVENT, 1414 NULL, 1250 1415 &pClient->pHGBuffer); 1251 1416 AssertRC(rc);
Note:
See TracChangeset
for help on using the changeset viewer.