Changeset 48411 in vbox for trunk/src/VBox/Runtime/testcase
- Timestamp:
- Sep 10, 2013 2:36:31 PM (11 years ago)
- Location:
- trunk/src/VBox/Runtime/testcase
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Runtime/testcase/tstRTR0Timer.cpp
r48165 r48411 32 32 33 33 #include <iprt/asm.h> 34 #include <iprt/asm-amd64-x86.h> 34 35 #include <iprt/cpuset.h> 35 36 #include <iprt/err.h> … … 106 107 } TSTRTR0TIMEROMNI1; 107 108 typedef TSTRTR0TIMEROMNI1 *PTSTRTR0TIMEROMNI1; 109 110 111 /******************************************************************************* 112 * Global Variables * 113 *******************************************************************************/ 114 /** 115 * Latency data. 116 */ 117 static 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 */ 137 static 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 108 156 109 157 … … 807 855 break; 808 856 } 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 809 923 } 810 924 -
trunk/src/VBox/Runtime/testcase/tstRTR0Timer.h
r32736 r48411 55 55 TSTRTR0TIMER_PERIODIC_OMNI, 56 56 TSTRTR0TIMER_PERIODIC_OMNI_HIRES, 57 TSTRTR0TIMER_LATENCY_OMNI, 58 TSTRTR0TIMER_LATENCY_OMNI_HIRES, 57 59 TSTRTR0TIMER_END 58 60 } TSTRTR0TIMER; … … 69 71 || (uOperation) == TSTRTR0TIMER_PERIODIC_SPECIFIC_HIRES \ 70 72 || (uOperation) == TSTRTR0TIMER_PERIODIC_OMNI_HIRES \ 73 || (uOperation) == TSTRTR0TIMER_LATENCY_OMNI_HIRES \ 71 74 ) 72 75 -
trunk/src/VBox/Runtime/testcase/tstRTR0TimerDriver.cpp
r48165 r48411 57 57 return rcExit; 58 58 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 { 59 66 # 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 { 67 74 # if 1 68 75 # 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"); 71 78 # 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); 75 82 # 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 } 80 87 # endif 81 88 82 89 # 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 { 90 97 # if 1 91 98 # 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"); 94 101 # 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); 98 105 # 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 102 111 } 103 # endif104 112 105 113 /*
Note:
See TracChangeset
for help on using the changeset viewer.