OpenCores
URL https://opencores.org/ocsvn/openmsp430/openmsp430/trunk

Subversion Repositories openmsp430

[/] [openmsp430/] [trunk/] [core/] [sim/] [rtl_sim/] [src-c/] [dhrystone_4mcu/] [original_files/] [timers_b.c] - Blame information for rev 145

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 145 olivier.gi
/*****************************************************/
2
/* Various timer routines.                           */
3
/* Al Aburto, aburto@nosc.mil, 18 Feb 1997           */
4
/*                                                   */
5
/* t = dtime() outputs the current time in seconds.  */
6
/* Use CAUTION as some of these routines will mess   */
7
/* up when timing across the hour mark!!!            */
8
/*                                                   */
9
/* For timing I use the 'user' time whenever         */
10
/* possible. Using 'user+sys' time is a separate     */
11
/* issue.                                            */
12
/*                                                   */
13
/* Example Usage:                                    */
14
/* [timer options added here]                        */
15
/* main()                                            */
16
/* {                                                 */
17
/* double starttime,benchtime,dtime();               */
18
/*                                                   */
19
/* starttime = dtime();                              */
20
/* [routine to time]                                 */
21
/* benchtime = dtime() - starttime;                  */
22
/* }                                                 */
23
/*                                                   */
24
/* [timer code below added here]                     */
25
/*****************************************************/
26
 
27
/***************************************************************************
28
 * Adapted for embedded microcontrollers by Graham Davies, ECROS Technology.
29
 **************************************************************************/
30
 
31
/***************************************************************/
32
/* Timer options. You MUST uncomment one of the options below  */
33
/* or compile, for example, with the '-DUNIX' option.          */
34
/***************************************************************/
35
/* #define Amiga       */
36
/* #define UNIX        */
37
/* #define UNIX_Old    */
38
/* #define VMS         */
39
/* #define BORLAND_C   */
40
/* #define MSC         */
41
/* #define MAC         */
42
/* #define IPSC        */
43
/* #define FORTRAN_SEC */
44
/* #define GTODay      */
45
/* #define CTimer      */
46
/* #define UXPM        */
47
/* #define MAC_TMgr    */
48
/* #define PARIX       */
49
/* #define POSIX       */
50
/* #define WIN32       */
51
/* #define POSIX1      */
52
/***********************/
53
 
54
/*********************************/
55
/* Timer code.                   */
56
/*********************************/
57
 
58
/************************************/
59
/* Embedded microcontroller dtime() */
60
/************************************/
61
#if defined( __AVR_ARCH__ ) || defined( __ENCORE__ )
62
double dtime( void )
63
{
64
   return 0.0;
65
}
66
#endif
67
 
68
/*******************/
69
/*  Amiga dtime()  */
70
/*******************/
71
#ifdef Amiga
72
#include <ctype.h>
73
#define HZ 50
74
 
75
double dtime()
76
{
77
 double q;
78
 
79
 struct tt
80
       {
81
        long  days;
82
        long  minutes;
83
        long  ticks;
84
       } tt;
85
 
86
 DateStamp(&tt);
87
 
88
 q = ((double)(tt.ticks + (tt.minutes * 60L * 50L))) / (double)HZ;
89
 
90
 return q;
91
}
92
#endif
93
 
94
/*****************************************************/
95
/*  UNIX dtime(). This is the preferred UNIX timer.  */
96
/*  Provided by: Markku Kolkka, mk59200@cc.tut.fi    */
97
/*  HP-UX Addition by: Bo Thide', bt@irfu.se         */
98
/*****************************************************/
99
#ifdef UNIX
100
#include <sys/time.h>
101
#include <sys/resource.h>
102
 
103
#ifdef hpux
104
#include <sys/syscall.h>
105
#define getrusage(a,b) syscall(SYS_getrusage,a,b)
106
#endif
107
 
108
struct rusage rusage;
109
 
110
double dtime()
111
{
112
 double q;
113
 
114
 getrusage(RUSAGE_SELF,&rusage);
115
 
116
 q = (double)(rusage.ru_utime.tv_sec);
117
 q = q + (double)(rusage.ru_utime.tv_usec) * 1.0e-06;
118
 
119
 return q;
120
}
121
#endif
122
 
123
/***************************************************/
124
/*  UNIX_Old dtime(). This is the old UNIX timer.  */
125
/*  Make sure HZ is properly defined in param.h !! */
126
/***************************************************/
127
#ifdef UNIX_Old
128
#include <sys/types.h>
129
#include <sys/times.h>
130
#include <sys/param.h>
131
 
132
#ifndef HZ
133
#define HZ 60
134
#endif
135
 
136
struct tms tms;
137
 
