VirtualBox

Changeset 42383 in vbox


Ignore:
Timestamp:
Jul 25, 2012 10:07:58 AM (12 years ago)
Author:
vboxsync
Message:

Main/VirtualBox+Machine: optimize reaction time on session changes by adapting the waiting timeout, and signal near session closing (which unfortunately cannot be done precisely, as the session link to the Machine needs to be removed before the session is actually closed, and this makes notifications impossible)

Location:
trunk/src/VBox/Main/src-server
Files:
2 edited

Legend:

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

    r42382 r42383  
    1221212212    }
    1221312213
     12214    /* signal the client watcher thread, because the client is going away */
     12215    mParent->updateClientWatcher();
     12216
    1221412217    LogFlowThisFuncLeave();
    1221512218    return S_OK;
  • trunk/src/VBox/Main/src-server/VirtualBoxImpl.cpp

    r42231 r42383  
    107107// static
    108108Bstr VirtualBox::sAPIVersion;
     109
     110#ifdef VBOX_WITH_SYS_V_IPC_SESSION_WATCHER
     111/** Table for adaptive timeouts in the client watcher. The counter starts at
     112 * the maximum value and decreases to 0. */
     113static const RTMSINTERVAL s_updateAdaptTimeouts[] = { 500, 200, 100, 50, 20, 10, 5 };
     114#endif
    109115
    110116////////////////////////////////////////////////////////////////////////////////
     
    283289    // the following are data for the client watcher thread
    284290    const UPDATEREQTYPE                 updateReq;
     291#ifdef VBOX_WITH_SYS_V_IPC_SESSION_WATCHER
     292    uint8_t                             updateAdaptCtr;
     293#endif
    285294    const RTTHREAD                      threadClientWatcher;
    286295    typedef std::list<RTPROCESS> ProcessList;
     
    516525#elif defined(VBOX_WITH_SYS_V_IPC_SESSION_WATCHER)
    517526        RTSemEventCreate(&unconst(m->updateReq));
     527        ASMAtomicUoWriteU8(&m->updateAdaptCtr, 0);
    518528#else
    519529# error "Port me!"
     
    26272637    RTSemEventSignal(m->updateReq);
    26282638#elif defined(VBOX_WITH_SYS_V_IPC_SESSION_WATCHER)
     2639    ASMAtomicUoWriteU8(&m->updateAdaptCtr, RT_ELEMENTS(s_updateAdaptTimeouts) - 1);
    26292640    RTSemEventSignal(m->updateReq);
    26302641#else
     
    48104821            autoCaller.release();
    48114822
    4812             int rc = RTSemEventWait(that->m->updateReq, 500);
     4823            /* determine wait timeout adaptively: after updating information
     4824             * relevant to the client watcher, check a few times more
     4825             * frequently. This ensures good reaction time when the signalling
     4826             * has to be done a bit before the actual change for technical
     4827             * reasons, and saves CPU cycles when no activities are expected. */
     4828            RTMSINTERVAL cMillies;
     4829            {
     4830                uint8_t uOld, uNew;
     4831                do
     4832                {
     4833                    uOld = ASMAtomicUoReadU8(&that->m->updateAdaptCtr);
     4834                    uNew = uOld ? uOld - 1 : uOld;
     4835                } while (!ASMAtomicCmpXchgU8(&that->m->updateAdaptCtr, uNew, uOld));
     4836                Assert(uOld <= RT_ELEMENTS(s_updateAdaptTimeouts) - 1);
     4837                cMillies = s_updateAdaptTimeouts[uOld];
     4838            }
     4839
     4840            int rc = RTSemEventWait(that->m->updateReq, cMillies);
    48134841
    48144842            /*
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