VirtualBox

source: vbox/trunk/src/VBox/Runtime/testcase/tstRTR0Timer.cpp@ 56768

Last change on this file since 56768 was 56768, checked in by vboxsync, 10 years ago

tstRTR0Timer.cpp: Fixed 'Unknown test #16' problem on windows and solaris.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 40.6 KB
Line 
1/* $Id: tstRTR0Timer.cpp 56768 2015-07-03 11:29:35Z vboxsync $ */
2/** @file
3 * IPRT R0 Testcase - Timers.
4 */
5
6/*
7 * Copyright (C) 2009-2015 Oracle Corporation
8 *
9 * This file is part of VirtualBox Open Source Edition (OSE), as
10 * available from http://www.215389.xyz. This file is free software;
11 * you can redistribute it and/or modify it under the terms of the GNU
12 * General Public License (GPL) as published by the Free Software
13 * Foundation, in version 2 as it comes in the "COPYING" file of the
14 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
15 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
16 *
17 * The contents of this file may alternatively be used under the terms
18 * of the Common Development and Distribution License Version 1.0
19 * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
20 * VirtualBox OSE distribution, in which case the provisions of the
21 * CDDL are applicable instead of those of the GPL.
22 *
23 * You may elect to license modified versions of this file under the
24 * terms and conditions of either the GPL or the CDDL or both.
25 */
26
27
28/*******************************************************************************
29* Header Files *
30*******************************************************************************/
31#include <iprt/timer.h>
32
33#include <iprt/asm.h>
34#include <iprt/asm-amd64-x86.h>
35#include <iprt/cpuset.h>
36#include <iprt/err.h>
37#include <iprt/mem.h>
38#include <iprt/mp.h>
39#include <iprt/param.h>
40#include <iprt/string.h>
41#include <iprt/thread.h>
42#include <iprt/time.h>
43#include <VBox/sup.h>
44#include "tstRTR0Timer.h"
45#include "tstRTR0Common.h"
46
47
48/*******************************************************************************
49* Structures and Typedefs *
50*******************************************************************************/
51typedef struct
52{
53 /** Array of nano second timestamp of the first few shots. */
54 uint64_t volatile aShotNsTSes[10];
55 /** The number of shots. */
56 uint32_t volatile cShots;
57 /** The shot at which action is to be taken. */
58 uint32_t iActionShot;
59 /** The RC of whatever operation performed in the handler. */
60 int volatile rc;
61 /** Set if it's a periodic test. */
62 bool fPeriodic;
63 /** Test specific stuff. */
64 union
65 {
66 /** tstRTR0TimerCallbackU32ChangeInterval parameters. */
67 struct
68 {
69 /** The interval change step. */
70 uint32_t cNsChangeStep;
71 /** The current timer interval. */
72 uint32_t cNsCurInterval;
73 /** The minimum interval. */
74 uint32_t cNsMinInterval;
75 /** The maximum interval. */
76 uint32_t cNsMaxInterval;
77 /** Direction flag; false = decrement, true = increment. */
78 bool fDirection;
79 /** The number of steps between each change. */
80 uint8_t cStepsBetween;
81 } ChgInt;
82 /** tstRTR0TimerCallbackSpecific parameters. */
83 struct
84 {
85 /** The expected CPU. */
86 RTCPUID idCpu;
87 /** Set if this failed. */
88 bool fFailed;
89 } Specific;
90 } u;
91} TSTRTR0TIMERS1;
92typedef TSTRTR0TIMERS1 *PTSTRTR0TIMERS1;
93
94
95/**
96 * Per cpu state for an omni timer test.
97 */
98typedef struct TSTRTR0TIMEROMNI1
99{
100 /** When we started receiving timer callbacks on this CPU. */
101 uint64_t u64Start;
102 /** When we received the last tick on this timer. */
103 uint64_t u64Last;
104 /** The number of ticks received on this CPU. */
105 uint32_t volatile cTicks;
106 uint32_t u32Padding;
107} TSTRTR0TIMEROMNI1;
108typedef 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
156
157
158/**
159 * Callback which increments a 32-bit counter.
160 *
161 * @param pTimer The timer.
162 * @param iTick The current tick.
163 * @param pvUser The user argument.
164 */
165static DECLCALLBACK(void) tstRTR0TimerCallbackOmni(PRTTIMER pTimer, void *pvUser, uint64_t iTick)
166{
167 PTSTRTR0TIMEROMNI1 paStates = (PTSTRTR0TIMEROMNI1)pvUser;
168 RTCPUID idCpu = RTMpCpuId();
169 uint32_t iCpu = RTMpCpuIdToSetIndex(idCpu);
170 NOREF(pTimer);
171
172 RTR0TESTR0_CHECK_MSG(iCpu < RTCPUSET_MAX_CPUS, ("iCpu=%d idCpu=%u\n", iCpu, idCpu));
173 if (iCpu < RTCPUSET_MAX_CPUS)
174 {
175 uint32_t iCountedTick = ASMAtomicIncU32(&paStates[iCpu].cTicks);
176 RTR0TESTR0_CHECK_MSG(iCountedTick == iTick,
177 ("iCountedTick=%u iTick=%u iCpu=%d idCpu=%u\n", iCountedTick, iTick, iCpu, idCpu));
178 paStates[iCpu].u64Last = RTTimeSystemNanoTS();
179 if (!paStates[iCpu].u64Start)
180 {
181 paStates[iCpu].u64Start = paStates[iCpu].u64Last;
182 RTR0TESTR0_CHECK_MSG(iCountedTick == 1, ("iCountedTick=%u iCpu=%d idCpu=%u\n", iCountedTick, iCpu, idCpu));
183 }
184 }
185}
186
187
188/**
189 * Callback which increments a 32-bit counter.
190 *
191 * @param pTimer The timer.
192 * @param iTick The current tick.
193 * @param pvUser The user argument.
194 */
195static DECLCALLBACK(void) tstRTR0TimerCallbackSpecific(PRTTIMER pTimer, void *pvUser, uint64_t iTick)
196{
197 PTSTRTR0TIMERS1 pState = (PTSTRTR0TIMERS1)pvUser;
198 uint32_t iShot = ASMAtomicIncU32(&pState->cShots);
199 NOREF(pTimer);
200
201 if (iShot <= RT_ELEMENTS(pState->aShotNsTSes))
202 pState->aShotNsTSes[iShot - 1] = RTTimeSystemNanoTS();
203
204 RTCPUID idCpu = RTMpCpuId();
205 if (pState->u.Specific.idCpu != idCpu)
206 pState->u.Specific.fFailed = true;
207 RTR0TESTR0_CHECK_MSG(pState->u.Specific.idCpu == idCpu, ("idCpu=%u, expected %u\n", idCpu, pState->u.Specific.idCpu));
208
209 if (pState->fPeriodic)
210 RTR0TESTR0_CHECK_MSG(iShot == iTick, ("iShot=%u iTick=%u\n", iShot, iTick));
211 else
212 RTR0TESTR0_CHECK_MSG(iTick == 1, ("iShot=%u iTick=%u\n", iShot, iTick));
213}
214
215
216/**
217 * Callback which changes the interval at each invocation.
218 *
219 * The changes are governed by TSTRTR0TIMERS1::ChangeInterval. The callback
220 * calls RTTimerStop at iActionShot.
221 *
222 * @param pTimer The timer.
223 * @param iTick The current tick.
224 * @param pvUser The user argument.
225 */
226static DECLCALLBACK(void) tstRTR0TimerCallbackChangeInterval(PRTTIMER pTimer, void *pvUser, uint64_t iTick)
227{
228 PTSTRTR0TIMERS1 pState = (PTSTRTR0TIMERS1)pvUser;
229 uint32_t iShot = ASMAtomicIncU32(&pState->cShots) - 1;
230
231 if (iShot < RT_ELEMENTS(pState->aShotNsTSes))
232 pState->aShotNsTSes[iShot] = RTTimeSystemNanoTS();
233 if (pState->fPeriodic)
234 RTR0TESTR0_CHECK_MSG(iShot + 1 == iTick, ("iShot=%u iTick=%u\n", iShot, iTick));
235 else
236 RTR0TESTR0_CHECK_MSG(iTick == 1, ("iShot=%u iTick=%u\n", iShot, iTick));
237
238 if (!(iShot % pState->u.ChgInt.cStepsBetween))
239 {
240 if (pState->u.ChgInt.fDirection)
241 {
242 pState->u.ChgInt.cNsCurInterval += pState->u.ChgInt.cNsChangeStep;
243 if ( pState->u.ChgInt.cNsCurInterval > pState->u.ChgInt.cNsMaxInterval
244 || pState->u.ChgInt.cNsCurInterval < pState->u.ChgInt.cNsMinInterval
245 || !pState->u.ChgInt.cNsCurInterval)
246 {
247 pState->u.ChgInt.cNsCurInterval = pState->u.ChgInt.cNsMaxInterval;
248 pState->u.ChgInt.fDirection = false;
249 }
250 }
251 else
252 {
253 pState->u.ChgInt.cNsCurInterval -= pState->u.ChgInt.cNsChangeStep;
254 if ( pState->u.ChgInt.cNsCurInterval < pState->u.ChgInt.cNsMinInterval
255 || pState->u.ChgInt.cNsCurInterval > pState->u.ChgInt.cNsMaxInterval
256 || pState->u.ChgInt.cNsCurInterval)
257 {
258 pState->u.ChgInt.cNsCurInterval = pState->u.ChgInt.cNsMinInterval;
259 pState->u.ChgInt.fDirection = true;
260 }
261 }
262
263 RTR0TESTR0_CHECK_RC(RTTimerChangeInterval(pTimer, pState->u.ChgInt.cNsCurInterval), VINF_SUCCESS);
264 }
265
266 if (iShot == pState->iActionShot)
267 RTR0TESTR0_CHECK_RC(pState->rc = RTTimerStop(pTimer), VINF_SUCCESS);
268}
269
270
271/**
272 * Callback which increments destroy the timer when it fires.
273 *
274 * @param pTimer The timer.
275 * @param iTick The current tick.
276 * @param pvUser The user argument.
277 */
278static DECLCALLBACK(void) tstRTR0TimerCallbackDestroyOnce(PRTTIMER pTimer, void *pvUser, uint64_t iTick)
279{
280 PTSTRTR0TIMERS1 pState = (PTSTRTR0TIMERS1)pvUser;
281 uint32_t iShot = ASMAtomicIncU32(&pState->cShots);
282
283 if (iShot <= RT_ELEMENTS(pState->aShotNsTSes))
284 pState->aShotNsTSes[iShot - 1] = RTTimeSystemNanoTS();
285 if (pState->fPeriodic)
286 RTR0TESTR0_CHECK_MSG(iShot == iTick, ("iShot=%u iTick=%u\n", iShot, iTick));
287 else
288 RTR0TESTR0_CHECK_MSG(iTick == 1, ("iShot=%u iTick=%u\n", iShot, iTick));
289
290 if (iShot == pState->iActionShot + 1)
291 RTR0TESTR0_CHECK_RC(pState->rc = RTTimerDestroy(pTimer), VINF_SUCCESS);
292}
293
294
295/**
296 * Callback which increments restarts a timer once.
297 *
298 * @param pTimer The timer.
299 * @param iTick The current tick.
300 * @param pvUser The user argument.
301 */
302static DECLCALLBACK(void) tstRTR0TimerCallbackRestartOnce(PRTTIMER pTimer, void *pvUser, uint64_t iTick)
303{
304 PTSTRTR0TIMERS1 pState = (PTSTRTR0TIMERS1)pvUser;
305 uint32_t iShot = ASMAtomicIncU32(&pState->cShots);
306
307 if (iShot <= RT_ELEMENTS(pState->aShotNsTSes))
308 pState->aShotNsTSes[iShot - 1] = RTTimeSystemNanoTS();
309 if (pState->fPeriodic)
310 RTR0TESTR0_CHECK_MSG(iShot == iTick, ("iShot=%u iTick=%u\n", iShot, iTick));
311 else
312 RTR0TESTR0_CHECK_MSG(iTick == 1, ("iShot=%u iTick=%u\n", iShot, iTick));
313
314 if (iShot == pState->iActionShot + 1)
315 RTR0TESTR0_CHECK_RC(pState->rc = RTTimerStart(pTimer, 10000000 /* 10ms */), VINF_SUCCESS);
316}
317
318
319/**
320 * Callback which increments a 32-bit counter.
321 *
322 * @param pTimer The timer.
323 * @param iTick The current tick.
324 * @param pvUser The user argument.
325 */
326static DECLCALLBACK(void) tstRTR0TimerCallbackU32Counter(PRTTIMER pTimer, void *pvUser, uint64_t iTick)
327{
328 PTSTRTR0TIMERS1 pState = (PTSTRTR0TIMERS1)pvUser;
329 uint32_t iShot = ASMAtomicIncU32(&pState->cShots);
330 NOREF(pTimer);
331
332 if (iShot <= RT_ELEMENTS(pState->aShotNsTSes))
333 pState->aShotNsTSes[iShot - 1] = RTTimeSystemNanoTS();
334 if (pState->fPeriodic)
335 RTR0TESTR0_CHECK_MSG(iShot == iTick, ("iShot=%u iTick=%u\n", iShot, iTick));
336 else
337 RTR0TESTR0_CHECK_MSG(iTick == 1, ("iShot=%u iTick=%u\n", iShot, iTick));
338}
339
340
341#ifdef SOME_UNUSED_FUNCTION
342/**
343 * Checks that the interval between two timer shots are within the specified
344 * range.
345 *
346 * @returns 0 if ok, 1 if bad.
347 * @param iShot The shot number (for bitching).
348 * @param uPrevTS The time stamp of the previous shot (ns).
349 * @param uThisTS The timer stamp of this shot (ns).
350 * @param uMin The minimum interval (ns).
351 * @param uMax The maximum interval (ns).
352 */
353static int tstRTR0TimerCheckShotInterval(uint32_t iShot, uint64_t uPrevTS, uint64_t uThisTS, uint32_t uMin, uint32_t uMax)
354{
355 uint64_t uDelta = uThisTS - uPrevTS;
356 RTR0TESTR0_CHECK_MSG_RET(uDelta >= uMin, ("iShot=%u uDelta=%lld uMin=%u\n", iShot, uDelta, uMin), 1);
357 RTR0TESTR0_CHECK_MSG_RET(uDelta <= uMax, ("iShot=%u uDelta=%lld uMax=%u\n", iShot, uDelta, uMax), 1);
358 return 0;
359}
360#endif
361
362
363/**
364 * Checks that the interval between timer shots are within a certain range.
365 *
366 * @returns Number of violations (i.e. 0 is ok).
367 * @param pState The state.
368 * @param uStartNsTS The start time stamp (ns).
369 * @param uMin The minimum interval (ns).
370 * @param uMax The maximum interval (ns).
371 */
372static int tstRTR0TimerCheckShotIntervals(PTSTRTR0TIMERS1 pState, uint64_t uStartNsTS, uint32_t uMin, uint32_t uMax)
373{
374 uint64_t uMaxDelta = 0;
375 uint64_t uMinDelta = UINT64_MAX;
376 uint32_t cBadShots = 0;
377 uint32_t cShots = pState->cShots;
378 uint64_t uPrevTS = uStartNsTS;
379 for (uint32_t iShot = 0; iShot < cShots; iShot++)
380 {
381 uint64_t uThisTS = pState->aShotNsTSes[iShot];
382 uint64_t uDelta = uThisTS - uPrevTS;
383 if (uDelta > uMaxDelta)
384 uMaxDelta = uDelta;
385 if (uDelta < uMinDelta)
386 uMinDelta = uDelta;
387 cBadShots += !(uDelta >= uMin && uDelta <= uMax);
388
389 RTR0TESTR0_CHECK_MSG(uDelta >= uMin, ("iShot=%u uDelta=%lld uMin=%u\n", iShot, uDelta, uMin));
390 RTR0TESTR0_CHECK_MSG(uDelta <= uMax, ("iShot=%u uDelta=%lld uMax=%u\n", iShot, uDelta, uMax));
391
392 uPrevTS = uThisTS;
393 }
394
395 RTR0TestR0Info("uMaxDelta=%llu uMinDelta=%llu\n", uMaxDelta, uMinDelta);
396 return cBadShots;
397}
398
399
400/**
401 * Service request callback function.
402 *
403 * @returns VBox status code.
404 * @param pSession The caller's session.
405 * @param u64Arg 64-bit integer argument.
406 * @param pReqHdr The request header. Input / Output. Optional.
407 */
408DECLEXPORT(int) TSTRTR0TimerSrvReqHandler(PSUPDRVSESSION pSession, uint32_t uOperation,
409 uint64_t u64Arg, PSUPR0SERVICEREQHDR pReqHdr)
410{
411 RTR0TESTR0_SRV_REQ_PROLOG_RET(pReqHdr);
412 NOREF(pSession);
413
414 /*
415 * Common parameter and state variables.
416 */
417 uint32_t const cNsSysHz = RTTimerGetSystemGranularity();
418 uint32_t const cNsMaxHighResHz = 10000; /** @todo need API for this */
419 TSTRTR0TIMERS1 State;
420 if ( cNsSysHz < UINT32_C(1000)
421 || cNsSysHz > UINT32_C(1000000000)
422 || cNsMaxHighResHz < UINT32_C(1)
423 || cNsMaxHighResHz > UINT32_C(1000000000))
424 {
425 RTR0TESTR0_CHECK_MSG(cNsSysHz > UINT32_C(1000) && cNsSysHz < UINT32_C(1000000000), ("%u", cNsSysHz));
426 RTR0TESTR0_CHECK_MSG(cNsMaxHighResHz > UINT32_C(1) && cNsMaxHighResHz < UINT32_C(1000000000), ("%u", cNsMaxHighResHz));
427 RTR0TESTR0_SRV_REQ_EPILOG(pReqHdr);
428 return VINF_SUCCESS;
429 }
430
431 /*
432 * The big switch.
433 */
434 switch (uOperation)
435 {
436 RTR0TESTR0_IMPLEMENT_SANITY_CASES();
437 RTR0TESTR0_IMPLEMENT_DEFAULT_CASE(uOperation);
438
439 case TSTRTR0TIMER_ONE_SHOT_BASIC:
440 case TSTRTR0TIMER_ONE_SHOT_BASIC_HIRES:
441 {
442 /* Create a one-shot timer and take one shot. */
443 PRTTIMER pTimer;
444 uint32_t fFlags = TSTRTR0TIMER_IS_HIRES(uOperation) ? RTTIMER_FLAGS_HIGH_RES : 0;
445 int rc = RTTimerCreateEx(&pTimer, 0, fFlags, tstRTR0TimerCallbackU32Counter, &State);
446 if (rc == VERR_NOT_SUPPORTED)
447 {
448 RTR0TestR0Info("one-shot timer are not supported, skipping\n");
449 break;
450 }
451 RTR0TESTR0_CHECK_RC_BREAK(rc, VINF_SUCCESS);
452
453 do /* break loop */
454 {
455 RT_ZERO(State); ASMAtomicWriteU32(&State.cShots, State.cShots);
456 RTR0TESTR0_CHECK_RC_BREAK(RTTimerStart(pTimer, 0), VINF_SUCCESS);
457 for (uint32_t i = 0; i < 1000 && !ASMAtomicUoReadU32(&State.cShots); i++)
458 RTThreadSleep(5);
459 RTR0TESTR0_CHECK_MSG_BREAK(ASMAtomicUoReadU32(&State.cShots) == 1, ("cShots=%u\n", State.cShots));
460
461 /* check that it is restartable. */
462 RT_ZERO(State); ASMAtomicWriteU32(&State.cShots, State.cShots);
463 RTR0TESTR0_CHECK_RC_BREAK(RTTimerStart(pTimer, 0), VINF_SUCCESS);
464 for (uint32_t i = 0; i < 1000 && !ASMAtomicUoReadU32(&State.cShots); i++)
465 RTThreadSleep(5);
466 RTR0TESTR0_CHECK_MSG_BREAK(ASMAtomicUoReadU32(&State.cShots) == 1, ("cShots=%u\n", State.cShots));
467
468 /* check that it respects the timeout value and can be cancelled. */
469 RT_ZERO(State); ASMAtomicWriteU32(&State.cShots, State.cShots);
470 RTR0TESTR0_CHECK_RC(RTTimerStart(pTimer, 5*UINT64_C(1000000000)), VINF_SUCCESS);
471 RTR0TESTR0_CHECK_RC(RTTimerStop(pTimer), VINF_SUCCESS);
472 RTThreadSleep(1);
473 RTR0TESTR0_CHECK_MSG_BREAK(ASMAtomicUoReadU32(&State.cShots) == 0, ("cShots=%u\n", State.cShots));
474
475 /* Check some double starts and stops (shall not assert). */
476 RT_ZERO(State); ASMAtomicWriteU32(&State.cShots, State.cShots);
477 RTR0TESTR0_CHECK_RC(RTTimerStart(pTimer, 5*UINT64_C(1000000000)), VINF_SUCCESS);
478 RTR0TESTR0_CHECK_RC(RTTimerStart(pTimer, 0), VERR_TIMER_ACTIVE);
479 RTR0TESTR0_CHECK_RC(RTTimerStop(pTimer), VINF_SUCCESS);
480 RTR0TESTR0_CHECK_RC(RTTimerStop(pTimer), VERR_TIMER_SUSPENDED);
481 RTThreadSleep(1);
482 RTR0TESTR0_CHECK_MSG_BREAK(ASMAtomicUoReadU32(&State.cShots) == 0, ("cShots=%u\n", State.cShots));
483 } while (0);
484 RTR0TESTR0_CHECK_RC(RTTimerDestroy(pTimer), VINF_SUCCESS);
485 RTR0TESTR0_CHECK_RC(RTTimerDestroy(NULL), VINF_SUCCESS);
486 break;
487 }
488
489 case TSTRTR0TIMER_ONE_SHOT_RESTART:
490 case TSTRTR0TIMER_ONE_SHOT_RESTART_HIRES:
491 {
492#if !defined(RT_OS_SOLARIS) /* Not expected to work on all hosts. */
493 /* Create a one-shot timer and restart it in the callback handler. */
494 PRTTIMER pTimer;
495 uint32_t fFlags = TSTRTR0TIMER_IS_HIRES(uOperation) ? RTTIMER_FLAGS_HIGH_RES : 0;
496 for (uint32_t iTest = 0; iTest < 2; iTest++)
497 {
498 int rc = RTTimerCreateEx(&pTimer, 0, fFlags, tstRTR0TimerCallbackRestartOnce, &State);
499 if (rc == VERR_NOT_SUPPORTED)
500 {
501 RTR0TestR0Info("one-shot timer are not supported, skipping\n");
502 break;
503 }
504 RTR0TESTR0_CHECK_RC_BREAK(rc, VINF_SUCCESS);
505
506 RT_ZERO(State);
507 State.iActionShot = 0;
508 ASMAtomicWriteU32(&State.cShots, State.cShots);
509 do /* break loop */
510 {
511 RTR0TESTR0_CHECK_RC_BREAK(RTTimerStart(pTimer, cNsSysHz * iTest), VINF_SUCCESS);
512 for (uint32_t i = 0; i < 1000 && ASMAtomicUoReadU32(&State.cShots) < 2; i++)
513 RTThreadSleep(5);
514 RTR0TESTR0_CHECK_MSG_BREAK(ASMAtomicUoReadU32(&State.cShots) == 2, ("cShots=%u\n", State.cShots));
515 } while (0);
516 RTR0TESTR0_CHECK_RC(RTTimerDestroy(pTimer), VINF_SUCCESS);
517 }
518#else
519 RTR0TestR0Info("restarting from callback not supported on this platform\n");
520
521#endif
522 break;
523 }
524
525 case TSTRTR0TIMER_ONE_SHOT_DESTROY:
526 case TSTRTR0TIMER_ONE_SHOT_DESTROY_HIRES:
527 {
528#if !defined(RT_OS_SOLARIS) && !defined(RT_OS_WINDOWS) /* Not expected to work on all hosts. */
529 /* Create a one-shot timer and destroy it in the callback handler. */
530 PRTTIMER pTimer;
531 uint32_t fFlags = TSTRTR0TIMER_IS_HIRES(uOperation) ? RTTIMER_FLAGS_HIGH_RES : 0;
532 for (uint32_t iTest = 0; iTest < 2; iTest++)
533 {
534 int rc = RTTimerCreateEx(&pTimer, 0, fFlags, tstRTR0TimerCallbackDestroyOnce, &State);
535 if (rc == VERR_NOT_SUPPORTED)
536 {
537 RTR0TestR0Info("one-shot timer are not supported, skipping\n");
538 break;
539 }
540 RTR0TESTR0_CHECK_RC_BREAK(rc, VINF_SUCCESS);
541
542 RT_ZERO(State);
543 State.rc = VERR_IPE_UNINITIALIZED_STATUS;
544 State.iActionShot = 0;
545 ASMAtomicWriteU32(&State.cShots, State.cShots);
546 do /* break loop */
547 {
548 RTR0TESTR0_CHECK_RC_BREAK(RTTimerStart(pTimer, cNsSysHz * iTest), VINF_SUCCESS);
549 for (uint32_t i = 0; i < 1000 && (ASMAtomicUoReadU32(&State.cShots) < 1 || State.rc == VERR_IPE_UNINITIALIZED_STATUS); i++)
550 RTThreadSleep(5);
551 RTR0TESTR0_CHECK_MSG_BREAK(ASMAtomicReadU32(&State.cShots) == 1, ("cShots=%u\n", State.cShots));
552 RTR0TESTR0_CHECK_MSG_BREAK(State.rc == VINF_SUCCESS, ("rc=%Rrc\n", State.rc));
553 } while (0);
554 if (RT_FAILURE(State.rc))
555 RTR0TESTR0_CHECK_RC(RTTimerDestroy(pTimer), VINF_SUCCESS);
556 }
557#else
558 RTR0TestR0Info("destroying from callback not supported on this platform\n");
559#endif
560 break;
561 }
562
563 case TSTRTR0TIMER_ONE_SHOT_SPECIFIC:
564 case TSTRTR0TIMER_ONE_SHOT_SPECIFIC_HIRES:
565 {
566 PRTTIMER pTimer = NULL;
567 RTCPUSET OnlineSet;
568 RTMpGetOnlineSet(&OnlineSet);
569 for (uint32_t iCpu = 0; iCpu < RTCPUSET_MAX_CPUS; iCpu++)
570 if (RTCpuSetIsMemberByIndex(&OnlineSet, iCpu))
571 {
572 RT_ZERO(State);
573 State.iActionShot = 0;
574 State.rc = VINF_SUCCESS;
575 State.u.Specific.idCpu = RTMpCpuIdFromSetIndex(iCpu);
576 ASMAtomicWriteU32(&State.cShots, State.cShots);
577
578 uint32_t fFlags = TSTRTR0TIMER_IS_HIRES(uOperation) ? RTTIMER_FLAGS_HIGH_RES : 0;
579 fFlags |= RTTIMER_FLAGS_CPU(iCpu);
580 int rc = RTTimerCreateEx(&pTimer, 0, fFlags, tstRTR0TimerCallbackSpecific, &State);
581 if (rc == VERR_NOT_SUPPORTED)
582 {
583 RTR0TestR0Info("one-shot specific timer are not supported, skipping\n");
584 break;
585 }
586 RTR0TESTR0_CHECK_RC_BREAK(rc, VINF_SUCCESS);
587
588 for (uint32_t i = 0; i < 5 && !RTR0TestR0HaveErrors(); i++)
589 {
590 ASMAtomicWriteU32(&State.cShots, 0);
591 RTR0TESTR0_CHECK_RC_BREAK(RTTimerStart(pTimer, (i & 2 ? cNsSysHz : cNsSysHz / 2) * (i & 1)), VINF_SUCCESS);
592 uint64_t cNsElapsed = RTTimeSystemNanoTS();
593 for (uint32_t j = 0; j < 1000 && ASMAtomicUoReadU32(&State.cShots) < 1; j++)
594 RTThreadSleep(5);
595 cNsElapsed = RTTimeSystemNanoTS() - cNsElapsed;
596 RTR0TESTR0_CHECK_MSG_BREAK(ASMAtomicReadU32(&State.cShots) == 1,
597 ("cShots=%u iCpu=%u i=%u iCurCpu=%u cNsElapsed=%'llu\n",
598 State.cShots, iCpu, i, RTMpCpuIdToSetIndex(RTMpCpuId()), cNsElapsed ));
599 RTR0TESTR0_CHECK_MSG_BREAK(State.rc == VINF_SUCCESS, ("rc=%Rrc\n", State.rc));
600 RTR0TESTR0_CHECK_MSG_BREAK(!State.u.Specific.fFailed, ("iCpu=%u i=%u\n", iCpu, i));
601 }
602
603 RTR0TESTR0_CHECK_RC(RTTimerDestroy(pTimer), VINF_SUCCESS);
604 pTimer = NULL;
605 if (RTR0TestR0HaveErrors())
606 break;
607
608 RTMpGetOnlineSet(&OnlineSet);
609 }
610 RTR0TESTR0_CHECK_RC(RTTimerDestroy(pTimer), VINF_SUCCESS);
611 break;
612 }
613
614 case TSTRTR0TIMER_PERIODIC_BASIC:
615 case TSTRTR0TIMER_PERIODIC_BASIC_HIRES:
616 {
617 /* Create a periodic timer running at 10 HZ. */
618 uint32_t const u10HzAsNs = 100000000;
619 uint32_t const u10HzAsNsMin = u10HzAsNs - u10HzAsNs / 2;
620 uint32_t const u10HzAsNsMax = u10HzAsNs + u10HzAsNs / 2;
621 PRTTIMER pTimer;
622 uint32_t fFlags = TSTRTR0TIMER_IS_HIRES(uOperation) ? RTTIMER_FLAGS_HIGH_RES : 0;
623 RTR0TESTR0_CHECK_RC_BREAK(RTTimerCreateEx(&pTimer, u10HzAsNs, fFlags, tstRTR0TimerCallbackU32Counter, &State),
624 VINF_SUCCESS);
625
626 for (uint32_t iTest = 0; iTest < 2; iTest++)
627 {
628 RT_ZERO(State);
629 State.fPeriodic = true;
630 ASMAtomicWriteU32(&State.cShots, State.cShots);
631
632 uint64_t uStartNsTS = RTTimeSystemNanoTS();
633 RTR0TESTR0_CHECK_RC_BREAK(RTTimerStart(pTimer, u10HzAsNs), VINF_SUCCESS);
634 for (uint32_t i = 0; i < 1000 && ASMAtomicUoReadU32(&State.cShots) < 10; i++)
635 RTThreadSleep(10);
636 RTR0TESTR0_CHECK_RC_BREAK(RTTimerStop(pTimer), VINF_SUCCESS);
637 RTR0TESTR0_CHECK_MSG_BREAK(ASMAtomicUoReadU32(&State.cShots) == 10, ("cShots=%u\n", State.cShots));
638 if (tstRTR0TimerCheckShotIntervals(&State, uStartNsTS, u10HzAsNsMin, u10HzAsNsMax))
639 break;
640 RTThreadSleep(1); /** @todo RTTimerStop doesn't currently make sure the timer callback not is running
641 * before returning on windows, linux (low res) and possible other plaforms. */
642 }
643 RTR0TESTR0_CHECK_RC(RTTimerDestroy(pTimer), VINF_SUCCESS);
644 RTR0TESTR0_CHECK_RC(RTTimerDestroy(NULL), VINF_SUCCESS);
645 break;
646 }
647
648 case TSTRTR0TIMER_PERIODIC_CSSD_LOOPS:
649 case TSTRTR0TIMER_PERIODIC_CSSD_LOOPS_HIRES:
650 {
651 /* create, start, stop & destroy high res timers a number of times. */
652 uint32_t fFlags = TSTRTR0TIMER_IS_HIRES(uOperation) ? RTTIMER_FLAGS_HIGH_RES : 0;
653 for (uint32_t i = 0; i < 40; i++)
654 {
655 PRTTIMER pTimer;
656 RTR0TESTR0_CHECK_RC_BREAK(RTTimerCreateEx(&pTimer, cNsSysHz, fFlags, tstRTR0TimerCallbackU32Counter, &State),
657 VINF_SUCCESS);
658 for (uint32_t j = 0; j < 10; j++)
659 {
660 RT_ZERO(State);
661 State.fPeriodic = true;
662 ASMAtomicWriteU32(&State.cShots, State.cShots); /* ordered, necessary? */
663
664 RTR0TESTR0_CHECK_RC_BREAK(RTTimerStart(pTimer, i < 20 ? 0 : cNsSysHz), VINF_SUCCESS);
665 for (uint32_t k = 0; k < 1000 && ASMAtomicUoReadU32(&State.cShots) < 2; k++)
666 RTThreadSleep(1);
667 RTR0TESTR0_CHECK_RC_BREAK(RTTimerStop(pTimer), VINF_SUCCESS);
668 RTThreadSleep(1); /** @todo RTTimerStop doesn't currently make sure the timer callback not is running
669 * before returning on windows, linux (low res) and possible other plaforms. */
670 }
671 RTR0TESTR0_CHECK_RC(RTTimerDestroy(pTimer), VINF_SUCCESS);
672 }
673 break;
674 }
675
676 case TSTRTR0TIMER_PERIODIC_CHANGE_INTERVAL:
677 case TSTRTR0TIMER_PERIODIC_CHANGE_INTERVAL_HIRES:
678 {
679 /* Initialize the test parameters, using the u64Arg value for selecting variations. */
680 RT_ZERO(State);
681 State.cShots = 0;
682 State.rc = VERR_IPE_UNINITIALIZED_STATUS;
683 State.iActionShot = 42;
684 State.fPeriodic = true;
685 State.u.ChgInt.fDirection = !!(u64Arg & 1);
686 if (uOperation == TSTRTR0TIMER_PERIODIC_CHANGE_INTERVAL_HIRES)
687 {
688 State.u.ChgInt.cNsMaxInterval = RT_MAX(cNsMaxHighResHz * 10, 20000000); /* 10x / 20 ms */
689 State.u.ChgInt.cNsMinInterval = RT_MAX(cNsMaxHighResHz, 10000); /* min / 10 us */
690 }
691 else
692 {
693 State.u.ChgInt.cNsMaxInterval = cNsSysHz * 4;
694 State.u.ChgInt.cNsMinInterval = cNsSysHz;
695 }
696 State.u.ChgInt.cNsChangeStep = (State.u.ChgInt.cNsMaxInterval - State.u.ChgInt.cNsMinInterval) / 10;
697 State.u.ChgInt.cNsCurInterval = State.u.ChgInt.fDirection
698 ? State.u.ChgInt.cNsMaxInterval : State.u.ChgInt.cNsMinInterval;
699 State.u.ChgInt.cStepsBetween = u64Arg & 4 ? 1 : 3;
700 RTR0TESTR0_CHECK_MSG_BREAK(State.u.ChgInt.cNsMinInterval > 1000, ("%u\n", State.u.ChgInt.cNsMinInterval));
701 RTR0TESTR0_CHECK_MSG_BREAK(State.u.ChgInt.cNsMaxInterval > State.u.ChgInt.cNsMinInterval, ("max=%u min=%u\n", State.u.ChgInt.cNsMaxInterval, State.u.ChgInt.cNsMinInterval));
702 ASMAtomicWriteU32(&State.cShots, State.cShots);
703
704 /* create the timer and check if RTTimerChangeInterval is supported. */
705 PRTTIMER pTimer;
706 uint32_t fFlags = TSTRTR0TIMER_IS_HIRES(uOperation) ? RTTIMER_FLAGS_HIGH_RES : 0;
707 RTR0TESTR0_CHECK_RC_BREAK(RTTimerCreateEx(&pTimer, cNsSysHz, fFlags, tstRTR0TimerCallbackChangeInterval, &State),
708 VINF_SUCCESS);
709 int rc = RTTimerChangeInterval(pTimer, State.u.ChgInt.cNsMinInterval);
710 if (rc == VERR_NOT_SUPPORTED)
711 {
712 RTR0TestR0Info("RTTimerChangeInterval not supported, skipped");
713 RTR0TESTR0_CHECK_RC(RTTimerDestroy(pTimer), VINF_SUCCESS);
714 break;
715 }
716
717 /* do the test. */
718 RTR0TESTR0_CHECK_RC_BREAK(RTTimerStart(pTimer, u64Arg & 2 ? State.u.ChgInt.cNsCurInterval : 0), VINF_SUCCESS);
719 for (uint32_t k = 0;
720 k < 1000
721 && ASMAtomicReadU32(&State.cShots) <= State.iActionShot
722 && State.rc == VERR_IPE_UNINITIALIZED_STATUS;
723 k++)
724 RTThreadSleep(10);
725
726 rc = RTTimerStop(pTimer);
727 RTR0TESTR0_CHECK_MSG_BREAK(rc == VERR_TIMER_SUSPENDED || rc == VINF_SUCCESS, ("rc = %Rrc (RTTimerStop)\n", rc));
728 RTR0TESTR0_CHECK_RC(RTTimerDestroy(pTimer), VINF_SUCCESS);
729 break;
730 }
731
732 case TSTRTR0TIMER_PERIODIC_SPECIFIC:
733 case TSTRTR0TIMER_PERIODIC_SPECIFIC_HIRES:
734 {
735 PRTTIMER pTimer = NULL;
736 RTCPUSET OnlineSet;
737 RTMpGetOnlineSet(&OnlineSet);
738 for (uint32_t iCpu = 0; iCpu < RTCPUSET_MAX_CPUS; iCpu++)
739 if (RTCpuSetIsMemberByIndex(&OnlineSet, iCpu))
740 {
741 RT_ZERO(State);
742 State.iActionShot = 0;
743 State.rc = VINF_SUCCESS;
744 State.fPeriodic = true;
745 State.u.Specific.idCpu = RTMpCpuIdFromSetIndex(iCpu);
746 ASMAtomicWriteU32(&State.cShots, State.cShots);
747
748 uint32_t fFlags = TSTRTR0TIMER_IS_HIRES(uOperation) ? RTTIMER_FLAGS_HIGH_RES : 0;
749 fFlags |= RTTIMER_FLAGS_CPU(iCpu);
750 int rc = RTTimerCreateEx(&pTimer, cNsSysHz, fFlags, tstRTR0TimerCallbackSpecific, &State);
751 if (rc == VERR_NOT_SUPPORTED)
752 {
753 RTR0TestR0Info("specific timer are not supported, skipping\n");
754 break;
755 }
756 RTR0TESTR0_CHECK_RC_BREAK(rc, VINF_SUCCESS);
757
758 for (uint32_t i = 0; i < 3 && !RTR0TestR0HaveErrors(); i++)
759 {
760 ASMAtomicWriteU32(&State.cShots, 0);
761 RTR0TESTR0_CHECK_RC_BREAK(RTTimerStart(pTimer, (i & 2 ? cNsSysHz : cNsSysHz / 2) * (i & 1)), VINF_SUCCESS);
762 uint64_t cNsElapsed = RTTimeSystemNanoTS();
763 for (uint32_t j = 0; j < 1000 && ASMAtomicUoReadU32(&State.cShots) < 8; j++)
764 RTThreadSleep(5);
765 cNsElapsed = RTTimeSystemNanoTS() - cNsElapsed;
766 RTR0TESTR0_CHECK_RC_BREAK(RTTimerStop(pTimer), VINF_SUCCESS);
767 RTR0TESTR0_CHECK_MSG_BREAK(ASMAtomicReadU32(&State.cShots) > 5,
768 ("cShots=%u iCpu=%u i=%u iCurCpu=%u cNsElapsed=%'llu\n",
769 State.cShots, iCpu, i, RTMpCpuIdToSetIndex(RTMpCpuId()), cNsElapsed));
770 RTThreadSleep(1); /** @todo RTTimerStop doesn't currently make sure the timer callback not is running
771 * before returning on windows, linux (low res) and possible other plaforms. */
772 RTR0TESTR0_CHECK_MSG_BREAK(State.rc == VINF_SUCCESS, ("rc=%Rrc\n", State.rc));
773 RTR0TESTR0_CHECK_MSG_BREAK(!State.u.Specific.fFailed, ("iCpu=%u i=%u\n", iCpu, i));
774 }
775
776 RTR0TESTR0_CHECK_RC(RTTimerDestroy(pTimer), VINF_SUCCESS);
777 pTimer = NULL;
778 if (RTR0TestR0HaveErrors())
779 break;
780
781 RTMpGetOnlineSet(&OnlineSet);
782 }
783 RTR0TESTR0_CHECK_RC(RTTimerDestroy(pTimer), VINF_SUCCESS);
784 break;
785 }
786
787 case TSTRTR0TIMER_PERIODIC_OMNI:
788 case TSTRTR0TIMER_PERIODIC_OMNI_HIRES:
789 {
790 /* Create a periodic timer running at max host frequency, but no more than 1000 Hz. */
791 uint32_t cNsInterval = cNsSysHz;
792 while (cNsInterval < UINT32_C(1000000))
793 cNsInterval *= 2;
794 PTSTRTR0TIMEROMNI1 paStates = (PTSTRTR0TIMEROMNI1)RTMemAllocZ(sizeof(paStates[0]) * RTCPUSET_MAX_CPUS);
795 RTR0TESTR0_CHECK_MSG_BREAK(paStates, ("%d\n", RTCPUSET_MAX_CPUS));
796
797 PRTTIMER pTimer;
798 uint32_t fFlags = (TSTRTR0TIMER_IS_HIRES(uOperation) ? RTTIMER_FLAGS_HIGH_RES : 0)
799 | RTTIMER_FLAGS_CPU_ALL;
800 int rc = RTTimerCreateEx(&pTimer, cNsInterval, fFlags, tstRTR0TimerCallbackOmni, paStates);
801 if (rc == VERR_NOT_SUPPORTED)
802 {
803 RTR0TESTR0_SKIP_BREAK();
804 }
805 RTR0TESTR0_CHECK_RC_BREAK(rc, VINF_SUCCESS);
806
807 for (uint32_t iTest = 0; iTest < 3 && !RTR0TestR0HaveErrors(); iTest++)
808 {
809 /* reset the state */
810 for (uint32_t iCpu = 0; iCpu < RTCPUSET_MAX_CPUS; iCpu++)
811 {
812 paStates[iCpu].u64Start = 0;
813 paStates[iCpu].u64Last = 0;
814 ASMAtomicWriteU32(&paStates[iCpu].cTicks, 0);
815 }
816
817 /* run it for 1 second. */
818 RTCPUSET OnlineSet;
819 uint64_t uStartNsTS = RTTimeSystemNanoTS();
820 RTR0TESTR0_CHECK_RC_BREAK(RTTimerStart(pTimer, 0), VINF_SUCCESS);
821 RTMpGetOnlineSet(&OnlineSet);
822
823 for (uint32_t i = 0; i < 5000 && RTTimeSystemNanoTS() - uStartNsTS <= UINT32_C(1000000000); i++)
824 RTThreadSleep(2);
825
826 RTR0TESTR0_CHECK_RC_BREAK(RTTimerStop(pTimer), VINF_SUCCESS);
827 uint64_t cNsElapsedX = RTTimeNanoTS() - uStartNsTS;
828
829 /* Do a min/max on the start and stop times and calculate the test period. */
830 uint64_t u64MinStart = UINT64_MAX;
831 uint64_t u64MaxStop = 0;
832 for (uint32_t iCpu = 0; iCpu < RTCPUSET_MAX_CPUS; iCpu++)
833 {
834 if (paStates[iCpu].u64Start)
835 {
836 if (paStates[iCpu].u64Start < u64MinStart)
837 u64MinStart = paStates[iCpu].u64Start;
838 if (paStates[iCpu].u64Last > u64MaxStop)
839 u64MaxStop = paStates[iCpu].u64Last;
840 }
841 }
842 RTR0TESTR0_CHECK_MSG(u64MinStart < u64MaxStop, ("%llu, %llu", u64MinStart, u64MaxStop));
843 uint64_t cNsElapsed = u64MaxStop - u64MinStart;
844 RTR0TESTR0_CHECK_MSG(cNsElapsed <= cNsElapsedX + 100000, ("%llu, %llu", cNsElapsed, cNsElapsedX)); /* the fudge factor is time drift */
845 uint32_t cAvgTicks = cNsElapsed / cNsInterval + 1;
846
847 /* Check tick counts. ASSUMES no cpu on- or offlining.
848 This only catches really bad stuff. */
849 uint32_t cMinTicks = cAvgTicks - cAvgTicks / 10;
850 uint32_t cMaxTicks = cAvgTicks + cAvgTicks / 10 + 1;
851 for (uint32_t iCpu = 0; iCpu < RTCPUSET_MAX_CPUS; iCpu++)
852 if (paStates[iCpu].cTicks)
853 {
854 RTR0TESTR0_CHECK_MSG(RTCpuSetIsMemberByIndex(&OnlineSet, iCpu), ("%d\n", iCpu));
855 RTR0TESTR0_CHECK_MSG(paStates[iCpu].cTicks <= cMaxTicks && paStates[iCpu].cTicks >= cMinTicks,
856 ("min=%u, ticks=%u, avg=%u max=%u, iCpu=%u, interval=%'u, elapsed=%'llu/%'llu\n",
857 cMinTicks, paStates[iCpu].cTicks, cAvgTicks, cMaxTicks, iCpu,
858 cNsInterval, cNsElapsed, cNsElapsedX));
859 }
860 else
861 RTR0TESTR0_CHECK_MSG(!RTCpuSetIsMemberByIndex(&OnlineSet, iCpu), ("%d\n", iCpu));
862 }
863
864 RTR0TESTR0_CHECK_RC(RTTimerDestroy(pTimer), VINF_SUCCESS);
865 RTMemFree(paStates);
866 break;
867 }
868
869 case TSTRTR0TIMER_LATENCY_OMNI:
870 case TSTRTR0TIMER_LATENCY_OMNI_HIRES:
871 {
872 /*
873 * Create a periodic timer running at max host frequency, but no more than 1000 Hz.
874 */
875 PRTTIMER pTimer;
876 uint32_t fFlags = (TSTRTR0TIMER_IS_HIRES(uOperation) ? RTTIMER_FLAGS_HIGH_RES : 0)
877 | RTTIMER_FLAGS_CPU_ALL;
878 uint32_t cNsInterval = cNsSysHz;
879 while (cNsInterval < UINT32_C(1000000))
880 cNsInterval *= 2;
881 int rc = RTTimerCreateEx(&pTimer, cNsInterval, fFlags, tstRTR0TimerCallbackLatencyOmni, NULL);
882 if (rc == VERR_NOT_SUPPORTED)
883 {
884 RTR0TESTR0_SKIP_BREAK();
885 }
886 RTR0TESTR0_CHECK_RC_BREAK(rc, VINF_SUCCESS);
887
888 /*
889 * Reset the state and run the test for 4 seconds.
890 */
891 RT_ZERO(g_aOmniLatency);
892
893 RTCPUSET OnlineSet;
894 uint64_t uStartNsTS = RTTimeSystemNanoTS();
895 RTR0TESTR0_CHECK_RC_BREAK(RTTimerStart(pTimer, 0), VINF_SUCCESS);
896 RTMpGetOnlineSet(&OnlineSet);
897
898 for (uint32_t i = 0; i < 5000 && RTTimeSystemNanoTS() - uStartNsTS <= UINT64_C(4000000000); i++)
899 RTThreadSleep(2);
900
901 RTR0TESTR0_CHECK_RC_BREAK(RTTimerStop(pTimer), VINF_SUCCESS);
902
903 /*
904 * Process the result.
905 */
906 int32_t cNsLow = cNsInterval / 4 * 3; /* 75% */
907 int32_t cNsHigh = cNsInterval / 4 * 5; /* 125% */
908 uint32_t cTotal = 0;
909 uint32_t cLow = 0;
910 uint32_t cHigh = 0;
911 for (uint32_t iCpu = 0; iCpu < RT_ELEMENTS(g_aOmniLatency); iCpu++)
912 {
913 uint32_t cSamples = g_aOmniLatency[iCpu].cSamples;
914 if (cSamples > 1)
915 {
916 cTotal += cSamples - 1;
917 for (uint32_t iSample = 1; iSample < cSamples; iSample++)
918 {
919 int64_t cNsDelta = g_aOmniLatency[iCpu].aSamples[iSample - 1].uNanoTs
920 - g_aOmniLatency[iCpu].aSamples[iSample].uNanoTs;
921 if (cNsDelta < cNsLow)
922 cLow++;
923 else if (cNsDelta > cNsHigh)
924 cHigh++;
925 }
926 }
927 }
928 RTR0TestR0Info("125%%: %u; 75%%: %u; total: %u", cHigh, cLow, cTotal);
929 RTR0TESTR0_CHECK_RC(RTTimerDestroy(pTimer), VINF_SUCCESS);
930 break;
931 }
932
933 }
934
935 RTR0TESTR0_SRV_REQ_EPILOG(pReqHdr);
936 /* The error indicator is the '!' in the message buffer. */
937 return VINF_SUCCESS;
938}
939
Note: See TracBrowser for help on using the repository browser.

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