The Design and Implementation of the FreeBSD Operating System, Second Edition
Now available: The Design and Implementation of the FreeBSD Operating System (Second Edition)


[ source navigation ] [ diff markup ] [ identifier search ] [ freetext search ] [ file search ] [ list types ] [ track identifier ]

FreeBSD/Linux Kernel Cross Reference
sys/kern/mach_timer.h

Version: -  FREEBSD  -  FREEBSD-13-STABLE  -  FREEBSD-13-0  -  FREEBSD-12-STABLE  -  FREEBSD-12-0  -  FREEBSD-11-STABLE  -  FREEBSD-11-0  -  FREEBSD-10-STABLE  -  FREEBSD-10-0  -  FREEBSD-9-STABLE  -  FREEBSD-9-0  -  FREEBSD-8-STABLE  -  FREEBSD-8-0  -  FREEBSD-7-STABLE  -  FREEBSD-7-0  -  FREEBSD-6-STABLE  -  FREEBSD-6-0  -  FREEBSD-5-STABLE  -  FREEBSD-5-0  -  FREEBSD-4-STABLE  -  FREEBSD-3-STABLE  -  FREEBSD22  -  l41  -  OPENBSD  -  linux-2.6  -  MK84  -  PLAN9  -  xnu-8792 
SearchContext: -  none  -  3  -  10 

    1 /* 
    2  * Mach Operating System
    3  * Copyright (c) 1993,1992 Carnegie Mellon University
    4  * All Rights Reserved.
    5  * 
    6  * Permission to use, copy, modify and distribute this software and its
    7  * documentation is hereby granted, provided that both the copyright
    8  * notice and this permission notice appear in all copies of the
    9  * software, derivative works or modified versions, and any portions
   10  * thereof, and that both notices appear in supporting documentation.
   11  * 
   12  * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
   13  * CONDITION.  CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
   14  * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
   15  * 
   16  * Carnegie Mellon requests users of this software to return to
   17  * 
   18  *  Software Distribution Coordinator  or  Software.Distribution@CS.CMU.EDU
   19  *  School of Computer Science
   20  *  Carnegie Mellon University
   21  *  Pittsburgh PA 15213-3890
   22  * 
   23  * any improvements or extensions that they make and grant Carnegie Mellon
   24  * the rights to redistribute these changes.
   25  */
   26 /*
   27  * HISTORY
   28  * $Log:        mach_timer.h,v $
   29  * Revision 2.2  93/11/17  17:16:14  dbg
   30  *      Changed timer_arm_internal to timer_sleep_periodic.
   31  *      Added BUSY bit to show that timer is either enqueued
   32  *      or in timeout routine.
   33  *      [93/07/15            dbg]
   34  * 
   35  *      Return actual wakeup time for timer_sleep.
   36  *      [93/07/13            dbg]
   37  * 
   38  *      Added timer_start_time.
   39  *      [93/07/01            dbg]
   40  * 
   41  *      Changed timer_ipc_lock to timer_lock, timer_lock to
   42  *      timer_ref_lock.  Added mach_timer_thread_reference,
   43  *      mach_timer_thread_deallocate, so that a timer that is
   44  *      in use by a thread will remain even if all send rights
   45  *      vanish.
   46  *      [93/06/24            dbg]
   47  * 
   48  *      Added tm_overruns.
   49  *      [93/05/06            dbg]
   50  * 
   51  *      Moved kernel time_out element definitions to this file.
   52  *      [93/04/09            dbg]
   53  * 
   54  *      Fixed to put in kernel.  Based on kernel timer elements.
   55  * 
   56  *      Changed time_values_t to time_spec_t to account for timer hardware skew.
   57  *      [92/07/18       savage]
   58  *      Redefined timer structure for user exportation.  Forced to define
   59  *      it as mach_timer_t instead of timer_t...  I'd love to change timer_t
   60  *      into counter_t but I'm sure the political headache isn't worth it.
   61  *      [92/06/12       savage]
   62  *      changed locks to work on multiprocessor (one hopes...)
   63  *      [92/06/10]      savage]
   64  *      Created
   65  *      [92/05/01       savage]
   66  * 
   67  */
   68 
   69 #ifndef _KERN_MACH_TIMER_H_
   70 #define _KERN_MACH_TIMER_H_
   71 
   72 #include <mach/boolean.h>
   73 #include <mach/message.h>
   74 #include <mach/time_spec.h>
   75 #include <mach/timer.h>
   76 
   77 #include <kern/eventcount.h>
   78 #include <kern/lock.h>
   79 #include <kern/macro_help.h>
   80 #include <kern/queue.h>
   81 #include <kern/kern_types.h>
   82 
   83 /*
   84  *      A timer element is queued on a clock.
   85  */
   86 struct mach_clock;                      /* opaque imported type */
   87 
   88 /*
   89  *      Common structure for head of timer element list and
   90  *      head of queue.  Allows use of a sentinel at the end
   91  *      of the list.
   92  */
   93 struct timer_elt_head {
   94         queue_chain_t   chain;          /* chain in order of expiration */
   95         time_spec_t     expire_time;    /* expiration time */
   96 };
   97 
   98 /*
   99  *      The internal timer element structure.
  100  */
  101 struct timer_elt {
  102         struct timer_elt_head
  103                         te_head;        /* chain/expire time */
  104         void            (*te_fcn)(void *);
  105                                         /* function to call */
  106         void *          te_param;       /* with this parameter */
  107         unsigned int    te_flags;       /* unset | set | allocated | periodic*/
  108         struct mach_clock *
  109                         te_clock;       /* clock that keeps time for
  110                                            this timer */
  111         time_spec_t     te_period;      /* period */
  112 };
  113 #define te_chain        te_head.chain
  114 #define te_expire_time  te_head.expire_time
  115 
  116 #define TELT_UNSET      0               /* timer not set */
  117 #define TELT_SET        0x01            /* timer set */
  118 #define TELT_ALLOC      0x02            /* timer allocated from pool */
  119 #define TELT_PERIODIC   0x10            /* periodic timer */
  120 #define TELT_ABSOLUTE   0x20            /* expiration time is absolute */
  121 
  122 typedef struct timer_elt        timer_elt_data_t;
  123 typedef struct timer_elt        *timer_elt_t;
  124 
  125 /*
  126  *      Add a timer element to its clock queue.
  127  *      if absolute, time is absolute expiration time;
  128  *      otherwise, time is interval from clock time.
  129  *      Returns FALSE if expiration time is in the past.
  130  */
  131 extern boolean_t timer_elt_enqueue(
  132         timer_elt_t     elt,
  133         time_spec_t     time,
  134         boolean_t       absolute);
  135 
  136 /*
  137  *      Remove a timer element from its clock queue.
  138  *      Return TRUE if the timer element was on the queue.
  139  */
  140 extern boolean_t timer_elt_dequeue(
  141         timer_elt_t     telt);
  142 
  143 /*
  144  *      Fast version of timer_elt_dequeue.
  145  */
  146 #define timer_elt_remove(telt) \
  147     MACRO_BEGIN \
  148         if (((telt)->te_flags & TELT_SET) != 0) { \
  149             (void) timer_elt_dequeue(telt); \
  150         } \
  151     MACRO_END
  152 
  153 /*
  154  * Convert milliseconds to seconds/nanoseconds.
  155  */
  156 #define milliseconds_to_time_spec(milli, interval)              \
  157 MACRO_BEGIN                                                     \
  158         (interval).seconds = (milli) / 1000;                    \
  159         (interval).nanoseconds = ((milli) % 1000) * 1000000;    \
  160 MACRO_END
  161 
  162 /*
  163  * Timeout functions are called at AST time.
  164  */
  165 
  166 extern void timer_ast(void);
  167 
  168 
  169 
  170 /*
  171  *      The mach_timer structure is an exported form
  172  *      of a timer element.
  173  */
  174 struct mach_timer {
  175         struct timer_elt te;            /* chain,
  176                                            expire_time,
  177                                            function/param,
  178                                            set/unset,
  179                                            period */
  180         struct ipc_port *tm_self;       /* kernel port for timer */
  181         decl_simple_lock_data(,tm_ref_lock)     /* lock for ref count*/
  182         int             tm_ref_count;   /* number of references to me */
  183         decl_simple_lock_data(,tm_lock) /* lock for everything else */
  184         int             tm_misc;        /* flags: */
  185 #define TM_ACTIVE               0x01            /* timer alive */
  186 #define TM_EVENT_ALLOC          0x02            /* event counter allocated */
  187 #define TM_BUSY                 0x04            /* timer enqueued or
  188                                                    timeout routine running */
  189 #define TM_SUSPEND              0x08            /* suspend thread at
  190                                                    expiration */
  191         struct ipc_port *tm_expire;     /* timer expiration send right */
  192         struct evc      tm_event;       /* event! blame sandro not me :-) */
  193         thread_t        tm_thread;      /* thread to be suspended or awoken */
  194         int             tm_overruns;    /* number of times a periodic timer
  195                                            could not send message */
  196 };
  197 
  198 #define tm_chain        te.te_chain
  199 #define tm_expire_time  te.te_expire_time
  200 #define tm_fcn          te.te_fcn
  201 #define tm_param        te.te_param
  202 #define tm_flags        te.te_flags
  203 #define tm_clock        te.te_clock
  204 #define tm_period       te.te_period
  205 
  206 typedef struct mach_timer       *mach_timer_t;
  207 typedef struct mach_timer       mach_timer_data_t;
  208 
  209 #define TIMER_NULL      ((mach_timer_t) 0)
  210 
  211 /* 
  212  *      For zalloc()
  213  */
  214 #define TIMER_MAX               1024
  215 #define TIMER_CHUNK             64
  216 
  217 /*
  218  *      Macros to lock and unlock timer
  219  */
  220 #define timer_lock(tm)          simple_lock(&(tm)->tm_lock)
  221 #define timer_unlock(tm)        simple_unlock(&(tm)->tm_lock)
  222 
  223 #define timer_ref_lock(tm)      simple_lock(&(tm)->tm_ref_lock)
  224 #define timer_ref_unlock(tm)    simple_unlock(&(tm)->tm_ref_lock)
  225 
  226 /*
  227  *      Internal only routines
  228  */
  229 extern void     mach_timer_init(void);
  230 extern void     mach_timer_reference(mach_timer_t);
  231 extern void             mach_timer_deallocate(mach_timer_t);
  232 extern boolean_t        mach_timer_thread_reference(mach_timer_t);
  233 extern void             mach_timer_thread_deallocate(mach_timer_t);
  234 
  235 extern mach_timer_t     convert_port_to_timer(struct ipc_port *);
  236 extern struct ipc_port *convert_timer_to_port(mach_timer_t);
  237 
  238 extern boolean_t        timer_notify(mach_msg_header_t *);
  239 
  240 /*
  241  *      Exported routines
  242  */
  243 extern kern_return_t timer_arm(
  244         mach_timer_t    timer,
  245         time_spec_t     expire_time,
  246         time_spec_t     interval_time,
  247         struct ipc_port *expire_port,
  248         thread_t        thread,
  249         int             flags);
  250 
  251 extern kern_return_t timer_cancel(
  252         mach_timer_t    timer,
  253         int             flags);
  254 
  255 extern kern_return_t timer_create(
  256         struct mach_clock *clock,
  257         mach_timer_t    *timer);
  258 
  259 extern kern_return_t timer_get_evc(
  260         mach_timer_t    timer,
  261         natural_t       *event);
  262 
  263 extern kern_return_t timer_info(
  264         mach_timer_t    timer,
  265         int             flavor,
  266         struct mach_clock **clock,              /* out */
  267         struct ipc_port **expire_port,          /* out */
  268         thread_t        *thread,                /* out */
  269         mach_timer_info_t timer_info_out,       /* out */
  270         natural_t       *timer_info_count);     /* inout */
  271 
  272 extern kern_return_t timer_sleep(
  273         mach_timer_t    timer,
  274         time_spec_t     expire_time,
  275         int             flags,
  276         time_spec_t     *wakeup_time);
  277 
  278 extern kern_return_t timer_terminate(
  279         mach_timer_t    timer);
  280 
  281 /*
  282  *      Internal-only routines (mostly for periodic threads)
  283  */
  284 extern kern_return_t timer_sleep_periodic(
  285         mach_timer_t    timer,
  286         time_spec_t     expire_time,
  287         time_spec_t     interval_time,
  288         thread_t        thread,
  289         int             flags);
  290 
  291 extern void timer_wait(
  292         mach_timer_t    timer,
  293         thread_t        thread);
  294 
  295 extern kern_return_t timer_rearm(
  296         mach_timer_t    timer,
  297         time_spec_t     new_expire_time,
  298         time_spec_t     new_interval,
  299         int             flags);
  300 
  301 extern boolean_t timer_start_time(
  302         mach_timer_t    timer,
  303         time_spec_t     *start_time);   /* OUT */
  304 
  305 #endif  /*_KERN_MACH_TIMER_H_ */
  306 

Cache object: 0385ab3976a19c2627bdfa4d697f97fa


[ source navigation ] [ diff markup ] [ identifier search ] [ freetext search ] [ file search ] [ list types ] [ track identifier ]


This page is part of the FreeBSD/Linux Linux Kernel Cross-Reference, and was automatically generated using a modified version of the LXR engine.