VirtualBox

Changeset 4492 in vbox for trunk/src/VBox


Ignore:
Timestamp:
Sep 3, 2007 12:10:30 PM (17 years ago)
Author:
vboxsync
Message:

Continued Main-VMMDev work on memory ballooning.

Location:
trunk/src/VBox
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Devices/VMMDev/VBoxDev.cpp

    r4194 r4492  
    11791179
    11801180
     1181        case VMMDevReq_GetMemBalloonChangeRequest:
     1182        {
     1183            Log(("VMMDevReq_GetMemBalloonChangeRequest\n"));
     1184            if (requestHeader->size != sizeof(VMMDevGetMemBalloonChangeRequest))
     1185            {
     1186                requestHeader->rc = VERR_INVALID_PARAMETER;
     1187            }
     1188            else
     1189            {
     1190                VMMDevGetMemBalloonChangeRequest *memBalloonChangeRequest = (VMMDevGetMemBalloonChangeRequest*)requestHeader;
     1191                /* just pass on the information */
     1192                Log(("VMMDev: returning memory balloon size =%d\n", pData->u32MemoryBalloonSize));
     1193                memBalloonChangeRequest->u32BalloonSize = pData->u32MemoryBalloonSize;
     1194
     1195                if (memBalloonChangeRequest->eventAck == VMMDEV_EVENT_BALLOON_CHANGE_REQUEST)
     1196                {
     1197                    /* Remember which mode the client has queried. */
     1198                    pData->u32LastMemoryBalloonSize = pData->u32MemoryBalloonSize;
     1199                }
     1200
     1201                requestHeader->rc = VINF_SUCCESS;
     1202            }
     1203            break;
     1204        }
     1205
     1206        case VMMDevReq_ReportGuestStats:
     1207        {
     1208            Log(("VMMDevReq_ReportGuestStats\n"));
     1209            if (requestHeader->size != sizeof(VMMDevReportGuestStats))
     1210            {
     1211                requestHeader->rc = VERR_INVALID_PARAMETER;
     1212            }
     1213            else
     1214            {
     1215                VMMDevReportGuestStats *stats = (VMMDevReportGuestStats*)requestHeader;
     1216
     1217                /* Update the last known memory balloon size */
     1218                if (stats->guestStats.u32StatCaps & VBOX_GUEST_STAT_PHYS_MEM_BALLOON)
     1219                    pData->u32LastMemoryBalloonSize = stats->guestStats.u32PhysMemBalloon;
     1220
     1221                /* forward the call */
     1222                requestHeader->rc = pData->pDrv->pfnReportStatistics(pData->pDrv, &stats->guestStats);
     1223            }
     1224            break;
     1225        }
     1226
    11811227        case VMMDevReq_QueryCredentials:
    11821228        {
     
    16251671        /* IRQ so the guest knows what's going on */
    16261672        VMMDevNotifyGuest (pData, VMMDEV_EVENT_SEAMLESS_MODE_CHANGE_REQUEST);
     1673    }
     1674
     1675    return VINF_SUCCESS;
     1676}
     1677
     1678static DECLCALLBACK(int) vmmdevSetMemoryBalloon(PPDMIVMMDEVPORT pInterface, uint32_t ulBalloonSize)
     1679{
     1680    VMMDevState *pData = IVMMDEVPORT_2_VMMDEVSTATE(pInterface);
     1681
     1682    /* Verify that the new resolution is different and that guest does not yet know about it. */
     1683    bool fSame = (pData->u32LastMemoryBalloonSize == ulBalloonSize);
     1684
     1685    Log(("vmmdevSetMemoryBalloon: old=%d. new=%d\n", pData->u32LastMemoryBalloonSize, ulBalloonSize));
     1686
     1687    if (!fSame)
     1688    {
     1689        /* we could validate the information here but hey, the guest can do that as well! */
     1690        pData->u32MemoryBalloonSize = ulBalloonSize;
     1691
     1692        /* IRQ so the guest knows what's going on */
     1693        VMMDevNotifyGuest (pData, VMMDEV_EVENT_BALLOON_CHANGE_REQUEST);
    16271694    }
    16281695
     
    19171984    pData->Port.pfnVBVAChange             = vmmdevVBVAChange;
    19181985    pData->Port.pfnRequestSeamlessChange  = vmmdevRequestSeamlessChange;
     1986    pData->Port.pfnSetMemoryBalloon       = vmmdevSetMemoryBalloon;
    19191987
    19201988    /* Shared folder LED */
     
    20452113    /* disable seamless mode */
    20462114    pData->fLastSeamlessEnabled = false;
     2115
     2116    /* disabled memory ballooning */
     2117    pData->u32LastMemoryBalloonSize = 0;
    20472118
    20482119    /* Clear the event variables.
  • trunk/src/VBox/Devices/VMMDev/VMMDevState.h

    r4071 r4492  
    132132    } credentialsJudge;
    133133
     134    /* memory balloon change request */
     135    uint32_t    u32MemoryBalloonSize, u32LastMemoryBalloonSize;
     136
    134137    /* seamless mode change request */
    135138    bool fLastSeamlessEnabled, fSeamlessEnabled;
  • trunk/src/VBox/Main/GuestImpl.cpp

    r4321 r4492  
    174174STDMETHODIMP Guest::COMSETTER(MemoryBalloonSize) (ULONG aMemoryBalloonSize)
    175175{
    176     /** @todo fail if larger than physical memory */
    177 
    178     AutoCaller autoCaller (this);
    179     CheckComRCReturnRC (autoCaller.rc());
    180 
    181     AutoReaderLock alock (this);
    182 
    183     mMemoryBalloonSize = aMemoryBalloonSize;
    184 
    185     return S_OK;
     176    AutoCaller autoCaller (this);
     177    CheckComRCReturnRC (autoCaller.rc());
     178
     179    AutoReaderLock alock (this);
     180
     181    HRESULT ret = mParent->machine()->COMSETTER(MemoryBalloonSize)(aMemoryBalloonSize);
     182    if (ret == S_OK)
     183    {
     184        mMemoryBalloonSize = aMemoryBalloonSize;
     185        /* forward the information to the VMM device */
     186        VMMDev *vmmDev = mParent->getVMMDev();
     187        if (vmmDev)
     188            vmmDev->getVMMDevPort()->pfnSetMemoryBalloon(vmmDev->getVMMDevPort(), aMemoryBalloonSize);
     189    }
     190
     191    return ret;
    186192}
    187193
  • trunk/src/VBox/Main/MachineImpl.cpp

    r4475 r4492  
    4141#include "GuestOSTypeImpl.h"
    4242#include "VirtualBoxErrorInfoImpl.h"
     43#include "GuestImpl.h"
    4344
    4445#include "USBProxyService.h"
     
    164165    /* default values for a newly created machine */
    165166    mMemorySize = 128;
     167    mMemoryBalloonSize = 0;
    166168    mVRAMSize = 8;
    167169    mMonitorCount = 1;
     
    188190
    189191    if (mMemorySize != that.mMemorySize ||
     192        mMemoryBalloonSize != that.mMemoryBalloonSize ||
    190193        mVRAMSize != that.mVRAMSize ||
    191194        mMonitorCount != that.mMonitorCount ||
     
    977980    return S_OK;
    978981}
     982
     983
     984STDMETHODIMP Machine::COMGETTER(MemoryBalloonSize) (ULONG *memoryBalloonSize)
     985{
     986    if (!memoryBalloonSize)
     987        return E_POINTER;
     988
     989    AutoCaller autoCaller (this);
     990    CheckComRCReturnRC (autoCaller.rc());
     991
     992    AutoReaderLock alock (this);
     993
     994    *memoryBalloonSize = mHWData->mMemoryBalloonSize;
     995
     996    return S_OK;
     997}
     998
     999STDMETHODIMP Machine::COMSETTER(MemoryBalloonSize) (ULONG memoryBalloonSize)
     1000{
     1001    /* check limits */
     1002    if (memoryBalloonSize >= VMMDEV_MAX_MEMORY_BALLOON(mHWData->mMemorySize))
     1003        return setError (E_INVALIDARG,
     1004            tr ("Invalid memory balloon size: %lu MB (must be in range [%lu, %lu] MB)"),
     1005                memoryBalloonSize, 0, VMMDEV_MAX_MEMORY_BALLOON(mHWData->mMemorySize));
     1006
     1007    AutoCaller autoCaller (this);
     1008    CheckComRCReturnRC (autoCaller.rc());
     1009
     1010    AutoLock alock (this);
     1011
     1012    HRESULT rc = checkStateDependency (MutableStateDep);
     1013    CheckComRCReturnRC (rc);
     1014
     1015    mHWData.backup();
     1016    mHWData->mMemoryBalloonSize = memoryBalloonSize;
     1017
     1018    return S_OK;
     1019}
     1020
    9791021
    9801022STDMETHODIMP Machine::COMGETTER(MonitorCount) (ULONG *monitorCount)
     
    40114053#endif
    40124054
     4055    /* Guest node (optional) */
     4056    CFGNODE GuestNode = 0;
     4057    CFGLDRGetChildNode (aNode, "Guest", 0, &GuestNode);
     4058    if (GuestNode)
     4059    {
     4060        uint32_t memoryBalloonSize;
     4061        CFGLDRQueryUInt32 (GuestNode, "memoryBalloonSize", &memoryBalloonSize);
     4062        mHWData->mMemoryBalloonSize = memoryBalloonSize;
     4063
     4064        CFGLDRReleaseNode (GuestNode);
     4065    }
     4066
    40134067    /* BIOS node (required) */
    40144068    {
     
    59105964    }
    59115965#endif
     5966
     5967    /* Guest node (optional) */
     5968    {
     5969        CFGNODE GuestNode = 0;
     5970        CFGLDRCreateChildNode (aNode, "Guest", &GuestNode);
     5971        CFGLDRSetUInt32 (GuestNode, "memoryBalloonSize", mHWData->mMemoryBalloonSize);
     5972        CFGLDRReleaseNode (GuestNode);
     5973    }
    59125974
    59135975    /* BIOS (required) */
  • trunk/src/VBox/Main/VMMDevInterface.cpp

    r4071 r4492  
    351351        *pcRect = cRect;
    352352    }
     353
     354    return VINF_SUCCESS;
     355}
     356
     357/**
     358 * Request the statistics interval
     359 *
     360 * @returns VBox status code.
     361 * @param   pInterface          Pointer to this interface.
     362 * @param   pulInterval         Pointer to interval in seconds
     363 * @thread  The emulation thread.
     364 */
     365DECLCALLBACK(int) vmmdevQueryStatisticsInterval(PPDMIVMMDEVCONNECTOR pInterface, uint32_t *pulInterval)
     366{
     367    PDRVMAINVMMDEV pDrv = PDMIVMMDEVCONNECTOR_2_MAINVMMDEV(pInterface);
     368    ULONG          val = 0;
     369
     370    if (!pulInterval)
     371        return VERR_INVALID_POINTER;
     372
     373    /* store that information in IGuest */
     374    Guest* guest = pDrv->pVMMDev->getParent()->getGuest();
     375    Assert(guest);
     376    if (!guest)
     377        return VERR_INVALID_PARAMETER; /** @todo wrong error */
     378
     379    guest->COMGETTER(StatisticsUpdateInterval)(&val);
     380    *pulInterval = val;
     381    return VINF_SUCCESS;
     382}
     383
     384/**
     385 * Report new guest statistics
     386 *
     387 * @returns VBox status code.
     388 * @param   pInterface          Pointer to this interface.
     389 * @param   pGuestStats         Guest statistics
     390 * @thread  The emulation thread.
     391 */
     392DECLCALLBACK(int) vmmdevReportStatistics(PPDMIVMMDEVCONNECTOR pInterface, VBoxGuestStatistics *pGuestStats)
     393{
     394    PDRVMAINVMMDEV pDrv = PDMIVMMDEVCONNECTOR_2_MAINVMMDEV(pInterface);
     395
     396    Assert(pGuestStats);
     397    if (!pGuestStats)
     398        return VERR_INVALID_POINTER;
     399
     400    /* store that information in IGuest */
     401    Guest* guest = pDrv->pVMMDev->getParent()->getGuest();
     402    Assert(guest);
     403    if (!guest)
     404        return VERR_INVALID_PARAMETER; /** @todo wrong error */
     405
     406    if (pGuestStats->u32StatCaps & VBOX_GUEST_STAT_CPU_LOAD)
     407        guest->SetStatistic(GuestStatisticType_CPULoad, pGuestStats->u32CpuLoad);
     408
     409    if (pGuestStats->u32StatCaps & VBOX_GUEST_STAT_THREADS)
     410        guest->SetStatistic(GuestStatisticType_Threads, pGuestStats->u32Threads);
     411
     412    if (pGuestStats->u32StatCaps & VBOX_GUEST_STAT_PROCESSES)
     413        guest->SetStatistic(GuestStatisticType_Processes, pGuestStats->u32Processes);
     414
     415    if (pGuestStats->u32StatCaps & VBOX_GUEST_STAT_PHYS_MEM_TOTAL)
     416        guest->SetStatistic(GuestStatisticType_PhysMemTotal, pGuestStats->u32PhysMemTotal);
     417
     418    if (pGuestStats->u32StatCaps & VBOX_GUEST_STAT_PHYS_MEM_AVAIL)
     419        guest->SetStatistic(GuestStatisticType_PhysMemAvailable, pGuestStats->u32PhysMemAvail);
     420
     421    if (pGuestStats->u32StatCaps & VBOX_GUEST_STAT_PHYS_MEM_BALLOON)
     422        guest->SetStatistic(GuestStatisticType_PhysMemBalloon, pGuestStats->u32PhysMemBalloon);
     423
     424    if (pGuestStats->u32StatCaps & VBOX_GUEST_STAT_PAGE_FILE_SIZE)
     425        guest->SetStatistic(GuestStatisticType_PageFileSize, pGuestStats->u32PageFileSize);
    353426
    354427    return VINF_SUCCESS;
     
    543616    pData->Connector.pfnSetVisibleRegion              = vmmdevSetVisibleRegion;
    544617    pData->Connector.pfnQueryVisibleRegion            = vmmdevQueryVisibleRegion;
     618    pData->Connector.pfnReportStatistics              = vmmdevReportStatistics;
     619    pData->Connector.pfnQueryStatisticsInterval       = vmmdevQueryStatisticsInterval;
    545620
    546621#ifdef VBOX_HGCM
  • trunk/src/VBox/Main/idl/VirtualBox.xidl

    r4324 r4492  
    409409  <enum
    410410     name="GuestStatisticType"
    411      uuid="da89a1b7-e602-45ac-84b7-29c9d12b92d5"
     411     uuid="a7cffd08-665f-4156-b2e9-2b3c64e213da"
    412412     >
    413413    <const name="CPULoad"              value="0">
     
    436436      </desc>
    437437    </const>
    438     <const name="PageFileSize"         value="5">
     438    <const name="PhysMemBalloon"       value="5">
     439      <desc>
     440        Ballooned physical memory in megabytes.
     441      </desc>
     442    </const>
     443    <const name="PageFileSize"         value="6">
    439444      <desc>
    440445        Pagefile size in megabytes.
     
    20162021  <interface
    20172022     name="IMachine" extends="$unknown"
    2018      uuid="31f7169f-14da-4c55-8cb6-a3665186e35e"
     2023     uuid="dcfb87c4-18a9-4a1e-9b1f-6f68f920535b"
    20192024     wsmap="managed"
    20202025     >
     
    21632168
    21642169    <attribute name="memorySize" type="unsigned long">
    2165       <desc>Sytem memory size in megabytes.</desc>
     2170      <desc>System memory size in megabytes.</desc>
     2171    </attribute>
     2172
     2173    <attribute name="memoryBalloonSize" type="unsigned long">
     2174      <desc>Initial memory balloon size in megabytes.</desc>
    21662175    </attribute>
    21672176
  • trunk/src/VBox/Main/include/MachineImpl.h

    r4071 r4492  
    221221
    222222        ULONG          mMemorySize;
     223        ULONG          mMemoryBalloonSize;
    223224        ULONG          mVRAMSize;
    224225        ULONG          mMonitorCount;
     
    441442    STDMETHOD(COMGETTER(MemorySize))(ULONG *memorySize);
    442443    STDMETHOD(COMSETTER(MemorySize))(ULONG memorySize);
     444    STDMETHOD(COMGETTER(MemoryBalloonSize))(ULONG *memoryBalloonSize);
     445    STDMETHOD(COMSETTER(MemoryBalloonSize))(ULONG memoryBalloonSize);
    443446    STDMETHOD(COMGETTER(VRAMSize))(ULONG *memorySize);
    444447    STDMETHOD(COMSETTER(VRAMSize))(ULONG memorySize);
  • trunk/src/VBox/Main/xml/VirtualBox-settings-common.xsd

    r4339 r4492  
    383383</xsd:complexType>
    384384
     385<xsd:complexType name="TGuest">
     386  <xsd:element name="MemoryBalloonSize" type="xsd:unsignedInt" default="0"/>
     387</xsd:complexType>
     388
    385389<xsd:complexType name="TBoot">
    386390  <xsd:sequence>
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