1 /* 2 * Copyright 1991-1998 by Open Software Foundation, Inc. 3 * All Rights Reserved 4 * 5 * Permission to use, copy, modify, and distribute this software and 6 * its documentation for any purpose and without fee is hereby granted, 7 * provided that the above copyright notice appears in all copies and 8 * that both the copyright notice and this permission notice appear in 9 * supporting documentation. 10 * 11 * OSF DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE 12 * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 13 * FOR A PARTICULAR PURPOSE. 14 * 15 * IN NO EVENT SHALL OSF BE LIABLE FOR ANY SPECIAL, INDIRECT, OR 16 * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM 17 * LOSS OF USE, DATA OR PROFITS, WHETHER IN ACTION OF CONTRACT, 18 * NEGLIGENCE, OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION 19 * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 20 */ 21 /* 22 * MkLinux 23 */ 24 25 /* 26 * File: clock_types.h 27 * Purpose: Clock facility header definitions. These 28 * definitons are needed by both kernel and 29 * user-level software. 30 */ 31 32 #ifndef _MACH_CLOCK_TYPES_H_ 33 #define _MACH_CLOCK_TYPES_H_ 34 35 /* 36 * Reserved clock id values for default clocks. 37 */ 38 #define REALTIME_CLOCK 0 /* required for all systems */ 39 #define BATTERY_CLOCK 1 /* optional */ 40 #define HIGHRES_CLOCK 2 /* optional */ 41 42 /* Any number of distributed clocks may be defined. */ 43 #define DIST_CLOCK_0 3 /* optional */ 44 #define DIST_CLOCK_1 4 /* optional */ 45 46 /* 47 * Type definitions. 48 */ 49 typedef int alarm_type_t; /* alarm time type */ 50 typedef int sleep_type_t; /* sleep time type */ 51 typedef int clock_id_t; /* clock identification type */ 52 typedef int clock_flavor_t; /* clock flavor type */ 53 typedef int *clock_attr_t; /* clock attribute type */ 54 typedef int clock_res_t; /* clock resolution type */ 55 56 57 /* 58 * Attribute names. 59 */ 60 #define CLOCK_GET_TIME_RES 1 /* get_time call resolution */ 61 #define CLOCK_MAP_TIME_RES 2 /* map_time call resolution */ 62 #define CLOCK_ALARM_CURRES 3 /* current alarm resolution */ 63 #define CLOCK_ALARM_MINRES 4 /* minimum alarm resolution */ 64 #define CLOCK_ALARM_MAXRES 5 /* maximum alarm resolution */ 65 #define CLOCK_BASE_FREQ 6 /* base counter frequency */ 66 /* Attribute names specific to DISTRIBUTED_CLOCK */ 67 #define DCLOCK_STATE 7 68 #define DCLOCK_PARAM_BOUND 8 69 #define DCLOCK_PARAM_DRIFT_CONST 9 70 #define DCLOCK_OPARAM_REFCLOCK 10 71 72 /* DISTRIBUTED_CLOCK states (accessible via attribute DCLOCK_STATE) */ 73 #define DCLOCK_STATE_UNINITIALIZED 0 74 #define DCLOCK_STATE_MANAGED 1 75 #define DCLOCK_STATE_INITIALIZED 2 76 #define DCLOCK_STATE_RUNNING 3 77 #define DCLOCK_STATE_FAILED 4 78 79 /* 80 * Normal time specification used by the kernel clock facility. 81 */ 82 struct tvalspec { 83 unsigned int tv_sec; /* seconds */ 84 clock_res_t tv_nsec; /* nanoseconds */ 85 }; 86 typedef struct tvalspec tvalspec_t; 87 typedef struct tvalspec mach_timespec_t; 88 89 90 #ifdef NSEC_PER_SEC 91 #undef NSEC_PER_SEC 92 #endif 93 #ifdef USEC_PER_SEC 94 #undef USEC_PER_SEC 95 #endif 96 #ifdef NSEC_PER_USEC 97 #undef NSEC_PER_USEC 98 #endif 99 #define NSEC_PER_USEC 1000ll /* nanoseconds per microsecond */ 100 #define USEC_PER_SEC 1000000ll /* microseconds per second */ 101 #define NSEC_PER_SEC 1000000000ll /* nanoseconds per second */ 102 #define BAD_TVALSPEC(t) \ 103 ((t)->tv_nsec < 0 || (t)->tv_nsec >= NSEC_PER_SEC) 104 105 /* t1 <=> t2 */ 106 #define CMP_TVALSPEC(t1, t2) \ 107 ((t1)->tv_sec > (t2)->tv_sec ? +1 : \ 108 ((t1)->tv_sec < (t2)->tv_sec ? -1 : (t1)->tv_nsec - (t2)->tv_nsec)) 109 110 /* t1 += t2 */ 111 #define ADD_TVALSPEC(t1, t2) \ 112 { \ 113 if (((t1)->tv_nsec += (t2)->tv_nsec) >= NSEC_PER_SEC) { \ 114 (t1)->tv_nsec -= NSEC_PER_SEC; \ 115 (t1)->tv_sec += 1; \ 116 } \ 117 (t1)->tv_sec += (t2)->tv_sec; \ 118 } 119 120 /* t1 -= t2 */ 121 #define SUB_TVALSPEC(t1, t2) \ 122 { \ 123 if (((t1)->tv_nsec -= (t2)->tv_nsec) < 0) { \ 124 (t1)->tv_nsec += NSEC_PER_SEC; \ 125 (t1)->tv_sec -= 1; \ 126 } \ 127 (t1)->tv_sec -= (t2)->tv_sec; \ 128 } 129 130 /* 131 * Mapped time specification used by the kernel clock facility. 132 */ 133 struct mapped_tvalspec { 134 tvalspec_t mtv_time; 135 #define mtv_sec mtv_time.tv_sec /* seconds */ 136 #define mtv_nsec mtv_time.tv_nsec /* nanoseconds */ 137 unsigned int mtv_csec; /* check seconds */ 138 }; 139 typedef struct mapped_tvalspec mapped_tvalspec_t; 140 141 /* 142 * Macro for reading a consistant tvalspec_t value "ts" 143 * from a mapped time specification "mts". (On a multi 144 * processor, it is assumed that processors see writes 145 * in the "correct" order since the kernel updates the 146 * mapped time in the inverse order it is read here.) 147 */ 148 #define MTS_TO_TS(mts, ts) \ 149 do { \ 150 (ts)->tv_sec = (mts)->mtv_sec; \ 151 (ts)->tv_nsec = (mts)->mtv_nsec; \ 152 } while ((ts)->tv_sec != (mts)->mtv_csec); 153 154 /* 155 * Alarm parameter defines. 156 */ 157 #define ALRMTYPE 0xff /* type (8-bit field) */ 158 #define TIME_ABSOLUTE 0x0 /* absolute time */ 159 #define TIME_RELATIVE 0x1 /* relative time */ 160 #define BAD_ALRMTYPE(t) \ 161 (((t) & 0xfe) != 0) 162 163 #endif /* _MACH_CLOCK_TYPES_H_ */ 164