VirtualBox

儲存庫 vbox 的更動 48411


忽略:
時間撮記:
2013-9-10 下午02:36:31 (11 年 以前)
作者:
vboxsync
訊息:

latency testcase in the works...

位置:
trunk/src/VBox/Runtime/testcase
檔案:
修改 3 筆資料

圖例:

未更動
新增
刪除
  • trunk/src/VBox/Runtime/testcase/tstRTR0Timer.cpp

    r48165 r48411  
    3232
    3333#include <iprt/asm.h>
     34#include <iprt/asm-amd64-x86.h>
    3435#include <iprt/cpuset.h>
    3536#include <iprt/err.h>
     
    106107} TSTRTR0TIMEROMNI1;
    107108typedef TSTRTR0TIMEROMNI1 *PTSTRTR0TIMEROMNI1;
     109
     110
     111/*******************************************************************************
     112*   Global Variables                                                           *
     113*******************************************************************************/
     114/**
     115 * Latency data.
     116 */
     117static struct TSTRTR0TIMEROMNILATENCY
     118{
     119    /** The number of samples.  */
     120    volatile uint32_t   cSamples;
     121    uint32_t            auPadding[3];
     122    struct
     123    {
     124        uint64_t        uTsc;
     125        uint64_t        uNanoTs;
     126    } aSamples[4096];
     127} g_aOmniLatency[16];
     128
     129
     130/**
     131 * Callback for the omni timer latency test, adds a sample to g_aOmniLatency.
     132 *
     133 * @param   pTimer      The timer.
     134 * @param   iTick       The current tick.
     135 * @param   pvUser      The user argument.
     136 */
     137static DECLCALLBACK(void) tstRTR0TimerCallbackLatencyOmni(PRTTIMER pTimer, void *pvUser, uint64_t iTick)
     138{
     139    RTCPUID             idCpu    = RTMpCpuId();
     140    uint32_t            iCpu     = RTMpCpuIdToSetIndex(idCpu);
     141    NOREF(pTimer); NOREF(pvUser); NOREF(iTick);
     142
     143    RTR0TESTR0_CHECK_MSG(iCpu < RT_ELEMENTS(g_aOmniLatency), ("iCpu=%d idCpu=%u\n", iCpu, idCpu));
     144    if (iCpu < RT_ELEMENTS(g_aOmniLatency))
     145    {
     146        uint32_t iSample = g_aOmniLatency[iCpu].cSamples;
     147        if (iSample < RT_ELEMENTS(g_aOmniLatency[iCpu].aSamples))
     148        {
     149            g_aOmniLatency[iCpu].aSamples[iSample].uTsc    = ASMReadTSC();
     150            g_aOmniLatency[iCpu].aSamples[iSample].uNanoTs = RTTimeSystemNanoTS();
     151            g_aOmniLatency[iCpu].cSamples = iSample + 1;
     152        }
     153    }
     154}
     155
    108156
    109157
     
    807855            break;
    808856        }
     857
     858        case TSTRTR0TIMER_LATENCY_OMNI:
     859        case TSTRTR0TIMER_LATENCY_OMNI_HIRES:
     860        {
     861            /*
     862             * Create a periodic timer running at max host frequency, but no more than 1000 Hz.
     863             */
     864            PRTTIMER        pTimer;
     865            uint32_t        fFlags = (TSTRTR0TIMER_IS_HIRES(uOperation) ? RTTIMER_FLAGS_HIGH_RES : 0)
     866                                   | RTTIMER_FLAGS_CPU_ALL;
     867            uint32_t        cNsInterval = cNsSysHz;
     868            while (cNsInterval < UINT32_C(1000000))
     869                cNsInterval *= 2;
     870            int rc = RTTimerCreateEx(&pTimer, cNsInterval, fFlags, tstRTR0TimerCallbackLatencyOmni, NULL);
     871            if (rc == VERR_NOT_SUPPORTED)
     872            {
     873                RTR0TESTR0_SKIP_BREAK();
     874            }
     875            RTR0TESTR0_CHECK_RC_BREAK(rc, VINF_SUCCESS);
     876
     877            /*
     878             * Reset the state and run the test for 4 seconds.
     879             */
     880            RT_ZERO(g_aOmniLatency);
     881
     882            RTCPUSET OnlineSet;
     883            uint64_t uStartNsTS = RTTimeSystemNanoTS();
     884            RTR0TESTR0_CHECK_RC_BREAK(RTTimerStart(pTimer, 0), VINF_SUCCESS);
     885            RTMpGetOnlineSet(&OnlineSet);
     886
     887            for (uint32_t i = 0; i < 5000 && RTTimeSystemNanoTS() - uStartNsTS <= UINT64_C(4000000000); i++)
     888                RTThreadSleep(2);
     889
     890            RTR0TESTR0_CHECK_RC_BREAK(RTTimerStop(pTimer), VINF_SUCCESS);
     891            uint64_t    cNsElapsedX = RTTimeNanoTS() - uStartNsTS;
     892
     893            /*
     894             * Process the result.
     895             */
     896            int32_t     cNsDiv = cNsInterval / 4; /* 25% */
     897            uint32_t    cTotal = 0;
     898            uint32_t    cLow   = 0;
     899            uint32_t    cHigh  = 0;
     900            for (uint32_t iCpu = 0; iCpu < RTCPUSET_MAX_CPUS; iCpu++)
     901            {
     902                uint32_t cSamples = g_aOmniLatency[iCpu].cSamples;
     903                if (cSamples > 1)
     904                {
     905                    cTotal += cSamples - 1;
     906                    for (uint32_t iSample = 1; iSample < cSamples; iSample++)
     907                    {
     908                        int64_t cNsDelta = g_aOmniLatency[iCpu].aSamples[iSample - 1].uNanoTs
     909                                         - g_aOmniLatency[iCpu].aSamples[iSample].uNanoTs;
     910                        if (cNsDelta < 0 && cNsDelta < -cNsDiv)
     911                            cLow++;
     912                        else if (cNsDelta > 0 && cNsDelta > cNsDiv)
     913                            cHigh++;
     914                    }
     915                }
     916            }
     917
     918            RTR0TestR0Info("25%: %u; -25%: %u; total: %u", cHigh, cLow, cTotal);
     919            RTR0TESTR0_CHECK_RC(RTTimerDestroy(pTimer), VINF_SUCCESS);
     920            break;
     921        }
     922
    809923    }
    810924
  • trunk/src/VBox/Runtime/testcase/tstRTR0Timer.h

    r32736 r48411  
    5555    TSTRTR0TIMER_PERIODIC_OMNI,
    5656    TSTRTR0TIMER_PERIODIC_OMNI_HIRES,
     57    TSTRTR0TIMER_LATENCY_OMNI,
     58    TSTRTR0TIMER_LATENCY_OMNI_HIRES,
    5759    TSTRTR0TIMER_END
    5860} TSTRTR0TIMER;
     
    6971     || (uOperation) == TSTRTR0TIMER_PERIODIC_SPECIFIC_HIRES \
    7072     || (uOperation) == TSTRTR0TIMER_PERIODIC_OMNI_HIRES \
     73     || (uOperation) == TSTRTR0TIMER_LATENCY_OMNI_HIRES \
    7174    )
    7275
  • trunk/src/VBox/Runtime/testcase/tstRTR0TimerDriver.cpp

    r48165 r48411  
    5757        return rcExit;
    5858
     59    if (argc == 2 && !strcmp(argv[1], "latency"))
     60    {
     61        RTR3TestR0SimpleTest(TSTRTR0TIMER_LATENCY_OMNI, "Latency omni timer");
     62        RTR3TestR0SimpleTest(TSTRTR0TIMER_LATENCY_OMNI_HIRES, "Latency omni hires timer");
     63    }
     64    else
     65    {
    5966# if 1
    60     /*
    61      * Standard timers.
    62      */
    63     RTR3TestR0SimpleTest(TSTRTR0TIMER_ONE_SHOT_BASIC,       "Basic one shot");
    64     RTR3TestR0SimpleTest(TSTRTR0TIMER_PERIODIC_BASIC,       "Basic periodic");
    65     if (RTTestErrorCount(g_hTest) == 0)
    66     {
     67        /*
     68         * Standard timers.
     69         */
     70        RTR3TestR0SimpleTest(TSTRTR0TIMER_ONE_SHOT_BASIC,       "Basic one shot");
     71        RTR3TestR0SimpleTest(TSTRTR0TIMER_PERIODIC_BASIC,       "Basic periodic");
     72        if (RTTestErrorCount(g_hTest) == 0)
     73        {
    6774#  if 1
    6875#   ifndef RT_OS_SOLARIS        /* Solaris cannot call back into cyclic subsystem from a cyclic callback. */
    69         RTR3TestR0SimpleTest(TSTRTR0TIMER_ONE_SHOT_RESTART, "Restart one shot from callback");
    70         RTR3TestR0SimpleTest(TSTRTR0TIMER_ONE_SHOT_DESTROY, "Destroy one shot from callback");
     76            RTR3TestR0SimpleTest(TSTRTR0TIMER_ONE_SHOT_RESTART, "Restart one shot from callback");
     77            RTR3TestR0SimpleTest(TSTRTR0TIMER_ONE_SHOT_DESTROY, "Destroy one shot from callback");
    7178#   endif
    72         RTR3TestR0SimpleTest(TSTRTR0TIMER_PERIODIC_CSSD_LOOPS, "Create-start-stop-destroy loops");
    73         for (uint32_t i = 0; i <= 7; i++)
    74             RTR3TestR0SimpleTestWithArg(TSTRTR0TIMER_PERIODIC_CHANGE_INTERVAL, i, "Change interval from callback, variation %u", i);
     79            RTR3TestR0SimpleTest(TSTRTR0TIMER_PERIODIC_CSSD_LOOPS, "Create-start-stop-destroy loops");
     80            for (uint32_t i = 0; i <= 7; i++)
     81                RTR3TestR0SimpleTestWithArg(TSTRTR0TIMER_PERIODIC_CHANGE_INTERVAL, i, "Change interval from callback, variation %u", i);
    7582#  endif
    76         RTR3TestR0SimpleTest(TSTRTR0TIMER_ONE_SHOT_SPECIFIC, "One shot cpu specific");
    77         RTR3TestR0SimpleTest(TSTRTR0TIMER_PERIODIC_SPECIFIC, "Periodic cpu specific");
    78         RTR3TestR0SimpleTest(TSTRTR0TIMER_PERIODIC_OMNI, "Periodic omni timer");
    79     }
     83            RTR3TestR0SimpleTest(TSTRTR0TIMER_ONE_SHOT_SPECIFIC, "One shot cpu specific");
     84            RTR3TestR0SimpleTest(TSTRTR0TIMER_PERIODIC_SPECIFIC, "Periodic cpu specific");
     85            RTR3TestR0SimpleTest(TSTRTR0TIMER_PERIODIC_OMNI, "Periodic omni timer");
     86        }
    8087# endif
    8188
    8289# if 1
    83     /*
    84      * High resolution timers.
    85      */
    86     RTR3TestR0SimpleTest(TSTRTR0TIMER_ONE_SHOT_BASIC_HIRES, "Basic hires one shot");
    87     RTR3TestR0SimpleTest(TSTRTR0TIMER_PERIODIC_BASIC_HIRES, "Basic hires periodic");
    88     if (RTTestErrorCount(g_hTest) == 0)
    89     {
     90        /*
     91         * High resolution timers.
     92         */
     93        RTR3TestR0SimpleTest(TSTRTR0TIMER_ONE_SHOT_BASIC_HIRES, "Basic hires one shot");
     94        RTR3TestR0SimpleTest(TSTRTR0TIMER_PERIODIC_BASIC_HIRES, "Basic hires periodic");
     95        if (RTTestErrorCount(g_hTest) == 0)
     96        {
    9097#  if 1
    9198#   ifndef RT_OS_SOLARIS        /* Solaris cannot call back into cyclic subsystem from a cyclic callback. */
    92         RTR3TestR0SimpleTest(TSTRTR0TIMER_ONE_SHOT_RESTART_HIRES, "Restart hires one shot from callback");
    93         RTR3TestR0SimpleTest(TSTRTR0TIMER_ONE_SHOT_DESTROY_HIRES, "Destroy hires one shot from callback");
     99            RTR3TestR0SimpleTest(TSTRTR0TIMER_ONE_SHOT_RESTART_HIRES, "Restart hires one shot from callback");
     100            RTR3TestR0SimpleTest(TSTRTR0TIMER_ONE_SHOT_DESTROY_HIRES, "Destroy hires one shot from callback");
    94101#   endif
    95         RTR3TestR0SimpleTest(TSTRTR0TIMER_PERIODIC_CSSD_LOOPS_HIRES, "Create-start-stop-destroy loops, hires");
    96         for (uint32_t i = 0; i <= 7; i++)
    97             RTR3TestR0SimpleTestWithArg(TSTRTR0TIMER_PERIODIC_CHANGE_INTERVAL, i, "Change interval from callback, hires, variation %u", i);
     102            RTR3TestR0SimpleTest(TSTRTR0TIMER_PERIODIC_CSSD_LOOPS_HIRES, "Create-start-stop-destroy loops, hires");
     103            for (uint32_t i = 0; i <= 7; i++)
     104                RTR3TestR0SimpleTestWithArg(TSTRTR0TIMER_PERIODIC_CHANGE_INTERVAL, i, "Change interval from callback, hires, variation %u", i);
    98105#  endif
    99         RTR3TestR0SimpleTest(TSTRTR0TIMER_ONE_SHOT_SPECIFIC_HIRES, "One shot hires cpu specific");
    100         RTR3TestR0SimpleTest(TSTRTR0TIMER_PERIODIC_SPECIFIC_HIRES, "Periodic hires cpu specific");
    101         RTR3TestR0SimpleTest(TSTRTR0TIMER_PERIODIC_OMNI, "Periodic omni hires timer");
     106            RTR3TestR0SimpleTest(TSTRTR0TIMER_ONE_SHOT_SPECIFIC_HIRES, "One shot hires cpu specific");
     107            RTR3TestR0SimpleTest(TSTRTR0TIMER_PERIODIC_SPECIFIC_HIRES, "Periodic hires cpu specific");
     108            RTR3TestR0SimpleTest(TSTRTR0TIMER_PERIODIC_OMNI, "Periodic omni hires timer");
     109        }
     110# endif
    102111    }
    103 # endif
    104112
    105113    /*
注意: 瀏覽 TracChangeset 來幫助您使用更動檢視器

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