VirtualBox

Changeset 4594 in vbox for trunk/src/VBox


Ignore:
Timestamp:
Sep 7, 2007 8:53:27 AM (17 years ago)
Author:
vboxsync
Message:

Split up stats & memory balloon management

Location:
trunk/src/VBox/Additions/WINNT/VBoxService
Files:
2 edited
2 moved

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Additions/WINNT/VBoxService/Makefile.kmk

    r4540 r4594  
    3333        VBoxVRDP.cpp \
    3434        VBoxRestore.cpp \
    35         VBoxGuest.cpp \
     35        VBoxStatistics.cpp \
     36        VBoxMemBalloon.cpp \
    3637        helpers.cpp \
    3738        VBoxService.rc
  • trunk/src/VBox/Additions/WINNT/VBoxService/VBoxService.cpp

    r4540 r4594  
    2121#include "VBoxRestore.h"
    2222#include "VBoxVRDP.h"
    23 #include "VBoxGuest.h"
     23#include "VBoxStatistics.h"
     24#include "VBoxMemBalloon.h"
    2425#include <VBoxHook.h>
    2526#include "resource.h"
     
    100101#ifdef VBOX_WITH_MANAGEMENT
    101102    {
    102         "Guest Management",
    103         VBoxGuestInit,
    104         VBoxGuestThread,
    105         VBoxGuestDestroy,
     103        "Memory Balloon",
     104        VBoxMemBalloonInit,
     105        VBoxMemBalloonThread,
     106        VBoxMemBalloonDestroy,
     107    },
     108    {
     109        "Guest Statistics",
     110        VBoxStatsInit,
     111        VBoxStatsThread,
     112        VBoxStatsDestroy,
    106113    },
    107114#endif
  • trunk/src/VBox/Additions/WINNT/VBoxService/VBoxStatistics.cpp

    r4585 r4594  
    11/** @file
    22 *
    3  * VBoxGuest - Guest management notification
     3 * VBoxStats - Guest statistics notification
    44 *
    55 */
     
    2020#include <psapi.h>
    2121#include "VBoxService.h"
    22 #include "VBoxGuest.h"
     22#include "VBoxStatistics.h"
     23#include "VBoxMemBalloon.h"
    2324#include <VBoxDisplay.h>
    2425#include <VBox/VBoxDev.h>
     26#include <VBox/VBoxGuest.h>
    2527#include <VBoxGuestInternal.h>
    2628#include <iprt/assert.h>
     
    2830#include <winternl.h>
    2931
    30 typedef struct _VBOXGUESTCONTEXT
     32typedef struct _VBOXSTATSCONTEXT
    3133{
    3234    const VBOXSERVICEENV *pEnv;
    3335    uint32_t              uStatInterval;
    34     uint32_t              uMemBalloonSize;
    3536
    3637    uint64_t              ullLastCpuLoad_Idle;
     
    4142    void     (WINAPI *pfnGlobalMemoryStatusEx)(LPMEMORYSTATUSEX lpBuffer);
    4243    BOOL     (WINAPI *pfnGetPerformanceInfo)(PPERFORMANCE_INFORMATION pPerformanceInformation, DWORD cb);
    43 } VBOXGUESTCONTEXT;
    44 
    45 
    46 static VBOXGUESTCONTEXT gCtx = {0};
    47 
    48 
    49 int VBoxGuestInit(const VBOXSERVICEENV *pEnv, void **ppInstance, bool *pfStartThread)
     44} VBOXSTATSCONTEXT;
     45
     46
     47static VBOXSTATSCONTEXT gCtx = {0};
     48
     49
     50int VBoxStatsInit(const VBOXSERVICEENV *pEnv, void **ppInstance, bool *pfStartThread)
    5051{
    5152    HANDLE gVBoxDriver = pEnv->hDriver;
    5253    DWORD  cbReturned;
    5354
    54     dprintf(("VBoxGuestInit\n"));
     55    dprintf(("VBoxStatsInit\n"));
    5556
    5657    gCtx.pEnv                   = pEnv;
     
    5960    gCtx.ullLastCpuLoad_Kernel  = 0;
    6061    gCtx.ullLastCpuLoad_User    = 0;
    61     gCtx.uMemBalloonSize        = 0;
    6262
    6363    VMMDevGetStatisticsChangeRequest req;
     
    6767    if (DeviceIoControl(gVBoxDriver, IOCTL_VBOXGUEST_VMMREQUEST, &req, req.header.size, &req, req.header.size, &cbReturned, NULL))
    6868    {
    69         dprintf(("VBoxGuestThread: new statistics interval %d seconds\n", req.u32StatInterval));
     69        dprintf(("VBoxStatsThread: new statistics interval %d seconds\n", req.u32StatInterval));
    7070        gCtx.uStatInterval = req.u32StatInterval * 1000;
    7171    }
    7272    else
    73         dprintf(("VBoxGuestThread: DeviceIoControl failed with %d\n", GetLastError()));
     73        dprintf(("VBoxStatsThread: DeviceIoControl failed with %d\n", GetLastError()));
    7474
    7575    /* NtQuerySystemInformation might be dropped in future releases, so load it dynamically as per Microsoft's recommendation */
     
    111111    }
    112112
    113     /* Check balloon size */
    114     DWORD dwMemBalloonSize;
    115     if (DeviceIoControl(gVBoxDriver, IOCTL_VBOXGUEST_CTL_CHECK_BALLOON, NULL, 0, &dwMemBalloonSize, sizeof(dwMemBalloonSize), &cbReturned, NULL))
    116     {
    117         dprintf(("VBoxGuestThread: new balloon size % MB\n", dwMemBalloonSize));
    118         gCtx.uMemBalloonSize = dwMemBalloonSize;
    119     }
    120     else
    121         dprintf(("VBoxGuestThread: DeviceIoControl (balloon) failed with %d\n", GetLastError()));
    122 
    123113    *pfStartThread = true;
    124114    *ppInstance = &gCtx;
     
    127117
    128118
    129 void VBoxGuestDestroy(const VBOXSERVICEENV *pEnv, void *pInstance)
    130 {
    131     dprintf(("VBoxGuestDestroy\n"));
     119void VBoxStatsDestroy(const VBOXSERVICEENV *pEnv, void *pInstance)
     120{
     121    dprintf(("VBoxStatsDestroy\n"));
    132122    return;
    133123}
    134124
    135 void VBoxGuestReportStatistics(VBOXGUESTCONTEXT *pCtx)
     125void VBoxStatsReportStatistics(VBOXSTATSCONTEXT *pCtx)
    136126{
    137127    SYSTEM_INFO systemInfo;
     
    160150    req.guestStats.u32PageFileSize      = (uint32_t)(memStatus.ullTotalPageFile / systemInfo.dwPageSize);
    161151    req.guestStats.u32MemoryLoad        = memStatus.dwMemoryLoad;
    162     req.guestStats.u32PhysMemBalloon    = pCtx->uMemBalloonSize * (_1M/systemInfo.dwPageSize);    /* was in megabytes */
     152    req.guestStats.u32PhysMemBalloon    = VBoxMemBalloonQuerySize() * (_1M/systemInfo.dwPageSize);    /* was in megabytes */
    163153    req.guestStats.u32StatCaps          = VBOX_GUEST_STAT_PHYS_MEM_TOTAL | VBOX_GUEST_STAT_PHYS_MEM_AVAIL | VBOX_GUEST_STAT_PAGE_FILE_SIZE | VBOX_GUEST_STAT_MEMORY_LOAD | VBOX_GUEST_STAT_PHYS_MEM_BALLOON;
    164154
     
    229219        if (DeviceIoControl(gVBoxDriver, IOCTL_VBOXGUEST_VMMREQUEST, &req, req.header.size, &req, req.header.size, &cbReturned, NULL))
    230220        {
    231             dprintf(("VBoxGuestThread: new statistics reported successfully!\n"));
    232         }
    233         else
    234             dprintf(("VBoxGuestThread: DeviceIoControl (stats report) failed with %d\n", GetLastError()));
     221            dprintf(("VBoxStatsThread: new statistics reported successfully!\n"));
     222        }
     223        else
     224            dprintf(("VBoxStatsThread: DeviceIoControl (stats report) failed with %d\n", GetLastError()));
    235225    }
    236226
     
    242232 * requests
    243233 */
    244 unsigned __stdcall VBoxGuestThread(void *pInstance)
    245 {
    246     VBOXGUESTCONTEXT *pCtx = (VBOXGUESTCONTEXT *)pInstance;
     234unsigned __stdcall VBoxStatsThread(void *pInstance)
     235{
     236    VBOXSTATSCONTEXT *pCtx = (VBOXSTATSCONTEXT *)pInstance;
    247237    HANDLE gVBoxDriver = pCtx->pEnv->hDriver;
    248238    bool fTerminate = false;
     
    250240    DWORD cbReturned;
    251241
    252     maskInfo.u32OrMask = VMMDEV_EVENT_BALLOON_CHANGE_REQUEST | VMMDEV_EVENT_STATISTICS_INTERVAL_CHANGE_REQUEST;
     242    maskInfo.u32OrMask = VMMDEV_EVENT_STATISTICS_INTERVAL_CHANGE_REQUEST;
    253243    maskInfo.u32NotMask = 0;
    254244    if (DeviceIoControl (gVBoxDriver, IOCTL_VBOXGUEST_CTL_FILTER_MASK, &maskInfo, sizeof (maskInfo), NULL, 0, &cbReturned, NULL))
    255245    {
    256         dprintf(("VBoxGuestThread: DeviceIOControl(CtlMask - or) succeeded\n"));
     246        dprintf(("VBoxStatsThread: DeviceIOControl(CtlMask - or) succeeded\n"));
    257247    }
    258248    else
    259249    {
    260         dprintf(("VBoxGuestThread: DeviceIOControl(CtlMask) failed, SeamlessChangeThread exited\n"));
     250        dprintf(("VBoxStatsThread: DeviceIOControl(CtlMask) failed, SeamlessChangeThread exited\n"));
    261251        return 0;
    262252    }
     
    267257        VBoxGuestWaitEventInfo waitEvent;
    268258        waitEvent.u32TimeoutIn = (pCtx->uStatInterval) ? pCtx->uStatInterval : 1000;
    269         waitEvent.u32EventMaskIn = VMMDEV_EVENT_BALLOON_CHANGE_REQUEST | VMMDEV_EVENT_STATISTICS_INTERVAL_CHANGE_REQUEST;
     259        waitEvent.u32EventMaskIn = VMMDEV_EVENT_STATISTICS_INTERVAL_CHANGE_REQUEST;
    270260        if (DeviceIoControl(gVBoxDriver, IOCTL_VBOXGUEST_WAITEVENT, &waitEvent, sizeof(waitEvent), &waitEvent, sizeof(waitEvent), &cbReturned, NULL))
    271261        {
    272             dprintf(("VBoxGuestThread: DeviceIOControl succeded\n"));
     262            dprintf(("VBoxStatsThread: DeviceIOControl succeded\n"));
    273263
    274264            /* are we supposed to stop? */
     
    276266                break;
    277267
    278             dprintf(("VBoxGuestThread: checking event\n"));
     268            dprintf(("VBoxStatsThread: checking event\n"));
    279269
    280270            /* did we get the right event? */
    281             if (waitEvent.u32EventFlagsOut & VMMDEV_EVENT_BALLOON_CHANGE_REQUEST)
    282             {
    283                 DWORD dwMemBalloonSize;
    284                 if (DeviceIoControl(gVBoxDriver, IOCTL_VBOXGUEST_CTL_CHECK_BALLOON, NULL, 0, &dwMemBalloonSize, sizeof(dwMemBalloonSize), &cbReturned, NULL))
    285                 {
    286                     dprintf(("VBoxGuestThread: new balloon size % MB\n", dwMemBalloonSize));
    287                     pCtx->uMemBalloonSize = dwMemBalloonSize;
    288                 }
    289                 else
    290                     dprintf(("VBoxGuestThread: DeviceIoControl (balloon) failed with %d\n", GetLastError()));
    291             }
    292271            if (waitEvent.u32EventFlagsOut & VMMDEV_EVENT_STATISTICS_INTERVAL_CHANGE_REQUEST)
    293272            {
     
    298277                if (DeviceIoControl(gVBoxDriver, IOCTL_VBOXGUEST_VMMREQUEST, &req, req.header.size, &req, req.header.size, &cbReturned, NULL))
    299278                {
    300                     dprintf(("VBoxGuestThread: new statistics interval %d seconds\n", req.u32StatInterval));
     279                    dprintf(("VBoxStatsThread: new statistics interval %d seconds\n", req.u32StatInterval));
    301280                    pCtx->uStatInterval = req.u32StatInterval * 1000;
    302281                }
    303282                else
    304                     dprintf(("VBoxGuestThread: DeviceIoControl (stat) failed with %d\n", GetLastError()));
     283                    dprintf(("VBoxStatsThread: DeviceIoControl (stat) failed with %d\n", GetLastError()));
    305284            }
    306285        }
    307286        else
    308287        {
    309             dprintf(("VBoxGuestThread: error 0 from DeviceIoControl IOCTL_VBOXGUEST_WAITEVENT\n"));
     288            dprintf(("VBoxStatsThread: error 0 from DeviceIoControl IOCTL_VBOXGUEST_WAITEVENT\n"));
    310289
    311290            /* sleep a bit to not eat too much CPU in case the above call always fails */
     
    320299            &&  gCtx.pfnNtQuerySystemInformation)
    321300        {
    322             VBoxGuestReportStatistics(pCtx);
     301            VBoxStatsReportStatistics(pCtx);
    323302        }
    324303    }
     
    326305
    327306    maskInfo.u32OrMask = 0;
    328     maskInfo.u32NotMask = VMMDEV_EVENT_BALLOON_CHANGE_REQUEST | VMMDEV_EVENT_STATISTICS_INTERVAL_CHANGE_REQUEST;
     307    maskInfo.u32NotMask = VMMDEV_EVENT_STATISTICS_INTERVAL_CHANGE_REQUEST;
    329308    if (DeviceIoControl (gVBoxDriver, IOCTL_VBOXGUEST_CTL_FILTER_MASK, &maskInfo, sizeof (maskInfo), NULL, 0, &cbReturned, NULL))
    330309    {
    331         dprintf(("VBoxGuestThread: DeviceIOControl(CtlMask - not) succeeded\n"));
     310        dprintf(("VBoxStatsThread: DeviceIOControl(CtlMask - not) succeeded\n"));
    332311    }
    333312    else
    334313    {
    335         dprintf(("VBoxGuestThread: DeviceIOControl(CtlMask) failed\n"));
    336     }
    337 
    338     dprintf(("VBoxGuestThread: finished seamless change request thread\n"));
     314        dprintf(("VBoxStatsThread: DeviceIOControl(CtlMask) failed\n"));
     315    }
     316
     317    dprintf(("VBoxStatsThread: finished seamless change request thread\n"));
    339318    return 0;
    340319}
  • trunk/src/VBox/Additions/WINNT/VBoxService/VBoxStatistics.h

    r4584 r4594  
    11/** @file
    2  * VBoxGuest - Guest management notification
     2 * VBoxGuest - Guest statistics notification
    33 */
    44
     
    1515 */
    1616
    17 #ifndef __VBOXSERVICEGUEST__H
    18 #define __VBOXSERVICEGUEST__H
     17#ifndef __VBOXSERVICESTATS__H
     18#define __VBOXSERVICESTATS__H
    1919
    2020/* The guest management service prototypes. */
    21 int                VBoxGuestInit    (const VBOXSERVICEENV *pEnv, void **ppInstance, bool *pfStartThread);
    22 unsigned __stdcall VBoxGuestThread  (void *pInstance);
    23 void               VBoxGuestDestroy (const VBOXSERVICEENV *pEnv, void *pInstance);
     21int                VBoxStatsInit    (const VBOXSERVICEENV *pEnv, void **ppInstance, bool *pfStartThread);
     22unsigned __stdcall VBoxStatsThread  (void *pInstance);
     23void               VBoxStatsDestroy (const VBOXSERVICEENV *pEnv, void *pInstance);
    2424
    25 #endif /* __VBOXSERVICEGUEST__H */
     25#endif /* __VBOXSERVICESTATS__H */
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