1 '\" te
2 .\" Copyright (c) 2009, Sun Microsystems, Inc. All Rights Reserved
3 .\" The contents of this file are subject to the terms of the Common Development and Distribution License (the "License"). You may not use this file except in compliance with the License. You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE or http://www.opensolaris.org/os/licensing.
4 .\" See the License for the specific language governing permissions and limitations under the License. When distributing Covered Code, include this CDDL HEADER in each file and include the License file at usr/src/OPENSOLARIS.LICENSE. If applicable, add the following below this CDDL HEADER, with
5 .\" the fields enclosed by brackets "[]" replaced with your own identifying information: Portions Copyright [yyyy] [name of copyright owner]
6 .TH DDI_PERIODIC_ADD 9F "Apr 13, 2009"
7 .SH NAME
8 ddi_periodic_add \- issue nanosecond periodic timeout requests
9 .SH SYNOPSIS
10 .LP
11 .nf
12 #include <sys/dditypes.h>
13 #include <sys/sunddi.h>
14
15 \fBddi_periodic_t\fR \fBddi_periodic_add\fR(\fBvoid (*\fR\fIfunc\fR)(\fBvoid *)\fR, \fBvoid\fR \fIarg\fR,
16 \fBhrtime_t\fR \fIinterval\fR, \fBint\fR \fIlevel\fR);
17 .fi
18
19 .SH INTERFACE LEVEL
20 .sp
21 .LP
22 Solaris DDI specific (Solaris DDI)
23 .SH PARAMETERS
24 .sp
25 .ne 2
26 .na
27 \fB\fIfunc\fR\fR
28 .ad
29 .RS 12n
30 The callback function is invoked periodically in the specified interval. If the
31 argument level is zero, the function is invoked in kernel context. Otherwise,
32 it's invoked in interrupt context at the specified level.
33 .RE
34
35 .sp
36 .ne 2
37 .na
38 \fB\fIarg\fR\fR
39 .ad
40 .RS 12n
41 The argument passed to the callback function.
42 .RE
43
44 .sp
45 .ne 2
46 .na
47 \fB\fIinterval\fR\fR
48 .ad
49 .RS 12n
50 Interval time in nanoseconds.
51 .RE
52
53 .sp
54 .ne 2
55 .na
56 \fB\fIlevel\fR\fR
57 .ad
58 .RS 12n
59 Callback interrupt level. If the value is zero, the callback function is
60 invoked in kernel context. If the value is more than zero, but less than or
61 equal to ten, the callback function is invoked in interrupt context at the
62 specified interrupt level, which may be used for real time applications.
63 .sp
64 This value must be in range of 0-10, which can be either a numeric number, a
65 pre-defined macro (\fBDDI_IPL_0\fR, ... , \fBDDI_IPL_10\fR), or the
66 \fBDDI_INTR_PRI\fR macro with the interrupt priority.
67 .RE
68
69 .SH DESCRIPTION
70 .sp
71 .LP
72 The \fBddi_periodic_add()\fR function schedules the specified function to be
73 periodically invoked in the nanosecond interval time.
74 .sp
75 .LP
76 As with \fBtimeout\fR(9F), the exact time interval over which the function
77 takes effect cannot be guaranteed, but the value given is a close
78 approximation.
79 .SH RETURN VALUES
80 .sp
81 .LP
82 \fBddi_periodic_add()\fRreturns the non-zero opaque value
83 (\fBddi_periodic_t\fR), which might be used for \fBddi_periodic_delete\fR(9F)
84 to specify the request.
85 .SH CONTEXT
86 .sp
87 .LP
88 The \fBddi_periodic_add()\fR function may be called from user or kernel
89 context.
90 .SH EXAMPLES
91 .LP
92 \fBExample 1 \fRUsing \fBddi_periodic_add()\fR for a periodic callback function
93 .sp
94 .LP
95 In the following example, the device driver registers a periodic callback
96 function invoked in kernel context.
97
98 .sp
99 .in +2
100 .nf
101 static void
102 my_periodic_func(void *arg)
103 {
104 /*
105 * This handler is invoked periodically.
106 */
107 struct my_state *statep = (struct my_state *)arg;
108
109 mutex_enter(&statep->lock);
110 if (load_unbalanced(statep)) {
111 balance_tasks(statep);
112 }
113 mutex_exit(&statep->lock);
114 }
115
116 static void
117 start_periodic_timer(struct my_state *statep)
118 {
119 hrtime_t interval = CHECK_INTERVAL;
120
121 mutex_init(&statep->lock, NULL, MUTEX_DRIVER,
122 (void *)DDI_IPL_0);
123
124 /*
125 * Register my_callback which is invoked periodically
126 * in CHECK_INTERVAL in kernel context.
127 */
128 statep->periodic_id = ddi_periodic_add(my_periodic_func,
129 statep, interval, DDI_IPL_0);
130 .fi
131 .in -2
132
133 .sp
134 .LP
135 In the following example, the device driver registers a callback function
136 invoked in interrupt context at level 7.
137 .sp
138 .in +2
139 .nf
140 /*
141 * This handler is invoked periodically in interrupt context.
142 */
143 static void
144 my_periodic_int7_func(void *arg)
145 {
146 struct my_state *statep = (struct my_state *)arg;
147 mutex_enter(&statep->lock);
148 monitor_device(statep);
149 mutex_exit(&statep->lock);
150 }
151
152 static void
153 start_monitor_device(struct my_state *statep)
154 {
155 hrtime_t interval = MONITOR_INTERVAL;
156
157 mutex_init(&statep->lock, NULL, MUTEX_DRIVER,
158 (void *)DDI_IPL_7);
159
160 /*
161 * Register the callback function invoked periodically
162 * at interrupt level 7.
163 */
164 statep->periodic_id = ddi_periodic_add(my_periodic_int7_func,
165 statep, interval, DDI_IPL_7);
166 }
167 .fi
168 .in -2
169
170 .SH SEE ALSO
171 .sp
172 .LP
173 \fBcv_timedwait\fR(9F), \fBddi_intr_get_pri\fR(9F),
174 \fBddi_periodic_delete\fR(9F), \fBddi_intr_get_softint_pri\fR(9F),
175 \fBdelay\fR(9F), \fBdrv_usectohz\fR(9F), \fBqtimeout\fR(9F),
176 \fBquntimeout\fR(9F), \fBtimeout\fR(9F), \fBuntimeout\fR(9F)
177 .SH NOTES
178 .sp
179 .LP
180 A caller can only specify an interval in an integral multiple of 10ms. No other
181 values are supported at this time. The interval specified is a lower bound on
182 the interval on which the callback occurs.
|
1 '\" te
2 .\" Copyright (c) 2009, Sun Microsystems, Inc. All Rights Reserved
3 .\" Copyright 2013, Joyent, Inc. All Rights Reserved.
4 .\" The contents of this file are subject to the terms of the Common Development and Distribution License (the "License"). You may not use this file except in compliance with the License. You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE or http://www.opensolaris.org/os/licensing.
5 .\" See the License for the specific language governing permissions and limitations under the License. When distributing Covered Code, include this CDDL HEADER in each file and include the License file at usr/src/OPENSOLARIS.LICENSE. If applicable, add the following below this CDDL HEADER, with
6 .\" the fields enclosed by brackets "[]" replaced with your own identifying information: Portions Copyright [yyyy] [name of copyright owner]
7 .TH DDI_PERIODIC_ADD 9F "Jul 23, 2013"
8 .SH NAME
9 ddi_periodic_add \- request periodic function invocation
10 .SH SYNOPSIS
11 .LP
12 .nf
13 #include <sys/dditypes.h>
14 #include <sys/sunddi.h>
15
16 \fBddi_periodic_t\fR \fBddi_periodic_add\fR(\fBvoid (*\fR\fIfunc\fR)(\fBvoid *)\fR, \fBvoid\fR \fIarg\fR,
17 \fBhrtime_t\fR \fIinterval\fR, \fBint\fR \fIlevel\fR);
18 .fi
19
20 .SH INTERFACE LEVEL
21 .sp
22 .LP
23 Solaris DDI specific (Solaris DDI)
24 .SH PARAMETERS
25 .sp
26 .ne 2
27 .na
28 \fB\fIfunc\fR\fR
29 .ad
30 .RS 12n
31 The callback function to be invoked periodically in the specified interval.
32 .RE
33
34 .sp
35 .ne 2
36 .na
37 \fB\fIarg\fR\fR
38 .ad
39 .RS 12n
40 The argument passed to the callback function.
41 .RE
42
43 .sp
44 .ne 2
45 .na
46 \fB\fIinterval\fR\fR
47 .ad
48 .RS 12n
49 The periodic interval time in nanoseconds.
50 .RE
51
52 .sp
53 .ne 2
54 .na
55 \fB\fIlevel\fR\fR
56 .ad
57 .RS 12n
58 The callback function is invoked at this priority level. If the value of
59 \fIlevel\fR is zero, the callback function is invoked in kernel context.
60 If the value is greater than zero, but less than or equal to ten, the callback
61 function is invoked in interrupt context at the specified interrupt level,
62 which may be used for real time applications.
63 .sp
64 This value must be in range of 0-10, which can be either an integer literal, a
65 pre-defined macro (\fBDDI_IPL_0\fR, ... , \fBDDI_IPL_10\fR), or the
66 \fBDDI_INTR_PRI\fR macro with the interrupt priority.
67 .RE
68
69 .SH DESCRIPTION
70 .sp
71 .LP
72 The \fBddi_periodic_add()\fR function schedules the specified function to be
73 periodically invoked in the nanosecond interval time.
74 .sp
75 .LP
76 As with \fBtimeout\fR(9F), the exact time interval over which the function
77 takes effect cannot be guaranteed, but the value given is a close
78 approximation. If the callback function has not finished execution when the
79 next interval expires, the system will skip running the callback for that
80 interval.
81 .SH RETURN VALUES
82 .sp
83 .LP
84 \fBddi_periodic_add()\fR returns the non-zero opaque value
85 (\fBddi_periodic_t\fR), which is later used to cancel the periodic request
86 with \fBddi_periodic_delete\fR(9F).
87 .SH CONTEXT
88 .sp
89 .LP
90 The \fBddi_periodic_add()\fR function may be called from user or kernel
91 context.
92 .SH EXAMPLES
93 .LP
94 \fBExample 1 \fRUsing \fBddi_periodic_add()\fR for a periodic callback function
95 .sp
96 .LP
97 In the following example, the device driver registers a periodic callback
98 function invoked in kernel context.
99
100 .sp
101 .in +2
102 .nf
103 static void
104 my_periodic_func(void *arg)
105 {
106 /*
107 * This handler is invoked periodically.
108 */
109 struct my_state *statep = (struct my_state *)arg;
110
111 mutex_enter(&statep->lock);
112 if (load_unbalanced(statep)) {
113 balance_tasks(statep);
114 }
115 mutex_exit(&statep->lock);
116 }
117
118 static void
119 start_periodic_timer(struct my_state *statep)
120 {
121 hrtime_t interval = CHECK_INTERVAL;
122
123 mutex_init(&statep->lock, NULL, MUTEX_DRIVER, DDI_IPL_0);
124
125 /*
126 * Register my_callback which is invoked periodically
127 * in CHECK_INTERVAL in kernel context.
128 */
129 statep->periodic_id = ddi_periodic_add(my_periodic_func,
130 statep, interval, DDI_IPL_0);
131 .fi
132 .in -2
133
134 .sp
135 .LP
136 In the following example, the device driver registers a callback function
137 invoked in interrupt context at level 7.
138 .sp
139 .in +2
140 .nf
141 /*
142 * This handler is invoked periodically in interrupt context.
143 */
144 static void
145 my_periodic_int7_func(void *arg)
146 {
147 struct my_state *statep = (struct my_state *)arg;
148 mutex_enter(&statep->lock);
149 monitor_device(statep);
150 mutex_exit(&statep->lock);
151 }
152
153 static void
154 start_monitor_device(struct my_state *statep)
155 {
156 hrtime_t interval = MONITOR_INTERVAL;
157
158 mutex_init(&statep->lock, NULL, MUTEX_DRIVER, DDI_IPL_7);
159
160 /*
161 * Register the callback function invoked periodically
162 * at interrupt level 7.
163 */
164 statep->periodic_id = ddi_periodic_add(my_periodic_int7_func,
165 statep, interval, DDI_IPL_7);
166 }
167 .fi
168 .in -2
169
170 .SH SEE ALSO
171 .sp
172 .LP
173 \fBcv_timedwait\fR(9F), \fBddi_intr_get_pri\fR(9F),
174 \fBddi_periodic_delete\fR(9F), \fBddi_intr_get_softint_pri\fR(9F),
175 \fBqtimeout\fR(9F), \fBquntimeout\fR(9F), \fBtimeout\fR(9F), \fBuntimeout\fR(9F)
176 .SH NOTES
177 .sp
178 .LP
179 The caller must specify \fIinterval\fR as an even, non-zero multiple of 10ms.
180 No other values are supported at this time. The interval specified is a lower
181 bound on the interval between executions of the callback.
|