Home My Page Projects Code Snippets Project Openings SML/NJ
Summary Activity Forums Tracker Lists Tasks Docs Surveys News SCM Files

SCM Repository

[smlnj] Annotation of /sml/trunk/src/runtime/kernel/unix-timers.c
ViewVC logotype

Annotation of /sml/trunk/src/runtime/kernel/unix-timers.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2 - (view) (download) (as text)

1 : monnier 2 /* unix-timers.c
2 :     *
3 :     * COPYRIGHT (c) 1995 by AT&T Bell Laboratories.
4 :     *
5 :     * A UNIX specific interface to the system timers.
6 :     */
7 :    
8 :     #include "ml-unixdep.h"
9 :     #include "ml-base.h"
10 :     #include "ml-state.h"
11 :     #include "ml-timer.h"
12 :    
13 :     #ifdef HAS_GETRUSAGE
14 :    
15 :     #include <sys/time.h>
16 :     #include <sys/resource.h>
17 :     typedef struct rusage time_struct_t;
18 :     #define GET_TIME(t) getrusage(RUSAGE_SELF, &(t))
19 :     #define SYS_TIME(t) ((t).ru_stime)
20 :     #define USR_TIME(t) ((t).ru_utime)
21 :     #define SET_TIME(tp, t) { *((struct timeval *)(tp)) = (t); }
22 :    
23 :     #else /* !HAS_GETRUSAGE */
24 :    
25 :     #include <sys/times.h>
26 :     PVT long ClksPerSec = 0;
27 :     typedef struct tms time_struct_t;
28 :     #define GET_TIME(t) times(&(t))
29 :     #define SYS_TIME(t) ((t).tms_stime)
30 :     #define USR_TIME(t) ((t).tms_utime)
31 :     #define SET_TIME(tp, t) { \
32 :     Time_t *__tp = (tp); \
33 :     clock_t __t = (t); \
34 :     __tp->uSeconds = ((__t % ClksPerSec) * 1000000) / ClksPerSec; \
35 :     __tp->seconds = (__t / ClksPerSec); \
36 :     }
37 :    
38 :     #endif /* HAS_GETRUSAGE */
39 :    
40 :    
41 :    
42 :     /* Several versions of Unix seem to allow time values to decrease on successive
43 :     * calls to getrusage. To avoid problems in the SML code, which assumes that
44 :     * time is monotonically increasing, we latch the time values.
45 :     *
46 :     * NOTE: this should probably be move to the VProc structure to avoid problems
47 :     * on MP machines.
48 :     */
49 :     PVT Time_t lastU, lastS;
50 :    
51 :    
52 :     /* InitTimers:
53 :     *
54 :     * Do any system specific timer initialization.
55 :     */
56 :     void InitTimers ()
57 :     {
58 :     lastU.seconds = lastU.uSeconds = 0;
59 :     lastS.seconds = lastS.uSeconds = 0;
60 :    
61 :     #ifndef HAS_GETRUSAGE
62 :     if (ClksPerSec == 0)
63 :     ClksPerSec = sysconf(_SC_CLK_TCK);
64 :     #endif
65 :    
66 :     } /* end of InitTimers */
67 :    
68 :    
69 :     /* GetCPUTime:
70 :     *
71 :     * Get the user and/or system cpu times in a system independent way.
72 :     */
73 :     void GetCPUTime (Time_t *usrT, Time_t *sysT)
74 :     {
75 :     time_struct_t ts;
76 :    
77 :     GET_TIME(ts);
78 :    
79 :     if (usrT != NIL(Time_t *)) {
80 :     SET_TIME(usrT, USR_TIME(ts));
81 :     if (usrT->seconds < lastU.seconds)
82 :     usrT->seconds = lastU.seconds;
83 :     if ((usrT->seconds == lastU.seconds) && (usrT->uSeconds < lastU.uSeconds))
84 :     usrT->uSeconds = lastU.uSeconds;
85 :     lastU = *usrT;
86 :     }
87 :    
88 :     if (sysT != NIL(Time_t *)) {
89 :     SET_TIME(sysT, SYS_TIME(ts));
90 :     if (sysT->seconds < lastS.seconds)
91 :     sysT->seconds = lastS.seconds;
92 :     if ((sysT->seconds == lastS.seconds) && (sysT->uSeconds < lastS.uSeconds))
93 :     sysT->uSeconds = lastS.uSeconds;
94 :     lastS = *sysT;
95 :     }
96 :    
97 :     } /* end of GetCPUTime. */

root@smlnj-gforge.cs.uchicago.edu
ViewVC Help
Powered by ViewVC 1.0.0