15 static struct linux_timezone systz
;
24 systz
.tz_minuteswest
= 0;
27 if(t
= localtime(time(nil
)))
28 systz
.tz_minuteswest
= t
->tzoff
/ 60;
36 int sys_clock_gettime(int clock
, void *t
)
38 struct linux_timespec
*ts
= t
;
41 trace("sys_clock_gettime(%d, %p)", clock
, t
);
43 ts
->tv_sec
= (long)(x
/1000000000LL);
44 ts
->tv_nsec
= (long)(x%1000000000LL
);
48 int sys_gettimeofday(void *tvp
, void *tzp
)
50 struct linux_timeval
*tv
= tvp
;
51 struct linux_timezone
*tz
= tzp
;
54 trace("sys_gettimeofday(%p, %p)", tvp
, tzp
);
57 tv
->tv_sec
= (long)(t
/1000000000LL);
58 tv
->tv_usec
= (long)((t%1000000000LL
)/1000);
66 int sys_nanosleep(void *rqp
, void *rmp
)
68 struct linux_timespec
*req
= rqp
;
69 struct linux_timespec
*rem
= rmp
;
73 trace("sys_nanosleep(%p, %p)", rqp
, rmp
);
77 if(req
->tv_sec
< 0 || req
->tv_nsec
< 0 || req
->tv_nsec
>= 1000000000LL)
81 if(current
->restart
->syscall
){
82 t
= current
->restart
->nanosleep
.timeout
;
84 t
= now
+ req
->tv_sec
*1000000000LL + req
->tv_nsec
;
91 err
= sleep((t
- now
) / 1000000LL);
97 current
->restart
->nanosleep
.timeout
= t
;
100 rem
->tv_sec
= (long)(t
/1000000000LL);
101 rem
->tv_nsec
= (long)(t%1000000000LL
);
111 int proctimes(Uproc
*p
, ulong
*t
)
113 char buf
[1024], *f
[12];
116 t
[0] = t
[1] = t
[2] = t
[3] = 0;
117 snprint(buf
, sizeof(buf
), "/proc/%d/status", p
->kpid
);
118 if((fd
= open(buf
, OREAD
)) < 0)
120 if((n
= read(fd
, buf
, sizeof(buf
)-1)) <= 0){
126 if(getfields(buf
, f
, 12, 1, "\t ") != 12)
128 t
[0] = atoi(f
[2])*HZ
/ 1000;
129 t
[1] = atoi(f
[3])*HZ
/ 1000;
130 t
[2] = atoi(f
[4])*HZ
/ 1000;
131 t
[3] = atoi(f
[5])*HZ
/ 1000;
143 int sys_times(void *m
)
145 struct linux_tms
*x
= m
;
149 trace("sys_times(%p)", m
);
152 if((err
= proctimes(current
, t
)) < 0)
156 x
->tms_cutime
= t
[2];
157 x
->tms_cstime
= t
[3];
159 return (HZ
*(nsec() - boottime
)) / 1000000000LL;