1 | /* $Id: tstRTR0Timer.cpp 69111 2017-10-17 14:26:02Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * IPRT R0 Testcase - Timers.
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2009-2017 Oracle Corporation
|
---|
8 | *
|
---|
9 | * This file is part of VirtualBox Open Source Edition (OSE), as
|
---|
10 | * available from http://www.virtualbox.org. 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 | *********************************************************************************************************************************/
|
---|
51 | typedef 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;
|
---|
92 | typedef TSTRTR0TIMERS1 *PTSTRTR0TIMERS1;
|
---|
93 |
|
---|
94 |
|
---|
95 | /**
|
---|
96 | * Per cpu state for an omni timer test.
|
---|
97 | */
|
---|
98 | typedef 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;
|
---|
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 |
|
---|
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 | */
|
---|
165 | static 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 | */
|
---|
195 | static 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 | */
|
---|
226 | static 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 | */
|
---|
278 | static 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 | */
|
---|
302 | static 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 | */
|
---|
326 | static 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 | */
|
---|
353 | static 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 | */
|
---|
372 | static 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 | */
|
---|
408 | DECLEXPORT(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 | RTR0TESTR0_SKIP();
|
---|
450 | break;
|
---|
451 | }
|
---|
452 | RTR0TESTR0_CHECK_RC_BREAK(rc, VINF_SUCCESS);
|
---|
453 |
|
---|
454 | do /* break loop */
|
---|
455 | {
|
---|
456 | RT_ZERO(State); ASMAtomicWriteU32(&State.cShots, State.cShots);
|
---|
457 | RTR0TESTR0_CHECK_RC_BREAK(RTTimerStart(pTimer, 0), VINF_SUCCESS);
|
---|
458 | for (uint32_t i = 0; i < 1000 && !ASMAtomicUoReadU32(&State.cShots); i++)
|
---|
459 | RTThreadSleep(5);
|
---|
460 | RTR0TESTR0_CHECK_MSG_BREAK(ASMAtomicUoReadU32(&State.cShots) == 1, ("cShots=%u\n", State.cShots));
|
---|
461 |
|
---|
462 | /* check that it is restartable. */
|
---|
463 | RT_ZERO(State); ASMAtomicWriteU32(&State.cShots, State.cShots);
|
---|
464 | RTR0TESTR0_CHECK_RC_BREAK(RTTimerStart(pTimer, 0), VINF_SUCCESS);
|
---|
465 | for (uint32_t i = 0; i < 1000 && !ASMAtomicUoReadU32(&State.cShots); i++)
|
---|
466 | RTThreadSleep(5);
|
---|
467 | RTR0TESTR0_CHECK_MSG_BREAK(ASMAtomicUoReadU32(&State.cShots) == 1, ("cShots=%u\n", State.cShots));
|
---|
468 |
|
---|
469 | /* check that it respects the timeout value and can be cancelled. */
|
---|
470 | RT_ZERO(State); ASMAtomicWriteU32(&State.cShots, State.cShots);
|
---|
471 | RTR0TESTR0_CHECK_RC(RTTimerStart(pTimer, 5*UINT64_C(1000000000)), VINF_SUCCESS);
|
---|
472 | RTR0TESTR0_CHECK_RC(RTTimerStop(pTimer), VINF_SUCCESS);
|
---|
473 | RTThreadSleep(1);
|
---|
474 | RTR0TESTR0_CHECK_MSG_BREAK(ASMAtomicUoReadU32(&State.cShots) == 0, ("cShots=%u\n", State.cShots));
|
---|
475 |
|
---|
476 | /* Check some double starts and stops (shall not assert). */
|
---|
477 | RT_ZERO(State); ASMAtomicWriteU32(&State.cShots, State.cShots);
|
---|
478 | RTR0TESTR0_CHECK_RC(RTTimerStart(pTimer, 5*UINT64_C(1000000000)), VINF_SUCCESS);
|
---|
479 | RTR0TESTR0_CHECK_RC(RTTimerStart(pTimer, 0), VERR_TIMER_ACTIVE);
|
---|
480 | RTR0TESTR0_CHECK_RC(RTTimerStop(pTimer), VINF_SUCCESS);
|
---|
481 | RTR0TESTR0_CHECK_RC(RTTimerStop(pTimer), VERR_TIMER_SUSPENDED);
|
---|
482 | RTThreadSleep(1);
|
---|
483 | RTR0TESTR0_CHECK_MSG_BREAK(ASMAtomicUoReadU32(&State.cShots) == 0, ("cShots=%u\n", State.cShots));
|
---|
484 | } while (0);
|
---|
485 | RTR0TESTR0_CHECK_RC(RTTimerDestroy(pTimer), VINF_SUCCESS);
|
---|
486 | RTR0TESTR0_CHECK_RC(RTTimerDestroy(NULL), VINF_SUCCESS);
|
---|
487 | break;
|
---|
488 | }
|
---|
489 |
|
---|
490 | case TSTRTR0TIMER_ONE_SHOT_RESTART:
|
---|
491 | case TSTRTR0TIMER_ONE_SHOT_RESTART_HIRES:
|
---|
492 | {
|
---|
493 | #if !defined(RT_OS_SOLARIS) /* Not expected to work on all hosts. */
|
---|
494 | /* Create a one-shot timer and restart it in the callback handler. */
|
---|
495 | PRTTIMER pTimer;
|
---|
496 | uint32_t fFlags = TSTRTR0TIMER_IS_HIRES(uOperation) ? RTTIMER_FLAGS_HIGH_RES : 0;
|
---|
497 | for (uint32_t iTest = 0; iTest < 2; iTest++)
|
---|
498 | {
|
---|
499 | int rc = RTTimerCreateEx(&pTimer, 0, fFlags, tstRTR0TimerCallbackRestartOnce, &State);
|
---|
500 | if (rc == VERR_NOT_SUPPORTED)
|
---|
501 | {
|
---|
502 | RTR0TestR0Info("one-shot timer are not supported, skipping\n");
|
---|
503 | RTR0TESTR0_SKIP();
|
---|
504 | break;
|
---|
505 | }
|
---|
506 | RTR0TESTR0_CHECK_RC_BREAK(rc, VINF_SUCCESS);
|
---|
507 |
|
---|
508 | RT_ZERO(State);
|
---|
509 | State.iActionShot = 0;
|
---|
510 | ASMAtomicWriteU32(&State.cShots, State.cShots);
|
---|
511 | do /* break loop */
|
---|
512 | {
|
---|
513 | RTR0TESTR0_CHECK_RC_BREAK(RTTimerStart(pTimer, cNsSysHz * iTest), VINF_SUCCESS);
|
---|
514 | for (uint32_t i = 0; i < 1000 && ASMAtomicUoReadU32(&State.cShots) < 2; i++)
|
---|
515 | RTThreadSleep(5);
|
---|
516 | RTR0TESTR0_CHECK_MSG_BREAK(ASMAtomicUoReadU32(&State.cShots) == 2, ("cShots=%u\n", State.cShots));
|
---|
517 | } while (0);
|
---|
518 | RTR0TESTR0_CHECK_RC(RTTimerDestroy(pTimer), VINF_SUCCESS);
|
---|
519 | }
|
---|
520 | #else
|
---|
521 | RTR0TestR0Info("restarting from callback not supported on this platform\n");
|
---|
522 | RTR0TESTR0_SKIP();
|
---|
523 | #endif
|
---|
524 | break;
|
---|
525 | }
|
---|
526 |
|
---|
527 | case TSTRTR0TIMER_ONE_SHOT_DESTROY:
|
---|
528 | case TSTRTR0TIMER_ONE_SHOT_DESTROY_HIRES:
|
---|
529 | {
|
---|
530 | #if !defined(RT_OS_SOLARIS) && !defined(RT_OS_WINDOWS) /* Not expected to work on all hosts. */
|
---|
531 | /* Create a one-shot timer and destroy it in the callback handler. */
|
---|
532 | PRTTIMER pTimer;
|
---|
533 | uint32_t fFlags = TSTRTR0TIMER_IS_HIRES(uOperation) ? RTTIMER_FLAGS_HIGH_RES : 0;
|
---|
534 | for (uint32_t iTest = 0; iTest < 2; iTest++)
|
---|
535 | {
|
---|
536 | int rc = RTTimerCreateEx(&pTimer, 0, fFlags, tstRTR0TimerCallbackDestroyOnce, &State);
|
---|
537 | if (rc == VERR_NOT_SUPPORTED)
|
---|
538 | {
|
---|
539 | RTR0TestR0Info("one-shot timer are not supported, skipping\n");
|
---|
540 | RTR0TESTR0_SKIP();
|
---|
541 | break;
|
---|
542 | }
|
---|
543 | RTR0TESTR0_CHECK_RC_BREAK(rc, VINF_SUCCESS);
|
---|
544 |
|
---|
545 | RT_ZERO(State);
|
---|
546 | State.rc = VERR_IPE_UNINITIALIZED_STATUS;
|
---|
547 | State.iActionShot = 0;
|
---|
548 | ASMAtomicWriteU32(&State.cShots, State.cShots);
|
---|
549 | do /* break loop */
|
---|
550 | {
|
---|
551 | RTR0TESTR0_CHECK_RC_BREAK(RTTimerStart(pTimer, cNsSysHz * iTest), VINF_SUCCESS);
|
---|
552 | for (uint32_t i = 0; i < 1000 && (ASMAtomicUoReadU32(&State.cShots) < 1 || State.rc == VERR_IPE_UNINITIALIZED_STATUS); i++)
|
---|
553 | RTThreadSleep(5);
|
---|
554 | RTR0TESTR0_CHECK_MSG_BREAK(ASMAtomicReadU32(&State.cShots) == 1, ("cShots=%u\n", State.cShots));
|
---|
555 | RTR0TESTR0_CHECK_MSG_BREAK(State.rc == VINF_SUCCESS, ("rc=%Rrc\n", State.rc));
|
---|
556 | } while (0);
|
---|
557 | if (RT_FAILURE(State.rc))
|
---|
558 | RTR0TESTR0_CHECK_RC(RTTimerDestroy(pTimer), VINF_SUCCESS);
|
---|
559 | }
|
---|
560 | #else
|
---|
561 | RTR0TestR0Info("destroying from callback not supported on this platform\n");
|
---|
562 | RTR0TESTR0_SKIP();
|
---|
563 | #endif
|
---|
564 | break;
|
---|
565 | }
|
---|
566 |
|
---|
567 | case TSTRTR0TIMER_ONE_SHOT_SPECIFIC:
|
---|
568 | case TSTRTR0TIMER_ONE_SHOT_SPECIFIC_HIRES:
|
---|
569 | {
|
---|
570 | PRTTIMER pTimer = NULL;
|
---|
571 | RTCPUSET OnlineSet;
|
---|
572 | RTMpGetOnlineSet(&OnlineSet);
|
---|
573 | for (uint32_t iCpu = 0; iCpu < RTCPUSET_MAX_CPUS; iCpu++)
|
---|
574 | if (RTCpuSetIsMemberByIndex(&OnlineSet, iCpu))
|
---|
575 | {
|
---|
576 | RT_ZERO(State);
|
---|
577 | State.iActionShot = 0;
|
---|
578 | State.rc = VINF_SUCCESS;
|
---|
579 | State.u.Specific.idCpu = RTMpCpuIdFromSetIndex(iCpu);
|
---|
580 | ASMAtomicWriteU32(&State.cShots, State.cShots);
|
---|
581 |
|
---|
582 | uint32_t fFlags = TSTRTR0TIMER_IS_HIRES(uOperation) ? RTTIMER_FLAGS_HIGH_RES : 0;
|
---|
583 | fFlags |= RTTIMER_FLAGS_CPU(iCpu);
|
---|
584 | int rc = RTTimerCreateEx(&pTimer, 0, fFlags, tstRTR0TimerCallbackSpecific, &State);
|
---|
585 | if (rc == VERR_NOT_SUPPORTED)
|
---|
586 | {
|
---|
587 | RTR0TestR0Info("one-shot specific timer are not supported, skipping\n");
|
---|
588 | RTR0TESTR0_SKIP();
|
---|
589 | break;
|
---|
590 | }
|
---|
591 | RTR0TESTR0_CHECK_RC_BREAK(rc, VINF_SUCCESS);
|
---|
592 |
|
---|
593 | for (uint32_t i = 0; i < 5 && !RTR0TestR0HaveErrors(); i++)
|
---|
594 | {
|
---|
595 | ASMAtomicWriteU32(&State.cShots, 0);
|
---|
596 | RTR0TESTR0_CHECK_RC_BREAK(RTTimerStart(pTimer, (i & 2 ? cNsSysHz : cNsSysHz / 2) * (i & 1)), VINF_SUCCESS);
|
---|
597 | uint64_t cNsElapsed = RTTimeSystemNanoTS();
|
---|
598 | for (uint32_t j = 0; j < 1000 && ASMAtomicUoReadU32(&State.cShots) < 1; j++)
|
---|
599 | RTThreadSleep(5);
|
---|
600 | cNsElapsed = RTTimeSystemNanoTS() - cNsElapsed;
|
---|
601 | RTR0TESTR0_CHECK_MSG_BREAK(ASMAtomicReadU32(&State.cShots) == 1,
|
---|
602 | ("cShots=%u iCpu=%u i=%u iCurCpu=%u cNsElapsed=%'llu\n",
|
---|
603 | State.cShots, iCpu, i, RTMpCpuIdToSetIndex(RTMpCpuId()), cNsElapsed ));
|
---|
604 | RTR0TESTR0_CHECK_MSG_BREAK(State.rc == VINF_SUCCESS, ("rc=%Rrc\n", State.rc));
|
---|
605 | RTR0TESTR0_CHECK_MSG_BREAK(!State.u.Specific.fFailed, ("iCpu=%u i=%u\n", iCpu, i));
|
---|
606 | }
|
---|
607 |
|
---|
608 | RTR0TESTR0_CHECK_RC(RTTimerDestroy(pTimer), VINF_SUCCESS);
|
---|
609 | pTimer = NULL;
|
---|
610 | if (RTR0TestR0HaveErrors())
|
---|
611 | break;
|
---|
612 |
|
---|
613 | RTMpGetOnlineSet(&OnlineSet);
|
---|
614 | }
|
---|
615 | RTR0TESTR0_CHECK_RC(RTTimerDestroy(pTimer), VINF_SUCCESS);
|
---|
616 | break;
|
---|
617 | }
|
---|
618 |
|
---|
619 | case TSTRTR0TIMER_PERIODIC_BASIC:
|
---|
620 | case TSTRTR0TIMER_PERIODIC_BASIC_HIRES:
|
---|
621 | {
|
---|
622 | /* Create a periodic timer running at 10 HZ. */
|
---|
623 | uint32_t const u10HzAsNs = 100000000;
|
---|
624 | uint32_t const u10HzAsNsMin = u10HzAsNs - u10HzAsNs / 2;
|
---|
625 | uint32_t const u10HzAsNsMax = u10HzAsNs + u10HzAsNs / 2;
|
---|
626 | PRTTIMER pTimer;
|
---|
627 | uint32_t fFlags = TSTRTR0TIMER_IS_HIRES(uOperation) ? RTTIMER_FLAGS_HIGH_RES : 0;
|
---|
628 | RTR0TESTR0_CHECK_RC_BREAK(RTTimerCreateEx(&pTimer, u10HzAsNs, fFlags, tstRTR0TimerCallbackU32Counter, &State),
|
---|
629 | VINF_SUCCESS);
|
---|
630 |
|
---|
631 | for (uint32_t iTest = 0; iTest < 2; iTest++)
|
---|
632 | {
|
---|
633 | RT_ZERO(State);
|
---|
634 | State.fPeriodic = true;
|
---|
635 | ASMAtomicWriteU32(&State.cShots, State.cShots);
|
---|
636 |
|
---|
637 | uint64_t uStartNsTS = RTTimeSystemNanoTS();
|
---|
638 | RTR0TESTR0_CHECK_RC_BREAK(RTTimerStart(pTimer, u10HzAsNs), VINF_SUCCESS);
|
---|
639 | for (uint32_t i = 0; i < 1000 && ASMAtomicUoReadU32(&State.cShots) < 10; i++)
|
---|
640 | RTThreadSleep(10);
|
---|
641 | RTR0TESTR0_CHECK_RC_BREAK(RTTimerStop(pTimer), VINF_SUCCESS);
|
---|
642 | RTR0TESTR0_CHECK_MSG_BREAK(ASMAtomicUoReadU32(&State.cShots) == 10, ("cShots=%u\n", State.cShots));
|
---|
643 | if (tstRTR0TimerCheckShotIntervals(&State, uStartNsTS, u10HzAsNsMin, u10HzAsNsMax))
|
---|
644 | break;
|
---|
645 | RTThreadSleep(1); /** @todo RTTimerStop doesn't currently make sure the timer callback not is running
|
---|
646 | * before returning on windows, linux (low res) and possible other plaforms. */
|
---|
647 | }
|
---|
648 | RTR0TESTR0_CHECK_RC(RTTimerDestroy(pTimer), VINF_SUCCESS);
|
---|
649 | RTR0TESTR0_CHECK_RC(RTTimerDestroy(NULL), VINF_SUCCESS);
|
---|
650 | break;
|
---|
651 | }
|
---|
652 |
|
---|
653 | case TSTRTR0TIMER_PERIODIC_CSSD_LOOPS:
|
---|
654 | case TSTRTR0TIMER_PERIODIC_CSSD_LOOPS_HIRES:
|
---|
655 | {
|
---|
656 | /* create, start, stop & destroy high res timers a number of times. */
|
---|
657 | uint32_t fFlags = TSTRTR0TIMER_IS_HIRES(uOperation) ? RTTIMER_FLAGS_HIGH_RES : 0;
|
---|
658 | for (uint32_t i = 0; i < 40; i++)
|
---|
659 | {
|
---|
660 | PRTTIMER pTimer;
|
---|
661 | RTR0TESTR0_CHECK_RC_BREAK(RTTimerCreateEx(&pTimer, cNsSysHz, fFlags, tstRTR0TimerCallbackU32Counter, &State),
|
---|
662 | VINF_SUCCESS);
|
---|
663 | for (uint32_t j = 0; j < 10; j++)
|
---|
664 | {
|
---|
665 | RT_ZERO(State);
|
---|
666 | State.fPeriodic = true;
|
---|
667 | ASMAtomicWriteU32(&State.cShots, State.cShots); /* ordered, necessary? */
|
---|
668 |
|
---|
669 | RTR0TESTR0_CHECK_RC_BREAK(RTTimerStart(pTimer, i < 20 ? 0 : cNsSysHz), VINF_SUCCESS);
|
---|
670 | for (uint32_t k = 0; k < 1000 && ASMAtomicUoReadU32(&State.cShots) < 2; k++)
|
---|
671 | RTThreadSleep(1);
|
---|
672 | RTR0TESTR0_CHECK_RC_BREAK(RTTimerStop(pTimer), VINF_SUCCESS);
|
---|
673 | RTThreadSleep(1); /** @todo RTTimerStop doesn't currently make sure the timer callback not is running
|
---|
674 | * before returning on windows, linux (low res) and possible other plaforms. */
|
---|
675 | }
|
---|
676 | RTR0TESTR0_CHECK_RC(RTTimerDestroy(pTimer), VINF_SUCCESS);
|
---|
677 | }
|
---|
678 | break;
|
---|
679 | }
|
---|
680 |
|
---|
681 | case TSTRTR0TIMER_PERIODIC_CHANGE_INTERVAL:
|
---|
682 | case TSTRTR0TIMER_PERIODIC_CHANGE_INTERVAL_HIRES:
|
---|
683 | {
|
---|
684 | /* Initialize the test parameters, using the u64Arg value for selecting variations. */
|
---|
685 | RT_ZERO(State);
|
---|
686 | State.cShots = 0;
|
---|
687 | State.rc = VERR_IPE_UNINITIALIZED_STATUS;
|
---|
688 | State.iActionShot = 42;
|
---|
689 | State.fPeriodic = true;
|
---|
690 | State.u.ChgInt.fDirection = !!(u64Arg & 1);
|
---|
691 | if (uOperation == TSTRTR0TIMER_PERIODIC_CHANGE_INTERVAL_HIRES)
|
---|
692 | {
|
---|
693 | State.u.ChgInt.cNsMaxInterval = RT_MAX(cNsMaxHighResHz * 10, 20000000); /* 10x / 20 ms */
|
---|
694 | State.u.ChgInt.cNsMinInterval = RT_MAX(cNsMaxHighResHz, 10000); /* min / 10 us */
|
---|
695 | }
|
---|
696 | else
|
---|
697 | {
|
---|
698 | State.u.ChgInt.cNsMaxInterval = cNsSysHz * 4;
|
---|
699 | State.u.ChgInt.cNsMinInterval = cNsSysHz;
|
---|
700 | }
|
---|
701 | State.u.ChgInt.cNsChangeStep = (State.u.ChgInt.cNsMaxInterval - State.u.ChgInt.cNsMinInterval) / 10;
|
---|
702 | State.u.ChgInt.cNsCurInterval = State.u.ChgInt.fDirection
|
---|
703 | ? State.u.ChgInt.cNsMaxInterval : State.u.ChgInt.cNsMinInterval;
|
---|
704 | State.u.ChgInt.cStepsBetween = u64Arg & 4 ? 1 : 3;
|
---|
705 | RTR0TESTR0_CHECK_MSG_BREAK(State.u.ChgInt.cNsMinInterval > 1000, ("%u\n", State.u.ChgInt.cNsMinInterval));
|
---|
706 | 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));
|
---|
707 | ASMAtomicWriteU32(&State.cShots, State.cShots);
|
---|
708 |
|
---|
709 | /* create the timer and check if RTTimerChangeInterval is supported. */
|
---|
710 | PRTTIMER pTimer;
|
---|
711 | uint32_t fFlags = TSTRTR0TIMER_IS_HIRES(uOperation) ? RTTIMER_FLAGS_HIGH_RES : 0;
|
---|
712 | RTR0TESTR0_CHECK_RC_BREAK(RTTimerCreateEx(&pTimer, cNsSysHz, fFlags, tstRTR0TimerCallbackChangeInterval, &State),
|
---|
713 | VINF_SUCCESS);
|
---|
714 | int rc = RTTimerChangeInterval(pTimer, State.u.ChgInt.cNsMinInterval);
|
---|
715 | if (rc == VERR_NOT_SUPPORTED)
|
---|
716 | {
|
---|
717 | RTR0TestR0Info("RTTimerChangeInterval not supported, skipped");
|
---|
718 | RTR0TESTR0_CHECK_RC(RTTimerDestroy(pTimer), VINF_SUCCESS);
|
---|
719 | RTR0TESTR0_SKIP();
|
---|
720 | break;
|
---|
721 | }
|
---|
722 |
|
---|
723 | /* do the test. */
|
---|
724 | RTR0TESTR0_CHECK_RC_BREAK(RTTimerStart(pTimer, u64Arg & 2 ? State.u.ChgInt.cNsCurInterval : 0), VINF_SUCCESS);
|
---|
725 | for (uint32_t k = 0;
|
---|
726 | k < 1000
|
---|
727 | && ASMAtomicReadU32(&State.cShots) <= State.iActionShot
|
---|
728 | && State.rc == VERR_IPE_UNINITIALIZED_STATUS;
|
---|
729 | k++)
|
---|
730 | RTThreadSleep(10);
|
---|
731 |
|
---|
732 | rc = RTTimerStop(pTimer);
|
---|
733 | RTR0TESTR0_CHECK_MSG_BREAK(rc == VERR_TIMER_SUSPENDED || rc == VINF_SUCCESS, ("rc = %Rrc (RTTimerStop)\n", rc));
|
---|
734 | RTR0TESTR0_CHECK_RC(RTTimerDestroy(pTimer), VINF_SUCCESS);
|
---|
735 | break;
|
---|
736 | }
|
---|
737 |
|
---|
738 | case TSTRTR0TIMER_PERIODIC_SPECIFIC:
|
---|
739 | case TSTRTR0TIMER_PERIODIC_SPECIFIC_HIRES:
|
---|
740 | {
|
---|
741 | PRTTIMER pTimer = NULL;
|
---|
742 | RTCPUSET OnlineSet;
|
---|
743 | RTMpGetOnlineSet(&OnlineSet);
|
---|
744 | for (uint32_t iCpu = 0; iCpu < RTCPUSET_MAX_CPUS; iCpu++)
|
---|
745 | if (RTCpuSetIsMemberByIndex(&OnlineSet, iCpu))
|
---|
746 | {
|
---|
747 | RT_ZERO(State);
|
---|
748 | State.iActionShot = 0;
|
---|
749 | State.rc = VINF_SUCCESS;
|
---|
750 | State.fPeriodic = true;
|
---|
751 | State.u.Specific.idCpu = RTMpCpuIdFromSetIndex(iCpu);
|
---|
752 | ASMAtomicWriteU32(&State.cShots, State.cShots);
|
---|
753 |
|
---|
754 | uint32_t fFlags = TSTRTR0TIMER_IS_HIRES(uOperation) ? RTTIMER_FLAGS_HIGH_RES : 0;
|
---|
755 | fFlags |= RTTIMER_FLAGS_CPU(iCpu);
|
---|
756 | int rc = RTTimerCreateEx(&pTimer, cNsSysHz, fFlags, tstRTR0TimerCallbackSpecific, &State);
|
---|
757 | if (rc == VERR_NOT_SUPPORTED)
|
---|
758 | {
|
---|
759 | RTR0TestR0Info("specific timer are not supported, skipping\n");
|
---|
760 | RTR0TESTR0_SKIP();
|
---|
761 | break;
|
---|
762 | }
|
---|
763 | RTR0TESTR0_CHECK_RC_BREAK(rc, VINF_SUCCESS);
|
---|
764 |
|
---|
765 | for (uint32_t i = 0; i < 3 && !RTR0TestR0HaveErrors(); i++)
|
---|
766 | {
|
---|
767 | ASMAtomicWriteU32(&State.cShots, 0);
|
---|
768 | RTR0TESTR0_CHECK_RC_BREAK(RTTimerStart(pTimer, (i & 2 ? cNsSysHz : cNsSysHz / 2) * (i & 1)), VINF_SUCCESS);
|
---|
769 | uint64_t cNsElapsed = RTTimeSystemNanoTS();
|
---|
770 | for (uint32_t j = 0; j < 1000 && ASMAtomicUoReadU32(&State.cShots) < 8; j++)
|
---|
771 | RTThreadSleep(5);
|
---|
772 | cNsElapsed = RTTimeSystemNanoTS() - cNsElapsed;
|
---|
773 | RTR0TESTR0_CHECK_RC_BREAK(RTTimerStop(pTimer), VINF_SUCCESS);
|
---|
774 | RTR0TESTR0_CHECK_MSG_BREAK(ASMAtomicReadU32(&State.cShots) > 5,
|
---|
775 | ("cShots=%u iCpu=%u i=%u iCurCpu=%u cNsElapsed=%'llu\n",
|
---|
776 | State.cShots, iCpu, i, RTMpCpuIdToSetIndex(RTMpCpuId()), cNsElapsed));
|
---|
777 | RTThreadSleep(1); /** @todo RTTimerStop doesn't currently make sure the timer callback not is running
|
---|
778 | * before returning on windows, linux (low res) and possible other plaforms. */
|
---|
779 | RTR0TESTR0_CHECK_MSG_BREAK(State.rc == VINF_SUCCESS, ("rc=%Rrc\n", State.rc));
|
---|
780 | RTR0TESTR0_CHECK_MSG_BREAK(!State.u.Specific.fFailed, ("iCpu=%u i=%u\n", iCpu, i));
|
---|
781 | }
|
---|
782 |
|
---|
783 | RTR0TESTR0_CHECK_RC(RTTimerDestroy(pTimer), VINF_SUCCESS);
|
---|
784 | pTimer = NULL;
|
---|
785 | if (RTR0TestR0HaveErrors())
|
---|
786 | break;
|
---|
787 |
|
---|
788 | RTMpGetOnlineSet(&OnlineSet);
|
---|
789 | }
|
---|
790 | RTR0TESTR0_CHECK_RC(RTTimerDestroy(pTimer), VINF_SUCCESS);
|
---|
791 | break;
|
---|
792 | }
|
---|
793 |
|
---|
794 | case TSTRTR0TIMER_PERIODIC_OMNI:
|
---|
795 | case TSTRTR0TIMER_PERIODIC_OMNI_HIRES:
|
---|
796 | {
|
---|
797 | /* Create a periodic timer running at max host frequency, but no more than 1000 Hz. */
|
---|
798 | uint32_t cNsInterval = cNsSysHz;
|
---|
799 | while (cNsInterval < UINT32_C(1000000))
|
---|
800 | cNsInterval *= 2;
|
---|
801 | PTSTRTR0TIMEROMNI1 paStates = (PTSTRTR0TIMEROMNI1)RTMemAllocZ(sizeof(paStates[0]) * RTCPUSET_MAX_CPUS);
|
---|
802 | RTR0TESTR0_CHECK_MSG_BREAK(paStates, ("%d\n", RTCPUSET_MAX_CPUS));
|
---|
803 |
|
---|
804 | PRTTIMER pTimer;
|
---|
805 | uint32_t fFlags = (TSTRTR0TIMER_IS_HIRES(uOperation) ? RTTIMER_FLAGS_HIGH_RES : 0)
|
---|
806 | | RTTIMER_FLAGS_CPU_ALL;
|
---|
807 | int rc = RTTimerCreateEx(&pTimer, cNsInterval, fFlags, tstRTR0TimerCallbackOmni, paStates);
|
---|
808 | if (rc == VERR_NOT_SUPPORTED)
|
---|
809 | {
|
---|
810 | RTR0TESTR0_SKIP_BREAK();
|
---|
811 | }
|
---|
812 | RTR0TESTR0_CHECK_RC_BREAK(rc, VINF_SUCCESS);
|
---|
813 |
|
---|
814 | for (uint32_t iTest = 0; iTest < 3 && !RTR0TestR0HaveErrors(); iTest++)
|
---|
815 | {
|
---|
816 | /* reset the state */
|
---|
817 | for (uint32_t iCpu = 0; iCpu < RTCPUSET_MAX_CPUS; iCpu++)
|
---|
818 | {
|
---|
819 | paStates[iCpu].u64Start = 0;
|
---|
820 | paStates[iCpu].u64Last = 0;
|
---|
821 | ASMAtomicWriteU32(&paStates[iCpu].cTicks, 0);
|
---|
822 | }
|
---|
823 |
|
---|
824 | /* run it for 1 second. */
|
---|
825 | RTCPUSET OnlineSet;
|
---|
826 | uint64_t uStartNsTS = RTTimeSystemNanoTS();
|
---|
827 | RTR0TESTR0_CHECK_RC_BREAK(RTTimerStart(pTimer, 0), VINF_SUCCESS);
|
---|
828 | RTMpGetOnlineSet(&OnlineSet);
|
---|
829 |
|
---|
830 | for (uint32_t i = 0; i < 5000 && RTTimeSystemNanoTS() - uStartNsTS <= UINT32_C(1000000000); i++)
|
---|
831 | RTThreadSleep(2);
|
---|
832 |
|
---|
833 | RTR0TESTR0_CHECK_RC_BREAK(RTTimerStop(pTimer), VINF_SUCCESS);
|
---|
834 | uint64_t cNsElapsedX = RTTimeNanoTS() - uStartNsTS;
|
---|
835 |
|
---|
836 | /* Do a min/max on the start and stop times and calculate the test period. */
|
---|
837 | uint64_t u64MinStart = UINT64_MAX;
|
---|
838 | uint64_t u64MaxStop = 0;
|
---|
839 | for (uint32_t iCpu = 0; iCpu < RTCPUSET_MAX_CPUS; iCpu++)
|
---|
840 | {
|
---|
841 | if (paStates[iCpu].u64Start)
|
---|
842 | {
|
---|
843 | if (paStates[iCpu].u64Start < u64MinStart)
|
---|
844 | u64MinStart = paStates[iCpu].u64Start;
|
---|
845 | if (paStates[iCpu].u64Last > u64MaxStop)
|
---|
846 | u64MaxStop = paStates[iCpu].u64Last;
|
---|
847 | }
|
---|
848 | }
|
---|
849 | RTR0TESTR0_CHECK_MSG(u64MinStart < u64MaxStop, ("%llu, %llu", u64MinStart, u64MaxStop));
|
---|
850 | uint64_t cNsElapsed = u64MaxStop - u64MinStart;
|
---|
851 | RTR0TESTR0_CHECK_MSG(cNsElapsed <= cNsElapsedX + 100000, ("%llu, %llu", cNsElapsed, cNsElapsedX)); /* the fudge factor is time drift */
|
---|
852 | uint32_t cAvgTicks = cNsElapsed / cNsInterval + 1;
|
---|
853 |
|
---|
854 | /* Check tick counts. ASSUMES no cpu on- or offlining.
|
---|
855 | This only catches really bad stuff. */
|
---|
856 | uint32_t cMinTicks = cAvgTicks - cAvgTicks / 10;
|
---|
857 | uint32_t cMaxTicks = cAvgTicks + cAvgTicks / 10 + 1;
|
---|
858 | for (uint32_t iCpu = 0; iCpu < RTCPUSET_MAX_CPUS; iCpu++)
|
---|
859 | if (paStates[iCpu].cTicks)
|
---|
860 | {
|
---|
861 | RTR0TESTR0_CHECK_MSG(RTCpuSetIsMemberByIndex(&OnlineSet, iCpu), ("%d\n", iCpu));
|
---|
862 | RTR0TESTR0_CHECK_MSG(paStates[iCpu].cTicks <= cMaxTicks && paStates[iCpu].cTicks >= cMinTicks,
|
---|
863 | ("min=%u, ticks=%u, avg=%u max=%u, iCpu=%u, iCpuCurr=%u, interval=%'u, elapsed=%'llu/%'llu\n",
|
---|
864 | cMinTicks, paStates[iCpu].cTicks, cAvgTicks, cMaxTicks, iCpu,
|
---|
865 | RTMpCpuIdToSetIndex(RTMpCpuId()),
|
---|
866 | cNsInterval, cNsElapsed, cNsElapsedX));
|
---|
867 | }
|
---|
868 | else
|
---|
869 | RTR0TESTR0_CHECK_MSG(!RTCpuSetIsMemberByIndex(&OnlineSet, iCpu), ("%d\n", iCpu));
|
---|
870 | }
|
---|
871 |
|
---|
872 | RTR0TESTR0_CHECK_RC(RTTimerDestroy(pTimer), VINF_SUCCESS);
|
---|
873 | RTMemFree(paStates);
|
---|
874 | break;
|
---|
875 | }
|
---|
876 |
|
---|
877 | case TSTRTR0TIMER_LATENCY_OMNI:
|
---|
878 | case TSTRTR0TIMER_LATENCY_OMNI_HIRES:
|
---|
879 | {
|
---|
880 | /*
|
---|
881 | * Create a periodic timer running at max host frequency, but no more than 1000 Hz.
|
---|
882 | */
|
---|
883 | PRTTIMER pTimer;
|
---|
884 | uint32_t fFlags = (TSTRTR0TIMER_IS_HIRES(uOperation) ? RTTIMER_FLAGS_HIGH_RES : 0)
|
---|
885 | | RTTIMER_FLAGS_CPU_ALL;
|
---|
886 | uint32_t cNsInterval = cNsSysHz;
|
---|
887 | while (cNsInterval < UINT32_C(1000000))
|
---|
888 | cNsInterval *= 2;
|
---|
889 | int rc = RTTimerCreateEx(&pTimer, cNsInterval, fFlags, tstRTR0TimerCallbackLatencyOmni, NULL);
|
---|
890 | if (rc == VERR_NOT_SUPPORTED)
|
---|
891 | {
|
---|
892 | RTR0TESTR0_SKIP_BREAK();
|
---|
893 | }
|
---|
894 | RTR0TESTR0_CHECK_RC_BREAK(rc, VINF_SUCCESS);
|
---|
895 |
|
---|
896 | /*
|
---|
897 | * Reset the state and run the test for 4 seconds.
|
---|
898 | */
|
---|
899 | RT_ZERO(g_aOmniLatency);
|
---|
900 |
|
---|
901 | RTCPUSET OnlineSet;
|
---|
902 | uint64_t uStartNsTS = RTTimeSystemNanoTS();
|
---|
903 | RTR0TESTR0_CHECK_RC_BREAK(RTTimerStart(pTimer, 0), VINF_SUCCESS);
|
---|
904 | RTMpGetOnlineSet(&OnlineSet);
|
---|
905 |
|
---|
906 | for (uint32_t i = 0; i < 5000 && RTTimeSystemNanoTS() - uStartNsTS <= UINT64_C(4000000000); i++)
|
---|
907 | RTThreadSleep(2);
|
---|
908 |
|
---|
909 | RTR0TESTR0_CHECK_RC_BREAK(RTTimerStop(pTimer), VINF_SUCCESS);
|
---|
910 |
|
---|
911 | /*
|
---|
912 | * Process the result.
|
---|
913 | */
|
---|
914 | int32_t cNsLow = cNsInterval / 4 * 3; /* 75% */
|
---|
915 | int32_t cNsHigh = cNsInterval / 4 * 5; /* 125% */
|
---|
916 | uint32_t cTotal = 0;
|
---|
917 | uint32_t cLow = 0;
|
---|
918 | uint32_t cHigh = 0;
|
---|
919 | for (uint32_t iCpu = 0; iCpu < RT_ELEMENTS(g_aOmniLatency); iCpu++)
|
---|
920 | {
|
---|
921 | uint32_t cSamples = g_aOmniLatency[iCpu].cSamples;
|
---|
922 | if (cSamples > 1)
|
---|
923 | {
|
---|
924 | cTotal += cSamples - 1;
|
---|
925 | for (uint32_t iSample = 1; iSample < cSamples; iSample++)
|
---|
926 | {
|
---|
927 | int64_t cNsDelta = g_aOmniLatency[iCpu].aSamples[iSample - 1].uNanoTs
|
---|
928 | - g_aOmniLatency[iCpu].aSamples[iSample].uNanoTs;
|
---|
929 | if (cNsDelta < cNsLow)
|
---|
930 | cLow++;
|
---|
931 | else if (cNsDelta > cNsHigh)
|
---|
932 | cHigh++;
|
---|
933 | }
|
---|
934 | }
|
---|
935 | }
|
---|
936 | RTR0TestR0Info("125%%: %u; 75%%: %u; total: %u", cHigh, cLow, cTotal);
|
---|
937 | RTR0TESTR0_CHECK_RC(RTTimerDestroy(pTimer), VINF_SUCCESS);
|
---|
938 | break;
|
---|
939 | }
|
---|
940 |
|
---|
941 | }
|
---|
942 |
|
---|
943 | RTR0TESTR0_SRV_REQ_EPILOG(pReqHdr);
|
---|
944 | /* The error indicator is the '!' in the message buffer. */
|
---|
945 | return VINF_SUCCESS;
|
---|
946 | }
|
---|
947 |
|
---|