1delay(9F)                Kernel Functions for Drivers                delay(9F)
2
3
4

NAME

6       delay - delay execution for a specified number of clock ticks
7

SYNOPSIS

9       #include <sys/ddi.h>
10
11
12
13       void delay(clock_t ticks);
14
15

INTERFACE LEVEL

17       Architecture independent level 1 (DDI/DKI).
18

PARAMETERS

20       ticks     The number of clock cycles to delay.
21
22

DESCRIPTION

24       delay()  provides a mechanism for a driver to delay its execution for a
25       given period of time. Since the speed of the clock  varies  among  sys‐
26       tems,  drivers  should  base  their time values on microseconds and use
27       drv_usectohz(9F) to convert microseconds into clock ticks.
28
29
30       delay() uses timeout(9F) to schedule an internal function to be  called
31       after  the  specified  amount  of  time has elapsed. delay() then waits
32       until the function is called. Because timeout() is subject to  priority
33       inversion,  drivers  waiting on behalf of processes with real-time con‐
34       straints should use cv_timedwait(9F) rather than delay().
35
36
37       delay()  does  not  busy-wait.  If  busy-waiting   is   required,   use
38       drv_usecwait(9F).
39

CONTEXT

41       delay() can be called from user and kernel contexts.
42

EXAMPLES

44       Example 1 delay() Example
45
46
47       Before  a driver I/O routine allocates buffers and stores any user data
48       in them, it checks the status of the device (line 12).  If  the  device
49       needs manual intervention (such as, needing to be refilled with paper),
50       a message is displayed on the system  console  (line  14).  The  driver
51       waits an allotted time (line 17) before repeating the procedure.
52
53
54          1  struct  device  {    /* layout of physical device registers */
55          2          int      control; /* physical device control word */
56          3          int      status;  /* physical device status word */
57          4          short    xmit_char;    /* transmit character to device */
58          5  };
59          6
60          7
61                . . .
62          9   /* get device registers  */
63         10      register struct device *rp = ...
64         11
65         12      while (rp->status & NOPAPER) {  /* while printer is out of paper */
66         13       /* display message and ring bell */
67                  /* on system console */
68         14          cmn_err(CE_WARN, "^\007",
69         15                            (getminor(dev) & 0xf));
70         16          /* wait one minute and try again */
71         17          delay(60 * drv_usectohz(1000000));
72         18      }
73
74

SEE ALSO

76       biodone(9F),     biowait(9F),    cv_timedwait(9F),    ddi_in_panic(9F),
77       drv_hztousec(9F),  drv_usectohz(9F),   drv_usecwait(9F),   timeout(9F),
78       untimeout(9F)
79
80
81       Writing Device Drivers
82
83
84
85SunOS 5.11                        15 Oct 2001                        delay(9F)
Impressum