Print this page
OS-2366 ddi_periodic_add(9F) is entirely rubbish
   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.
   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.