1drv_usectohz(9F) Kernel Functions for Drivers drv_usectohz(9F)
2
3
4
6 drv_usectohz - convert microseconds to clock ticks
7
9 #include <sys/types.h>
10 #include <sys/ddi.h>
11
12
13
14 clock_t drv_usectohz(clock_t microsecs);
15
16
18 Architecture independent level 1 (DDI/DKI).
19
21 microsecs The number of microseconds to convert.
22
23
25 The drv_usectohz() function converts a length of time expressed in
26 microseconds to a number of system clock ticks. The time arguments to
27 timeout(9F) and delay(9F) are expressed in clock ticks.
28
29
30 The drv_usectohz() function is a portable interface for drivers to make
31 calls to timeout(9F) and delay(9F) and remain binary compatible should
32 the driver object file be used on a system with a different clock speed
33 (a different number of ticks in a second).
34
36 The value returned is the number of system clock ticks equivalent to
37 the microsecs argument. No error value is returned. If the clock tick
38 equivalent to microsecs is too large to be represented as a clock_t,
39 then the maximum clock_t value will be returned.
40
42 The drv_usectohz() function can be called from user, interrupt, or ker‐
43 nel context.
44
46 delay(9F), drv_hztousec(9F), timeout(9F)
47
48
49 Writing Device Drivers
50
52 If the microsecs argument to drv_usectohz() is less than
53 drv_hztousec(9F), drv_usectohz() returns one tick. This, coupled with
54 multiplication, can result in significantly longer durations than
55 expected. For example, on a machine where hz is 100, calling drv_usec‐
56 tohz() with a microsecs value less than 10000 returns a result equiva‐
57 lent to 10000 (1 tick). This type of mistake causes code such as"5000 *
58 drv_usectohz(1000)" to compute a duration of 50 seconds instead of the
59 intended 5 seconds.
60
61
62
63SunOS 5.11 24 Apr 2008 drv_usectohz(9F)