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_DELETE 9F "May 6, 2009"
   7 .SH NAME
   8 ddi_periodic_delete \- cancel nanosecond periodic timeout requests
   9 .SH SYNOPSIS
  10 .LP
  11 .nf
  12 #include <sys/dditypes.h>
  13 #include <sys/sunddi.h>
  14 
  15 \fBvoid\fR \fBddi_periodic_delete\fR(\fBddi_periodic_t\fR \fIreq\fR\fB);\fR
  16 .fi
  17 
  18 .SH INTERFACE LEVEL
  19 .sp
  20 .LP
  21 Solaris DDI specific (Solaris DDI)
  22 .SH PARAMETERS
  23 .sp
  24 .ne 2
  25 .na
  26 \fB\fIreq\fR\fR
  27 .ad
  28 .RS 7n
  29 \fBddi_periodic_t\fR opaque value returned by \fBddi_periodic_add\fR(9F)
  30 .RE
  31 
  32 .SH DESCRIPTION
  33 .sp
  34 .LP
  35 The \fBddi_periodic_delete()\fR function cancels the \fBddi_periodic_add\fR(9F)
  36 request that was previously issued.
  37 .sp
  38 .LP
  39 As with \fBuntimeout\fR(9F), calling \fBddi_periodic_delete()\fR against a
  40 periodic \fItimeout\fR request which is either running on another CPU, or has
  41 already been canceled causes no problems. Unlike \fBuntimeout\fR(9F), there are
  42 no restrictions on the lock which might be held across the call to
  43 \fBddi_periodic_delete()\fR.
  44 .SH CONTEXT
  45 .sp
  46 .LP
  47 The \fBddi_periodic_delete()\fR function may be called from user or kernel
  48 context.
  49 .SH EXAMPLES
  50 .LP
  51 \fBExample 1 \fRCancelling a timeout request
  52 .sp
  53 .LP
  54 In the following example, the device driver cancels the \fItimeout\fR request
  55 by calling \fBddi_periodic_delete()\fR against the request that was previously
  56 issued.
  57 
  58 .sp
  59 .in +2
  60 .nf
  61 /*
  62 * Stop the periodic timer
  63 */
  64 static void
  65 stop_periodic_timer(struct my_state *statep)
  66 {
  67          ddi_periodic_delete(statep->periodic_id);
  68          delay(1); /* wait for one tick */
  69          mutex_destory(&statep->lock);
  70 }
  71 
  72 static void
  73 start_periodic_timer(struct my_state *statep)
  74 {
  75          hrtime_t interval = CHECK_INTERVAL;
  76 
  77          mutex_init(&statep->lock, NULL, MUTEX_DRIVER,
  78              (void *)DDI_IPL_0);
  79 
  80          /*
  81           * Register my_callback which is invoked periodically
  82           * in CHECK_INTERVAL in kernel context.
  83           */
  84          statep->periodic_id = ddi_periodic_add(my_periodic_func,
  85              statep, interval, DDI_IPL_0);
  86 }
  87 
  88 static void
  89 my_periodic_func(void *arg)
  90 {
  91            /*
  92             * This handler is invoked periodically.
  93             */
  94            struct my_state *statep = (struct my_state *)arg;
  95 
  96            mutex_enter(&statep->lock);
  97            if (load_unbalanced(statep)) {
  98                balance_tasks(statep);
  99            }
 100            mutex_exit(&statep->lock);
 101 }
 102 .fi
 103 .in -2
 104 
 105 .SH SEE ALSO
 106 .sp
 107 .LP
 108 \fBcv_timedwait\fR(9F), \fBddi_intr_get_pri\fR(9F), \fBddi_periodic_add\fR(9F),
 109 \fBdelay\fR(9F), \fBdrv_usectohz\fR(9F), \fBqtimeout\fR(9F),
 110 \fBquntimeout\fR(9F), \fBtimeout\fR(9F), \fBuntimeout\fR(9F)
 111 .SH NOTES
 112 .sp
 113 .LP
 114 There might be a race between a callback invocation and
 115 \fBddi_periodic_delete()\fR. A device driver should take a responsibility for
 116 this avoidance if needed by using the kernel synchronization such as a mutex
 117 lock or calling \fBdelay\fR(9F) as in the example above.