|
|
#include <sys/types.h> #include <sys/clock.h> #include <sys/ddi.h>clock_t TICKS(void);
clock_t TICKS_SINCE(clock_t start_ticks);
clock_t TICKS_BETWEEN(clock_t start_ticks, clock_t end_ticks);
clock_t TICKS_FARPAST(void);
clock_t TICKS_FARFUTURE(void);
int TICKS_LATER(clock_t ticks1, clock_t ticks2);
The lbolt counter underlying TICKS( ), TICKS_FARPAST( ), and TICKS_FARFUTURE( ) is of finite size and will wrap around if the system stays up long enough. At any given moment, only times in the range:
[current_lbolt - CLOCK_MAX] through [current_lbolt + CLOCK_MAX]can be represented. See ``CLOCK_MAX'' in HDK Technical Reference. Assuming 100 ticks-per-second, this is a range of 497 days, 248 before and 248 after the current day. The representation is signed; these macros can return a value that is negative, zero, or positive.
The following macros compare lbolt values:
start_time = TICKS();Performance instrumentation code will often contain sequences such as:/* ...perform some device operation... */
if (TICKS_SINCE(start_time) > timeout_ticks) { /* operation took too long */ }
start_time = TICKS();TICKS_BETWEEN( ) is seen less often, and then usually to perform the same calculation as TICKS_SINCE( ) when the current lbolt value is already available from another source, as in:/* ...perform some device operation... */
/* see how long the operation took, in microseconds */ interval = drv_hztousec(TICKS_SINCE(start_time));
interval = drv_hztousec(TICKS_BETWEEN(start_time, current_lbolt));The comparison macro TICKS_LATER( ) is the only means for determining the relative vintage of two lbolt-based timestamps when a driver has no way of knowing which is earlier; it is rarely needed because such situations typically do not arise. As a matter of style, it is suggested that drivers avoid using TICKS_LATER( ) unnecessarily or introducing circumstances in which TICKS_LATER( ) must be used, such as:
/* DON'T DO THIS */ end_time = TICKS() + timeout_ticks;The same effect is better achieved using the first example above./* ...perform some device operation... */
if (TICKS_LATER(TICKS(), end_time)) { /* operation took too long */
The TICKS_FARPAST( ) and TICKS_FARFUTURE( ) macros are generally used to provide boundary values for algorithms involving TICKS_LATER( ), and are also rarely needed. Be aware that a TICKS_FARFUTURE( ) value ages over time and eventually falls back into the past. Similarly, a TICKS_FARPAST( ) value will eventually look like a future time as lbolt approaches it in circular fashion. TICKS_FARPAST( ) and TICKS_FARFUTURE( ) values obtained at widely-separated times may not appear to bear the expected relationship when compared using the TICKS_LATER( ) macro. For similar reasons, it is wise to avoid any situation where a timestamp value may linger in the system for long periods of time (on the order of months).
Do not use any value, including zero, to represent a special case when interpreting the return values of the TICKS( ), TICKS_FARPAST( ), and TICKS_FARFUTURE( ) macros, since they will periodically return that value if the system stays up indefinitely.
See ``lbolt'' in HDK Technical Reference for more details about pitfalls involved when doing arithmetic manipulations and comparisons of lbolt values.
``CLOCK_MAX'' in HDK Technical Reference
``lbolt'' in HDK Technical Reference