VM: static data structure for mem allocation
[minix3.git] / servers / pm / time.c
blob747a0bd652b66a383bf72305b40cba8d40e62e18
1 /* This file takes care of those system calls that deal with time.
3 * The entry points into this file are
4 * do_time: perform the TIME system call
5 * do_stime: perform the STIME system call
6 * do_times: perform the TIMES system call
7 */
9 #include "pm.h"
10 #include <minix/callnr.h>
11 #include <minix/com.h>
12 #include <signal.h>
13 #include "mproc.h"
14 #include "param.h"
16 /*===========================================================================*
17 * do_time *
18 *===========================================================================*/
19 int do_time()
21 /* Perform the time(tp) system call. This returns the time in seconds since
22 * 1.1.1970. MINIX is an astrophysically naive system that assumes the earth
23 * rotates at a constant rate and that such things as leap seconds do not
24 * exist.
26 clock_t uptime, boottime;
27 int s;
29 if ( (s=getuptime2(&uptime, &boottime)) != OK)
30 panic("do_time couldn't get uptime: %d", s);
32 mp->mp_reply.reply_time = (time_t) (boottime + (uptime/system_hz));
33 mp->mp_reply.reply_utime = (uptime%system_hz)*1000000/system_hz;
34 return(OK);
37 /*===========================================================================*
38 * do_stime *
39 *===========================================================================*/
40 int do_stime()
42 /* Perform the stime(tp) system call. Retrieve the system's uptime (ticks
43 * since boot) and pass the new time in seconds at system boot to the kernel.
45 clock_t uptime, boottime;
46 int s;
48 if (mp->mp_effuid != SUPER_USER) {
49 return(EPERM);
51 if ( (s=getuptime(&uptime)) != OK)
52 panic("do_stime couldn't get uptime: %d", s);
53 boottime = (long) m_in.stime - (uptime/system_hz);
55 s= sys_stime(boottime); /* Tell kernel about boottime */
56 if (s != OK)
57 panic("pm: sys_stime failed: %d", s);
59 return(OK);
62 /*===========================================================================*
63 * do_times *
64 *===========================================================================*/
65 int do_times()
67 /* Perform the times(buffer) system call. */
68 register struct mproc *rmp = mp;
69 clock_t user_time, sys_time, uptime;
70 int s;
72 if (OK != (s=sys_times(who_e, &user_time, &sys_time, &uptime, NULL)))
73 panic("do_times couldn't get times: %d", s);
74 rmp->mp_reply.reply_t1 = user_time; /* user time */
75 rmp->mp_reply.reply_t2 = sys_time; /* system time */
76 rmp->mp_reply.reply_t3 = rmp->mp_child_utime; /* child user time */
77 rmp->mp_reply.reply_t4 = rmp->mp_child_stime; /* child system time */
78 rmp->mp_reply.reply_t5 = uptime; /* uptime since boot */
80 return(OK);