VirtualBox

Ignore:
Timestamp:
Feb 19, 2015 11:16:49 AM (10 years ago)
Author:
vboxsync
Message:

HostDrivers/Support: TSC-delta thread adjustments for tsc-delta measurement ioctl.

Location:
trunk/src/VBox/HostDrivers/Support
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/HostDrivers/Support/SUPDrv.c

    r54282 r54290  
    60126012        RTSpinlockAcquire(pDevExt->hTscDeltaSpinlock);
    60136013
    6014     pDevExt->enmTscDeltaState = kSupDrvTscDeltaState_Butchered;
     6014    pDevExt->enmTscDeltaThreadState = kTscDeltaThreadState_Butchered;
    60156015    RTSpinlockRelease(pDevExt->hTscDeltaSpinlock);
    60166016    OSDBGPRINT(("supdrvTscDeltaThreadButchered: %s. rc=%Rrc\n", rcFailed));
     
    60376037         * Switch on the current state.
    60386038         */
    6039         SUPDRVTSCDELTASTATE enmState;
     6039        SUPDRVTSCDELTATHREADSTATE enmState;
    60406040        RTSpinlockAcquire(pDevExt->hTscDeltaSpinlock);
    6041         enmState = pDevExt->enmTscDeltaState;
     6041        enmState = pDevExt->enmTscDeltaThreadState;
    60426042        switch (enmState)
    60436043        {
    6044             case kSupDrvTscDeltaState_Creating:
    6045             {
    6046                 pDevExt->enmTscDeltaState = kSupDrvTscDeltaState_Listening;
     6044            case kTscDeltaThreadState_Creating:
     6045            {
     6046                pDevExt->enmTscDeltaThreadState = kTscDeltaThreadState_Listening;
    60476047                rc = RTSemEventSignal(pDevExt->hTscDeltaEvent);
    60486048                if (RT_FAILURE(rc))
     
    60516051            }
    60526052
    6053             case kSupDrvTscDeltaState_Listening:
     6053            case kTscDeltaThreadState_Listening:
    60546054            {
    60556055                RTSpinlockRelease(pDevExt->hTscDeltaSpinlock);
     
    60736073            }
    60746074
    6075             case kSupDrvTscDeltaState_WaitAndMeasure:
    6076             {
    6077                 pDevExt->enmTscDeltaState = kSupDrvTscDeltaState_Measuring;
     6075            case kTscDeltaThreadState_WaitAndMeasure:
     6076            {
     6077                pDevExt->enmTscDeltaThreadState = kTscDeltaThreadState_Measuring;
    60786078                rc = RTSemEventSignal(pDevExt->hTscDeltaEvent);
    60796079                if (RT_FAILURE(rc))
     
    60856085            }
    60866086
    6087             case kSupDrvTscDeltaState_Measuring:
     6087            case kTscDeltaThreadState_Measuring:
    60886088            {
    60896089                cConsecutiveTimeouts = 0;
     
    61176117                }
    61186118                RTSpinlockAcquire(pDevExt->hTscDeltaSpinlock);
    6119                 if (pDevExt->enmTscDeltaState == kSupDrvTscDeltaState_Measuring)
    6120                     pDevExt->enmTscDeltaState = kSupDrvTscDeltaState_Listening;
     6119                if (pDevExt->enmTscDeltaThreadState == kTscDeltaThreadState_Measuring)
     6120                    pDevExt->enmTscDeltaThreadState = kTscDeltaThreadState_Listening;
    61216121                RTSpinlockRelease(pDevExt->hTscDeltaSpinlock);
    61226122                Assert(rc != VERR_NOT_AVAILABLE);   /* VERR_NOT_AVAILABLE is used as the initial value. */
     
    61256125            }
    61266126
    6127             case kSupDrvTscDeltaState_Terminating:
     6127            case kTscDeltaThreadState_Terminating:
    61286128                RTSpinlockRelease(pDevExt->hTscDeltaSpinlock);
    61296129                return VINF_SUCCESS;
    61306130
    6131             case kSupDrvTscDeltaState_Butchered:
     6131            case kTscDeltaThreadState_Butchered:
    61326132            default:
    61336133                return supdrvTscDeltaThreadButchered(pDevExt, true /* fSpinlockHeld */, "Invalid state", VERR_INVALID_STATE);
     
    61496149 * @param   enmNewState     The new state we're waiting for it to enter.
    61506150 */
    6151 static int supdrvTscDeltaThreadWait(PSUPDRVDEVEXT pDevExt, SUPDRVTSCDELTASTATE enmCurState, SUPDRVTSCDELTASTATE enmNewState)
     6151static int supdrvTscDeltaThreadWait(PSUPDRVDEVEXT pDevExt, SUPDRVTSCDELTATHREADSTATE enmCurState,
     6152                                    SUPDRVTSCDELTATHREADSTATE enmNewState)
    61526153{
    61536154    /*
     
    61576158    RTSemEventWait(pDevExt->hTscDeltaEvent, RT_MS_1SEC);
    61586159    RTSpinlockAcquire(pDevExt->hTscDeltaSpinlock);
    6159     if (pDevExt->enmTscDeltaState == enmNewState)
     6160    if (pDevExt->enmTscDeltaThreadState == enmNewState)
    61606161    {
    61616162        RTSpinlockRelease(pDevExt->hTscDeltaSpinlock);
    61626163        rc = VINF_SUCCESS;
    61636164    }
    6164     else if (pDevExt->enmTscDeltaState == enmCurState)
     6165    else if (pDevExt->enmTscDeltaThreadState == enmCurState)
    61656166    {
    61666167        /*
     
    61756176             * Check the state whether we've succeeded.
    61766177             */
    6177             SUPDRVTSCDELTASTATE enmState;
     6178            SUPDRVTSCDELTATHREADSTATE enmState;
    61786179            RTSpinlockAcquire(pDevExt->hTscDeltaSpinlock);
    6179             enmState = pDevExt->enmTscDeltaState;
     6180            enmState = pDevExt->enmTscDeltaThreadState;
    61806181            RTSpinlockRelease(pDevExt->hTscDeltaSpinlock);
    61816182            if (enmState == enmNewState)
     
    62176218    int rc;
    62186219    RTSpinlockAcquire(pDevExt->hTscDeltaSpinlock);
    6219     pDevExt->enmTscDeltaState = kSupDrvTscDeltaState_Terminating;
     6220    pDevExt->enmTscDeltaThreadState = kTscDeltaThreadState_Terminating;
    62206221    RTSpinlockRelease(pDevExt->hTscDeltaSpinlock);
    62216222    RTThreadUserSignal(pDevExt->hTscDeltaThread);
     
    62596260        if (RT_SUCCESS(rc))
    62606261        {
    6261             pDevExt->enmTscDeltaState   = kSupDrvTscDeltaState_Creating;
     6262            pDevExt->enmTscDeltaThreadState   = kTscDeltaThreadState_Creating;
    62626263            pDevExt->cMsTscDeltaTimeout = 1;
    62636264            RTCpuSetEmpty(&pDevExt->TscDeltaCpuSet);
     
    62676268            if (RT_SUCCESS(rc))
    62686269            {
    6269                 rc = supdrvTscDeltaThreadWait(pDevExt, kSupDrvTscDeltaState_Creating, kSupDrvTscDeltaState_Listening);
     6270                rc = supdrvTscDeltaThreadWait(pDevExt, kTscDeltaThreadState_Creating, kTscDeltaThreadState_Listening);
    62706271                if (RT_SUCCESS(rc))
    62716272                {
     
    71027103        RTSpinlockAcquire(pDevExt->hTscDeltaSpinlock);
    71037104        RTCpuSetAdd(&pDevExt->TscDeltaCpuSet, idCpu);
    7104         if (   pDevExt->enmTscDeltaState == kSupDrvTscDeltaState_Listening
    7105             || pDevExt->enmTscDeltaState == kSupDrvTscDeltaState_Measuring)
    7106         {
    7107             pDevExt->enmTscDeltaState = kSupDrvTscDeltaState_WaitAndMeasure;
     7105        if (   pDevExt->enmTscDeltaThreadState == kTscDeltaThreadState_Listening
     7106            || pDevExt->enmTscDeltaThreadState == kTscDeltaThreadState_Measuring)
     7107        {
     7108            pDevExt->enmTscDeltaThreadState = kTscDeltaThreadState_WaitAndMeasure;
    71087109        }
    71097110        RTSpinlockRelease(pDevExt->hTscDeltaSpinlock);
     
    83488349                RTSpinlockAcquire(pDevExt->hTscDeltaSpinlock);
    83498350                RTCpuSetAdd(&pDevExt->TscDeltaCpuSet, pGipCpuWorker->idCpu);
    8350                 if (   pDevExt->enmTscDeltaState == kSupDrvTscDeltaState_Listening
    8351                     || pDevExt->enmTscDeltaState == kSupDrvTscDeltaState_Measuring)
     8351                if (   pDevExt->enmTscDeltaThreadState == kTscDeltaThreadState_Listening
     8352                    || pDevExt->enmTscDeltaThreadState == kTscDeltaThreadState_Measuring)
    83528353                {
    8353                     pDevExt->enmTscDeltaState = kSupDrvTscDeltaState_WaitAndMeasure;
     8354                    pDevExt->enmTscDeltaThreadState = kTscDeltaThreadState_WaitAndMeasure;
    83548355                }
    83558356                RTSpinlockRelease(pDevExt->hTscDeltaSpinlock);
     
    83578358                return VINF_SUCCESS;
    83588359            }
     8360
     8361            /*
     8362             * If a TSC-delta measurement request is already being serviced by the thread,
     8363             * wait 'cTries' times if a retry-timeout is provided, otherwise bail as busy.
     8364             */
     8365            while (cTries-- > 0)
     8366            {
     8367                SUPDRVTSCDELTATHREADSTATE enmState;
     8368                RTSpinlockAcquire(pDevExt->hTscDeltaSpinlock);
     8369                enmState = pDevExt->enmTscDeltaThreadState;
     8370                RTSpinlockRelease(pDevExt->hTscDeltaSpinlock);
     8371
     8372                if (   enmState == kTscDeltaThreadState_Measuring
     8373                    || enmState == kTscDeltaThreadState_WaitAndMeasure)
     8374                {
     8375                    if (   !cTries
     8376                        || !cMsWaitRetry)
     8377                        return VERR_SUPDRV_TSC_DELTA_MEASUREMENT_BUSY;
     8378                    if (cMsWaitRetry)
     8379                        RTThreadSleep(cMsWaitRetry);
     8380                }
     8381            }
     8382            cTries = RT_MAX(pReq->u.In.cRetries + 1, 10);
    83598383#endif
    83608384
  • trunk/src/VBox/HostDrivers/Support/SUPDrvInternal.h

    r54262 r54290  
    231231#endif
    232232
    233 #if 0
     233#if 1
    234234/**  Use a dedicated kernel thread to service TSC-delta measurement requests.
    235235 *   @todo Test on servers with many CPUs and sockets. */
     
    247247 * TSC-delta measurement thread state machine.
    248248 */
    249 typedef enum SUPDRVTSCDELTASTATE
     249typedef enum SUPDRVTSCDELTATHREADSTATE
    250250{
    251251    /** Uninitialized/invalid value. */
    252     kSupDrvTscDeltaState_Invalid = 0,
     252    kTscDeltaThreadState_Invalid = 0,
    253253    /** The thread is being created. */
    254     kSupDrvTscDeltaState_Creating,
     254    kTscDeltaThreadState_Creating,
    255255    /** The thread is listening for events. */
    256     kSupDrvTscDeltaState_Listening,
     256    kTscDeltaThreadState_Listening,
    257257    /** The thread is sleeping before starting a measurement. */
    258     kSupDrvTscDeltaState_WaitAndMeasure,
     258    kTscDeltaThreadState_WaitAndMeasure,
    259259    /** The thread is currently servicing a measurement request. */
    260     kSupDrvTscDeltaState_Measuring,
     260    kTscDeltaThreadState_Measuring,
    261261    /** The thread is terminating. */
    262     kSupDrvTscDeltaState_Terminating,
     262    kTscDeltaThreadState_Terminating,
    263263    /** The thread is butchered due to an unexpected error. */
    264     kSupDrvTscDeltaState_Butchered,
     264    kTscDeltaThreadState_Butchered,
    265265    /** The thread is destroyed. */
    266     kSupDrvTscDeltaState_Destroyed,
     266    kTscDeltaThreadState_Destroyed,
    267267    /** The usual 32-bit blowup hack. */
    268     kSupDrvTscDeltaState_32BitHack = 0x7fffffff
    269 } SUPDRVTSCDELTASTATE;
     268    kTscDeltaThreadState_32BitHack = 0x7fffffff
     269} SUPDRVTSCDELTATHREADSTATE, *PSUPDRVTSCDELTATHREADSTATE;
    270270#endif
    271271
     
    717717    /** @name TSC-delta measurement thread.
    718718     *  @{ */
    719     /** Spinlock protecting enmTscDeltaState. */
     719    /** Spinlock protecting enmTscDeltaThreadState. */
    720720    RTSPINLOCK                      hTscDeltaSpinlock;
    721721    /** TSC-delta measurement thread. */
     
    724724    RTSEMEVENT                      hTscDeltaEvent;
    725725    /** The state of the TSC-delta measurement thread. */
    726     SUPDRVTSCDELTASTATE             enmTscDeltaState;
     726    SUPDRVTSCDELTATHREADSTATE       enmTscDeltaThreadState;
    727727    /** Thread timeout time before rechecking state in ms. */
    728728    RTMSINTERVAL                    cMsTscDeltaTimeout;
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