summaryrefslogtreecommitdiff
path: root/usr/src/man/man9f/ddi_periodic_add.9f
blob: d565e4abd3517d205813da324475f5c08cb0717b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
'\" te
.\"  Copyright (c) 2009, Sun Microsystems, Inc. All Rights Reserved
.\" Copyright (c) 2017, Joyent, Inc. All Rights Reserved.
.\" 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.
.\"  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
.\" the fields enclosed by brackets "[]" replaced with your own identifying information: Portions Copyright [yyyy] [name of copyright owner]
.TH DDI_PERIODIC_ADD 9F "May 04, 2017"
.SH NAME
ddi_periodic_add \- request periodic function invocation
.SH SYNOPSIS
.nf
#include <sys/dditypes.h>
#include <sys/sunddi.h>

\fBddi_periodic_t\fR \fBddi_periodic_add\fR(\fBvoid (*\fR\fIfunc\fR)(\fBvoid *)\fR, \fBvoid *\fR\fIarg\fR,
     \fBhrtime_t\fR \fIinterval\fR, \fBint\fR \fIlevel\fR);
.fi

.SH INTERFACE LEVEL
illumos DDI specific (illumos DDI)
.SH PARAMETERS
.ne 2
.na
\fB\fIfunc\fR\fR
.ad
.RS 12n
The callback function to be invoked periodically in the specified interval.
.RE

.sp
.ne 2
.na
\fB\fIarg\fR\fR
.ad
.RS 12n
The argument passed to the callback function.
.RE

.sp
.ne 2
.na
\fB\fIinterval\fR\fR
.ad
.RS 12n
The periodic interval time in nanoseconds.
.RE

.sp
.ne 2
.na
\fB\fIlevel\fR\fR
.ad
.RS 12n
The callback function is invoked at this priority level.  If the value of
\fIlevel\fR is zero, the callback function is invoked in kernel context.
If the value is greater than zero, but less than or equal to ten, the callback
function is invoked in interrupt context at the specified interrupt level,
which may be used for real time applications.
.sp
This value must be in range of 0-10, which can be either an integer literal, a
pre-defined macro (\fBDDI_IPL_0\fR, ... , \fBDDI_IPL_10\fR), or the
\fBDDI_INTR_PRI\fR macro with the interrupt priority.
.RE

.SH DESCRIPTION
The \fBddi_periodic_add()\fR function schedules the specified function to be
periodically invoked in the nanosecond interval time.
.sp
.LP
As with \fBtimeout\fR(9F), the exact time interval over which the function
takes effect cannot be guaranteed, but the value given is a close
approximation.  If the callback function has not finished execution when the
next interval expires, the system will skip running the callback for that
interval.
.SH RETURN VALUES
\fBddi_periodic_add()\fR returns the non-zero opaque value
(\fBddi_periodic_t\fR), which is later used to cancel the periodic request
with \fBddi_periodic_delete\fR(9F).
.SH CONTEXT
The \fBddi_periodic_add()\fR function may be called from user or kernel
context.
.SH EXAMPLES
\fBExample 1 \fRUsing \fBddi_periodic_add()\fR for a periodic callback function
.sp
.LP
In the following example, the device driver registers a periodic callback
function invoked in kernel context.

.sp
.in +2
.nf
static void
my_periodic_func(void *arg)
{
         /*
          * This handler is invoked periodically.
          */
         struct my_state *statep = (struct my_state *)arg;

         mutex_enter(&statep->lock);
         if (load_unbalanced(statep)) {
                 balance_tasks(statep);
         }
         mutex_exit(&statep->lock);
}

static void
start_periodic_timer(struct my_state *statep)
{
         hrtime_t interval = CHECK_INTERVAL;

         mutex_init(&statep->lock, NULL, MUTEX_DRIVER, DDI_IPL_0);

         /*
          * Register my_callback which is invoked periodically
          * in CHECK_INTERVAL in kernel context.
          */
          statep->periodic_id = ddi_periodic_add(my_periodic_func,
              statep, interval, DDI_IPL_0);
.fi
.in -2

.sp
.LP
In the following example, the device driver registers a callback function
invoked in interrupt context at level 7.
.sp
.in +2
.nf
/*
 * This handler is invoked periodically in interrupt context.
 */
 static void
 my_periodic_int7_func(void *arg)
 {
          struct my_state *statep = (struct my_state *)arg;
          mutex_enter(&statep->lock);
          monitor_device(statep);
          mutex_exit(&statep->lock);
  }

  static void
  start_monitor_device(struct my_state *statep)
  {
          hrtime_t interval = MONITOR_INTERVAL;

          mutex_init(&statep->lock, NULL, MUTEX_DRIVER, DDI_IPL_7);

          /*
           * Register the callback function invoked periodically
           * at interrupt level 7.
           */
          statep->periodic_id = ddi_periodic_add(my_periodic_int7_func,
              statep, interval, DDI_IPL_7);
    }
.fi
.in -2

.SH SEE ALSO
.BR cv_timedwait (9F),
.BR ddi_intr_get_pri (9F),
.BR ddi_intr_get_softint_pri (9F),
.BR ddi_periodic_delete (9F),
.BR qtimeout (9F),
.BR quntimeout (9F),
.BR timeout (9F),
.BR untimeout (9F)
.SH NOTES
The caller must specify \fIinterval\fR as an even, non-zero multiple of 10ms.
No other values are supported at this time. The interval specified is a lower
bound on the interval between executions of the callback.