VirtualBox

Changeset 31287 in vbox for trunk/src/VBox


Ignore:
Timestamp:
Aug 2, 2010 12:13:00 PM (15 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
64314
Message:

Initial API changes for resource control (storage/network/cpu)

Location:
trunk/src/VBox/Main
Files:
9 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Main/ConsoleImpl2.cpp

    r31180 r31287  
    769769        InsertConfigInteger(pPDMAcFile, "CacheSize", ioCacheSize * _1M);
    770770
    771         /* Maximum I/O bandwidth */
    772         ULONG ioBandwidthMax = 0;
    773         hrc = pMachine->COMGETTER(IoBandwidthMax)(&ioBandwidthMax);                         H();
    774         if (ioBandwidthMax != 0)
    775         {
    776             InsertConfigInteger(pPDMAcFile, "VMTransferPerSecMax", ioBandwidthMax * _1M);
    777         }
    778 
    779771        /*
    780772         * Devices
  • trunk/src/VBox/Main/MachineImpl.cpp

    r31281 r31287  
    213213    mIoCacheEnabled = true;
    214214    mIoCacheSize    = 5; /* 5MB */
    215     mIoBandwidthMax = 0; /* Unlimited */
     215
     216    /* Maximum CPU priority by default. */
     217    mCpuPriority = 100;
    216218}
    217219
     
    12791281    return S_OK;
    12801282}
     1283
     1284STDMETHODIMP Machine::COMGETTER(CPUPriority)(ULONG *aPriority)
     1285{
     1286    if (!aPriority)
     1287        return E_POINTER;
     1288
     1289    AutoCaller autoCaller(this);
     1290    if (FAILED(autoCaller.rc())) return autoCaller.rc();
     1291
     1292    AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
     1293
     1294    *aPriority = mHWData->mCpuPriority;
     1295
     1296    return S_OK;
     1297}
     1298
     1299STDMETHODIMP Machine::COMSETTER(CPUPriority)(ULONG aPriority)
     1300{
     1301    /* check priority limits */
     1302    if (    aPriority < 1
     1303         || aPriority > 100
     1304       )
     1305        return setError(E_INVALIDARG,
     1306                        tr("Invalid CPU priority: %lu (must be in range [%lu, %lu])"),
     1307                        aPriority, 1, 100);
     1308
     1309    AutoCaller autoCaller(this);
     1310    if (FAILED(autoCaller.rc())) return autoCaller.rc();
     1311
     1312    AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
     1313
     1314    /* Todo: must always allow changes. */
     1315    HRESULT rc = checkStateDependency(MutableStateDep);
     1316    if (FAILED(rc)) return rc;
     1317
     1318    setModified(IsModified_MachineData);
     1319    mHWData.backup();
     1320    mHWData->mCpuPriority = aPriority;
     1321
     1322    return S_OK;
     1323}
     1324
    12811325
    12821326STDMETHODIMP Machine::COMGETTER(CPUHotPlugEnabled)(BOOL *enabled)
     
    26472691}
    26482692
    2649 STDMETHODIMP Machine::COMGETTER(IoBandwidthMax)(ULONG *aIoBandwidthMax)
    2650 {
    2651     CheckComArgOutPointerValid(aIoBandwidthMax);
    2652 
    2653     AutoCaller autoCaller(this);
    2654     if (FAILED(autoCaller.rc())) return autoCaller.rc();
    2655 
    2656     AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
    2657 
    2658     *aIoBandwidthMax = mHWData->mIoBandwidthMax;
    2659 
    2660     return S_OK;
    2661 }
    2662 
    2663 STDMETHODIMP Machine::COMSETTER(IoBandwidthMax)(ULONG  aIoBandwidthMax)
    2664 {
    2665     AutoCaller autoCaller(this);
    2666     if (FAILED(autoCaller.rc())) return autoCaller.rc();
    2667 
    2668     AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
    2669 
    2670     HRESULT rc = checkStateDependency(MutableStateDep);
    2671     if (FAILED(rc)) return rc;
    2672 
    2673     setModified(IsModified_MachineData);
    2674     mHWData.backup();
    2675     mHWData->mIoBandwidthMax = aIoBandwidthMax;
    2676 
    2677     return S_OK;
    2678 }
    26792693
    26802694/**
     
    68536867        mHWData->mSyntheticCpu                = data.fSyntheticCpu;
    68546868
    6855         mHWData->mCPUCount          = data.cCPUs;
    6856         mHWData->mCPUHotPlugEnabled = data.fCpuHotPlug;
     6869        mHWData->mCPUCount                    = data.cCPUs;
     6870        mHWData->mCPUHotPlugEnabled           = data.fCpuHotPlug;
     6871        mHWData->mCpuPriority                 = data.ulCpuPriority;
    68576872
    68586873        // cpu
     
    70097024        mHWData->mIoCacheEnabled = data.ioSettings.fIoCacheEnabled;
    70107025        mHWData->mIoCacheSize = data.ioSettings.ulIoCacheSize;
    7011         mHWData->mIoBandwidthMax = data.ioSettings.ulIoBandwidthMax;
    70127026
    70137027#ifdef VBOX_WITH_GUEST_PROPS
     
    79457959        }
    79467960
    7947         data.cCPUs       = mHWData->mCPUCount;
    7948         data.fCpuHotPlug = !!mHWData->mCPUHotPlugEnabled;
     7961        data.cCPUs         = mHWData->mCPUCount;
     7962        data.fCpuHotPlug   = !!mHWData->mCPUHotPlugEnabled;
     7963        data.ulCpuPriority = mHWData->mCpuPriority;
    79497964
    79507965        data.llCpus.clear();
     
    80748089        data.ioSettings.fIoCacheEnabled = !!mHWData->mIoCacheEnabled;
    80758090        data.ioSettings.ulIoCacheSize = mHWData->mIoCacheSize;
    8076         data.ioSettings.ulIoBandwidthMax = mHWData->mIoBandwidthMax;
    80778091
    80788092        // guest properties
  • trunk/src/VBox/Main/MediumAttachmentImpl.cpp

    r30681 r31287  
    5252    const LONG          lDevice;
    5353    const DeviceType_T  type;
    54     bool                fPassthrough : 1;
    55     bool                fImplicit : 1;
     54    bool                fPassthrough;
     55    bool                fImplicit;
     56    ULONG               mBandwidthLimit;
    5657};
    5758
     
    132133    m->bd->fImplicit = false;
    133134
     135    /* Default is no limit. */
     136    m->bd->mBandwidthLimit = 0;
     137
    134138    /* Confirm a successful initialization when it's the case */
    135139    autoInitSpan.setSucceeded();
     
    272276}
    273277
     278STDMETHODIMP MediumAttachment::COMGETTER(BandwidthLimit) (ULONG *aLimit)
     279{
     280    CheckComArgOutPointerValid(aLimit);
     281
     282    AutoCaller autoCaller(this);
     283    if (FAILED(autoCaller.rc())) return autoCaller.rc();
     284
     285    AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
     286
     287    *aLimit = m->bd->mBandwidthLimit;
     288    return S_OK;
     289}
     290
     291STDMETHODIMP MediumAttachment::COMSETTER(BandwidthLimit) (ULONG aLimit)
     292{
     293    AutoCaller autoCaller(this);
     294    if (FAILED(autoCaller.rc())) return autoCaller.rc();
     295
     296    /* the machine doesn't need to be mutable */
     297
     298    AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
     299
     300    if (aLimit != m->bd->mBandwidthLimit)
     301    {
     302        m->bd.backup();
     303        m->bd->mBandwidthLimit = aLimit;
     304
     305        /* todo: not all storage attachments will support this. */
     306    }
     307    return S_OK;
     308}
     309
    274310/**
    275311 *  @note Locks this object for writing.
  • trunk/src/VBox/Main/NetworkAdapterImpl.cpp

    r28800 r31287  
    8484    /* initialize data */
    8585    mData->mSlot = aSlot;
     86
     87    /* Default limit is not capped/unlimited. */
     88    mData->mBandwidthLimit = 0;
    8689
    8790    /* default to Am79C973 */
     
    749752}
    750753
     754STDMETHODIMP NetworkAdapter::COMGETTER(BandwidthLimit) (ULONG *aLimit)
     755{
     756    CheckComArgOutPointerValid(aLimit);
     757
     758    AutoCaller autoCaller(this);
     759    if (FAILED(autoCaller.rc())) return autoCaller.rc();
     760
     761    AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
     762
     763    *aLimit = mData->mBandwidthLimit;
     764    return S_OK;
     765}
     766
     767STDMETHODIMP NetworkAdapter::COMSETTER(BandwidthLimit) (ULONG aLimit)
     768{
     769    AutoCaller autoCaller(this);
     770    if (FAILED(autoCaller.rc())) return autoCaller.rc();
     771
     772    /* the machine doesn't need to be mutable */
     773
     774    AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
     775
     776    if (aLimit != mData->mBandwidthLimit)
     777    {
     778        mData.backup();
     779        mData->mBandwidthLimit = aLimit;
     780
     781        m_fModified = true;
     782        // leave the lock before informing callbacks
     783        alock.release();
     784
     785        AutoWriteLock mlock(mParent COMMA_LOCKVAL_SRC_POS);       // mParent is const, no need to lock
     786        mParent->setModified(Machine::IsModified_NetworkAdapters);
     787        mlock.release();
     788
     789        /* No change in CFGM logic => changeAdapter=FALSE. */
     790        mParent->onNetworkAdapterChange(this, FALSE);
     791    }
     792    return S_OK;
     793}
     794
    751795STDMETHODIMP NetworkAdapter::COMGETTER(TraceEnabled) (BOOL *aEnabled)
    752796{
     
    12181262    /* boot priority (defaults to 0, i.e. lowest) */
    12191263    mData->mBootPriority = data.ulBootPriority;
     1264    /* Bandwidth limit in Mbps. */
     1265    mData->mBandwidthLimit = data.ulBandwidthLimit;
    12201266
    12211267    switch (data.mode)
     
    13001346
    13011347    data.ulBootPriority = mData->mBootPriority;
     1348
     1349    data.ulBandwidthLimit = mData->mBandwidthLimit;
    13021350
    13031351    data.type = mData->mAdapterType;
  • trunk/src/VBox/Main/idl/VirtualBox.xidl

    r31280 r31287  
    36383638  <interface
    36393639     name="IMachine" extends="$unknown"
    3640      uuid="de8f0b23-f285-4779-acf4-08eddda7ec75"
     3640     uuid="e2d8679e-b144-41d9-9dfa-bbe2fd0ab2d1"
    36413641     wsmap="managed"
    36423642     >
     
    38353835    </attribute>
    38363836
    3837     <attribute name="memorySize" type="unsigned long">
     3837    <attribute name="CPUPriority" type="unsigned long">
     3838       <desc>
     3839         Priority of the virtual CPUs. Means to limit the number of CPU cycles
     3840         a guest can use. The unit is percentage of host CPU cycles per second.
     3841         The valid range is 1 - 100. 100 (the default) implies no limit.
     3842       </desc>
     3843    </attribute>
     3844
     3845      <attribute name="memorySize" type="unsigned long">
    38383846      <desc>System memory size in megabytes.</desc>
    38393847    </attribute>
     
    41914199    </attribute>
    41924200
    4193     <attribute name="ioBandwidthMax" type="unsigned long">
    4194       <desc>
    4195         The maximum number of MB the VM is allowed to transfer per second.
    4196         0 means unlimited bandwidth.
    4197       </desc>
    4198     </attribute>
    4199 
    42004201    <method name="lockMachine">
    42014202      <desc>
     
    85298530  <interface
    85308531    name="IMediumAttachment" extends="$unknown"
    8531     uuid="e58eb3eb-8627-428b-bdf8-34487c848de5"
     8532    uuid="c29452cc-ca72-404b-9261-cfc514f1e412"
    85328533    wsmap="struct"
    85338534  >
     
    85808581    <attribute name="passthrough" type="boolean" readonly="yes">
    85818582      <desc>Pass I/O requests through to a device on the host.</desc>
     8583    </attribute>
     8584
     8585    <attribute name="bandwidthLimit" type="unsigned long">
     8586      <desc>
     8587         Maximum throughput allowed for this medium attachment, in units of 1 mbps.
     8588         A zero value means uncapped/unlimited.
     8589      </desc>
    85828590    </attribute>
    85838591
     
    1107711085  <interface
    1107811086     name="INetworkAdapter" extends="$unknown"
    11079      uuid="5bdb9df8-a5e1-4322-a139-b7a4a734c790"
     11087     uuid="9bf58a46-c3f7-4f31-80fa-dde9a5dc0b7b"
    1108011088     wsmap="managed"
    1108111089     >
     
    1119211200    </attribute>
    1119311201
    11194     <method name="attachToNAT">
     11202    <attribute name="bandwidthLimit" type="unsigned long">
     11203      <desc>
     11204        Maximum throughput allowed for this network adapter, in units of 1 mbps.
     11205        A zero value means uncapped/unlimited.
     11206      </desc>
     11207    </attribute>
     11208
     11209      <method name="attachToNAT">
    1119511210      <desc>
    1119611211        Attach the network adapter to the Network Address Translation (NAT) interface.
  • trunk/src/VBox/Main/include/MachineImpl.h

    r31228 r31287  
    271271        ULONG                mCPUCount;
    272272        BOOL                 mCPUHotPlugEnabled;
     273        ULONG                mCpuPriority;
    273274        BOOL                 mAccelerate3DEnabled;
    274275        BOOL                 mHpetEnabled;
     
    296297        BOOL                 mIoCacheEnabled;
    297298        ULONG                mIoCacheSize;
    298         ULONG                mIoBandwidthMax;
    299299    };
    300300
     
    392392    STDMETHOD(COMGETTER(CPUHotPlugEnabled))(BOOL *enabled);
    393393    STDMETHOD(COMSETTER(CPUHotPlugEnabled))(BOOL enabled);
     394    STDMETHOD(COMGETTER(CPUPriority))(ULONG *aPriority);
     395    STDMETHOD(COMSETTER(CPUPriority))(ULONG aPriority);
    394396    STDMETHOD(COMGETTER(HpetEnabled))(BOOL *enabled);
    395397    STDMETHOD(COMSETTER(HpetEnabled))(BOOL enabled);
     
    451453    STDMETHOD(COMGETTER(IoCacheSize)) (ULONG *aIoCacheSize);
    452454    STDMETHOD(COMSETTER(IoCacheSize)) (ULONG  aIoCacheSize);
    453     STDMETHOD(COMGETTER(IoBandwidthMax)) (ULONG *aIoBandwidthMax);
    454     STDMETHOD(COMSETTER(IoBandwidthMax)) (ULONG  aIoBandwidthMax);
    455455
    456456    // IMachine methods
  • trunk/src/VBox/Main/include/MediumAttachmentImpl.h

    r30739 r31287  
    6161    STDMETHOD(COMGETTER(Type))(DeviceType_T *aType);
    6262    STDMETHOD(COMGETTER(Passthrough))(BOOL *aPassthrough);
     63    STDMETHOD(COMGETTER(BandwidthLimit))(ULONG *aLimit);
     64    STDMETHOD(COMSETTER(BandwidthLimit))(ULONG aLimit);
    6365
    6466    // public internal methods
  • trunk/src/VBox/Main/include/NetworkAdapterImpl.h

    r30764 r31287  
    6969        Bstr mNATNetwork;
    7070        ULONG mBootPriority;
     71        ULONG mBandwidthLimit;
    7172    };
    7273
     
    122123    STDMETHOD(COMGETTER(BootPriority)) (ULONG *aBootPriority);
    123124    STDMETHOD(COMSETTER(BootPriority)) (ULONG aBootPriority);
     125    STDMETHOD(COMGETTER(BandwidthLimit)) (ULONG *aLimit);
     126    STDMETHOD(COMSETTER(BandwidthLimit)) (ULONG aLimit);
    124127
    125128    // INetworkAdapter methods
  • trunk/src/VBox/Main/xml/Settings.cpp

    r31131 r31287  
    14891489          fCpuHotPlug(false),
    14901490          fHpetEnabled(false),
     1491          ulCpuPriority(100),
    14911492          ulMemorySizeMB((uint32_t)-1),
    14921493          ulVRAMSizeMB(8),
     
    15331534                  && (cCPUs                     == h.cCPUs)
    15341535                  && (fCpuHotPlug               == h.fCpuHotPlug)
     1536                  && (ulCpuPriority             == h.ulCpuPriority)
    15351537                  && (fHpetEnabled              == h.fHpetEnabled)
    15361538                  && (llCpus                    == h.llCpus)
     
    16421644    fIoCacheEnabled  = true;
    16431645    ulIoCacheSize    = 5;
    1644     ulIoBandwidthMax = 0;
    16451646}
    16461647
     
    18391840        pelmAdapter->getAttributeValue("tracefile", nic.strTraceFile);
    18401841        pelmAdapter->getAttributeValue("bootPriority", nic.ulBootPriority);
     1842        pelmAdapter->getAttributeValue("bandwidthLimit", nic.ulBandwidthLimit);
    18411843
    18421844        xml::ElementNodesList llNetworkModes;
     
    21932195
    21942196            pelmHwChild->getAttributeValue("hotplug", hw.fCpuHotPlug);
     2197            pelmHwChild->getAttributeValue("priority", hw.ulCpuPriority);
    21952198
    21962199            const xml::ElementNode *pelmCPUChild;
     
    25402543                pelmIoChild->getAttributeValue("enabled", hw.ioSettings.fIoCacheEnabled);
    25412544                pelmIoChild->getAttributeValue("size", hw.ioSettings.ulIoCacheSize);
    2542             }
    2543             if ((pelmIoChild = pelmHwChild->findChildElement("IoBandwidth")))
    2544             {
    2545                 pelmIoChild->getAttributeValue("max", hw.ioSettings.ulIoBandwidthMax);
    25462545            }
    25472546        }
     
    31073106        pelmCPU->createChild("SyntheticCpu")->setAttribute("enabled", hw.fSyntheticCpu);
    31083107    pelmCPU->setAttribute("count", hw.cCPUs);
     3108    if (hw.ulCpuPriority != 100)
     3109        pelmCPU->setAttribute("priority", hw.ulCpuPriority);
    31093110
    31103111    if (hw.fLargePages)
     
    33863387            pelmAdapter->setAttribute("tracefile", nic.strTraceFile);
    33873388        }
     3389        if (nic.ulBandwidthLimit)
     3390            pelmAdapter->setAttribute("bandwidthLimit", nic.ulBandwidthLimit);
    33883391
    33893392        const char *pcszType;
     
    35723575        pelmIoCache->setAttribute("size", hw.ioSettings.ulIoCacheSize);
    35733576        pelmIoBandwidth = pelmIo->createChild("IoBandwidth");
    3574         pelmIoBandwidth->setAttribute("max", hw.ioSettings.ulIoBandwidthMax);
    35753577    }
    35763578
     
    41884190             netit != hardwareMachine.llNetworkAdapters.end(); ++netit)
    41894191        {
     4192            if (netit->ulBandwidthLimit)
     4193            {
     4194                /* New in VirtualBox 3.3 */
     4195                m->sv = SettingsVersion_v1_11;
     4196                break;
     4197            }
     4198
    41904199            if (    netit->fEnabled
    41914200                 && netit->mode == NetworkAttachmentType_NAT
     
    42194228    }
    42204229    // VirtualBox 3.2: Check for non default I/O settings and bump the settings version.
    4221     if (m->sv < SettingsVersion_v1_10)
     4230    if (m->sv < SettingsVersion_v1_11)
    42224231    {
    42234232        if (   hardwareMachine.ioSettings.fIoCacheEnabled != true
    4224             || hardwareMachine.ioSettings.ulIoCacheSize != 5
    4225             || hardwareMachine.ioSettings.ulIoBandwidthMax != 0)
     4233            || hardwareMachine.ioSettings.ulIoCacheSize != 5)
    42264234            m->sv = SettingsVersion_v1_10;
    42274235    }
    42284236
    42294237    // VirtualBox 3.2 adds support for VRDP video channel
    4230     if (    m->sv < SettingsVersion_v1_10
     4238    if (    m->sv < SettingsVersion_v1_11
    42314239        && (    hardwareMachine.vrdpSettings.fVideoChannel
    42324240           )
     
    42404248       )
    42414249        m->sv = SettingsVersion_v1_11;
     4250
     4251    // VirtualBox 3.3 adds support for CPU priority
     4252    if (    m->sv < SettingsVersion_v1_11
     4253        && (    hardwareMachine.ulCpuPriority != 100
     4254           )
     4255       )
     4256        m->sv = SettingsVersion_v1_10;
    42424257}
    42434258
Note: See TracChangeset for help on using the changeset viewer.

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