VirtualBox

Ignore:
Timestamp:
Aug 10, 2016 4:00:33 PM (8 years ago)
Author:
vboxsync
Message:

VBoxBalloonCtrl: Using 'long' and 'unsigned long' is a terrible idea because it means code works differently on 64-bit windows and 64-bit everything-else. Switched it all to use uint32_t as probably was the intention, judging from the frequent %RU32 format strings. Fixed warnings.

Location:
trunk/src/VBox/Frontends/VBoxBalloonCtrl
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Frontends/VBoxBalloonCtrl/VBoxModAPIMonitor.cpp

    r63290 r63294  
    6969/** The VM group(s) the API monitor handles. If none, all VMs get handled. */
    7070static mapGroups                    g_vecAPIMonGroups; /** @todo Move this into module payload! */
    71 static APIMON_RESPONSE              g_enmAPIMonIslnResp     = APIMON_RESPONSE_NONE;
    72 static unsigned long                g_ulAPIMonIslnTimeoutMS = 0;
     71static APIMON_RESPONSE              g_enmAPIMonIslnResp = APIMON_RESPONSE_NONE;
     72static uint32_t                     g_cMsAPIMonIslnTimeout = 0;
    7373static Bstr                         g_strAPIMonIslnLastBeat;
    74 static unsigned long                g_ulAPIMonResponseTimeoutMS = 0;
     74static uint32_t                     g_cMsAPIMonResponseTimeout = 0;
    7575static uint64_t                     g_uAPIMonIslnLastBeatMS = 0;
    7676
     
    180180
    181181static int apimonMachineControl(const Bstr &strUuid, PVBOXWATCHDOG_MACHINE pMachine,
    182                                 APIMON_RESPONSE enmResp, unsigned long ulTimeout)
     182                                APIMON_RESPONSE enmResp, uint32_t cMsTimeout)
    183183{
    184184    /** @todo Add other commands (with enmResp) here. */
     
    186186
    187187    serviceLogVerbose(("apimon: Triggering \"%s\" (%RU32ms timeout) for machine \"%ls\"\n",
    188                       apimonResponseToStr(enmResp), ulTimeout, strUuid.raw()));
     188                      apimonResponseToStr(enmResp), cMsTimeout, strUuid.raw()));
    189189
    190190    if (   enmResp == APIMON_RESPONSE_NONE
     
    234234                                           strUuid.raw()));
    235235                        CHECK_ERROR_BREAK(console, PowerDown(progress.asOutParam()));
    236                         progress->WaitForCompletion(ulTimeout);
     236                        progress->WaitForCompletion(cMsTimeout);
    237237                        CHECK_PROGRESS_ERROR(progress, ("Failed to power off machine \"%ls\"",
    238238                                             strUuid.raw()));
     
    274274                        if (SUCCEEDED(rc))
    275275                        {
    276                             progress->WaitForCompletion(ulTimeout);
     276                            progress->WaitForCompletion(cMsTimeout);
    277277                            CHECK_PROGRESS_ERROR(progress, ("Failed to save machine state of machine \"%ls\"",
    278278                                                 strUuid.raw()));
     
    364364            {
    365365                int rc2 = apimonMachineControl(it->first /* Uuid */,
    366                                                &it->second /* Machine */, enmResp, g_ulAPIMonResponseTimeoutMS);
     366                                               &it->second /* Machine */, enmResp, g_cMsAPIMonResponseTimeout);
    367367                if (RT_FAILURE(rc2))
    368368                    serviceLog("apimon: Controlling machine \"%ls\" (response \"%s\") failed with rc=%Rrc",
     
    429429
    430430            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;
    434434                break;
    435435
    436436            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;
    440440                break;
    441441
     
    475475        }
    476476
    477         if (!g_ulAPIMonIslnTimeoutMS)
    478             cfgGetValueULong(g_pVirtualBox, NULL /* Machine */,
    479                              "VBoxInternal2/Watchdog/APIMonitor/IsolationTimeoutMS", NULL /* Per-machine */,
    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);
    482482
    483483        if (g_enmAPIMonIslnResp == APIMON_RESPONSE_NONE) /* Not set by command line? */
     
    496496        }
    497497
    498         if (!g_ulAPIMonResponseTimeoutMS)
    499             cfgGetValueULong(g_pVirtualBox, NULL /* Machine */,
    500                              "VBoxInternal2/Watchdog/APIMonitor/ResponseTimeoutMS", NULL /* Per-machine */,
    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);
    503503
    504504#ifdef DEBUG
     
    538538#ifdef DEBUG
    539539    serviceLogVerbose(("apimon: Checking for API heartbeat (%RU64ms) ...\n",
    540                        g_ulAPIMonIslnTimeoutMS));
     540                       g_cMsAPIMonIslnTimeout));
    541541#endif
    542542
     
    558558        {
    559559            g_uAPIMonIslnLastBeatMS += uDelta;
    560             if (g_uAPIMonIslnLastBeatMS > g_ulAPIMonIslnTimeoutMS)
     560            if (g_uAPIMonIslnLastBeatMS > g_cMsAPIMonIslnTimeout)
    561561            {
    562562                serviceLogVerbose(("apimon: No API heartbeat within time received (%RU64ms)\n",
    563                                    g_ulAPIMonIslnTimeoutMS));
     563                                   g_cMsAPIMonIslnTimeout));
    564564
    565565                vrc = apimonTrigger(g_enmAPIMonIslnResp);
  • trunk/src/VBox/Frontends/VBoxBalloonCtrl/VBoxModBallooning.cpp

    r63290 r63294  
    6767{
    6868    /** Last (most recent) ballooning size reported by the guest. */
    69     unsigned long ulBalloonCurLast;
     69    uint32_t cMbBalloonCurLast;
    7070    /** Last (most recent) ballooning request received. */
    71     unsigned long ulBalloonReqLast;
     71    uint32_t cMbBalloonReqLast;
    7272} VBOXWATCHDOG_BALLOONCTRL_PAYLOAD, *PVBOXWATCHDOG_BALLOONCTRL_PAYLOAD;
    7373
     
    7777*********************************************************************************************************************************/
    7878
    79 static unsigned long g_ulMemoryBalloonTimeoutMS    = 30 * 1000;
    80 static unsigned long g_ulMemoryBalloonIncrementMB  = 256;
    81 static unsigned long g_ulMemoryBalloonDecrementMB  = 128;
     79static uint32_t g_cMsMemoryBalloonTimeout    = 30 * 1000;
     80static uint32_t g_cMbMemoryBalloonIncrement  = 256;
     81static uint32_t g_cMbMemoryBalloonDecrement  = 128;
    8282/** Command line: Global balloon limit (in MB) for all VMs. Default is 0, which means
    8383 *  no global limit is set. See balloonGetMaxSize() for more information. */
    84 static unsigned long g_ulMemoryBalloonMaxMB        = 0;
    85 static unsigned long g_ulMemoryBalloonLowerLimitMB = 128;
    86 static unsigned long g_ulMemoryBalloonSafetyMB     = 1024;
     84static uint32_t g_cMbMemoryBalloonMax        = 0;
     85static uint32_t g_cMbMemoryBalloonLowerLimit = 128;
     86static uint32_t g_cbMemoryBalloonSafety     = 1024;
    8787
    8888
     
    9090*   Local Function Prototypes                                                                                                    *
    9191*********************************************************************************************************************************/
    92 static int balloonSetSize(PVBOXWATCHDOG_MACHINE pMachine, unsigned long ulBalloonCur);
     92static int balloonSetSize(PVBOXWATCHDOG_MACHINE pMachine, uint32_t cMbBalloonCur);
    9393
    9494/**
    9595 * Retrieves the current delta value
    9696 *
    97  * @return  long                Delta (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).
    9898 * @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 */
     104static 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));
    110109
    111110    /* Make sure that the requested new ballooning size does not
    112111     * 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)
    121118    {
    122119        /* Guest is running low on memory, we need to
    123120         * deflate the balloon. */
    124         lBalloonDelta = (g_ulMemoryBalloonDecrementMB * -1);
     121        cMbBalloonDelta = g_cMbMemoryBalloonDecrement * -1;
    125122
    126123        /* Ensure that the delta will not return a negative
    127124         * 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. */
    132129    {
    133130        /* 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;
    140138
    141139        /* 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;
    149147    }
    150148
    151149    /* Limit the ballooning to the available host memory, leaving some free.
    152150     * 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;
    156154        uint64_t cbHostRamAvail = 0;
    157155        int vrc = RTSystemQueryAvailableRam(&cbHostRamAvail);
     
    159157        {
    160158            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);
    164162        }
    165163        else
    166             lBalloonDelta = 0;
    167     }
    168 
    169     return lBalloonDelta;
     164            cMbBalloonDelta = 0;
     165    }
     166
     167    return cMbBalloonDelta;
    170168}
    171169
     
    173171 * Determines the maximum balloon size to set for the specified machine.
    174172 *
    175  * @return  unsigned long           Maximum ballooning size (in MB), 0 if no maximum set.
     173 * @return  Maximum ballooning size (in MB), 0 if no maximum set.
    176174 * @param   pMachine                Machine to determine maximum ballooning size for.
    177175 */
    178 static unsigned long balloonGetMaxSize(PVBOXWATCHDOG_MACHINE pMachine)
     176static uint32_t balloonGetMaxSize(PVBOXWATCHDOG_MACHINE pMachine)
    179177{
    180178    /*
     
    187185     * Precedence from top to bottom.
    188186     */
    189     unsigned long ulBalloonMax = 0;
     187    uint32_t cMbBalloonMax = 0;
    190188    char szSource[64];
    191189
     
    196194        && strValue.isNotEmpty())
    197195    {
    198         ulBalloonMax = Utf8Str(strValue).toUInt32();
     196        cMbBalloonMax = Utf8Str(strValue).toUInt32();
    199197        if (g_fVerbose)
    200198            RTStrPrintf(szSource, sizeof(szSource), "global extra-data");
     
    203201    if (strValue.isEmpty())
    204202    {
    205         Assert(ulBalloonMax == 0);
    206 
    207         ulBalloonMax = g_ulMemoryBalloonMaxMB;
     203        Assert(cMbBalloonMax == 0);
     204
     205        cMbBalloonMax = g_cMbMemoryBalloonMax;
    208206        if (g_fVerbose)
    209207            RTStrPrintf(szSource, sizeof(szSource), "command line");
    210208    }
    211209
    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;
    214212}
    215213
     
    219217 * @return  IPRT status code.
    220218 * @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 */
     222static int balloonGetCurrentSize(PVBOXWATCHDOG_MACHINE pMachine, uint32_t *pcMbBalloonCur)
     223{
     224    LONG cKbBalloonCur;
     225    int vrc = getMetric(pMachine, L"Guest/RAM/Usage/Balloon", &cKbBalloonCur);
    227226    if (RT_SUCCESS(vrc))
    228227    {
    229         lBalloonCur /= 1024; /* Convert to MB. */
    230         if (pulBalloonCur)
    231             *pulBalloonCur = (unsigned long)lBalloonCur;
     228        if (pcMbBalloonCur)
     229            *pcMbBalloonCur = (uint32_t)(cKbBalloonCur / 1024);
    232230    }
    233231
     
    238236 * Determines the requested balloon size to set for the specified machine.
    239237 *
    240  * @return  unsigned long           Requested ballooning size (in MB), 0 if ballooning should be disabled.
     238 * @return  Requested ballooning size (in MB), 0 if ballooning should be disabled.
    241239 * @param   pMachine                Machine to determine maximum ballooning size for.
    242240 */
    243 static unsigned long balloonGetRequestedSize(PVBOXWATCHDOG_MACHINE pMachine)
     241static uint32_t balloonGetRequestedSize(PVBOXWATCHDOG_MACHINE pMachine)
    244242{
    245243    const ComPtr<IMachine> &rptrMachine = pMachine->machine;
     
    252250     * Precedence from top to bottom.
    253251     */
    254     unsigned long ulBalloonReq = 0;
     252    uint32_t cMbBalloonReq = 0;
    255253    char szSource[64];
    256254
     
    261259        && strValue.isNotEmpty())
    262260    {
    263         ulBalloonReq = Utf8Str(strValue).toUInt32();
     261        cMbBalloonReq = Utf8Str(strValue).toUInt32();
    264262        if (g_fVerbose)
    265263            RTStrPrintf(szSource, sizeof(szSource), "per-VM extra-data");
     
    272270            && strValue.isNotEmpty())
    273271        {
    274             ulBalloonReq = Utf8Str(strValue).toUInt32();
     272            cMbBalloonReq = Utf8Str(strValue).toUInt32();
    275273            if (g_fVerbose)
    276274                RTStrPrintf(szSource, sizeof(szSource), "per-VM extra-data (legacy)");
     
    281279        || strValue.isEmpty())
    282280    {
    283         ulBalloonReq = 0;
     281        cMbBalloonReq = 0;
    284282        if (g_fVerbose)
    285283            RTStrPrintf(szSource, sizeof(szSource), "none (disabled)");
    286284    }
    287285
    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;
    290288}
    291289
     
    421419     * Get metrics collected at this point.
    422420     */
    423     LONG lGuestMemFree;
    424     unsigned 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);
    427425    if (RT_SUCCESS(vrc))
    428         vrc = balloonGetCurrentSize(pMachine, &ulBalloonCur);
     426        vrc = balloonGetCurrentSize(pMachine, &cMbBalloonCur);
    429427
    430428    if (RT_SUCCESS(vrc))
    431429    {
    432430        /* If guest statistics are not up and running yet, skip this iteration and try next time. */
    433         if (lGuestMemFree <= 0)
     431        if (cKbGuestMemFree <= 0)
    434432        {
    435433#ifdef DEBUG
     
    439437        }
    440438
    441         lGuestMemFree /= 1024;
    442 
    443         PVBOXWATCHDOG_BALLOONCTRL_PAYLOAD pData = (PVBOXWATCHDOG_BALLOONCTRL_PAYLOAD)
    444                                                   payloadFrom(pMachine, VBOX_MOD_BALLOONING_NAME);
     439        uint32_t cMbGuestMemFree = (ULONG)cKbGuestMemFree / 1024;
     440
     441        PVBOXWATCHDOG_BALLOONCTRL_PAYLOAD pData;
     442        pData = (PVBOXWATCHDOG_BALLOONCTRL_PAYLOAD)payloadFrom(pMachine, VBOX_MOD_BALLOONING_NAME);
    445443        AssertPtr(pData);
    446444
     
    449447
    450448        /* Determine the current set maximum balloon size. */
    451         unsigned long ulBalloonMax = balloonGetMaxSize(pMachine);
     449        uint32_t cMbBalloonMax = balloonGetMaxSize(pMachine);
    452450
    453451        /* Determine the requested balloon size. */
    454         unsigned long ulBalloonReq = balloonGetRequestedSize(pMachine);
     452        uint32_t cMbBalloonReq = balloonGetRequestedSize(pMachine);
    455453
    456454        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 (   ulBalloonMax
    460             && (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)
    463461                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);
    465463        }
    466464
    467465        /* 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);
    470467#ifdef DEBUG
    471         serviceLogVerbose(("[%ls] lBalloonDelta=%RI32\n", pMachine->strName.raw(), lBalloonDelta));
     468        serviceLogVerbose(("[%ls] cMbBalloonDelta=%RI32\n", pMachine->strName.raw(), cMbBalloonDelta));
    472469#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;
    476473
    477474            if (fEnabled)
    478475            {
    479476                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);
    482479            }
    483480            else
    484481                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)
    490487        {
    491488            /* If ballooning is disabled, always bolt down the ballooning size to 0. */
     
    499496        }
    500497
    501         pData->ulBalloonCurLast = ulBalloonCur;
    502         pData->ulBalloonReqLast = ulBalloonReq;
     498        pData->cMbBalloonCurLast = cMbBalloonCur;
     499        pData->cMbBalloonReqLast = cMbBalloonReq;
    503500    }
    504501    else
     
    508505}
    509506
    510 static int balloonSetSize(PVBOXWATCHDOG_MACHINE pMachine, unsigned long ulBalloonCur)
     507static int balloonSetSize(PVBOXWATCHDOG_MACHINE pMachine, uint32_t cMbBalloonCur)
    511508{
    512509    int vrc = VINF_SUCCESS;
    513510
    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));
    515512
    516513    if (g_fDryrun)
     
    530527        rc = console->COMGETTER(Guest)(guest.asOutParam());
    531528        if (SUCCEEDED(rc))
    532             CHECK_ERROR_BREAK(guest, COMSETTER(MemoryBalloonSize)((LONG)ulBalloonCur));
     529            CHECK_ERROR_BREAK(guest, COMSETTER(MemoryBalloonSize)((LONG)cMbBalloonCur));
    533530        else
    534531            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);
    536533        if (FAILED(rc))
    537534            vrc = VERR_COM_IPRT_ERROR;
     
    576573        {
    577574            case GETOPTDEF_BALLOONCTRL_BALLOONDEC:
    578                 g_ulMemoryBalloonDecrementMB = ValueUnion.u32;
     575                g_cMbMemoryBalloonDecrement = ValueUnion.u32;
    579576                break;
    580577
    581578            case GETOPTDEF_BALLOONCTRL_BALLOONINC:
    582                 g_ulMemoryBalloonIncrementMB = ValueUnion.u32;
     579                g_cMbMemoryBalloonIncrement = ValueUnion.u32;
    583580                break;
    584581
     
    588585
    589586            case GETOPTDEF_BALLOONCTRL_BALLOONLOWERLIMIT:
    590                 g_ulMemoryBalloonLowerLimitMB = ValueUnion.u32;
     587                g_cMbMemoryBalloonLowerLimit = ValueUnion.u32;
    591588                break;
    592589
    593590            case GETOPTDEF_BALLOONCTRL_BALLOONMAX:
    594                 g_ulMemoryBalloonMaxMB = ValueUnion.u32;
     591                g_cMbMemoryBalloonMax = ValueUnion.u32;
    595592                break;
    596593
    597594            case GETOPTDEF_BALLOONCTRL_BALLOONSAFETY:
    598                 g_ulMemoryBalloonSafetyMB = ValueUnion.u32;
     595                g_cbMemoryBalloonSafety = ValueUnion.u32;
    599596                break;
    600597
     
    602599             *        this into a utility function! */
    603600            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;
    607604                break;
    608605
     
    623620static DECLCALLBACK(int) VBoxModBallooningInit(void)
    624621{
    625     if (!g_ulMemoryBalloonTimeoutMS)
    626         cfgGetValueULong(g_pVirtualBox, NULL /* Machine */,
    627                          "VBoxInternal2/Watchdog/BalloonCtrl/TimeoutMS", NULL /* Per-machine */,
    628                          &g_ulMemoryBalloonTimeoutMS, 30 * 1000 /* Default is 30 seconds timeout. */);
    629 
    630     if (!g_ulMemoryBalloonIncrementMB)
    631         cfgGetValueULong(g_pVirtualBox, NULL /* Machine */,
    632                          "VBoxInternal2/Watchdog/BalloonCtrl/BalloonIncrementMB", NULL /* Per-machine */,
    633                          &g_ulMemoryBalloonIncrementMB, 256);
    634 
    635     if (!g_ulMemoryBalloonDecrementMB)
    636         cfgGetValueULong(g_pVirtualBox, NULL /* Machine */,
    637                          "VBoxInternal2/Watchdog/BalloonCtrl/BalloonDecrementMB", NULL /* Per-machine */,
    638                          &g_ulMemoryBalloonDecrementMB, 128);
    639 
    640     if (!g_ulMemoryBalloonLowerLimitMB)
    641         cfgGetValueULong(g_pVirtualBox, NULL /* Machine */,
    642                          "VBoxInternal2/Watchdog/BalloonCtrl/BalloonLowerLimitMB", NULL /* Per-machine */,
    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);
    644641
    645642    return VINF_SUCCESS;
     
    648645static DECLCALLBACK(int) VBoxModBallooningMain(void)
    649646{
    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    }
    654656
    655657    int rc = VINF_SUCCESS;
     
    713715                                                                MachineState_T enmState)
    714716{
     717    RT_NOREF(enmState);
     718
    715719    PVBOXWATCHDOG_MACHINE pMachine = getMachine(strUuid);
    716720    /* Note: The machine state will change to "setting up" when machine gets deleted,
     
    724728static DECLCALLBACK(int) VBoxModBallooningOnServiceStateChanged(bool fAvailable)
    725729{
     730    RT_NOREF(fAvailable);
    726731    return VINF_SUCCESS;
    727732}
  • trunk/src/VBox/Frontends/VBoxBalloonCtrl/VBoxWatchdogInternal.h

    r59907 r63294  
    240240int cfgGetValueStr(const ComPtr<IVirtualBox> &rptrVBox, const ComPtr<IMachine> &rptrMachine,
    241241                   const char *pszGlobal, const char *pszVM, Utf8Str &strValue, Utf8Str strDefault);
    242 int cfgGetValueULong(const ComPtr<IVirtualBox> &rptrVBox, const ComPtr<IMachine> &rptrMachine,
    243                      const char *pszGlobal, const char *pszVM, unsigned long *pulValue, unsigned long ulDefault);
     242int cfgGetValueU32(const ComPtr<IVirtualBox> &rptrVBox, const ComPtr<IMachine> &rptrMachine,
     243                   const char *pszGlobal, const char *pszVM, uint32_t *puValue, uint32_t uDefault);
    244244RT_C_DECLS_END
    245245
  • trunk/src/VBox/Frontends/VBoxBalloonCtrl/VBoxWatchdogUtils.cpp

    r62493 r63294  
    252252}
    253253
    254 int cfgGetValueULong(const ComPtr<IVirtualBox> &rptrVBox, const ComPtr<IMachine> &rptrMachine,
    255                      const char *pszGlobal, const char *pszVM, unsigned long *pulValue, unsigned long ulDefault)
     254int cfgGetValueU32(const ComPtr<IVirtualBox> &rptrVBox, const ComPtr<IMachine> &rptrMachine,
     255                   const char *pszGlobal, const char *pszVM, uint32_t *puValue, uint32_t uDefault)
    256256{
    257257    Utf8Str strValue;
    258258    int rc = cfgGetValueStr(rptrVBox, rptrMachine, pszGlobal, pszVM, strValue, "" /* Default */);
    259259    if (RT_SUCCESS(rc))
    260     {
    261         *pulValue = strValue.toUInt32();
    262     }
     260        *puValue = strValue.toUInt32();
    263261    else
    264         *pulValue = ulDefault;
    265 
     262        *puValue = uDefault;
    266263    return rc;
    267264}
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette