VirtualBox

Changeset 30847 in vbox


Ignore:
Timestamp:
Jul 14, 2010 3:40:49 PM (14 years ago)
Author:
vboxsync
Message:

Main/Machine+Performance+VirtualBox: move deleting the performance metrics registration of a VM out of SessionMachine::uninit, where it was a risk of hangs due to callbacks. Doing it a little later won't hurt anyone. Additionally also make sure the total VMM memory stats are zeroed when the last VM has disabled its collector.

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

Legend:

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

    r30812 r30847  
    95979597    AutoMultiWriteLock3 multilock(mParent, mParent->host(), this COMMA_LOCKVAL_SRC_POS);
    95989598
    9599 #ifdef VBOX_WITH_RESOURCE_USAGE_API
    9600     unregisterMetrics(mParent->performanceCollector(), mPeer);
    9601 #endif /* VBOX_WITH_RESOURCE_USAGE_API */
     9599    // Trigger async cleanup tasks, avoid doing things here which are not
     9600    // vital to be done immediately and maybe need more locks. This calls
     9601    // Machine::unregisterMetrics().
     9602    mParent->onMachineUninit(mPeer);
    96029603
    96039604    if (aReason == Uninit::Abnormal)
  • trunk/src/VBox/Main/Performance.cpp

    r30764 r30847  
    120120
    121121#ifndef VBOX_COLLECTOR_TEST_CASE
     122
     123uint32_t CollectorGuestHAL::cVMsEnabled = 0;
     124
     125CollectorGuestHAL::CollectorGuestHAL(Machine *machine, CollectorHAL *hostHAL)
     126    : CollectorHAL(), cEnabled(0), mMachine(machine), mConsole(NULL),
     127      mGuest(NULL), mLastTick(0), mHostHAL(hostHAL), mCpuUser(0),
     128      mCpuKernel(0), mCpuIdle(0), mMemTotal(0), mMemFree(0),
     129      mMemBalloon(0), mMemShared(0), mMemCache(0), mPageTotal(0)
     130{
     131    Assert(mMachine);
     132    /* cannot use ComObjPtr<Machine> in Performance.h, do it manually */
     133    mMachine->AddRef();
     134}
     135
    122136CollectorGuestHAL::~CollectorGuestHAL()
    123137{
     138    /* cannot use ComObjPtr<Machine> in Performance.h, do it manually */
     139    mMachine->Release();
    124140    Assert(!cEnabled);
    125141}
     
    127143int CollectorGuestHAL::enable()
    128144{
     145    /* Must make sure that the machine object does not get uninitialized
     146     * in the middle of enabling this collector. Causes timing-related
     147     * behavior otherwise, which we don't want. In particular the
     148     * GetRemoteConsole call below can hang if the VM didn't completely
     149     * terminate (the VM processes stop processing events shortly before
     150     * closing the session). This avoids the hang. */
     151    AutoCaller autoCaller(mMachine);
     152    if (FAILED(autoCaller.rc())) return autoCaller.rc();
     153
    129154    HRESULT ret = S_OK;
    130155
    131156    if (ASMAtomicIncU32(&cEnabled) == 1)
    132157    {
     158        ASMAtomicIncU32(&cVMsEnabled);
    133159        ComPtr<IInternalSessionControl> directControl;
    134160
     
    153179    if (ASMAtomicDecU32(&cEnabled) == 0)
    154180    {
     181        if (ASMAtomicDecU32(&cVMsEnabled) == 0)
     182        {
     183            if (mHostHAL)
     184                mHostHAL->setMemHypervisorStats(0 /* ulMemAllocTotal */, 0 /* ulMemFreeTotal */, 0 /* ulMemBalloonTotal */, 0 /* ulMemSharedTotal */);
     185        }
    155186        Assert(mGuest && mConsole);
    156187        mGuest->COMSETTER(StatisticsUpdateInterval)(0 /* off */);
  • trunk/src/VBox/Main/VirtualBoxImpl.cpp

    r30825 r30847  
    27012701{
    27022702    postEvent(new GuestPropertyEvent(this, aMachineId, aName, aValue, aFlags));
     2703}
     2704
     2705/** Event for onMachineUninit(), this is not a CallbackEvent */
     2706class MachineUninitEvent : public Event
     2707{
     2708public:
     2709
     2710    MachineUninitEvent(VirtualBox *aVirtualBox, Machine *aMachine)
     2711        : mVirtualBox(aVirtualBox), mMachine(aMachine)
     2712    {
     2713        Assert(aVirtualBox);
     2714        Assert(aMachine);
     2715    }
     2716
     2717    void *handler()
     2718    {
     2719#ifdef VBOX_WITH_RESOURCE_USAGE_API
     2720        /* Handle unregistering metrics here, as it is not vital to get
     2721         * it done immediately. It reduces the number of locks needed and
     2722         * the lock contention in SessionMachine::uninit. */
     2723        mMachine->unregisterMetrics(mVirtualBox->performanceCollector(), mMachine);
     2724#endif /* VBOX_WITH_RESOURCE_USAGE_API */
     2725
     2726        return NULL;
     2727    }
     2728
     2729private:
     2730
     2731    /**
     2732     *  Note that this is a weak ref -- the CallbackEvent handler thread
     2733     *  is bound to the lifetime of the VirtualBox instance, so it's safe.
     2734     */
     2735    VirtualBox        *mVirtualBox;
     2736
     2737    /** Reference to the machine object. */
     2738    ComObjPtr<Machine> mMachine;
     2739};
     2740
     2741/**
     2742 *  Trigger internal event. This isn't meant to be signalled to clients.
     2743 *  @note Doesn't lock any object.
     2744 */
     2745void VirtualBox::onMachineUninit(Machine *aMachine)
     2746{
     2747    postEvent(new MachineUninitEvent(this, aMachine));
    27032748}
    27042749
  • trunk/src/VBox/Main/include/MachineImpl.h

    r30764 r30847  
    356356
    357357    void uninit();
     358
     359#ifdef VBOX_WITH_RESOURCE_USAGE_API
     360    // Needed from VirtualBox, for the delayed metrics cleanup.
     361    void unregisterMetrics(PerformanceCollector *aCollector, Machine *aMachine);
     362#endif /* VBOX_WITH_RESOURCE_USAGE_API */
    358363
    359364protected:
     
    801806#ifdef VBOX_WITH_RESOURCE_USAGE_API
    802807    void registerMetrics(PerformanceCollector *aCollector, Machine *aMachine, RTPROCESS pid);
    803     void unregisterMetrics(PerformanceCollector *aCollector, Machine *aMachine);
    804808
    805809    pm::CollectorGuestHAL  *mGuestHAL;
  • trunk/src/VBox/Main/include/Performance.h

    r29632 r30847  
    186186    {
    187187    public:
    188         CollectorGuestHAL(Machine *machine, CollectorHAL *hostHAL) : CollectorHAL(), cEnabled(0), mMachine(machine), mConsole(NULL), mGuest(NULL),
    189                                               mLastTick(0), mHostHAL(hostHAL), mCpuUser(0), mCpuKernel(0), mCpuIdle(0), mMemTotal(0), mMemFree(0),
    190                                               mMemBalloon(0), mMemShared(0), mMemCache(0), mPageTotal(0) {};
     188        CollectorGuestHAL(Machine *machine, CollectorHAL *hostHAL);
    191189        ~CollectorGuestHAL();
    192190
     
    236234        ULONG                mMemCache;
    237235        ULONG                mPageTotal;
     236
     237    private:
     238        static uint32_t      cVMsEnabled;
    238239    };
    239240
  • trunk/src/VBox/Main/include/VirtualBoxImpl.h

    r30832 r30847  
    215215    void onGuestPropertyChange(const Guid &aMachineId, IN_BSTR aName, IN_BSTR aValue,
    216216                               IN_BSTR aFlags);
     217    void onMachineUninit(Machine *aMachine);
    217218
    218219    ComObjPtr<GuestOSType> getUnknownOSType();
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