2 .\" Copyright (c) 2006 Sun Microsystems, Inc. All Rights Reserved.
3 .\" Copyright 1989 AT&T
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.
5 .\" 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.
6 .\" 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]
7 .TH TIMEOUT 9F "Jan 16, 2006"
9 timeout \- execute a function after a specified length of time
13 #include <sys/types.h>
18 \fBtimeout_id_t\fR \fBtimeout\fR(\fBvoid (\fR\fI* func\fR)(void \fI*\fR), \fBvoid\fR \fI*arg\fR,
19 \fBclock_t\fR \fIticks\fR);
25 Architecture independent level 1 (DDI/DKI).
33 Kernel function to invoke when the time increment expires.
42 Argument to the function.
51 Number of clock ticks to wait before the function is called. Use
52 \fBdrv_usectohz\fR(9F) to convert microseconds to clock ticks.
58 The \fBtimeout()\fR function schedules the specified function to be called
59 after a specified time interval. The exact time interval over which the timeout
60 takes effect cannot be guaranteed, but the value given is a close
64 The function called by \fBtimeout()\fR must adhere to the same restrictions as
65 a driver soft interrupt handler.
68 The \fBdelay\fR(9F) function calls \fBtimeout()\fR. Because \fBtimeout()\fR is
69 subject to priority inversion, drivers waiting on behalf of processes with
70 real-time constraints should use \fBcv_timedwait\fR(9F) rather than
75 The \fBtimeout()\fR function returns an opaque non-zero \fBtimeout\fR
76 identifier that can be passed to \fBuntimeout\fR(9F) to cancel the request.
80 The \fBtimeout()\fR function can be called from user, interrupt, or kernel
84 \fBExample 1 \fRUsing \fBtimeout()\fR
87 In the following example, the device driver has issued an IO request and is
88 waiting for the device to respond. If the device does not respond within 5
89 seconds, the device driver will print out an error message to the console.
95 xxtimeout_handler(void *arg)
97 struct xxstate *xsp = (struct xxstate *)arg;
98 mutex_enter(&xsp->lock);
100 xsp->flags |= TIMED_OUT;
101 mutex_exit(&xsp->lock);
107 struct xxstate *xsp = (struct xxstate *)arg;
111 mutex_enter(&xsp->lock);
112 /* Service interrupt */
114 mutex_exit(&xsp->lock);
115 if (xsp->timeout_id != 0) {
116 (void) untimeout(xsp->timeout_id);
119 return(DDI_INTR_CLAIMED);
122 xxcheckcond(struct xxstate *xsp)
127 xsp->timeout_id = timeout(xxtimeout_handler,
128 xsp, (5 * drv_usectohz(1000000)));
129 mutex_enter(&xsp->lock);
130 while (/* Waiting for interrupt or timeout*/)
131 cv_wait(&xsp->cv, &xsp->lock);
132 if (xsp->flags & TIMED_OUT)
133 cmn_err(CE_WARN, "Device not responding");
137 mutex_exit(&xsp->lock);
148 \fBbufcall\fR(9F), \fBcv_timedwait\fR(9F), \fBddi_in_panic\fR(9F),
149 \fBdelay\fR(9F), \fBdrv_usectohz\fR(9F), \fBuntimeout\fR(9F)
152 \fIWriting Device Drivers\fR