Merge commit '9276b3991ba20d5a5660887ba81b0bc7bed25a0c'
[unleashed.git] / share / man / man9f / ddi_periodic_add.9f
blob72b7430190a2b102e6989250711459945d149e71
1 '\" te
2 .\"  Copyright (c) 2009, Sun Microsystems, Inc. All Rights Reserved
3 .\" Copyright (c) 2017, 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 "May 04, 2017"
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>
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
20 .SH INTERFACE LEVEL
21 .LP
22 Solaris DDI specific (Solaris DDI)
23 .SH PARAMETERS
24 .ne 2
25 .na
26 \fB\fIfunc\fR\fR
27 .ad
28 .RS 12n
29 The callback function to be invoked periodically in the specified interval.
30 .RE
32 .sp
33 .ne 2
34 .na
35 \fB\fIarg\fR\fR
36 .ad
37 .RS 12n
38 The argument passed to the callback function.
39 .RE
41 .sp
42 .ne 2
43 .na
44 \fB\fIinterval\fR\fR
45 .ad
46 .RS 12n
47 The periodic interval time in nanoseconds.
48 .RE
50 .sp
51 .ne 2
52 .na
53 \fB\fIlevel\fR\fR
54 .ad
55 .RS 12n
56 The callback function is invoked at this priority level.  If the value of
57 \fIlevel\fR is zero, the callback function is invoked in kernel context.
58 If the value is greater than zero, but less than or equal to ten, the callback
59 function is invoked in interrupt context at the specified interrupt level,
60 which may be used for real time applications.
61 .sp
62 This value must be in range of 0-10, which can be either an integer literal, a
63 pre-defined macro (\fBDDI_IPL_0\fR, ... , \fBDDI_IPL_10\fR), or the
64 \fBDDI_INTR_PRI\fR macro with the interrupt priority.
65 .RE
67 .SH DESCRIPTION
68 .LP
69 The \fBddi_periodic_add()\fR function schedules the specified function to be
70 periodically invoked in the nanosecond interval time.
71 .sp
72 .LP
73 As with \fBtimeout\fR(9F), the exact time interval over which the function
74 takes effect cannot be guaranteed, but the value given is a close
75 approximation.  If the callback function has not finished execution when the
76 next interval expires, the system will skip running the callback for that
77 interval.
78 .SH RETURN VALUES
79 .LP
80 \fBddi_periodic_add()\fR returns the non-zero opaque value
81 (\fBddi_periodic_t\fR), which is later used to cancel the periodic request
82 with \fBddi_periodic_delete\fR(9F).
83 .SH CONTEXT
84 .LP
85 The \fBddi_periodic_add()\fR function may be called from user or kernel
86 context.
87 .SH EXAMPLES
88 .LP
89 \fBExample 1 \fRUsing \fBddi_periodic_add()\fR for a periodic callback function
90 .sp
91 .LP
92 In the following example, the device driver registers a periodic callback
93 function invoked in kernel context.
95 .sp
96 .in +2
97 .nf
98 static void
99 my_periodic_func(void *arg)
101          /*
102           * This handler is invoked periodically.
103           */
104          struct my_state *statep = (struct my_state *)arg;
106          mutex_enter(&statep->lock);
107          if (load_unbalanced(statep)) {
108                  balance_tasks(statep);
109          }
110          mutex_exit(&statep->lock);
113 static void
114 start_periodic_timer(struct my_state *statep)
116          hrtime_t interval = CHECK_INTERVAL;
118          mutex_init(&statep->lock, NULL, MUTEX_DRIVER, DDI_IPL_0);
120          /*
121           * Register my_callback which is invoked periodically
122           * in CHECK_INTERVAL in kernel context.
123           */
124           statep->periodic_id = ddi_periodic_add(my_periodic_func,
125               statep, interval, DDI_IPL_0);
127 .in -2
131 In the following example, the device driver registers a callback function
132 invoked in interrupt context at level 7.
134 .in +2
137  * This handler is invoked periodically in interrupt context.
138  */
139  static void
140  my_periodic_int7_func(void *arg)
142           struct my_state *statep = (struct my_state *)arg;
143           mutex_enter(&statep->lock);
144           monitor_device(statep);
145           mutex_exit(&statep->lock);
146   }
148   static void
149   start_monitor_device(struct my_state *statep)
150   {
151           hrtime_t interval = MONITOR_INTERVAL;
153           mutex_init(&statep->lock, NULL, MUTEX_DRIVER, DDI_IPL_7);
155           /*
156            * Register the callback function invoked periodically
157            * at interrupt level 7.
158            */
159           statep->periodic_id = ddi_periodic_add(my_periodic_int7_func,
160               statep, interval, DDI_IPL_7);
161     }
163 .in -2
165 .SH SEE ALSO
167 \fBcv_timedwait\fR(9F), \fBddi_intr_get_pri\fR(9F),
168 \fBddi_periodic_delete\fR(9F), \fBddi_intr_get_softint_pri\fR(9F),
169 \fBqtimeout\fR(9F), \fBquntimeout\fR(9F), \fBtimeout\fR(9F), \fBuntimeout\fR(9F)
170 .SH NOTES
172 The caller must specify \fIinterval\fR as an even, non-zero multiple of 10ms.
173 No other values are supported at this time. The interval specified is a lower
174 bound on the interval between executions of the callback.