VirtualBox

Changeset 54306 in vbox


Ignore:
Timestamp:
Feb 19, 2015 6:40:36 PM (10 years ago)
Author:
vboxsync
Message:

HostDrivers/Support: TSC-delta thread fixes.

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

Legend:

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

    r54298 r54306  
    60416041                    && rc != VERR_TIMEOUT)
    60426042                    return supdrvTscDeltaThreadButchered(pDevExt, false /* fSpinlockHeld */, "RTThreadUserWait", rc);
     6043                RTThreadUserReset(pDevExt->hTscDeltaThread);
    60436044                break;
    60446045            }
     
    60616062                if (!cTimesMeasured++)
    60626063                {
    6063                     rc = supdrvMeasureTscDeltas(pDevExt, NULL /* pidxMaster */);
    6064                     RTCpuSetCopy(&pDevExt->TscDeltaObtainedCpuSet, &pDevExt->pGip->OnlineCpuSet);
     6064                    int cTries = 8;
     6065                    int cMsWaitPerTry = 10;
     6066                    do
     6067                    {
     6068                        rc = supdrvMeasureTscDeltas(pDevExt, NULL /* pidxMaster */);
     6069                        if (   RT_SUCCESS(rc)
     6070                            || (   RT_FAILURE(rc)
     6071                                && rc != VERR_TRY_AGAIN
     6072                                && rc != VERR_CPU_OFFLINE))
     6073                        {
     6074                            break;
     6075                        }
     6076                        RTThreadSleep(cMsWaitPerTry);
     6077                    } while (cTries-- > 0);
    60656078                }
    60666079                else
     
    60816094                        {
    60826095                            rc |= supdrvMeasureTscDeltaOne(pDevExt, iCpu);
    6083                             RTCpuSetDel(&pDevExt->TscDeltaCpuSet, pGipCpuWorker->idCpu);
    6084                             if (pGipCpuWorker->i64TSCDelta != INT64_MAX)
    6085                                 RTCpuSetAdd(&pDevExt->TscDeltaObtainedCpuSet, pGipCpuWorker->idCpu);
    60866096                        }
    60876097                    }
     
    62316241        if (RT_SUCCESS(rc))
    62326242        {
    6233             pDevExt->enmTscDeltaThreadState   = kTscDeltaThreadState_Creating;
     6243            pDevExt->enmTscDeltaThreadState = kTscDeltaThreadState_Creating;
    62346244            pDevExt->cMsTscDeltaTimeout = 1;
    6235             RTCpuSetEmpty(&pDevExt->TscDeltaCpuSet);
    6236             RTCpuSetEmpty(&pDevExt->TscDeltaObtainedCpuSet);
    62376245            rc = RTThreadCreate(&pDevExt->hTscDeltaThread, supdrvTscDeltaThread, pDevExt, 0 /* cbStack */,
    62386246                                RTTHREADTYPE_DEFAULT, RTTHREADFLAGS_WAITABLE, "VBoxTscThread");
     
    63146322        return VERR_THREAD_NOT_WAITABLE;
    63156323
    6316     cMsTotalWait = RT_MIN(pGip->cPresentCpus + 2, 150);
     6324    cMsTotalWait = RT_MIN(pGip->cPresentCpus + 10, 200);
    63176325    while (cTriesLeft-- > 0)
    63186326    {
     
    67336741    }
    67346742
     6743    RTCpuSetEmpty(&pDevExt->TscDeltaCpuSet);
     6744    RTCpuSetEmpty(&pDevExt->TscDeltaObtainedCpuSet);
    67356745#ifdef SUPDRV_USE_TSC_DELTA_THREAD
    67366746    if (pGip->enmUseTscDelta > SUPGIPUSETSCDELTA_ZERO_CLAIMED)
     
    67596769                    {
    67606770                        rc = supdrvMeasureTscDeltas(pDevExt, NULL /* pidxMaster */);
    6761                         if (rc != VERR_TRY_AGAIN)
     6771                        if (   rc != VERR_TRY_AGAIN
     6772                            && rc != VERR_CPU_OFFLINE)
    67626773                            break;
    67636774                    } while (--cTries > 0);
     
    69436954
    69446955    ASMSetFlags(uFlags);
     6956
     6957#ifdef SUPDRV_USE_TSC_DELTA_THREAD
     6958    if (   pGip->enmUseTscDelta > SUPGIPUSETSCDELTA_ZERO_CLAIMED
     6959        && !RTCpuSetIsEmpty(&pDevExt->TscDeltaCpuSet))
     6960    {
     6961        RTSpinlockAcquire(pDevExt->hTscDeltaSpinlock);
     6962        if (   pDevExt->enmTscDeltaThreadState == kTscDeltaThreadState_Listening
     6963            || pDevExt->enmTscDeltaThreadState == kTscDeltaThreadState_Measuring)
     6964            pDevExt->enmTscDeltaThreadState = kTscDeltaThreadState_WaitAndMeasure;
     6965        RTSpinlockRelease(pDevExt->hTscDeltaSpinlock);
     6966        /** @todo Do the actual poking using -- RTThreadUserSignal() */
     6967    }
     6968#endif
    69456969}
    69466970
     
    70637087    ASMAtomicIncU32(&pDevExt->cMpOnOffEvents);
    70647088
     7089    /* Add this CPU to the set of CPUs for which we need to calculate their TSC-deltas. */
     7090    if (pGip->enmUseTscDelta > SUPGIPUSETSCDELTA_ZERO_CLAIMED)
     7091    {
     7092        RTCpuSetAdd(&pDevExt->TscDeltaCpuSet, idCpu);
    70657093#ifdef SUPDRV_USE_TSC_DELTA_THREAD
    7066     /*
    7067      * Add this CPU to the set of CPUs that require their TSC delta to be measured.
    7068      *
    7069      * We cannot poke the TSC-delta measurement thread from this context (on all OSs), so we only
    7070      * update the state and it'll get serviced when the thread's listening interval times out.
    7071      */
    7072     if (pGip->enmUseTscDelta > SUPGIPUSETSCDELTA_ZERO_CLAIMED)
    7073     {
    70747094        RTSpinlockAcquire(pDevExt->hTscDeltaSpinlock);
    7075         RTCpuSetAdd(&pDevExt->TscDeltaCpuSet, idCpu);
    70767095        if (   pDevExt->enmTscDeltaThreadState == kTscDeltaThreadState_Listening
    70777096            || pDevExt->enmTscDeltaThreadState == kTscDeltaThreadState_Measuring)
     
    70807099        }
    70817100        RTSpinlockRelease(pDevExt->hTscDeltaSpinlock);
    7082     }
    70837101#endif
     7102    }
    70847103
    70857104    /* commit it */
     
    71287147    }
    71297148
    7130     /* Reset the TSC delta, we will recalculate it lazily. */
    71317149    if (pGip->enmUseTscDelta > SUPGIPUSETSCDELTA_ZERO_CLAIMED)
    71327150    {
     7151        /* Reset the TSC delta, we will recalculate it lazily. */
    71337152        ASMAtomicWriteS64(&pGip->aCPUs[i].i64TSCDelta, INT64_MAX);
    7134 #ifdef SUPDRV_USE_TSC_DELTA_THREAD
    71357153        /* Remove this CPU from the set of CPUs that we have obtained the TSC deltas. */
    71367154        RTCpuSetDel(&pDevExt->TscDeltaObtainedCpuSet, idCpu);
    7137 #endif
    71387155    }
    71397156
     
    74397456
    74407457        if (pGipCpuWorker->i64TSCDelta != INT64_MAX)
     7458        {
     7459            if (idCpu == idMaster)
     7460            {
     7461                RTCpuSetDel(&pDevExt->TscDeltaCpuSet, pGipCpuMaster->idCpu);
     7462                RTCpuSetAdd(&pDevExt->TscDeltaObtainedCpuSet, pGipCpuMaster->idCpu);
     7463            }
     7464            else
     7465            {
     7466                RTCpuSetDel(&pDevExt->TscDeltaCpuSet, pGipCpuWorker->idCpu);
     7467                RTCpuSetAdd(&pDevExt->TscDeltaObtainedCpuSet, pGipCpuWorker->idCpu);
     7468            }
    74417469            break;
     7470        }
    74427471    }
    74437472}
     
    76167645        PSUPGIPCPU pGipCpuWorker = &pGip->aCPUs[iCpu];
    76177646        if (   iCpu != idxMaster
    7618             && RTCpuSetIsMember(&pGip->OnlineCpuSet, pGipCpuWorker->idCpu))
     7647            && RTCpuSetIsMember(&pDevExt->TscDeltaCpuSet, pGipCpuWorker->idCpu))
    76197648        {
    76207649            rc = supdrvMeasureTscDeltaOne(pDevExt, iCpu);
     
    76287657            if (ASMAtomicReadU32(&pDevExt->cMpOnOffEvents) != cMpOnOffEvents)
    76297658            {
    7630                 SUPR0Printf("One or more CPUs transitioned between online & offline states. I'm confused, retrying...\n");
     7659                SUPR0Printf("One or more CPUs transitioned between online & offline states. I'm confused, retry...\n");
    76317660                rc = VERR_TRY_AGAIN;
    76327661                break;
     
    80658094    }
    80668095
    8067 
    80688096    /*
    80698097     * TSC History.
  • trunk/src/VBox/HostDrivers/Support/SUPDrvInternal.h

    r54301 r54306  
    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. */
     
    712712    /** Aligned pointer to the TSC delta sync. struct. */
    713713    PSUPTSCDELTASYNC                pTscDeltaSync;
     714    /** The set of CPUs we need to take measurements for. */
     715    RTCPUSET                        TscDeltaCpuSet;
     716    /** The set of CPUs we have completed taken measurements for. */
     717    RTCPUSET                        TscDeltaObtainedCpuSet;
    714718    /** @}  */
    715719
     
    727731    /** Thread timeout time before rechecking state in ms. */
    728732    RTMSINTERVAL                    cMsTscDeltaTimeout;
    729     /** The set of CPUs we need to take measurements for. */
    730     RTCPUSET                        TscDeltaCpuSet;
    731     /** The set of CPUs we have completed taken measurements for. */
    732     RTCPUSET                        TscDeltaObtainedCpuSet;
    733733    /** Whether the TSC-delta measurement was successful. */
    734734    int32_t volatile                rcTscDelta;
  • trunk/src/VBox/HostDrivers/Support/testcase/tstSupTscDelta.cpp

    r54288 r54306  
    165165                    if (pGip->aCPUs[iCpu].enmState == SUPGIPCPUSTATE_ONLINE)
    166166                    {
    167                         rc = SUPR3TscDeltaMeasure(pGip->aCPUs[iCpu].idCpu, false /*fAsync*/, true /*fForce*/,  64, 16 /*ms*/);
     167                        rc = SUPR3TscDeltaMeasure(pGip->aCPUs[iCpu].idCpu, false /*fAsync*/, true /*fForce*/, 64, 16 /*ms*/);
    168168                        if (RT_FAILURE(rc))
    169169                            RTTestFailed(hTest, "SUPR3TscDeltaMeasure failed on %#x: %Rrc", pGip->aCPUs[iCpu].idCpu, rc);
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