Annotation of OSKit-Mach/kern/timer.h, revision 1.1.1.1

1.1       root        1: /*
                      2:  * Mach Operating System
                      3:  * Copyright (c) 1991,1990,1989,1988,1987 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  [email protected]
                     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: #ifndef        _KERN_TIMER_H_
                     28: #define _KERN_TIMER_H_
                     29: 
                     30: #include <cpus.h>
                     31: #include <stat_time.h>
                     32: 
                     33: #include <kern/macro_help.h>
                     34: 
                     35: #if    STAT_TIME
                     36: /*
                     37:  *     Statistical timer definitions - use microseconds in timer, seconds
                     38:  *     in high unit field.  No adjustment needed to convert to time_value_t
                     39:  *     as a result.  Service timers once an hour.
                     40:  */
                     41: 
                     42: #define TIMER_RATE     1000000
                     43: #define TIMER_HIGH_UNIT        TIMER_RATE
                     44: #undef TIMER_ADJUST
                     45: 
                     46: #else  /* STAT_TIME */
                     47: /*
                     48:  *     Machine dependent definitions based on hardware support.
                     49:  */
                     50: 
                     51: #include <machine/timer.h>
                     52: 
                     53: #endif /* STAT_TIME */
                     54: 
                     55: /*
                     56:  *     Definitions for accurate timers.  high_bits_check is a copy of
                     57:  *     high_bits that allows reader to verify that values read are ok.
                     58:  */
                     59: 
                     60: struct timer {
                     61:        unsigned        low_bits;
                     62:        unsigned        high_bits;
                     63:        unsigned        high_bits_check;
                     64:        unsigned        tstamp;
                     65: };
                     66: 
                     67: typedef struct timer           timer_data_t;
                     68: typedef        struct timer            *timer_t;
                     69: 
                     70: /*
                     71:  *     Mask to check if low_bits is in danger of overflowing
                     72:  */
                     73: 
                     74: #define        TIMER_LOW_FULL  0x80000000U
                     75: 
                     76: /*
                     77:  *     Kernel timers and current timer array.  [Exported]
                     78:  */
                     79: 
                     80: extern timer_t         current_timer[NCPUS];
                     81: extern timer_data_t    kernel_timer[NCPUS];
                     82: 
                     83: /*
                     84:  *     save structure for timer readings.  This is used to save timer
                     85:  *     readings for elapsed time computations.
                     86:  */
                     87: 
                     88: struct timer_save {
                     89:        unsigned        low;
                     90:        unsigned        high;
                     91: };
                     92: 
                     93: typedef struct timer_save      timer_save_data_t, *timer_save_t;
                     94: 
                     95: /*
                     96:  *     Exported kernel interface to timers
                     97:  */
                     98: 
                     99: #if    STAT_TIME
                    100: #define start_timer(timer)
                    101: #define timer_switch(timer)
                    102: #else  /* STAT_TIME */
                    103: extern void    start_timer();
                    104: extern void    timer_switch();
                    105: #endif /* STAT_TIME */
                    106: 
                    107: extern void            timer_read();
                    108: extern void            thread_read_times();
                    109: extern unsigned                timer_delta();
                    110: 
                    111: #if    STAT_TIME
                    112: /*
                    113:  *     Macro to bump timer values.
                    114:  */
                    115: #define timer_bump(timer, usec)                                        \
                    116: MACRO_BEGIN                                                    \
                    117:        (timer)->low_bits += usec;                              \
                    118:        if ((timer)->low_bits & TIMER_LOW_FULL) {               \
                    119:                timer_normalize(timer);                         \
                    120:        }                                                       \
                    121: MACRO_END
                    122: 
                    123: #else  /* STAT_TIME */
                    124: /*
                    125:  *     Exported hardware interface to timers
                    126:  */
                    127: extern void    time_trap_uentry();
                    128: extern void    time_trap_uexit();
                    129: extern timer_t time_int_entry();
                    130: extern void    time_int_exit();
                    131: #endif /* STAT_TIME */
                    132: 
                    133: /*
                    134:  *     TIMER_DELTA finds the difference between a timer and a saved value,
                    135:  *     and updates the saved value.  Look at high_bits check field after
                    136:  *     reading low because that's the first written by a normalize
                    137:  *     operation; this isn't necessary for current usage because
                    138:  *     this macro is only used when the timer can't be normalized:
                    139:  *     thread is not running, or running thread calls it on itself at
                    140:  *     splsched().
                    141:  */
                    142: 
                    143: #define TIMER_DELTA(timer, save, result)                       \
                    144: MACRO_BEGIN                                                    \
                    145:        register unsigned       temp;                           \
                    146:                                                                \
                    147:        temp = (timer).low_bits;                                \
                    148:        if ((save).high != (timer).high_bits_check) {           \
                    149:                result += timer_delta(&(timer), &(save));       \
                    150:        }                                                       \
                    151:        else {                                                  \
                    152:                result += temp - (save).low;                    \
                    153:                (save).low = temp;                              \
                    154:        }                                                       \
                    155: MACRO_END
                    156: 
                    157: #endif /* _KERN_TIMER_H_ */

unix.superglobalmegacorp.com

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