Annotation of kernel/kern/timer.h, revision 1.1.1.1

1.1       root        1: /*
                      2:  * Copyright (c) 1999 Apple Computer, Inc. All rights reserved.
                      3:  *
                      4:  * @APPLE_LICENSE_HEADER_START@
                      5:  * 
                      6:  * Portions Copyright (c) 1999 Apple Computer, Inc.  All Rights
                      7:  * Reserved.  This file contains Original Code and/or Modifications of
                      8:  * Original Code as defined in and that are subject to the Apple Public
                      9:  * Source License Version 1.1 (the "License").  You may not use this file
                     10:  * except in compliance with the License.  Please obtain a copy of the
                     11:  * License at http://www.apple.com/publicsource and read it before using
                     12:  * this file.
                     13:  * 
                     14:  * The Original Code and all software distributed under the License are
                     15:  * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
                     16:  * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
                     17:  * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
                     18:  * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT.  Please see the
                     19:  * License for the specific language governing rights and limitations
                     20:  * under the License.
                     21:  * 
                     22:  * @APPLE_LICENSE_HEADER_END@
                     23:  */
                     24: 
                     25: /* 
                     26:  * Mach Operating System
                     27:  * Copyright (c) 1989 Carnegie-Mellon University
                     28:  * Copyright (c) 1988 Carnegie-Mellon University
                     29:  * Copyright (c) 1987 Carnegie-Mellon University
                     30:  * All rights reserved.  The CMU software License Agreement specifies
                     31:  * the terms and conditions for use and redistribution.
                     32:  */
                     33: /*
                     34:  * HISTORY
                     35:  * Revision 1.1.1.1  1997/09/30 02:44:35  wsanchez
                     36:  * Import of kernel from umeshv/kernel
                     37:  *
                     38:  * Revision 2.9  89/12/22  15:54:21  rpd
                     39:  *     Minor stylistic change to TIMER_DELTA, plus explanatory comment.
                     40:  *     [89/11/28            dlb]
                     41:  * 
                     42:  * Revision 2.8  89/10/11  14:35:23  dlb
                     43:  *     Change internal representation of timers: flags field replaced
                     44:  *     by high_bits_check field.
                     45:  *     [89/09/12            dlb]
                     46:  * 
                     47:  *     Added TIMER_LOW_FULL mask to check for possible overflow of
                     48:  *     low_bits field.  Removed TIMER_SERVICE flag.
                     49:  *     [88/10/27            dlb]
                     50:  * 
                     51:  * Revision 2.7  89/03/09  20:17:32  rpd
                     52:  *     More cleanup.
                     53:  * 
                     54:  * Revision 2.6  89/02/25  18:10:52  gm0w
                     55:  *     Kernel code cleanup.
                     56:  *     Put entire file under #indef KERNEL.
                     57:  *     [89/02/15            mrt]
                     58:  * 
                     59:  * Revision 2.5  89/02/07  01:05:51  mwyoung
                     60:  * Relocated from sys/timer.h
                     61:  * 
                     62:  * Revision 2.4  89/01/30  22:08:37  rpd
                     63:  *     Updated macro definitions to the new style.
                     64:  *     Made declarations use "extern".
                     65:  *     [89/01/25  15:24:36  rpd]
                     66:  * 
                     67:  * Revision 2.3  88/08/24  02:49:17  mwyoung
                     68:  *     Adjusted include file references.
                     69:  *     [88/08/17  02:25:43  mwyoung]
                     70:  *
                     71:  *  7-Apr-88  David Black (dlb) at Carnegie-Mellon University
                     72:  *     Added interface definitions and null routines for STAT_TIME.
                     73:  *
                     74:  * 19-Feb-88  David Black (dlb) at Carnegie-Mellon University
                     75:  *     Renamed fields, added timer_save structure.
                     76:  *
                     77:  * 31-May-87  Avadis Tevanian (avie) at Carnegie-Mellon University
                     78:  *     machine/machtimer.h -> machine/timer.h
                     79:  *
                     80:  * 23-Feb-87  David L. Black (dlb) at Carnegie-Mellon University
                     81:  *     Created.
                     82:  */ 
                     83: 
                     84: #ifndef        _KERN_TIMER_H_
                     85: #define _KERN_TIMER_H_
                     86: 
                     87: #ifdef KERNEL_BUILD
                     88: #import <cpus.h>
                     89: #import <stat_time.h>
                     90: #else  /* KERNEL_BUILD */
                     91: #import <mach/features.h>
                     92: #endif /* KERNEL_BUILD */
                     93: 
                     94: #import <kernserv/macro_help.h>
                     95: 
                     96: #if    STAT_TIME
                     97: /*
                     98:  *     Statistical timer definitions - use microseconds in timer, seconds
                     99:  *     in high unit field.  No adjustment needed to convert to time_value_t
                    100:  *     as a result.  Service timers once an hour.
                    101:  */
                    102: 
                    103: #define TIMER_RATE     1000000
                    104: #define TIMER_HIGH_UNIT        TIMER_RATE
                    105: #undef TIMER_ADJUST
                    106: 
                    107: #else  /* STAT_TIME */
                    108: /*
                    109:  *     Machine dependent definitions based on hardware support.
                    110:  */
                    111: 
                    112: #import <machine/timer.h>
                    113: 
                    114: #endif /* STAT_TIME */
                    115: 
                    116: /*
                    117:  *     Definitions for accurate timers.  high_bits_check is a copy of
                    118:  *     high_bits that allows reader to verify that values read are ok.
                    119:  */
                    120: 
                    121: struct timer {
                    122:        unsigned        low_bits;
                    123:        unsigned        high_bits;
                    124:        unsigned        high_bits_check;
                    125:        unsigned        tstamp;
                    126: };
                    127: 
                    128: typedef struct timer           timer_data_t;
                    129: typedef        struct timer            *timer_t;
                    130: 
                    131: /*
                    132:  *     Mask to check if low_bits is in danger of overflowing
                    133:  */
                    134: 
                    135: #define        TIMER_LOW_FULL  0x80000000
                    136: 
                    137: /*
                    138:  *     Kernel timers and current timer array.  [Exported]
                    139:  */
                    140: 
                    141: extern timer_t         current_timer[NCPUS];
                    142: extern timer_data_t    kernel_timer[NCPUS];
                    143: 
                    144: /*
                    145:  *     save structure for timer readings.  This is used to save timer
                    146:  *     readings for elapsed time computations.
                    147:  */
                    148: 
                    149: struct timer_save {
                    150:        unsigned        low;
                    151:        unsigned        high;
                    152: };
                    153: 
                    154: typedef struct timer_save      timer_save_data_t, *timer_save_t;
                    155: 
                    156: /*
                    157:  *     Exported kernel interface to timers
                    158:  */
                    159: 
                    160: #if    STAT_TIME
                    161: #define start_timer(timer)
                    162: #define timer_switch(timer)
                    163: #else  /* STAT_TIME */
                    164: extern void    start_timer();
                    165: extern void    timer_switch();
                    166: #endif /* STAT_TIME */
                    167: 
                    168: extern void            timer_read();
                    169: extern void            thread_read_times();
                    170: extern unsigned                timer_delta();
                    171: 
                    172: #if    STAT_TIME
                    173: /*
                    174:  *     Macro to bump timer values.
                    175:  */    
                    176: #define timer_bump(timer, usec)                                        \
                    177: MACRO_BEGIN                                                    \
                    178:        (timer)->low_bits += usec;                              \
                    179:        if ((timer)->low_bits & TIMER_LOW_FULL) {               \
                    180:                timer_normalize(timer);                         \
                    181:        }                                                       \
                    182: MACRO_END
                    183: 
                    184: #else  /* STAT_TIME */
                    185: /*
                    186:  *     Exported hardware interface to timers
                    187:  */
                    188: extern void    time_trap_uentry();
                    189: extern void    time_trap_uexit();
                    190: extern timer_t time_int_entry();
                    191: extern void    time_int_exit();
                    192: #endif /* STAT_TIME */
                    193: 
                    194: /*
                    195:  *     TIMER_DELTA finds the difference between a timer and a saved value,
                    196:  *     and updates the saved value.  Look at high_bits check field after
                    197:  *     reading low because that's the first written by a normalize
                    198:  *     operation; this isn't necessary for current usage because
                    199:  *     this macro is only used when the timer can't be normalized:
                    200:  *     thread is not running, or running thread calls it on itself at
                    201:  *     splsched().
                    202:  */
                    203: 
                    204: #define TIMER_DELTA(timer, save, result)                       \
                    205: MACRO_BEGIN                                                    \
                    206:        register unsigned       temp;                           \
                    207:                                                                \
                    208:        temp = (timer).low_bits;                                \
                    209:        if ((save).high != (timer).high_bits_check) {           \
                    210:                result += timer_delta(&(timer), &(save));       \
                    211:        }                                                       \
                    212:        else {                                                  \
                    213:                result += temp - (save).low;                    \
                    214:                (save).low = temp;                              \
                    215:        }                                                       \
                    216: MACRO_END
                    217: 
                    218: #endif /* _KERN_TIMER_H_ */
                    219: 

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.