1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
|
/* $OpenBSD: rf_etimer.h,v 1.1 1999/01/11 14:29:20 niklas Exp $ */
/* $NetBSD: rf_etimer.h,v 1.1 1998/11/13 04:20:29 oster Exp $ */
/*
* Copyright (c) 1995 Carnegie-Mellon University.
* All rights reserved.
*
* Author: Mark Holland
*
* Permission to use, copy, modify and distribute this software and
* its documentation is hereby granted, provided that both the copyright
* notice and this permission notice appear in all copies of the
* software, derivative works or modified versions, and any portions
* thereof, and that both notices appear in supporting documentation.
*
* CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
* CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND
* FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
*
* Carnegie Mellon requests users of this software to return to
*
* Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
* School of Computer Science
* Carnegie Mellon University
* Pittsburgh PA 15213-3890
*
* any improvements or extensions that they make and grant Carnegie the
* rights to redistribute these changes.
*/
/* rf_etimer.h -- header file for code related to accurate timing
* This code currently assumes that the elapsed time between START_TIMER
* and START_TIMER is less than the period of the cycle counter. This
* means the events you want to time must be less than:
* clock speed max time
* ---------- --------
* 175 MHz 24 sec
* 150 MHz 28 sec
* 125 MHz 34 sec
*
*
* :
* Log: rf_etimer.h,v
* Revision 1.32 1996/08/13 18:11:09 jimz
* want MACH&&!__osf__, not just MACH for mach timing (MACH defined under OSF/1)
*
* Revision 1.31 1996/08/12 20:11:38 jimz
* use read_real_time() on AIX4+
*
* Revision 1.30 1996/08/09 18:48:12 jimz
* for now, use gettimeofday() on MACH
* (should eventually use better clock stuff)
*
* Revision 1.29 1996/08/07 21:09:08 jimz
* add IRIX as a gettimeofday system
*
* Revision 1.28 1996/08/06 22:25:23 jimz
* add LINUX_I386
*
* Revision 1.27 1996/07/30 04:45:53 jimz
* add ultrix stuff
*
* Revision 1.26 1996/07/28 20:31:39 jimz
* i386netbsd port
* true/false fixup
*
* Revision 1.25 1996/07/27 23:36:08 jimz
* Solaris port of simulator
*
* Revision 1.24 1996/07/27 18:40:24 jimz
* cleanup sweep
*
* Revision 1.23 1996/07/22 19:52:16 jimz
* switched node params to RF_DagParam_t, a union of
* a 64-bit int and a void *, for better portability
* attempted hpux port, but failed partway through for
* lack of a single C compiler capable of compiling all
* source files
*
* Revision 1.22 1996/07/18 22:57:14 jimz
* port simulator to AIX
*
* Revision 1.21 1996/07/17 21:00:58 jimz
* clean up timer interface, tracing
*
* Revision 1.20 1996/07/17 14:26:28 jimz
* rf_scc -> rf_rpcc
*
* Revision 1.19 1996/06/14 21:24:48 jimz
* move out ConfigureEtimer
*
* Revision 1.18 1996/06/03 23:28:26 jimz
* more bugfixes
* check in tree to sync for IPDS runs with current bugfixes
* there still may be a problem with threads in the script test
* getting I/Os stuck- not trivially reproducible (runs ~50 times
* in a row without getting stuck)
*
* Revision 1.17 1996/05/30 23:22:16 jimz
* bugfixes of serialization, timing problems
* more cleanup
*
* Revision 1.16 1996/05/30 12:59:18 jimz
* make etimer happier, more portable
*
* Revision 1.15 1996/05/27 18:56:37 jimz
* more code cleanup
* better typing
* compiles in all 3 environments
*
* Revision 1.14 1996/05/23 21:46:35 jimz
* checkpoint in code cleanup (release prep)
* lots of types, function names have been fixed
*
* Revision 1.13 1996/05/23 00:33:23 jimz
* code cleanup: move all debug decls to rf_options.c, all extern
* debug decls to rf_options.h, all debug vars preceded by rf_
*
* Revision 1.12 1996/05/18 19:51:34 jimz
* major code cleanup- fix syntax, make some types consistent,
* add prototypes, clean out dead code, et cetera
*
* Revision 1.11 1995/12/01 18:10:40 root
* added copyright info
*
* Revision 1.10 1995/09/29 14:27:32 wvcii
* removed printfs from ConfigureEtimer()
*
* Revision 1.9 95/09/19 22:57:31 jimz
* added kernel version of ConfigureEtimer
*
* Revision 1.8 1995/09/14 13:03:04 amiri
* set default CPU speed to 125Mhz to avoid divide by zero problems.
*
* Revision 1.7 1995/09/11 19:04:36 wvcii
* timer autoconfigs using pdl routine to check cpu speed
* value may still be overridden via config debug var timerTicksPerSec
*
*/
#ifndef _RF__RF_TIMER_H_
#define _RF__RF_TIMER_H_
#include "rf_options.h"
#ifdef _KERNEL
#define KERNEL
#endif
#if defined(__NetBSD__) || defined(__OpenBSD__)
#ifdef KERNEL
extern unsigned int rpcc(void);
#define rf_read_cycle_counter rpcc
#else /* KERNEL */
#if !defined(__NetBSD__) && !defined(__OpenBSD__)
/* XXX does this function even exist anywhere??? GO */
extern unsigned int rf_rpcc();
#endif
#define rf_read_cycle_counter rf_rpcc
#endif /* KERNEL */
#define RF_DEF_TIMER_MAX_VAL 0xFFFFFFFF
typedef struct RF_EtimerVal_s {
unsigned ccnt; /* cycle count */
} RF_EtimerVal_t;
struct RF_Etimer_s {
RF_EtimerVal_t st;
RF_EtimerVal_t et;
unsigned long ticks; /* elapsed time in ticks */
};
extern long rf_timer_max_val;
extern long rf_timer_ticks_per_second;
extern unsigned long rf_timer_ticks_per_usec;
#define RF_ETIMER_TICKS2US(_tcks_) ( (_tcks_) / rf_timer_ticks_per_usec )
#define RF_ETIMER_START(_t_) { (_t_).st.ccnt = rf_read_cycle_counter(); }
#define RF_ETIMER_STOP(_t_) { (_t_).et.ccnt = rf_read_cycle_counter(); }
#define RF_ETIMER_EVAL(_t_) { \
if ((_t_).st.ccnt < (_t_).et.ccnt) \
(_t_).ticks = (_t_).et.ccnt - (_t_).st.ccnt; \
else \
(_t_).ticks = rf_timer_max_val - ((_t_).st.ccnt - (_t_).et.ccnt); \
}
#define RF_ETIMER_VAL_TICKS(_t_) ((_t_).ticks)
#define RF_ETIMER_VAL_US(_t_) (RF_ETIMER_TICKS2US((_t_).ticks))
#define RF_ETIMER_VAL_MS(_t_) (RF_ETIMER_TICKS2US((_t_).ticks)/1000)
#endif /* __NetBSD__ || __OpenBSD__ */
#if defined(__alpha) && !defined(__NetBSD__) && !defined(__OpenBSD__)
#ifdef KERNEL
extern unsigned int rpcc();
#define rf_read_cycle_counter rpcc
#else /* KERNEL */
extern unsigned int rf_rpcc();
#define rf_read_cycle_counter rf_rpcc
#endif /* KERNEL */
#define RF_DEF_TIMER_MAX_VAL 0xFFFFFFFF
typedef struct RF_EtimerVal_s {
unsigned ccnt; /* cycle count */
} RF_EtimerVal_t;
struct RF_Etimer_s {
RF_EtimerVal_t st;
RF_EtimerVal_t et;
unsigned long ticks; /* elapsed time in ticks */
};
extern long rf_timer_max_val;
extern long rf_timer_ticks_per_second;
extern unsigned long rf_timer_ticks_per_usec;
#define RF_ETIMER_TICKS2US(_tcks_) ( (_tcks_) / rf_timer_ticks_per_usec )
#define RF_ETIMER_START(_t_) { (_t_).st.ccnt = rf_read_cycle_counter(); }
#define RF_ETIMER_STOP(_t_) { (_t_).et.ccnt = rf_read_cycle_counter(); }
#define RF_ETIMER_EVAL(_t_) { \
if ((_t_).st.ccnt < (_t_).et.ccnt) \
(_t_).ticks = (_t_).et.ccnt - (_t_).st.ccnt; \
else \
(_t_).ticks = rf_timer_max_val - ((_t_).st.ccnt - (_t_).et.ccnt); \
}
#define RF_ETIMER_VAL_TICKS(_t_) ((_t_).ticks)
#define RF_ETIMER_VAL_US(_t_) (RF_ETIMER_TICKS2US((_t_).ticks))
#define RF_ETIMER_VAL_MS(_t_) (RF_ETIMER_TICKS2US((_t_).ticks)/1000)
#endif /* __alpha */
#ifdef _IBMR2
extern void rf_rtclock(unsigned int *secs, unsigned int *nsecs);
#define RF_MSEC_PER_SEC 1000
#define RF_USEC_PER_SEC 1000000
#define RF_NSEC_PER_SEC 1000000000
typedef struct RF_EtimerVal_s {
unsigned int secs;
unsigned int nsecs;
} RF_EtimerVal_t;
struct RF_Etimer_s {
RF_EtimerVal_t start;
RF_EtimerVal_t end;
RF_EtimerVal_t elapsed;
};
#if RF_AIXVERS >= 4
#include <sys/time.h>
#define RF_ETIMER_START(_t_) { \
timebasestruct_t tb; \
tb.flag = 1; \
read_real_time(&tb, TIMEBASE_SZ); \
(_t_).start.secs = tb.tb_high; \
(_t_).start.nsecs = tb.tb_low; \
}
#define RF_ETIMER_STOP(_t_) { \
timebasestruct_t tb; \
tb.flag = 1; \
read_real_time(&tb, TIMEBASE_SZ); \
(_t_).end.secs = tb.tb_high; \
(_t_).end.nsecs = tb.tb_low; \
}
#else /* RF_AIXVERS >= 4 */
#define RF_ETIMER_START(_t_) { \
rf_rtclock(&((_t_).start.secs), &((_t_).start.nsecs)); \
}
#define RF_ETIMER_STOP(_t_) { \
rf_rtclock(&((_t_).end.secs), &((_t_).end.nsecs)); \
}
#endif /* RF_AIXVERS >= 4 */
#define RF_ETIMER_EVAL(_t_) { \
if ((_t_).end.nsecs >= (_t_).start.nsecs) { \
(_t_).elapsed.nsecs = (_t_).end.nsecs - (_t_).start.nsecs; \
(_t_).elapsed.secs = (_t_).end.secs - (_t_).start.nsecs; \
} \
else { \
(_t_).elapsed.nsecs = RF_NSEC_PER_SEC + (_t_).end.nsecs; \
(_t_).elapsed.nsecs -= (_t_).start.nsecs; \
(_t_).elapsed.secs = (_t_).end.secs - (_t_).start.secs + 1; \
} \
}
#define RF_ETIMER_VAL_US(_t_) (((_t_).elapsed.secs*RF_USEC_PER_SEC)+((_t_).elapsed.nsecs/1000))
#define RF_ETIMER_VAL_MS(_t_) (((_t_).elapsed.secs*RF_MSEC_PER_SEC)+((_t_).elapsed.nsecs/1000000))
#endif /* _IBMR2 */
/*
* XXX investigate better timing for these
*/
#if defined(hpux) || defined(sun) || defined(NETBSD_I386) || defined(OPENBSD_I386) || defined(ultrix) || defined(LINUX_I386) || defined(IRIX) || (defined(MACH) && !defined(__osf__))
#include <sys/time.h>
#define RF_USEC_PER_SEC 1000000
struct RF_Etimer_s {
struct timeval start;
struct timeval end;
struct timeval elapsed;
};
#if !defined(__NetBSD__) && !defined(__OpenBSD__)
#define RF_ETIMER_START(_t_) { \
gettimeofday(&((_t_).start), NULL); \
}
#define RF_ETIMER_STOP(_t_) { \
gettimeofday(&((_t_).end), NULL); \
}
#else
#define RF_ETIMER_START(_t_) { \
}
/* XXX these just drop off the end of the world... */
#define RF_ETIMER_STOP(_t_) { \
}
#endif
#define RF_ETIMER_EVAL(_t_) { \
if ((_t_).end.tv_usec >= (_t_).start.tv_usec) { \
(_t_).elapsed.tv_usec = (_t_).end.tv_usec - (_t_).start.tv_usec; \
(_t_).elapsed.tv_sec = (_t_).end.tv_sec - (_t_).start.tv_usec; \
} \
else { \
(_t_).elapsed.tv_usec = RF_USEC_PER_SEC + (_t_).end.tv_usec; \
(_t_).elapsed.tv_usec -= (_t_).start.tv_usec; \
(_t_).elapsed.tv_sec = (_t_).end.tv_sec - (_t_).start.tv_sec + 1; \
} \
}
#define RF_ETIMER_VAL_US(_t_) (((_t_).elapsed.tv_sec*RF_USEC_PER_SEC)+(_t_).elapsed.tv_usec)
#define RF_ETIMER_VAL_MS(_t_) (((_t_).elapsed.tv_sec*RF_MSEC_PER_SEC)+((_t_).elapsed.tv_usec/1000))
#endif /* hpux || sun || NETBSD_I386 || OPENBSD_I386 || ultrix || LINUX_I386 || IRIX || (MACH && !__osf__) */
#endif /* !_RF__RF_TIMER_H_ */
|