Annotation of Gnu-Mach/kern/timer.h, revision 1.1.1.4

1.1.1.2   root        1: /*
1.1       root        2:  * Mach Operating System
                      3:  * Copyright (c) 1991,1990,1989,1988,1987 Carnegie Mellon University
                      4:  * All Rights Reserved.
1.1.1.2   root        5:  *
1.1       root        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.
1.1.1.2   root       11:  *
1.1       root       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.
1.1.1.2   root       15:  *
1.1       root       16:  * Carnegie Mellon requests users of this software to return to
1.1.1.2   root       17:  *
1.1       root       18:  *  Software Distribution Coordinator  or  [email protected]
                     19:  *  School of Computer Science
                     20:  *  Carnegie Mellon University
                     21:  *  Pittsburgh PA 15213-3890
1.1.1.2   root       22:  *
1.1       root       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 <kern/macro_help.h>
                     31: 
                     32: #if    STAT_TIME
                     33: /*
                     34:  *     Statistical timer definitions - use microseconds in timer, seconds
                     35:  *     in high unit field.  No adjustment needed to convert to time_value_t
                     36:  *     as a result.  Service timers once an hour.
                     37:  */
                     38: 
1.1.1.3   root       39: /*
                     40:  *     TIMER_MAX is needed if a 32-bit rollover timer needs to be adjusted for
                     41:  *     maximum value.
                     42:  */
                     43: #undef TIMER_MAX
                     44: 
                     45: /*
                     46:  *     TIMER_RATE is the rate of the timer in ticks per second.  It is used to
                     47:  *     calculate percent cpu usage.
                     48:  */
1.1       root       49: #define TIMER_RATE     1000000
1.1.1.3   root       50: 
                     51: /*
                     52:  *     TIMER_HIGH_UNIT is the unit for high_bits in terms of low_bits.
                     53:  *     Setting it to TIMER_RATE makes the high unit seconds.
                     54:  */
1.1       root       55: #define TIMER_HIGH_UNIT        TIMER_RATE
1.1.1.3   root       56: 
                     57: /*
                     58:  *     TIMER_ADJUST is used to adjust the value of a timer after it has been
                     59:  *     copied into a time_value_t.  No adjustment is needed if high_bits is in
                     60:  *     seconds.
                     61:  */
1.1       root       62: #undef TIMER_ADJUST
                     63: 
1.1.1.3   root       64: /*
                     65:  *     MACHINE_TIMER_ROUTINES should defined if the timer routines are
                     66:  *     implemented in machine-dependent code (e.g. assembly language).
                     67:  */
                     68: #undef MACHINE_TIMER_ROUTINES
                     69: 
1.1.1.2   root       70: #else  /* STAT_TIME */
1.1       root       71: /*
                     72:  *     Machine dependent definitions based on hardware support.
                     73:  */
                     74: 
                     75: #include <machine/timer.h>
                     76: 
1.1.1.2   root       77: #endif /* STAT_TIME */
1.1       root       78: 
                     79: /*
                     80:  *     Definitions for accurate timers.  high_bits_check is a copy of
                     81:  *     high_bits that allows reader to verify that values read are ok.
                     82:  */
                     83: 
                     84: struct timer {
                     85:        unsigned        low_bits;
                     86:        unsigned        high_bits;
                     87:        unsigned        high_bits_check;
                     88:        unsigned        tstamp;
                     89: };
                     90: 
                     91: typedef struct timer           timer_data_t;
                     92: typedef        struct timer            *timer_t;
                     93: 
                     94: /*
                     95:  *     Mask to check if low_bits is in danger of overflowing
                     96:  */
                     97: 
                     98: #define        TIMER_LOW_FULL  0x80000000U
                     99: 
                    100: /*
                    101:  *     Kernel timers and current timer array.  [Exported]
                    102:  */
                    103: 
                    104: extern timer_t         current_timer[NCPUS];
                    105: extern timer_data_t    kernel_timer[NCPUS];
                    106: 
                    107: /*
                    108:  *     save structure for timer readings.  This is used to save timer
                    109:  *     readings for elapsed time computations.
                    110:  */
                    111: 
                    112: struct timer_save {
                    113:        unsigned        low;
                    114:        unsigned        high;
                    115: };
                    116: 
                    117: typedef struct timer_save      timer_save_data_t, *timer_save_t;
                    118: 
                    119: /*
                    120:  *     Exported kernel interface to timers
                    121:  */
                    122: 
                    123: #if    STAT_TIME
                    124: #define start_timer(timer)
                    125: #define timer_switch(timer)
1.1.1.2   root      126: #else  /* STAT_TIME */
1.1.1.3   root      127: extern void    start_timer(timer_t);
                    128: extern void    timer_switch(timer_t);
1.1.1.2   root      129: #endif /* STAT_TIME */
1.1       root      130: 
1.1.1.3   root      131: extern void            timer_read(timer_t, time_value_t *);
                    132: extern void            thread_read_times(thread_t, time_value_t *, time_value_t *);
                    133: extern unsigned                timer_delta(timer_t, timer_save_t);
                    134: extern void            timer_normalize(timer_t);
                    135: extern void            timer_init(timer_t);
1.1       root      136: 
                    137: #if    STAT_TIME
                    138: /*
                    139:  *     Macro to bump timer values.
1.1.1.2   root      140:  */
1.1       root      141: #define timer_bump(timer, usec)                                        \
                    142: MACRO_BEGIN                                                    \
                    143:        (timer)->low_bits += usec;                              \
                    144:        if ((timer)->low_bits & TIMER_LOW_FULL) {               \
                    145:                timer_normalize(timer);                         \
                    146:        }                                                       \
                    147: MACRO_END
                    148: 
1.1.1.2   root      149: #else  /* STAT_TIME */
1.1       root      150: /*
                    151:  *     Exported hardware interface to timers
                    152:  */
1.1.1.3   root      153: extern void    time_trap_uentry(unsigned);
                    154: extern void    time_trap_uexit(int);
                    155: extern timer_t time_int_entry(unsigned, timer_t);
                    156: extern void    time_int_exit(unsigned, timer_t);
1.1.1.2   root      157: #endif /* STAT_TIME */
1.1       root      158: 
                    159: /*
                    160:  *     TIMER_DELTA finds the difference between a timer and a saved value,
                    161:  *     and updates the saved value.  Look at high_bits check field after
                    162:  *     reading low because that's the first written by a normalize
                    163:  *     operation; this isn't necessary for current usage because
                    164:  *     this macro is only used when the timer can't be normalized:
                    165:  *     thread is not running, or running thread calls it on itself at
                    166:  *     splsched().
                    167:  */
                    168: 
                    169: #define TIMER_DELTA(timer, save, result)                       \
                    170: MACRO_BEGIN                                                    \
1.1.1.4 ! root      171:        unsigned        temp;                                   \
1.1       root      172:                                                                \
                    173:        temp = (timer).low_bits;                                \
                    174:        if ((save).high != (timer).high_bits_check) {           \
                    175:                result += timer_delta(&(timer), &(save));       \
                    176:        }                                                       \
                    177:        else {                                                  \
                    178:                result += temp - (save).low;                    \
                    179:                (save).low = temp;                              \
                    180:        }                                                       \
                    181: MACRO_END
                    182: 
1.1.1.3   root      183: extern void init_timers(void);
                    184: 
1.1.1.4 ! root      185: void timer_init(timer_t this_timer);
        !           186: 
1.1.1.2   root      187: #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.