Changeset 63294 in vbox for trunk/src/VBox/Frontends/VBoxBalloonCtrl
- Timestamp:
- Aug 10, 2016 4:00:33 PM (8 years ago)
- Location:
- trunk/src/VBox/Frontends/VBoxBalloonCtrl
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Frontends/VBoxBalloonCtrl/VBoxModAPIMonitor.cpp
r63290 r63294 69 69 /** The VM group(s) the API monitor handles. If none, all VMs get handled. */ 70 70 static mapGroups g_vecAPIMonGroups; /** @todo Move this into module payload! */ 71 static APIMON_RESPONSE g_enmAPIMonIslnResp 72 static u nsigned long g_ulAPIMonIslnTimeoutMS= 0;71 static APIMON_RESPONSE g_enmAPIMonIslnResp = APIMON_RESPONSE_NONE; 72 static uint32_t g_cMsAPIMonIslnTimeout = 0; 73 73 static Bstr g_strAPIMonIslnLastBeat; 74 static u nsigned long g_ulAPIMonResponseTimeoutMS= 0;74 static uint32_t g_cMsAPIMonResponseTimeout = 0; 75 75 static uint64_t g_uAPIMonIslnLastBeatMS = 0; 76 76 … … 180 180 181 181 static int apimonMachineControl(const Bstr &strUuid, PVBOXWATCHDOG_MACHINE pMachine, 182 APIMON_RESPONSE enmResp, u nsigned long ulTimeout)182 APIMON_RESPONSE enmResp, uint32_t cMsTimeout) 183 183 { 184 184 /** @todo Add other commands (with enmResp) here. */ … … 186 186 187 187 serviceLogVerbose(("apimon: Triggering \"%s\" (%RU32ms timeout) for machine \"%ls\"\n", 188 apimonResponseToStr(enmResp), ulTimeout, strUuid.raw()));188 apimonResponseToStr(enmResp), cMsTimeout, strUuid.raw())); 189 189 190 190 if ( enmResp == APIMON_RESPONSE_NONE … … 234 234 strUuid.raw())); 235 235 CHECK_ERROR_BREAK(console, PowerDown(progress.asOutParam())); 236 progress->WaitForCompletion( ulTimeout);236 progress->WaitForCompletion(cMsTimeout); 237 237 CHECK_PROGRESS_ERROR(progress, ("Failed to power off machine \"%ls\"", 238 238 strUuid.raw())); … … 274 274 if (SUCCEEDED(rc)) 275 275 { 276 progress->WaitForCompletion( ulTimeout);276 progress->WaitForCompletion(cMsTimeout); 277 277 CHECK_PROGRESS_ERROR(progress, ("Failed to save machine state of machine \"%ls\"", 278 278 strUuid.raw())); … … 364 364 { 365 365 int rc2 = apimonMachineControl(it->first /* Uuid */, 366 &it->second /* Machine */, enmResp, g_ ulAPIMonResponseTimeoutMS);366 &it->second /* Machine */, enmResp, g_cMsAPIMonResponseTimeout); 367 367 if (RT_FAILURE(rc2)) 368 368 serviceLog("apimon: Controlling machine \"%ls\" (response \"%s\") failed with rc=%Rrc", … … 429 429 430 430 case GETOPTDEF_APIMON_ISLN_TIMEOUT: 431 g_ ulAPIMonIslnTimeoutMS= ValueUnion.u32;432 if (g_ ulAPIMonIslnTimeoutMS< 1000) /* Don't allow timeouts < 1s. */433 g_ ulAPIMonIslnTimeoutMS= 1000;431 g_cMsAPIMonIslnTimeout = ValueUnion.u32; 432 if (g_cMsAPIMonIslnTimeout < 1000) /* Don't allow timeouts < 1s. */ 433 g_cMsAPIMonIslnTimeout = 1000; 434 434 break; 435 435 436 436 case GETOPTDEF_APIMON_RESP_TIMEOUT: 437 g_ ulAPIMonResponseTimeoutMS= ValueUnion.u32;438 if (g_ ulAPIMonResponseTimeoutMS< 5000) /* Don't allow timeouts < 5s. */439 g_ ulAPIMonResponseTimeoutMS= 5000;437 g_cMsAPIMonResponseTimeout = ValueUnion.u32; 438 if (g_cMsAPIMonResponseTimeout < 5000) /* Don't allow timeouts < 5s. */ 439 g_cMsAPIMonResponseTimeout = 5000; 440 440 break; 441 441 … … 475 475 } 476 476 477 if (!g_ ulAPIMonIslnTimeoutMS)478 cfgGetValueU Long(g_pVirtualBox, NULL /* Machine */,479 480 &g_ulAPIMonIslnTimeoutMS, 30 * 1000 /* Default is 30 seconds timeout. */);481 g_ ulAPIMonIslnTimeoutMS = RT_MIN(1000, g_ulAPIMonIslnTimeoutMS);477 if (!g_cMsAPIMonIslnTimeout) 478 cfgGetValueU32(g_pVirtualBox, NULL /* Machine */, 479 "VBoxInternal2/Watchdog/APIMonitor/IsolationTimeoutMS", NULL /* Per-machine */, 480 &g_cMsAPIMonIslnTimeout, 30 * 1000 /* Default is 30 seconds timeout. */); 481 g_cMsAPIMonIslnTimeout = RT_MIN(1000, g_cMsAPIMonIslnTimeout); 482 482 483 483 if (g_enmAPIMonIslnResp == APIMON_RESPONSE_NONE) /* Not set by command line? */ … … 496 496 } 497 497 498 if (!g_ ulAPIMonResponseTimeoutMS)499 cfgGetValueU Long(g_pVirtualBox, NULL /* Machine */,500 501 &g_ulAPIMonResponseTimeoutMS, 30 * 1000 /* Default is 30 seconds timeout. */);502 g_ ulAPIMonResponseTimeoutMS = RT_MIN(5000, g_ulAPIMonResponseTimeoutMS);498 if (!g_cMsAPIMonResponseTimeout) 499 cfgGetValueU32(g_pVirtualBox, NULL /* Machine */, 500 "VBoxInternal2/Watchdog/APIMonitor/ResponseTimeoutMS", NULL /* Per-machine */, 501 &g_cMsAPIMonResponseTimeout, 30 * 1000 /* Default is 30 seconds timeout. */); 502 g_cMsAPIMonResponseTimeout = RT_MIN(5000, g_cMsAPIMonResponseTimeout); 503 503 504 504 #ifdef DEBUG … … 538 538 #ifdef DEBUG 539 539 serviceLogVerbose(("apimon: Checking for API heartbeat (%RU64ms) ...\n", 540 g_ ulAPIMonIslnTimeoutMS));540 g_cMsAPIMonIslnTimeout)); 541 541 #endif 542 542 … … 558 558 { 559 559 g_uAPIMonIslnLastBeatMS += uDelta; 560 if (g_uAPIMonIslnLastBeatMS > g_ ulAPIMonIslnTimeoutMS)560 if (g_uAPIMonIslnLastBeatMS > g_cMsAPIMonIslnTimeout) 561 561 { 562 562 serviceLogVerbose(("apimon: No API heartbeat within time received (%RU64ms)\n", 563 g_ ulAPIMonIslnTimeoutMS));563 g_cMsAPIMonIslnTimeout)); 564 564 565 565 vrc = apimonTrigger(g_enmAPIMonIslnResp); -
trunk/src/VBox/Frontends/VBoxBalloonCtrl/VBoxModBallooning.cpp
r63290 r63294 67 67 { 68 68 /** Last (most recent) ballooning size reported by the guest. */ 69 u nsigned long ulBalloonCurLast;69 uint32_t cMbBalloonCurLast; 70 70 /** Last (most recent) ballooning request received. */ 71 u nsigned long ulBalloonReqLast;71 uint32_t cMbBalloonReqLast; 72 72 } VBOXWATCHDOG_BALLOONCTRL_PAYLOAD, *PVBOXWATCHDOG_BALLOONCTRL_PAYLOAD; 73 73 … … 77 77 *********************************************************************************************************************************/ 78 78 79 static u nsigned long g_ulMemoryBalloonTimeoutMS= 30 * 1000;80 static u nsigned long g_ulMemoryBalloonIncrementMB= 256;81 static u nsigned long g_ulMemoryBalloonDecrementMB= 128;79 static uint32_t g_cMsMemoryBalloonTimeout = 30 * 1000; 80 static uint32_t g_cMbMemoryBalloonIncrement = 256; 81 static uint32_t g_cMbMemoryBalloonDecrement = 128; 82 82 /** Command line: Global balloon limit (in MB) for all VMs. Default is 0, which means 83 83 * no global limit is set. See balloonGetMaxSize() for more information. */ 84 static u nsigned long g_ulMemoryBalloonMaxMB= 0;85 static u nsigned long g_ulMemoryBalloonLowerLimitMB= 128;86 static u nsigned long g_ulMemoryBalloonSafetyMB= 1024;84 static uint32_t g_cMbMemoryBalloonMax = 0; 85 static uint32_t g_cMbMemoryBalloonLowerLimit = 128; 86 static uint32_t g_cbMemoryBalloonSafety = 1024; 87 87 88 88 … … 90 90 * Local Function Prototypes * 91 91 *********************************************************************************************************************************/ 92 static int balloonSetSize(PVBOXWATCHDOG_MACHINE pMachine, u nsigned long ulBalloonCur);92 static int balloonSetSize(PVBOXWATCHDOG_MACHINE pMachine, uint32_t cMbBalloonCur); 93 93 94 94 /** 95 95 * Retrieves the current delta value 96 96 * 97 * @return longDelta (MB) of the balloon to be deflated (<0) or inflated (>0).97 * @return Delta (MB) of the balloon to be deflated (<0) or inflated (>0). 98 98 * @param pMachine Pointer to the machine's internal structure. 99 * @param ulGuestMemFree The guest's current free memory (MB). 100 * @param ulBalloonOld The balloon's current (old) size (MB). 101 * @param ulBalloonNew The balloon's new size (MB). 102 * @param ulBalloonMax The maximum ballooning size (MB) it can inflate to. 103 */ 104 static long balloonGetDelta(PVBOXWATCHDOG_MACHINE pMachine, 105 unsigned long ulGuestMemFree, 106 unsigned long ulBalloonOld, unsigned long ulBalloonNew, unsigned long ulBalloonMax) 107 { 108 serviceLogVerbose(("[%ls] ulGuestMemFree=%RU32, ulBalloonOld=%RU32, ulBalloonNew=%RU32, ulBalloonMax=%RU32\n", 109 pMachine->strName.raw(), ulGuestMemFree, ulBalloonOld, ulBalloonNew, ulBalloonMax)); 99 * @param uGuestMemFree The guest's current free memory (MB). 100 * @param cMbBalloonOld The balloon's current (old) size (MB). 101 * @param uBalloonNew The balloon's new size (MB). 102 * @param uBalloonMax The maximum ballooning size (MB) it can inflate to. 103 */ 104 static int32_t balloonGetDelta(PVBOXWATCHDOG_MACHINE pMachine, uint32_t cMbGuestMemFree, 105 uint32_t cMbBalloonOld, uint32_t cMbBalloonNew, uint32_t cMbBalloonMax) 106 { 107 serviceLogVerbose(("[%ls] cMbGuestMemFree=%RU32, cMbBalloonOld=%RU32, cMbBalloonNew=%RU32, cMbBalloonMax=%RU32\n", 108 pMachine->strName.raw(), cMbGuestMemFree, cMbBalloonOld, cMbBalloonNew, cMbBalloonMax)); 110 109 111 110 /* Make sure that the requested new ballooning size does not 112 111 * exceed the maximum ballooning size (if set). */ 113 if ( ulBalloonMax 114 && (ulBalloonNew > ulBalloonMax)) 115 { 116 ulBalloonNew = ulBalloonMax; 117 } 118 119 long lBalloonDelta = 0; 120 if (ulGuestMemFree < g_ulMemoryBalloonLowerLimitMB) 112 if ( cMbBalloonMax 113 && cMbBalloonNew > cMbBalloonMax) 114 cMbBalloonNew = cMbBalloonMax; 115 116 int32_t cMbBalloonDelta = 0; 117 if (cMbGuestMemFree < g_cMbMemoryBalloonLowerLimit) 121 118 { 122 119 /* Guest is running low on memory, we need to 123 120 * deflate the balloon. */ 124 lBalloonDelta = (g_ulMemoryBalloonDecrementMB * -1);121 cMbBalloonDelta = g_cMbMemoryBalloonDecrement * -1; 125 122 126 123 /* Ensure that the delta will not return a negative 127 124 * balloon size. */ 128 if (( long)ulBalloonOld + lBalloonDelta < 0)129 lBalloonDelta = 0;130 } 131 else if ( ulBalloonNew > ulBalloonOld) /* Inflate. */125 if ((int32_t)cMbBalloonOld + cMbBalloonDelta < 0) 126 cMbBalloonDelta = 0; 127 } 128 else if (cMbBalloonNew > cMbBalloonOld) /* Inflate. */ 132 129 { 133 130 /* We want to inflate the balloon if we have room. */ 134 unsigned long ulIncrement = g_ulMemoryBalloonIncrementMB; 135 while (ulIncrement >= 16 && (ulGuestMemFree - ulIncrement) < g_ulMemoryBalloonLowerLimitMB) 136 ulIncrement = (ulIncrement / 2); 137 138 if ((ulGuestMemFree - ulIncrement) > g_ulMemoryBalloonLowerLimitMB) 139 lBalloonDelta = (long)ulIncrement; 131 uint32_t cMbIncrement = g_cMbMemoryBalloonIncrement; 132 while ( cMbIncrement >= 16 133 && cMbGuestMemFree - cMbIncrement < g_cMbMemoryBalloonLowerLimit) 134 cMbIncrement /= 2; 135 136 if ((cMbGuestMemFree - cMbIncrement) > g_cMbMemoryBalloonLowerLimit) 137 cMbBalloonDelta = (int32_t)cMbIncrement; 140 138 141 139 /* Make sure we're still within bounds. */ 142 Assert( lBalloonDelta >= 0);143 if ( ulBalloonOld + lBalloonDelta > ulBalloonNew)144 lBalloonDelta = RT_MIN(g_ulMemoryBalloonIncrementMB, ulBalloonNew - ulBalloonOld);145 } 146 else if ( ulBalloonNew < ulBalloonOld) /* Deflate. */147 { 148 lBalloonDelta = RT_MIN(g_ulMemoryBalloonDecrementMB, ulBalloonOld - ulBalloonNew) * -1;140 Assert(cMbBalloonDelta >= 0); 141 if (cMbBalloonOld + cMbBalloonDelta > cMbBalloonNew) 142 cMbBalloonDelta = RT_MIN(g_cMbMemoryBalloonIncrement, cMbBalloonNew - cMbBalloonOld); 143 } 144 else if (cMbBalloonNew < cMbBalloonOld) /* Deflate. */ 145 { 146 cMbBalloonDelta = RT_MIN(g_cMbMemoryBalloonDecrement, cMbBalloonOld - cMbBalloonNew) * -1; 149 147 } 150 148 151 149 /* Limit the ballooning to the available host memory, leaving some free. 152 150 * If anything fails clamp the delta to 0. */ 153 if ( lBalloonDelta < 0)154 { 155 uint64_t cbSafety = (uint64_t)g_ ulMemoryBalloonSafetyMB* _1M;151 if (cMbBalloonDelta < 0) 152 { 153 uint64_t cbSafety = (uint64_t)g_cbMemoryBalloonSafety * _1M; 156 154 uint64_t cbHostRamAvail = 0; 157 155 int vrc = RTSystemQueryAvailableRam(&cbHostRamAvail); … … 159 157 { 160 158 if (cbHostRamAvail < cbSafety) 161 lBalloonDelta = 0;162 else if ((uint64_t)(- lBalloonDelta) > (cbHostRamAvail - cbSafety) / _1M)163 lBalloonDelta = -(long)((cbHostRamAvail - cbSafety) / _1M);159 cMbBalloonDelta = 0; 160 else if ((uint64_t)(-cMbBalloonDelta) > (cbHostRamAvail - cbSafety) / _1M) 161 cMbBalloonDelta = -(int32_t)((cbHostRamAvail - cbSafety) / _1M); 164 162 } 165 163 else 166 lBalloonDelta = 0;167 } 168 169 return lBalloonDelta;164 cMbBalloonDelta = 0; 165 } 166 167 return cMbBalloonDelta; 170 168 } 171 169 … … 173 171 * Determines the maximum balloon size to set for the specified machine. 174 172 * 175 * @return unsigned longMaximum ballooning size (in MB), 0 if no maximum set.173 * @return Maximum ballooning size (in MB), 0 if no maximum set. 176 174 * @param pMachine Machine to determine maximum ballooning size for. 177 175 */ 178 static u nsigned longballoonGetMaxSize(PVBOXWATCHDOG_MACHINE pMachine)176 static uint32_t balloonGetMaxSize(PVBOXWATCHDOG_MACHINE pMachine) 179 177 { 180 178 /* … … 187 185 * Precedence from top to bottom. 188 186 */ 189 u nsigned long ulBalloonMax = 0;187 uint32_t cMbBalloonMax = 0; 190 188 char szSource[64]; 191 189 … … 196 194 && strValue.isNotEmpty()) 197 195 { 198 ulBalloonMax = Utf8Str(strValue).toUInt32();196 cMbBalloonMax = Utf8Str(strValue).toUInt32(); 199 197 if (g_fVerbose) 200 198 RTStrPrintf(szSource, sizeof(szSource), "global extra-data"); … … 203 201 if (strValue.isEmpty()) 204 202 { 205 Assert( ulBalloonMax == 0);206 207 ulBalloonMax = g_ulMemoryBalloonMaxMB;203 Assert(cMbBalloonMax == 0); 204 205 cMbBalloonMax = g_cMbMemoryBalloonMax; 208 206 if (g_fVerbose) 209 207 RTStrPrintf(szSource, sizeof(szSource), "command line"); 210 208 } 211 209 212 serviceLogVerbose(("[%ls] Maximum balloning size is (%s): %RU32MB\n", pMachine->strName.raw(), szSource, ulBalloonMax));213 return ulBalloonMax;210 serviceLogVerbose(("[%ls] Maximum balloning size is (%s): %RU32MB\n", pMachine->strName.raw(), szSource, cMbBalloonMax)); 211 return cMbBalloonMax; 214 212 } 215 213 … … 219 217 * @return IPRT status code. 220 218 * @param pMachine Machine to determine maximum ballooning size for. 221 * @param pulBalloonCur Where to store the current (set) balloon size (in MB) on success. 222 */ 223 static int balloonGetCurrentSize(PVBOXWATCHDOG_MACHINE pMachine, unsigned long *pulBalloonCur) 224 { 225 LONG lBalloonCur; 226 int vrc = getMetric(pMachine, L"Guest/RAM/Usage/Balloon", &lBalloonCur); 219 * @param pcMbBalloonCur Where to store the current (set) balloon 220 * size (in MB) on success. 221 */ 222 static int balloonGetCurrentSize(PVBOXWATCHDOG_MACHINE pMachine, uint32_t *pcMbBalloonCur) 223 { 224 LONG cKbBalloonCur; 225 int vrc = getMetric(pMachine, L"Guest/RAM/Usage/Balloon", &cKbBalloonCur); 227 226 if (RT_SUCCESS(vrc)) 228 227 { 229 lBalloonCur /= 1024; /* Convert to MB. */ 230 if (pulBalloonCur) 231 *pulBalloonCur = (unsigned long)lBalloonCur; 228 if (pcMbBalloonCur) 229 *pcMbBalloonCur = (uint32_t)(cKbBalloonCur / 1024); 232 230 } 233 231 … … 238 236 * Determines the requested balloon size to set for the specified machine. 239 237 * 240 * @return unsigned longRequested ballooning size (in MB), 0 if ballooning should be disabled.238 * @return Requested ballooning size (in MB), 0 if ballooning should be disabled. 241 239 * @param pMachine Machine to determine maximum ballooning size for. 242 240 */ 243 static u nsigned longballoonGetRequestedSize(PVBOXWATCHDOG_MACHINE pMachine)241 static uint32_t balloonGetRequestedSize(PVBOXWATCHDOG_MACHINE pMachine) 244 242 { 245 243 const ComPtr<IMachine> &rptrMachine = pMachine->machine; … … 252 250 * Precedence from top to bottom. 253 251 */ 254 u nsigned long ulBalloonReq = 0;252 uint32_t cMbBalloonReq = 0; 255 253 char szSource[64]; 256 254 … … 261 259 && strValue.isNotEmpty()) 262 260 { 263 ulBalloonReq = Utf8Str(strValue).toUInt32();261 cMbBalloonReq = Utf8Str(strValue).toUInt32(); 264 262 if (g_fVerbose) 265 263 RTStrPrintf(szSource, sizeof(szSource), "per-VM extra-data"); … … 272 270 && strValue.isNotEmpty()) 273 271 { 274 ulBalloonReq = Utf8Str(strValue).toUInt32();272 cMbBalloonReq = Utf8Str(strValue).toUInt32(); 275 273 if (g_fVerbose) 276 274 RTStrPrintf(szSource, sizeof(szSource), "per-VM extra-data (legacy)"); … … 281 279 || strValue.isEmpty()) 282 280 { 283 ulBalloonReq = 0;281 cMbBalloonReq = 0; 284 282 if (g_fVerbose) 285 283 RTStrPrintf(szSource, sizeof(szSource), "none (disabled)"); 286 284 } 287 285 288 serviceLogVerbose(("[%ls] Requested balloning size is (%s): %RU32MB\n", pMachine->strName.raw(), szSource, ulBalloonReq));289 return ulBalloonReq;286 serviceLogVerbose(("[%ls] Requested balloning size is (%s): %RU32MB\n", pMachine->strName.raw(), szSource, cMbBalloonReq)); 287 return cMbBalloonReq; 290 288 } 291 289 … … 421 419 * Get metrics collected at this point. 422 420 */ 423 LONG lGuestMemFree;424 u nsigned long ulBalloonCur;425 426 int vrc = getMetric(pMachine, L"Guest/RAM/Usage/Free", & lGuestMemFree);421 LONG cKbGuestMemFree; 422 uint32_t cMbBalloonCur = 0; 423 424 int vrc = getMetric(pMachine, L"Guest/RAM/Usage/Free", &cKbGuestMemFree); 427 425 if (RT_SUCCESS(vrc)) 428 vrc = balloonGetCurrentSize(pMachine, & ulBalloonCur);426 vrc = balloonGetCurrentSize(pMachine, &cMbBalloonCur); 429 427 430 428 if (RT_SUCCESS(vrc)) 431 429 { 432 430 /* If guest statistics are not up and running yet, skip this iteration and try next time. */ 433 if ( lGuestMemFree <= 0)431 if (cKbGuestMemFree <= 0) 434 432 { 435 433 #ifdef DEBUG … … 439 437 } 440 438 441 lGuestMemFree /=1024;442 443 PVBOXWATCHDOG_BALLOONCTRL_PAYLOAD pData = (PVBOXWATCHDOG_BALLOONCTRL_PAYLOAD)444 439 uint32_t cMbGuestMemFree = (ULONG)cKbGuestMemFree / 1024; 440 441 PVBOXWATCHDOG_BALLOONCTRL_PAYLOAD pData; 442 pData = (PVBOXWATCHDOG_BALLOONCTRL_PAYLOAD)payloadFrom(pMachine, VBOX_MOD_BALLOONING_NAME); 445 443 AssertPtr(pData); 446 444 … … 449 447 450 448 /* Determine the current set maximum balloon size. */ 451 u nsigned long ulBalloonMax = balloonGetMaxSize(pMachine);449 uint32_t cMbBalloonMax = balloonGetMaxSize(pMachine); 452 450 453 451 /* Determine the requested balloon size. */ 454 u nsigned long ulBalloonReq = balloonGetRequestedSize(pMachine);452 uint32_t cMbBalloonReq = balloonGetRequestedSize(pMachine); 455 453 456 454 serviceLogVerbose(("[%ls] Free RAM (MB): %RI32, Ballooning: Current=%RU32MB, Requested=%RU32MB, Maximum=%RU32MB\n", 457 pMachine->strName.raw(), lGuestMemFree, ulBalloonCur, ulBalloonReq, ulBalloonMax));458 459 if ( ulBalloonMax460 && (ulBalloonReq > ulBalloonMax))461 { 462 if (pData-> ulBalloonReqLast != ulBalloonReq)455 pMachine->strName.raw(), cMbGuestMemFree, cMbBalloonCur, cMbBalloonReq, cMbBalloonMax)); 456 457 if ( cMbBalloonMax 458 && cMbBalloonReq > cMbBalloonMax) 459 { 460 if (pData->cMbBalloonReqLast != cMbBalloonReq) 463 461 serviceLog("[%ls] Warning: Requested ballooning size (%RU32MB) exceeds set maximum ballooning size (%RU32MB), limiting ...\n", 464 pMachine->strName.raw(), ulBalloonReq, ulBalloonMax);462 pMachine->strName.raw(), cMbBalloonReq, cMbBalloonMax); 465 463 } 466 464 467 465 /* Calculate current balloon delta. */ 468 long lBalloonDelta = balloonGetDelta(pMachine, 469 (unsigned long)lGuestMemFree, ulBalloonCur, ulBalloonReq, ulBalloonMax); 466 int32_t cMbBalloonDelta = balloonGetDelta(pMachine, cMbGuestMemFree, cMbBalloonCur, cMbBalloonReq, cMbBalloonMax); 470 467 #ifdef DEBUG 471 serviceLogVerbose(("[%ls] lBalloonDelta=%RI32\n", pMachine->strName.raw(), lBalloonDelta));468 serviceLogVerbose(("[%ls] cMbBalloonDelta=%RI32\n", pMachine->strName.raw(), cMbBalloonDelta)); 472 469 #endif 473 if ( lBalloonDelta) /* Only do ballooning if there's really smth. to change ... */474 { 475 ulBalloonCur = ulBalloonCur + lBalloonDelta;470 if (cMbBalloonDelta) /* Only do ballooning if there's really smth. to change ... */ 471 { 472 cMbBalloonCur = cMbBalloonCur + cMbBalloonDelta; 476 473 477 474 if (fEnabled) 478 475 { 479 476 serviceLog("[%ls] %s balloon by %RU32MB to %RU32MB ...\n", 480 pMachine->strName.raw(), lBalloonDelta > 0 ? "Inflating" : "Deflating", RT_ABS(lBalloonDelta), ulBalloonCur);481 vrc = balloonSetSize(pMachine, ulBalloonCur);477 pMachine->strName.raw(), cMbBalloonDelta > 0 ? "Inflating" : "Deflating", RT_ABS(cMbBalloonDelta), cMbBalloonCur); 478 vrc = balloonSetSize(pMachine, cMbBalloonCur); 482 479 } 483 480 else 484 481 serviceLogVerbose(("[%ls] Requested %s balloon by %RU32MB to %RU32MB, but ballooning is disabled\n", 485 pMachine->strName.raw(), lBalloonDelta > 0 ? "inflating" : "deflating",486 RT_ABS( lBalloonDelta), ulBalloonCur));487 } 488 489 if ( ulBalloonCur != pData->ulBalloonCurLast)482 pMachine->strName.raw(), cMbBalloonDelta > 0 ? "inflating" : "deflating", 483 RT_ABS(cMbBalloonDelta), cMbBalloonCur)); 484 } 485 486 if (cMbBalloonCur != pData->cMbBalloonCurLast) 490 487 { 491 488 /* If ballooning is disabled, always bolt down the ballooning size to 0. */ … … 499 496 } 500 497 501 pData-> ulBalloonCurLast = ulBalloonCur;502 pData-> ulBalloonReqLast = ulBalloonReq;498 pData->cMbBalloonCurLast = cMbBalloonCur; 499 pData->cMbBalloonReqLast = cMbBalloonReq; 503 500 } 504 501 else … … 508 505 } 509 506 510 static int balloonSetSize(PVBOXWATCHDOG_MACHINE pMachine, u nsigned long ulBalloonCur)507 static int balloonSetSize(PVBOXWATCHDOG_MACHINE pMachine, uint32_t cMbBalloonCur) 511 508 { 512 509 int vrc = VINF_SUCCESS; 513 510 514 serviceLogVerbose(("[%ls] Setting balloon size to %RU32MB ...\n", pMachine->strName.raw(), ulBalloonCur));511 serviceLogVerbose(("[%ls] Setting balloon size to %RU32MB ...\n", pMachine->strName.raw(), cMbBalloonCur)); 515 512 516 513 if (g_fDryrun) … … 530 527 rc = console->COMGETTER(Guest)(guest.asOutParam()); 531 528 if (SUCCEEDED(rc)) 532 CHECK_ERROR_BREAK(guest, COMSETTER(MemoryBalloonSize)((LONG) ulBalloonCur));529 CHECK_ERROR_BREAK(guest, COMSETTER(MemoryBalloonSize)((LONG)cMbBalloonCur)); 533 530 else 534 531 serviceLog("Error: Unable to set new balloon size %RU32 for machine '%ls', rc=%Rhrc\n", 535 ulBalloonCur, pMachine->strName.raw(), rc);532 cMbBalloonCur, pMachine->strName.raw(), rc); 536 533 if (FAILED(rc)) 537 534 vrc = VERR_COM_IPRT_ERROR; … … 576 573 { 577 574 case GETOPTDEF_BALLOONCTRL_BALLOONDEC: 578 g_ ulMemoryBalloonDecrementMB= ValueUnion.u32;575 g_cMbMemoryBalloonDecrement = ValueUnion.u32; 579 576 break; 580 577 581 578 case GETOPTDEF_BALLOONCTRL_BALLOONINC: 582 g_ ulMemoryBalloonIncrementMB= ValueUnion.u32;579 g_cMbMemoryBalloonIncrement = ValueUnion.u32; 583 580 break; 584 581 … … 588 585 589 586 case GETOPTDEF_BALLOONCTRL_BALLOONLOWERLIMIT: 590 g_ ulMemoryBalloonLowerLimitMB= ValueUnion.u32;587 g_cMbMemoryBalloonLowerLimit = ValueUnion.u32; 591 588 break; 592 589 593 590 case GETOPTDEF_BALLOONCTRL_BALLOONMAX: 594 g_ ulMemoryBalloonMaxMB= ValueUnion.u32;591 g_cMbMemoryBalloonMax = ValueUnion.u32; 595 592 break; 596 593 597 594 case GETOPTDEF_BALLOONCTRL_BALLOONSAFETY: 598 g_ ulMemoryBalloonSafetyMB= ValueUnion.u32;595 g_cbMemoryBalloonSafety = ValueUnion.u32; 599 596 break; 600 597 … … 602 599 * this into a utility function! */ 603 600 case GETOPTDEF_BALLOONCTRL_TIMEOUTMS: 604 g_ ulMemoryBalloonTimeoutMS= ValueUnion.u32;605 if (g_ ulMemoryBalloonTimeoutMS< 500)606 g_ ulMemoryBalloonTimeoutMS= 500;601 g_cMsMemoryBalloonTimeout = ValueUnion.u32; 602 if (g_cMsMemoryBalloonTimeout < 500) 603 g_cMsMemoryBalloonTimeout = 500; 607 604 break; 608 605 … … 623 620 static DECLCALLBACK(int) VBoxModBallooningInit(void) 624 621 { 625 if (!g_ ulMemoryBalloonTimeoutMS)626 cfgGetValueU Long(g_pVirtualBox, NULL /* Machine */,627 628 &g_ulMemoryBalloonTimeoutMS, 30 * 1000 /* Default is 30 seconds timeout. */);629 630 if (!g_ ulMemoryBalloonIncrementMB)631 cfgGetValueU Long(g_pVirtualBox, NULL /* Machine */,632 633 &g_ulMemoryBalloonIncrementMB, 256);634 635 if (!g_ ulMemoryBalloonDecrementMB)636 cfgGetValueU Long(g_pVirtualBox, NULL /* Machine */,637 638 &g_ulMemoryBalloonDecrementMB, 128);639 640 if (!g_ ulMemoryBalloonLowerLimitMB)641 cfgGetValueU Long(g_pVirtualBox, NULL /* Machine */,642 643 &g_ulMemoryBalloonLowerLimitMB, 128);622 if (!g_cMsMemoryBalloonTimeout) 623 cfgGetValueU32(g_pVirtualBox, NULL /* Machine */, 624 "VBoxInternal2/Watchdog/BalloonCtrl/TimeoutMS", NULL /* Per-machine */, 625 &g_cMsMemoryBalloonTimeout, 30 * 1000 /* Default is 30 seconds timeout. */); 626 627 if (!g_cMbMemoryBalloonIncrement) 628 cfgGetValueU32(g_pVirtualBox, NULL /* Machine */, 629 "VBoxInternal2/Watchdog/BalloonCtrl/BalloonIncrementMB", NULL /* Per-machine */, 630 &g_cMbMemoryBalloonIncrement, 256); 631 632 if (!g_cMbMemoryBalloonDecrement) 633 cfgGetValueU32(g_pVirtualBox, NULL /* Machine */, 634 "VBoxInternal2/Watchdog/BalloonCtrl/BalloonDecrementMB", NULL /* Per-machine */, 635 &g_cMbMemoryBalloonDecrement, 128); 636 637 if (!g_cMbMemoryBalloonLowerLimit) 638 cfgGetValueU32(g_pVirtualBox, NULL /* Machine */, 639 "VBoxInternal2/Watchdog/BalloonCtrl/BalloonLowerLimitMB", NULL /* Per-machine */, 640 &g_cMbMemoryBalloonLowerLimit, 128); 644 641 645 642 return VINF_SUCCESS; … … 648 645 static DECLCALLBACK(int) VBoxModBallooningMain(void) 649 646 { 650 static uint64_t s_msLast = RTTimeMilliTS(); 651 uint64_t msDelta = RTTimeMilliTS() - s_msLast; 652 if (msDelta <= g_ulMemoryBalloonTimeoutMS) 653 return VINF_SUCCESS; 647 static uint64_t s_msLast = UINT64_MAX; 648 if (s_msLast == UINT64_MAX) 649 s_msLast = RTTimeMilliTS(); 650 else 651 { 652 uint64_t msDelta = RTTimeMilliTS() - s_msLast; 653 if (msDelta <= g_cMsMemoryBalloonTimeout) 654 return VINF_SUCCESS; 655 } 654 656 655 657 int rc = VINF_SUCCESS; … … 713 715 MachineState_T enmState) 714 716 { 717 RT_NOREF(enmState); 718 715 719 PVBOXWATCHDOG_MACHINE pMachine = getMachine(strUuid); 716 720 /* Note: The machine state will change to "setting up" when machine gets deleted, … … 724 728 static DECLCALLBACK(int) VBoxModBallooningOnServiceStateChanged(bool fAvailable) 725 729 { 730 RT_NOREF(fAvailable); 726 731 return VINF_SUCCESS; 727 732 } -
trunk/src/VBox/Frontends/VBoxBalloonCtrl/VBoxWatchdogInternal.h
r59907 r63294 240 240 int cfgGetValueStr(const ComPtr<IVirtualBox> &rptrVBox, const ComPtr<IMachine> &rptrMachine, 241 241 const char *pszGlobal, const char *pszVM, Utf8Str &strValue, Utf8Str strDefault); 242 int cfgGetValueU Long(const ComPtr<IVirtualBox> &rptrVBox, const ComPtr<IMachine> &rptrMachine,243 const char *pszGlobal, const char *pszVM, unsigned long *pulValue, unsigned long ulDefault);242 int cfgGetValueU32(const ComPtr<IVirtualBox> &rptrVBox, const ComPtr<IMachine> &rptrMachine, 243 const char *pszGlobal, const char *pszVM, uint32_t *puValue, uint32_t uDefault); 244 244 RT_C_DECLS_END 245 245 -
trunk/src/VBox/Frontends/VBoxBalloonCtrl/VBoxWatchdogUtils.cpp
r62493 r63294 252 252 } 253 253 254 int cfgGetValueU Long(const ComPtr<IVirtualBox> &rptrVBox, const ComPtr<IMachine> &rptrMachine,255 const char *pszGlobal, const char *pszVM, unsigned long *pulValue, unsigned long ulDefault)254 int cfgGetValueU32(const ComPtr<IVirtualBox> &rptrVBox, const ComPtr<IMachine> &rptrMachine, 255 const char *pszGlobal, const char *pszVM, uint32_t *puValue, uint32_t uDefault) 256 256 { 257 257 Utf8Str strValue; 258 258 int rc = cfgGetValueStr(rptrVBox, rptrMachine, pszGlobal, pszVM, strValue, "" /* Default */); 259 259 if (RT_SUCCESS(rc)) 260 { 261 *pulValue = strValue.toUInt32(); 262 } 260 *puValue = strValue.toUInt32(); 263 261 else 264 *pulValue = ulDefault; 265 262 *puValue = uDefault; 266 263 return rc; 267 264 }
Note:
See TracChangeset
for help on using the changeset viewer.