138
double dtime()
139
{
140
 double q;
141
 
142
 times(&tms);
143
 
144
 q = (double)(tms.tms_utime) / (double)HZ;
145
 
146
 return q;
147
}
148
#endif
149
 
150
/*********************************************************/
151
/*  VMS dtime() for VMS systems.                         */
152
/*  Provided by: RAMO@uvphys.phys.UVic.CA                */
153
/*  Some people have run into problems with this timer.  */
154
/*********************************************************/
155
#ifdef VMS
156
#include time
157
 
158
#ifndef HZ
159
#define HZ 100
160
#endif
161
 
162
struct tbuffer_t
163
      {
164
       int proc_user_time;
165
       int proc_system_time;
166
       int child_user_time;
167
       int child_system_time;
168
      };
169
 
170
struct tbuffer_t tms;
171
 
172
double dtime()
173
{
174
 double q;
175
 
176
 times(&tms);
177
 
178
 q = (double)(tms.proc_user_time) / (double)HZ;
179
 
180
 return q;
181
}
182
#endif
183
 
184
/******************************/
185
/*  BORLAND C dtime() for DOS */
186
/******************************/
187
#ifdef BORLAND_C
188
#include <ctype.h>
189
#include <dos.h>
190
#include <time.h>
191
 
192
#define HZ 100
193
struct time tnow;
194
 
195
double dtime()
196
{
197
 double q;
198
 
199
 gettime(&tnow);
200
 
201
 q = 60.0 * (double)(tnow.ti_min);
202
 q = q + (double)(tnow.ti_sec);
203
 q = q + (double)(tnow.ti_hund)/(double)HZ;
204
 
205
 return q;
206
}
207
#endif
208
 
209
/**************************************/
210
/*  Microsoft C (MSC) dtime() for DOS */
211
/**************************************/
212
#ifdef MSC
213
#include <time.h>
214
#include <ctype.h>
215
 
216
#define HZ CLOCKS_PER_SEC
217
clock_t tnow;
218
 
219
double dtime()
220
{
221
 double q;
222
 
223
 tnow = clock();
224
 
225
 q = (double)tnow / (double)HZ;
226
 
227
 return q;
228
}
229
#endif
230
 
231
/*************************************/
232
/*  Macintosh (MAC) Think C dtime()  */
233
/*************************************/
234
#ifdef MAC
235
#include <time.h>
236
 
237
#define HZ 60
238
 
239
double dtime()
240
{
241
 double q;
242
 
243
 q = (double)clock() / (double)HZ;
244
 
245
 return q;
246
}
247
#endif
248
 
249
/************************************************************/
250
/*  iPSC/860 (IPSC) dtime() for i860.                       */
251
/*  Provided by: Dan Yergeau, yergeau@gloworm.Stanford.EDU  */
252
/************************************************************/
253
#ifdef IPSC
254
extern double dclock();
255
 
256
double dtime()
257
{
258
 double q;
259
 
260
 q = dclock();
261
 
262
 return q;
263
}
264
#endif
265
 
266
/**************************************************/
267
/*  FORTRAN dtime() for Cray type systems.        */
268
/*  This is the preferred timer for Cray systems. */
269
/**************************************************/
270
#ifdef FORTRAN_SEC
271
 
272
fortran double second();
273
 
274
double dtime()
275
{
276
 double q;
277
 
278
 second(&q);
279
 
280
 return q;
281
}
282
#endif
283
 
284
/***********************************************************/
285
/*  UNICOS C dtime() for Cray UNICOS systems.  Don't use   */
286
/*  unless absolutely necessary as returned time includes  */
287
/*  'user+system' time.  Provided by: R. Mike Dority,      */
288
/*  dority@craysea.cray.com                                */
289
/***********************************************************/
290
#ifdef CTimer
291
#include <time.h>
292
 
293
double dtime()
294
{
295
 double    q;
296
 clock_t   clock(void);
297
 
298
 q = (double)clock() / (double)CLOCKS_PER_SEC;
299
 
300
 return q;
301
}
302
#endif
303
 
304
/********************************************/
305
/* Another UNIX timer using gettimeofday(). */
306
/* However, getrusage() is preferred.       */
307
/********************************************/
308
#ifdef GTODay
309
#include <sys/time.h>
310
 
311
struct timeval tnow;
312
 
313
double dtime()
314
{
315
 double q;
316
 
317
 gettimeofday(&tnow,NULL);
318
 q = (double)tnow.tv_sec + (double)tnow.tv_usec * 1.0e-6;
319
 
320
 return q;
321
}
322
#endif
323
 
324
/*****************************************************/
325
/*  Fujitsu UXP/M timer.                             */
326
/*  Provided by: Mathew Lim, ANUSF, M.Lim@anu.edu.au */
327
/*****************************************************/
328
#ifdef UXPM
329
#include <sys/types.h>
330
#include <sys/timesu.h>
331
struct tmsu rusage;
332
 
333
double dtime()
334
{
335
 double q;
336
 
337
 timesu(&rusage);
338
 
339
 q = (double)(rusage.tms_utime) * 1.0e-06;
340
 
341
 return q;
342
}
343
#endif
344
 
345
/**********************************************/
346
/*    Macintosh (MAC_TMgr) Think C dtime()    */
347
/*   requires Think C Language Extensions or  */
348
/*    #include <MacHeaders> in the prefix     */
349
/*  provided by Francis H Schiffer 3rd (fhs)  */
350
/*         skipschiffer@genie.geis.com        */
351
/**********************************************/
352
#ifdef MAC_TMgr
353
#include <Timer.h>
354
#include <stdlib.h>
355
 
356
static TMTask   mgrTimer;
357
static Boolean  mgrInited = false;
358
static double   mgrClock;
359
 
360
#define RMV_TIMER RmvTime( (QElemPtr)&mgrTimer )
361
#define MAX_TIME  1800000000L
362
/* MAX_TIME limits time between calls to */
363
/* dtime( ) to no more than 30 minutes   */
364
/* this limitation could be removed by   */
365
/* creating a completion routine to sum  */
366
/* 30 minute segments (fhs 1994 feb 9)   */
367
 
368
static void Remove_timer( )
369
{
370
 RMV_TIMER;
371
 mgrInited = false;
372
}
373
 
374
double  dtime( )
375
{
376
 if( mgrInited ) {
377
   RMV_TIMER;
378
   mgrClock += (MAX_TIME + mgrTimer.tmCount)*1.0e-6;
379
 } else {
380
   if( _atexit( &Remove_timer ) == 0 ) mgrInited = true;
381
   mgrClock = 0.0;
382
 }
383
 
384
 if ( mgrInited )
385
   {
386
    mgrTimer.tmAddr = NULL;
387
    mgrTimer.tmCount = 0;
388
    mgrTimer.tmWakeUp = 0;
389
    mgrTimer.tmReserved = 0;
390
    InsTime( (QElemPtr)&mgrTimer );
391
    PrimeTime( (QElemPtr)&mgrTimer, -MAX_TIME );
392
   }
393
 return( mgrClock );
394
}
395
#endif
396
 
397
/***********************************************************/
398
/*  Parsytec GCel timer.                                   */
399
/*  Provided by: Georg Wambach, gw@informatik.uni-koeln.de */
400
/***********************************************************/
401
#ifdef PARIX
402
#include <sys/time.h>
403
 
404
double dtime()
405
{
406
 double q;
407
 
408
 q = (double) (TimeNowHigh()) / (double) CLK_TCK_HIGH;
409
 
410
 return q;
411
}
412
#endif
413
 
414
/************************************************/
415
/*  Sun Solaris POSIX dtime() routine           */
416
/*  Provided by: Case Larsen, CTLarsen.lbl.gov  */
417
/************************************************/
418
#ifdef POSIX
419
#include <sys/time.h>
420
#include <sys/resource.h>
421
#include <sys/rusage.h>
422
 
423
#ifdef __hpux
424
#include <sys/syscall.h>
425
#endif
426
 
427
struct rusage rusage;
428
 
429
double dtime()
430
{
431
 double q;
432
 
433
 getrusage(RUSAGE_SELF,&rusage);
434
 
435
 q = (double)(rusage.ru_utime.tv_sec);
436
 q = q + (double)(rusage.ru_utime.tv_nsec) * 1.0e-09;
437
 
438
 return q;
439
}
440
#endif
441
 
442
 
443
/****************************************************/
444
/*  Windows NT (32 bit) dtime() routine             */
445
/*  Provided by: Piers Haken, piersh@microsoft.com  */
446
/****************************************************/
447
#ifdef WIN32
448
#include <windows.h>
449
 
450
double dtime(void)
451
{
452
 double q;
453
 
454
 q = (double)GetTickCount() * 1.0e-03;
455
 
456
 return q;
457
}
458
#endif
459
 
460
/*****************************************************/
461
/* Time according to POSIX.1  -  <J.Pelan@qub.ac.uk> */
462
/* Ref: "POSIX Programmer's Guide"  O'Reilly & Assoc.*/
463
/*****************************************************/
464
#ifdef POSIX1
465
#define _POSIX_SOURCE 1
466
#include <unistd.h>
467
#include <limits.h>
468
#include <sys/times.h>
469
 
470
struct tms tms;
471
 
472
double dtime()
473
{
474
 double q;
475
 times(&tms);
476
 q = (double)tms.tms_utime / (double)CLK_TCK;
477
 return q;
478
}
479
#endif

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.