1 '\" te
   2 .\" Copyright 2013, Joyent, Inc. All Rights Reserved.
   3 .\"  Copyright (c) 2009, Sun Microsystems, 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_DELETE 9F "Jul 23, 2013"
   8 .SH NAME
   9 ddi_periodic_delete \- cancel periodic function invocation requests
  10 .SH SYNOPSIS
  11 .LP
  12 .nf
  13 #include <sys/dditypes.h>
  14 #include <sys/sunddi.h>
  15 
  16 \fBvoid\fR \fBddi_periodic_delete\fR(\fBddi_periodic_t\fR \fIrequest\fR\fB);\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\fIrequest\fR\fR
  28 .ad
  29 .RS 7n
  30 \fBddi_periodic_t\fR opaque value returned by \fBddi_periodic_add\fR(9F)
  31 .RE
  32 
  33 .SH DESCRIPTION
  34 .sp
  35 .LP
  36 The \fBddi_periodic_delete()\fR function cancels a periodic invocation request
  37 previously established with \fBddi_periodic_add\fR(9F).
  38 .sp
  39 .LP
  40 It is not possible to cancel a periodic invocation request from within the
  41 periodic callback itself; to do so is a programming error that will panic the
  42 system.  Instead, requests must be cancelled from some other user or kernel
  43 context routine, such as the \fBdetach\fR(9E) entry point of a module.
  44 .sp
  45 .LP
  46 If the callback function is already executing (for instance, on another CPU)
  47 when the request is cancelled, \fBddi_periodic_delete()\fR will block until
  48 it finishes executing and is completely unregistered.  The callback will not
  49 be invoked again after the call to \fBddi_periodic_delete()\fR returns.
  50 .SH CONTEXT
  51 .sp
  52 .LP
  53 The \fBddi_periodic_delete()\fR function may be called from user or kernel
  54 context.
  55 .SH EXAMPLES
  56 .LP
  57 \fBExample 1 \fRCancelling a periodic invocation request
  58 .sp
  59 .LP
  60 In the following example, the device driver cancels the request
  61 by calling \fBddi_periodic_delete()\fR and passing the opaque \fIrequest\fR
  62 identifier returned by a previous call to \fBddi_periodic_add\fR(9F).
  63 
  64 .sp
  65 .in +2
  66 .nf
  67 /*
  68  * Stop the periodic timer.
  69  */
  70 static void
  71 stop_periodic_timer(struct my_state *statep)
  72 {
  73         ddi_periodic_delete(statep->periodic_id);
  74         mutex_destroy(&statep->lock);
  75 }
  76 
  77 static void
  78 start_periodic_timer(struct my_state *statep)
  79 {
  80         hrtime_t interval = CHECK_INTERVAL;
  81 
  82         mutex_init(&statep->lock, NULL, MUTEX_DRIVER, DDI_IPL_0);
  83 
  84         /*
  85          * Register my_callback which is invoked periodically
  86          * in CHECK_INTERVAL in kernel context.
  87          */
  88         statep->periodic_id = ddi_periodic_add(my_periodic_func,
  89             statep, interval, DDI_IPL_0);
  90 }
  91 
  92 static void
  93 my_periodic_func(void *arg)
  94 {
  95         /*
  96          * This handler is invoked periodically.
  97          */
  98         struct my_state *statep = (struct my_state *)arg;
  99 
 100         mutex_enter(&statep->lock);
 101         if (load_unbalanced(statep)) {
 102                 balance_tasks(statep);
 103         }
 104         mutex_exit(&statep->lock);
 105 }
 106 .fi
 107 .in -2
 108 
 109 .SH SEE ALSO
 110 .sp
 111 .LP
 112 \fBcv_timedwait\fR(9F), \fBddi_intr_get_pri\fR(9F), \fBddi_periodic_add\fR(9F),
 113 \fBqtimeout\fR(9F), \fBquntimeout\fR(9F), \fBtimeout\fR(9F), \fBuntimeout\fR(9F)
 114 .SH NOTES
 115 .sp
 116 .LP
 117 Historically this interface was advertised as safe for use from within the
 118 periodic callback function.  In order to ensure the correct operation of the
 119 system, and as reflected in the documentation above, this unlikely (and
 120 unsafe) usage pattern is no longer allowed.