Print this page
OS-2366 ddi_periodic_add(9F) is entirely rubbish

Split Close
Expand all
Collapse all
          --- old/usr/src/man/man9f/ddi_periodic_delete.9f
          +++ new/usr/src/man/man9f/ddi_periodic_delete.9f
   1    1  '\" te
        2 +.\" Copyright 2013, Joyent, Inc. All Rights Reserved.
   2    3  .\"  Copyright (c) 2009, Sun Microsystems, Inc. All Rights Reserved
   3    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.
   4    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
   5    6  .\" 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 +.TH DDI_PERIODIC_DELETE 9F "Jul 23, 2013"
   7    8  .SH NAME
   8      -ddi_periodic_delete \- cancel nanosecond periodic timeout requests
        9 +ddi_periodic_delete \- cancel periodic function invocation requests
   9   10  .SH SYNOPSIS
  10   11  .LP
  11   12  .nf
  12   13  #include <sys/dditypes.h>
  13   14  #include <sys/sunddi.h>
  14   15  
  15      -\fBvoid\fR \fBddi_periodic_delete\fR(\fBddi_periodic_t\fR \fIreq\fR\fB);\fR
       16 +\fBvoid\fR \fBddi_periodic_delete\fR(\fBddi_periodic_t\fR \fIrequest\fR\fB);\fR
  16   17  .fi
  17   18  
  18   19  .SH INTERFACE LEVEL
  19   20  .sp
  20   21  .LP
  21   22  Solaris DDI specific (Solaris DDI)
  22   23  .SH PARAMETERS
  23   24  .sp
  24   25  .ne 2
  25   26  .na
  26      -\fB\fIreq\fR\fR
       27 +\fB\fIrequest\fR\fR
  27   28  .ad
  28   29  .RS 7n
  29   30  \fBddi_periodic_t\fR opaque value returned by \fBddi_periodic_add\fR(9F)
  30   31  .RE
  31   32  
  32   33  .SH DESCRIPTION
  33   34  .sp
  34   35  .LP
  35      -The \fBddi_periodic_delete()\fR function cancels the \fBddi_periodic_add\fR(9F)
  36      -request that was previously issued.
       36 +The \fBddi_periodic_delete()\fR function cancels a periodic invocation request
       37 +previously established with \fBddi_periodic_add\fR(9F).
  37   38  .sp
  38   39  .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.
       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.
  44   50  .SH CONTEXT
  45   51  .sp
  46   52  .LP
  47   53  The \fBddi_periodic_delete()\fR function may be called from user or kernel
  48   54  context.
  49   55  .SH EXAMPLES
  50   56  .LP
  51      -\fBExample 1 \fRCancelling a timeout request
       57 +\fBExample 1 \fRCancelling a periodic invocation request
  52   58  .sp
  53   59  .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.
       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).
  57   63  
  58   64  .sp
  59   65  .in +2
  60   66  .nf
  61   67  /*
  62      -* Stop the periodic timer
  63      -*/
       68 + * Stop the periodic timer.
       69 + */
  64   70  static void
  65   71  stop_periodic_timer(struct my_state *statep)
  66   72  {
  67      -         ddi_periodic_delete(statep->periodic_id);
  68      -         delay(1); /* wait for one tick */
  69      -         mutex_destory(&statep->lock);
       73 +        ddi_periodic_delete(statep->periodic_id);
       74 +        mutex_destroy(&statep->lock);
  70   75  }
  71   76  
  72   77  static void
  73   78  start_periodic_timer(struct my_state *statep)
  74   79  {
  75      -         hrtime_t interval = CHECK_INTERVAL;
       80 +        hrtime_t interval = CHECK_INTERVAL;
  76   81  
  77      -         mutex_init(&statep->lock, NULL, MUTEX_DRIVER,
  78      -             (void *)DDI_IPL_0);
       82 +        mutex_init(&statep->lock, NULL, MUTEX_DRIVER, DDI_IPL_0);
  79   83  
  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);
       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);
  86   90  }
  87   91  
  88   92  static void
  89   93  my_periodic_func(void *arg)
  90   94  {
  91      -           /*
  92      -            * This handler is invoked periodically.
  93      -            */
  94      -           struct my_state *statep = (struct my_state *)arg;
       95 +        /*
       96 +         * This handler is invoked periodically.
       97 +         */
       98 +        struct my_state *statep = (struct my_state *)arg;
  95   99  
  96      -           mutex_enter(&statep->lock);
  97      -           if (load_unbalanced(statep)) {
  98      -               balance_tasks(statep);
  99      -           }
 100      -           mutex_exit(&statep->lock);
      100 +        mutex_enter(&statep->lock);
      101 +        if (load_unbalanced(statep)) {
      102 +                balance_tasks(statep);
      103 +        }
      104 +        mutex_exit(&statep->lock);
 101  105  }
 102  106  .fi
 103  107  .in -2
 104  108  
 105  109  .SH SEE ALSO
 106  110  .sp
 107  111  .LP
 108  112  \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)
      113 +\fBqtimeout\fR(9F), \fBquntimeout\fR(9F), \fBtimeout\fR(9F), \fBuntimeout\fR(9F)
 111  114  .SH NOTES
 112  115  .sp
 113  116  .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.
      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.
    
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX