]> git.uio.no Git - u/mrichter/AliRoot.git/blob - MINICERN/packlib/kernlib/kerngen/ccgen/dosgs/timel.c
This commit was generated by cvs2svn to compensate for changes in r2,
[u/mrichter/AliRoot.git] / MINICERN / packlib / kernlib / kerngen / ccgen / dosgs / timel.c
1 /*
2  * $Id$
3  *
4  * $Log$
5  * Revision 1.1.1.1  1996/02/15 17:49:31  mclareni
6  * Kernlib
7  *
8  */
9 /*>    ROUTINE TIMEL
10   CERN PROGLIB# Z007    TIMEST          .VERSION KERNFOR  4.38  931108
11   ORIG. 01/03/85  FCA, mod 03/11/93 GF
12 */
13 #ifdef WIN32
14 #include <sys\types.h>
15 #else
16 #include <sys/types.h>
17 #endif
18 #include <time.h>
19 #ifndef WIN32
20 #include <sys/times.h>
21 #include <sys/param.h>
22 #include <sys/time.h>
23 #include <sys/resource.h>
24 #endif
25
26 #ifndef CLOCKS_PER_SEC
27 #define  CLOCKS_PER_SEC CLK_TCK
28 #endif
29
30
31 #ifndef RLIMIT_CPU
32 #define RLIMIT_CPU 0    /* For HP-UX... */
33 #endif
34 #ifndef RLIM_INFINITY
35 #define RLIM_INFINITY 0x7fffffff    /* For HP-UX... */
36 #endif
37
38 #if defined(CERNLIB_QSYSBSD)||defined(CERNLIB_QMVMI)||defined(CERNLIB_QMVAOS)
39 #define HZ 60.;
40 #endif
41
42 #ifndef HZ
43 #ifdef __GNUC__
44 #define HZ 1
45 #else
46 #define HZ 1./CLOCKS_PER_SEC
47 #endif
48 #endif
49
50 #if defined(CERNLIB_QMDOS)
51 #ifdef __GNUC__
52 #define sectim   1./timsec
53 #define time_t double
54 double timfac  = 1./CLOCKS_PER_SEC;
55 double timsec  = (double) 0x7fffffff/CLOCKS_PER_SEC;
56 #include <std.h>
57 #endif
58 #ifdef WIN32
59
60 /**************************************************************************\
61 *
62 *       For some reason 'clock()' returns elapsed time on at least the AXP
63 *       systems.  Substitute the routine 'ntclock()' for 'clock()'.
64 *
65 \**************************************************************************/
66
67 #define clock ntclock
68
69 #endif
70
71 #endif
72 #if !defined(CERNLIB_QMDOS)
73 struct tms tps;
74 #endif
75 static float timlim;
76 static time_t timstart, timlast;
77 static int tml_init = 1;
78 float deftim = 999.;
79
80 #if defined(CERNLIB_QX_SC)
81 #define timest timest_
82 #define timex  timex_
83 #define timed  timed_
84 #define timel  timel_
85 #endif
86 #if defined(CERNLIB_QXCAPT)
87 #define timest TIMEST
88 #define timex  TIMEX
89 #define timed  TIMED
90 #define timel  TIMEL
91 #endif
92
93                    /*  local routine called by timst, and time_init */
94 static void time_st(timl)
95 float timl;
96 {
97 #if !defined(CERNLIB_QMDOS)
98     times(&tps);
99 #endif
100     timlim = timl;
101 #if !defined(CERNLIB_QMDOS)
102     timstart =  tps.tms_utime+tps.tms_cutime+tps.tms_stime+tps.tms_cstime;
103 #endif
104 #if defined(CERNLIB_QMDOS)
105 #ifdef __GNUC__
106     timstart= (long)((time(NULL)&0xfffff)*sectim) * timsec
107               + (double)(clock()*timfac);
108 #else
109     timstart= clock();
110 #endif
111
112 #endif
113     timlast  = timstart;
114     tml_init = 0;
115     return;
116 }
117                    /*  local routine to start by default  */
118 static void time_init()
119 {
120 #if !defined(CERNLIB_QMDOS)
121         struct rlimit rlimit;
122 #endif
123         float  maxtime;
124
125         maxtime=deftim;
126
127 #if !defined(CERNLIB_QMDOS)
128         if (getrlimit(RLIMIT_CPU, &rlimit)==0) {
129                 if ( rlimit.rlim_cur != RLIM_INFINITY )
130                    maxtime = (float) rlimit.rlim_cur;
131         }
132
133 #endif
134         time_st(maxtime);
135         return;
136 }
137
138 void timest(timl)
139 float *timl;
140 {
141 #if !defined(CERNLIB_QMDOS)
142  struct rlimit rlimit;
143 #endif
144  float  maxtime;
145
146  if (tml_init != 0) {
147
148 /*  get maximum time allowed by system, and do not allow more */
149     maxtime = *timl;
150 #if !defined(CERNLIB_QMDOS)
151     if (getrlimit(RLIMIT_CPU, &rlimit)==0) {
152            maxtime = (float) rlimit.rlim_cur;
153            maxtime = ( maxtime > *timl ) ? *timl : maxtime;
154     }
155 #endif
156     time_st(maxtime);
157  }
158  return;
159 }
160 void timex(tx)
161 /*
162 C
163   CERN PROGLIB# Z007    TIMEX           .VERSION KERNFOR  4.38  931108
164 C
165 */
166 float *tx;
167 {
168    time_t timnow;
169    if (tml_init) {
170        time_init();
171        *tx = 0.;
172    }
173    else {
174 #if !defined(CERNLIB_QMDOS)
175        times(&tps);
176        timnow = tps.tms_utime+tps.tms_cutime+tps.tms_stime+tps.tms_cstime;
177 #endif
178 #if defined(CERNLIB_QMDOS)
179 #ifdef _MSDOS_
180        timnow= (long)((time(NULL)&0xfffff)*sectim) * timsec
181                + (double)(clock()*timfac);
182 #else
183        timnow= clock();
184 #endif
185 #endif
186        *tx = (float) (timnow - timstart) / HZ;
187    }
188    return;
189 }
190
191 void timed(td)
192 /*
193 C
194   CERN PROGLIB# Z007    TIMED           .VERSION KERNFOR  4.38  931108
195 C
196 */
197 float *td;
198 {
199    time_t timnow;
200    if (tml_init) {
201        time_init();
202        *td = timlim;
203    }
204    else {
205 #if !defined(CERNLIB_QMDOS)
206        times(&tps);
207        timnow = tps.tms_utime+tps.tms_cutime+tps.tms_stime+tps.tms_cstime;
208 #endif
209 #if defined(CERNLIB_QMDOS)
210 #ifdef _MSDOS_
211        timnow= (long)((time(NULL)&0xfffff)*sectim) * timsec
212                + (double)(clock()*timfac);
213 #else
214        timnow=clock();
215 #endif
216 #endif
217        *td = (float) (timnow - timlast) / HZ;
218        timlast = timnow;
219    }
220    return;
221 }
222
223 void timel(tl)
224 /*
225 C
226   CERN PROGLIB# Z007    TIMEL           .VERSION KERNFOR  4.38  931108
227 C
228 */
229 float *tl;
230 {
231    time_t timnow;
232    if (tml_init) {
233        time_init();
234        *tl = timlim;
235    }
236    else {
237 #if !defined(CERNLIB_QMDOS)
238        times(&tps);
239        timnow = tps.tms_utime+tps.tms_cutime+tps.tms_stime+tps.tms_cstime;
240 #endif
241 #if defined(CERNLIB_QMDOS)
242 #ifdef _MSDOS_
243        timnow= (long)((time(NULL)&0xfffff)*sectim) * timsec
244                + (double)(clock()*timfac);
245 #else
246        timnow= clock();
247 #endif
248 #endif
249        *tl = timlim - (float) (timnow - timstart) / HZ;
250    }
251    return;
252 }
253 #ifdef __GNUC__
254 #undef time_t
255 #endif
256
257 #ifdef WIN32
258 #undef clock
259
260 /**************************************************************************\
261 *  ntclock.c -- function to return sum of user and kernel time
262 *
263 *       For some reason 'clock()' returns elapsed time on at least the AXP
264 *       systems.  Call native WIN32 routines to get process CPU time, and
265 *       return in the same (weird) units defined by 'clock()'.
266 *
267 \**************************************************************************/
268
269 #include <windows.h>
270 #include <stdio.h>
271
272 clock_t ntclock ()
273 {
274     double      tTotal;
275     clock_t     cTotal;
276     DWORD       ret;
277     FILETIME    ftKernel, ftUser, ftCreate, ftExit;
278
279     static HANDLE hProcess = 0;
280
281     cTotal = 0;
282
283     if (hProcess == 0)
284       hProcess = GetCurrentProcess();
285
286     ret = GetProcessTimes (hProcess, &ftCreate, &ftExit, &ftKernel, &ftUser);
287     if (ret != TRUE){
288       ret = GetLastError ();
289       printf ("\n* Error on GetProcessTimes in ntclock()  0x%lx", (int)ret);
290       return cTotal;
291     }
292
293     /*
294      * Process times are returned in a 64-bit structure, as the number of
295      * 100 nanosecond ticks since 1 January 1601.  User mode and kernel mode
296      * times for this process are in separate 64-bit structures.
297      * To convert to floating point seconds, we will:
298      *
299      *          Convert sum of high 32-bit quantities to 64-bit float
300      *          Multiply by 2**32
301      *          Add low 32-bit tick counts
302      *          Divide by 10,000,000 to convert to seconds
303      *          Convert to 'clock_t' value in "clock ticks"
304      */
305
306     tTotal = ftKernel.dwHighDateTime + ftUser.dwHighDateTime;
307     tTotal = tTotal * 4294967296.0;
308     tTotal = tTotal + (ftKernel.dwLowDateTime + ftUser.dwLowDateTime);
309     tTotal = tTotal * 1.0E-7;
310     cTotal = tTotal * CLOCKS_PER_SEC;
311
312     return cTotal;
313 }
314
315 #endif
316
317 /*> END <----------------------------------------------------------*/