Changeset 32742 in vbox for trunk/src/VBox/Runtime/testcase/tstRTR0Timer.cpp
- Timestamp:
- Sep 23, 2010 11:22:32 PM (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Runtime/testcase/tstRTR0Timer.cpp
r32736 r32742 25 25 */ 26 26 27 27 28 /******************************************************************************* 28 29 * Header Files * … … 33 34 #include <iprt/cpuset.h> 34 35 #include <iprt/err.h> 36 #include <iprt/mem.h> 35 37 #include <iprt/mp.h> 36 38 #include <iprt/param.h> … … 56 58 /** The RC of whatever operation performed in the handler. */ 57 59 int volatile rc; 60 /** Set if it's a periodic test. */ 61 bool fPeriodic; 58 62 /** Test specific stuff. */ 59 63 union … … 83 87 bool fFailed; 84 88 } Specific; 85 struct86 {87 /** Per CPU ticks, indexed by the CPU set index. */88 uint32_t volatile * pacTickPerCpu;89 } Omni;90 89 } u; 91 90 } TSTRTR0TIMERS1; 92 91 typedef TSTRTR0TIMERS1 *PTSTRTR0TIMERS1; 93 92 93 94 /** 95 * Per cpu state for an omni timer test. 96 */ 97 typedef struct TSTRTR0TIMEROMNI1 98 { 99 /** When we started receiving timer callbacks on this CPU. */ 100 uint64_t u64Start; 101 /** When we received the last tick on this timer. */ 102 uint64_t u64Last; 103 /** The number of ticks received on this CPU. */ 104 uint32_t volatile cTicks; 105 uint32_t u32Padding; 106 } TSTRTR0TIMEROMNI1; 107 typedef TSTRTR0TIMEROMNI1 *PTSTRTR0TIMEROMNI1; 108 109 110 /** 111 * Callback which increments a 32-bit counter. 112 * 113 * @param pTimer The timer. 114 * @param iTick The current tick. 115 * @param pvUser The user argument. 116 */ 117 static DECLCALLBACK(void) tstRTR0TimerCallbackOmni(PRTTIMER pTimer, void *pvUser, uint64_t iTick) 118 { 119 PTSTRTR0TIMEROMNI1 paStates = (PTSTRTR0TIMEROMNI1)pvUser; 120 RTCPUID idCpu = RTMpCpuId(); 121 uint32_t iCpu = RTMpCpuIdToSetIndex(idCpu); 122 123 RTR0TESTR0_CHECK_MSG(iCpu < RTCPUSET_MAX_CPUS, ("iCpu=%d idCpu=%u\n", iCpu, idCpu)); 124 if (iCpu < RTCPUSET_MAX_CPUS) 125 { 126 uint32_t iCountedTick = ASMAtomicIncU32(&paStates[iCpu].cTicks) - 1; 127 RTR0TESTR0_CHECK_MSG(iCountedTick == iTick, 128 ("iCountedTick=%u iTick=%u iCpu=%d idCpu=%u\n", iCountedTick, iTick, iCpu, idCpu)); 129 paStates[iCpu].u64Last = RTTimeSystemNanoTS(); 130 if (paStates[iCpu].u64Start) 131 { 132 paStates[iCpu].u64Start = paStates[iCpu].u64Last; 133 RTR0TESTR0_CHECK_MSG(iCountedTick == 0, ("iCountedTick=%u iCpu=%d idCpu=%u\n", iCountedTick, iCpu, idCpu)); 134 } 135 } 136 } 94 137 95 138 … … 113 156 pState->u.Specific.fFailed = true; 114 157 RTR0TESTR0_CHECK_MSG(pState->u.Specific.idCpu == idCpu, ("idCpu=%u, expected %u\n", idCpu, pState->u.Specific.idCpu)); 158 159 if (pState->fPeriodic) 160 RTR0TESTR0_CHECK_MSG(iShot == iTick, ("iShot=%u iTick=%u\n", iShot, iTick)); 161 else 162 RTR0TESTR0_CHECK_MSG(iTick == 1, ("iShot=%u iTick=%u\n", iShot, iTick)); 115 163 } 116 164 … … 133 181 if (iShot < RT_ELEMENTS(pState->aShotNsTSes)) 134 182 pState->aShotNsTSes[iShot] = RTTimeSystemNanoTS(); 183 if (pState->fPeriodic) 184 RTR0TESTR0_CHECK_MSG(iShot == iTick, ("iShot=%u iTick=%u\n", iShot, iTick)); 185 else 186 RTR0TESTR0_CHECK_MSG(iTick == 1, ("iShot=%u iTick=%u\n", iShot, iTick)); 135 187 136 188 if (!(iShot % pState->u.ChgInt.cStepsBetween)) … … 181 233 if (iShot <= RT_ELEMENTS(pState->aShotNsTSes)) 182 234 pState->aShotNsTSes[iShot - 1] = RTTimeSystemNanoTS(); 235 if (pState->fPeriodic) 236 RTR0TESTR0_CHECK_MSG(iShot == iTick, ("iShot=%u iTick=%u\n", iShot, iTick)); 237 else 238 RTR0TESTR0_CHECK_MSG(iTick == 1, ("iShot=%u iTick=%u\n", iShot, iTick)); 183 239 184 240 if (iShot == pState->iActionShot + 1) … … 201 257 if (iShot <= RT_ELEMENTS(pState->aShotNsTSes)) 202 258 pState->aShotNsTSes[iShot - 1] = RTTimeSystemNanoTS(); 259 if (pState->fPeriodic) 260 RTR0TESTR0_CHECK_MSG(iShot == iTick, ("iShot=%u iTick=%u\n", iShot, iTick)); 261 else 262 RTR0TESTR0_CHECK_MSG(iTick == 1, ("iShot=%u iTick=%u\n", iShot, iTick)); 203 263 204 264 if (iShot == pState->iActionShot + 1) … … 221 281 if (iShot <= RT_ELEMENTS(pState->aShotNsTSes)) 222 282 pState->aShotNsTSes[iShot - 1] = RTTimeSystemNanoTS(); 283 if (pState->fPeriodic) 284 RTR0TESTR0_CHECK_MSG(iShot == iTick, ("iShot=%u iTick=%u\n", iShot, iTick)); 285 else 286 RTR0TESTR0_CHECK_MSG(iTick == 1, ("iShot=%u iTick=%u\n", iShot, iTick)); 223 287 } 224 288 … … 486 550 { 487 551 RT_ZERO(State); 552 State.fPeriodic = true; 488 553 uint64_t uStartNsTS = RTTimeSystemNanoTS(); 489 554 RTR0TESTR0_CHECK_RC_BREAK(RTTimerStart(pTimer, u10HzAsNs), VINF_SUCCESS); … … 513 578 { 514 579 RT_ZERO(State); 580 State.fPeriodic = true; 515 581 RTR0TESTR0_CHECK_RC_BREAK(RTTimerStart(pTimer, i < 20 ? 0 : cNsSysHz), VINF_SUCCESS); 516 582 for (uint32_t k = 0; k < 1000 && ASMAtomicUoReadU32(&State.cShots) < 2; k++) … … 531 597 State.rc = VERR_IPE_UNINITIALIZED_STATUS; 532 598 State.iActionShot = 42; 599 State.fPeriodic = true; 533 600 State.u.ChgInt.fDirection = !!(u64Arg & 1); 534 601 if (uOperation == TSTRTR0TIMER_PERIODIC_CHANGE_INTERVAL_HIRES) … … 589 656 State.iActionShot = 0; 590 657 State.rc = VINF_SUCCESS; 658 State.fPeriodic = true; 591 659 State.u.Specific.idCpu = RTMpCpuIdFromSetIndex(iCpu); 592 660 … … 628 696 } 629 697 630 631 698 case TSTRTR0TIMER_PERIODIC_OMNI: 632 699 case TSTRTR0TIMER_PERIODIC_OMNI_HIRES: 633 700 { 634 #if 0 /* To be continued... */635 701 /* Create a periodic timer running at max host frequency, but no more than 1000 Hz. */ 636 702 uint32_t cNsInterval = cNsSysHz; 637 703 while (cNsInterval < UINT32_C(1000000)) 638 704 cNsInterval *= 2; 639 State.u.Omni.pacTickPerCpu = RTMemAllocZ(sizeof(State.u.Omni.pacTickPerCpu[0]) * RTCPUSET_MAX_CPUS);640 RTR0TESTR0_CHECK_MSG_BREAK( State.u.Omni.pacTickPerCpu, ("%d\n", RTCPUSET_MAX_CPUS));705 PTSTRTR0TIMEROMNI1 paStates = (PTSTRTR0TIMEROMNI1)RTMemAllocZ(sizeof(paStates[0]) * RTCPUSET_MAX_CPUS); 706 RTR0TESTR0_CHECK_MSG_BREAK(paStates, ("%d\n", RTCPUSET_MAX_CPUS)); 641 707 642 708 PRTTIMER pTimer; 643 709 uint32_t fFlags = TSTRTR0TIMER_IS_HIRES(uOperation) ? RTTIMER_FLAGS_HIGH_RES : 0; 644 RTR0TESTR0_CHECK_RC_BREAK(RTTimerCreateEx(&pTimer, cNsInterval, fFlags, tstRTR0TimerCallbackOmni, &State),710 RTR0TESTR0_CHECK_RC_BREAK(RTTimerCreateEx(&pTimer, cNsInterval, fFlags, tstRTR0TimerCallbackOmni, paStates), 645 711 VINF_SUCCESS); 646 712 647 do /* break loop */ 648 { 713 for (uint32_t iTest = 0; iTest < 3 && !RTR0TestR0HaveErrors(); iTest++) 714 { 715 /* reset the state */ 716 for (uint32_t iCpu = 0; iCpu < RTCPUSET_MAX_CPUS; iCpu++) 717 ASMAtomicWriteU32(&paStates[iCpu].cTicks, 0); 718 649 719 /* run it for 1 second. */ 650 720 RTCPUSET OnlineSet; … … 658 728 RTR0TESTR0_CHECK_RC_BREAK(RTTimerStop(pTimer), VINF_SUCCESS); 659 729 730 /* Do a min/max on the start and stop times and calculate the test period. */ 731 uint64_t u64MinStart = UINT64_MAX; 732 uint64_t u64MaxStop = 0; 660 733 for (uint32_t iCpu = 0; iCpu < RTCPUSET_MAX_CPUS; iCpu++) 661 if () 734 { 735 if (paStates[iCpu].u64Start) 662 736 { 737 if (paStates[iCpu].u64Start < u64MinStart) 738 u64MinStart = paStates[iCpu].u64Start; 739 if (paStates[iCpu].u64Last > u64MaxStop) 740 u64MaxStop = paStates[iCpu].u64Last; 663 741 } 664 665 666 } while (0); 667 742 } 743 RTR0TESTR0_CHECK_MSG(u64MinStart < u64MaxStop, ("%llu, %llu", u64MinStart, u64MaxStop)); 744 uint64_t cNsElapsed = u64MaxStop - u64MinStart; 745 uint32_t cAvgTicks = cNsElapsed / cNsInterval; 746 747 /* Check tick counts. ASSUMES no cpu on- or offlining. 748 This only catches really bad stuff. */ 749 uint32_t cMinTicks = cAvgTicks - cAvgTicks / 10; 750 uint32_t cMaxTicks = cAvgTicks + cAvgTicks / 10 + 1; 751 for (uint32_t iCpu = 0; iCpu < RTCPUSET_MAX_CPUS; iCpu++) 752 if (paStates[iCpu].cTicks) 753 { 754 RTR0TESTR0_CHECK_MSG(RTCpuSetIsMemberByIndex(&OnlineSet, iCpu), ("%d\n", iCpu)); 755 RTR0TESTR0_CHECK_MSG(paStates[iCpu].cTicks >= cMinTicks, 756 ("%u, min=%u, iCpu=%u\n", paStates[iCpu].cTicks, cMinTicks, iCpu)); 757 RTR0TESTR0_CHECK_MSG(paStates[iCpu].cTicks <= cMaxTicks, 758 ("%u, max=%u, iCpu=%u\n", paStates[iCpu].cTicks, cMaxTicks, iCpu)); 759 } 760 else 761 RTR0TESTR0_CHECK_MSG(!RTCpuSetIsMemberByIndex(&OnlineSet, iCpu), ("%d\n", iCpu)); 762 } 668 763 669 764 RTR0TESTR0_CHECK_RC(RTTimerDestroy(pTimer), VINF_SUCCESS); 670 RTMemFree(State.u.Omni.pacTickPerCpu); 671 #endif 765 RTMemFree(paStates); 672 766 break; 673 767 }
Note:
See TracChangeset
for help on using the changeset viewer.