1ddi_periodic_add(9F) Kernel Functions for Drivers ddi_periodic_add(9F)
2
3
4
6 ddi_periodic_add - issue nanosecond periodic timeout requests
7
9 #include <sys/dditypes.h>
10 #include <sys/sunddi.h>
11
12 ddi_periodic_t ddi_periodic_add(void (*func)(void *), void arg,
13 hrtime_t interval, int level);
14
15
17 Solaris DDI specific (Solaris DDI)
18
20 func The callback function is invoked periodically in the speci‐
21 fied interval. If the argument level is zero, the function
22 is invoked in kernel context. Otherwise, it's invoked in
23 interrupt context at the specified level.
24
25
26 arg The argument passed to the callback function.
27
28
29 interval Interval time in nanoseconds.
30
31
32 level Callback interrupt level. If the value is zero, the call‐
33 back function is invoked in kernel context. If the value is
34 more than zero, but less than or equal to ten, the callback
35 function is invoked in interrupt context at the specified
36 interrupt level, which may be used for real time applica‐
37 tions.
38
39 This value must be in range of 0-10, which can be either a
40 numeric number, a pre-defined macro (DDI_IPL_0, ... ,
41 DDI_IPL_10), or the DDI_INTR_PRI macro with the interrupt
42 priority.
43
44
46 The ddi_periodic_add() function schedules the specified function to be
47 periodically invoked in the nanosecond interval time.
48
49
50 As with timeout(9F), the exact time interval over which the function
51 takes effect cannot be guaranteed, but the value given is a close
52 approximation.
53
55 ddi_periodic_add()returns the non-zero opaque value (ddi_periodic_t),
56 which might be used for ddi_periodic_delete(9F) to specify the request.
57
59 The ddi_periodic_add() function may be called from user or kernel con‐
60 text.
61
63 Example 1 Using ddi_periodic_add() for a periodic callback function
64
65
66 In the following example, the device driver registers a periodic call‐
67 back function invoked in kernel context.
68
69
70 static void
71 my_periodic_func(void *arg)
72 {
73 /*
74 * This handler is invoked periodically.
75 */
76 struct my_state *statep = (struct my_state *)arg;
77
78 mutex_enter(&statep->lock);
79 if (load_unbalanced(statep)) {
80 balance_tasks(statep);
81 }
82 mutex_exit(&statep->lock);
83 }
84
85 static void
86 start_periodic_timer(struct my_state *statep)
87 {
88 hrtime_t interval = CHECK_INTERVAL;
89
90 mutex_init(&statep->lock, NULL, MUTEX_DRIVER,
91 (void *)DDI_IPL_0);
92
93 /*
94 * Register my_callback which is invoked periodically
95 * in CHECK_INTERVAL in kernel context.
96 */
97 statep->periodic_id = ddi_periodic_add(my_periodic_func,
98 statep, interval, DDI_IPL_0);
99
100
101
102 In the following example, the device driver registers a callback func‐
103 tion invoked in interrupt context at level 7.
104
105 /*
106 * This handler is invoked periodically in interrupt context.
107 */
108 static void
109 my_periodic_int7_func(void *arg)
110 {
111 struct my_state *statep = (struct my_state *)arg;
112 mutex_enter(&statep->lock);
113 monitor_device(statep);
114 mutex_exit(&statep->lock);
115 }
116
117 static void
118 start_monitor_device(struct my_state *statep)
119 {
120 hrtime_t interval = MONITOR_INTERVAL;
121
122 mutex_init(&statep->lock, NULL, MUTEX_DRIVER,
123 (void *)DDI_IPL_7);
124
125 /*
126 * Register the callback function invoked periodically
127 * at interrupt level 7.
128 */
129 statep->periodic_id = ddi_periodic_add(my_periodic_int7_func,
130 statep, interval, DDI_IPL_7);
131 }
132
133
135 cv_timedwait(9F), ddi_intr_get_pri(9F), ddi_periodic_delete(9F),
136 ddi_intr_get_softint_pri(9F), delay(9F), drv_usectohz(9F), qtime‐
137 out(9F), quntimeout(9F), timeout(9F), untimeout(9F)
138
140 A caller can only specify an interval in an integral multiple of 10ms.
141 No other values are supported at this time. The interval specified is a
142 lower bound on the interval on which the callback occurs.
143
144
145
146SunOS 5.11 13 Apr 2009 ddi_periodic_add(9F)