if ((dep->de_flags & DEF_XMIT_BUSY)) {
if (from_int) panic("should not be sending ");
- getuptime(&now);
+ getticks(&now);
if ((now - dep->de_xmit_start) > 4) {
/* Transmitter timed out */
DEBUG(printf("3c501: transmitter timed out ... \n"));
outb_el1(dep, EL1_CSR, ECSR_RIDE | ECSR_XMIT); /* There it goes... */
unlock();
- getuptime(&dep->de_xmit_start);
+ getticks(&dep->de_xmit_start);
dep->de_flags &= NOT(DEF_SENDING);
}
return;
int ix;
short int TxStatus;
- getuptime(&now);
+ getticks(&now);
if ((dep->de_flags & DEF_XMIT_BUSY) &&
(now - dep->de_xmit_start) > 4) {
/* Writes packet */
el3_write_fifo(dep, count);
- getuptime(&dep->de_xmit_start);
+ getticks(&dep->de_xmit_start);
dep->de_flags |= (DEF_XMIT_BUSY | DEF_ACK_SEND);
if (inw_el3(dep, REG_TxFree) > ETH_MAX_PACK_SIZE) {
/* Tx has enough room for a packet of maximum size */
assert(fbd_buf != NULL);
- if ((r = getuptime(&uptime)) != OK)
+ if ((r = getticks(&uptime)) != OK)
panic("getuptime failed (%d)\n", r);
srand48(uptime);
} else {
if(next_alarm)
panic("overwriting alarm: %d", r);
- if ((r = getuptime(&next_alarm)) != OK)
+ if ((r = getticks(&next_alarm)) != OK)
panic("getuptime failed: %d", r);
next_alarm += dt;
}
t_or *orp;
int i, r;
- if (OK != (r = getuptime(&now)))
+ if (OK != (r = getticks(&now)))
panic("orinoco: getuptime() failed: %d", r);
if(now - last_reset < system_hz * 10) {
-#define NCALLS 114 /* number of system calls allowed */
+#define NCALLS 116 /* number of system calls allowed */
/* In case it isn't obvious enough: this list is sorted numerically. */
#define EXIT 1
#define GCOV_FLUSH 112 /* flush gcov data from server to gcov files */
#define PM_GETSID 113 /* PM getsid() */
+#define CLOCK_GETRES 114 /* clock_getres() */
+#define CLOCK_GETTIME 115 /* clock_gettime() */
#define TASK_REPLY 121 /* to VFS: reply code from drivers, not
* really a standalone call.
#define T_USER_TIME m4_l1 /* user time consumed by process */
#define T_SYSTEM_TIME m4_l2 /* system time consumed by process */
#define T_BOOTTIME m4_l3 /* Boottime in seconds (also for SYS_STIME) */
-#define T_BOOT_TICKS m4_l5 /* number of clock ticks since boot time */
+#define T_REAL_TICKS m4_l4 /* number of wall clock ticks since boottime */
+#define T_BOOT_TICKS m4_l5 /* number of hard clock ticks since boottime */
/* Field names for SYS_TRACE, SYS_PRIVCTL, SYS_STATECTL. */
#define CTL_ENDPT m2_i1 /* process number of the caller */
int printf(const char *fmt, ...);
void kputc(int c);
__dead void panic(const char *fmt, ...);
-int getuptime(clock_t *ticks);
-int getuptime2(clock_t *ticks, time_t *boottime);
+int getuptime(clock_t *ticks, clock_t *realtime, time_t *boottime);
+int getticks(clock_t *ticks);
int tickdelay(clock_t ticks);
int tsc_calibrate(void);
u32_t sys_hz(void);
struct itimerspec;
int clock_nanosleep(clockid_t, int, const struct timespec *, struct timespec *);
#ifndef __LIBC12_SOURCE__
-#ifndef __minix
int clock_getres(clockid_t, struct timespec *)
__RENAME(__clock_getres50);
int clock_gettime(clockid_t, struct timespec *)
__RENAME(__clock_gettime50);
+#ifndef __minix
int clock_settime(clockid_t, const struct timespec *)
__RENAME(__clock_settime50);
#endif /* !__minix */
m_ptr->T_SYSTEM_TIME = rp->p_sys_time;
}
m_ptr->T_BOOT_TICKS = get_monotonic();
+ m_ptr->T_REAL_TICKS = get_realtime();
m_ptr->T_BOOTTIME = boottime;
return(OK);
}
lchmod
lchown
clone
-clock_getres
-clock_gettime
clock_settime
extattr_*
fhopen
SRCS+= accept.c access.c bind.c brk.c sbrk.c m_closefrom.c getsid.c \
chdir.c chmod.c fchmod.c chown.c fchown.c chroot.c close.c \
+ clock_getres.c clock_gettime.c \
connect.c dup.c dup2.c execve.c fcntl.c flock.c fpathconf.c fork.c \
fstatfs.c fstatvfs.c fsync.c ftruncate.c getdents.c getegid.c getgid.c \
getgroups.c getitimer.c setitimer.c __getlogin.c getpeername.c \
--- /dev/null
+#include <sys/cdefs.h>
+#include <lib.h>
+#include "namespace.h"
+
+#include <sys/time.h>
+
+#ifdef __weak_alias
+__weak_alias(clock_getres, __clock_getres50);
+#endif
+
+int clock_getres(clockid_t clock_id, struct timespec *res)
+{
+ message m;
+
+ m.m2_l1 = (clockid_t) clock_id;
+
+ if (_syscall(PM_PROC_NR, CLOCK_GETRES, &m) < 0)
+ return -1;
+
+ res->tv_sec = (time_t) m.m2_l1;
+ res->tv_nsec = (long) m.m2_l2;
+
+ return 0;
+}
+
--- /dev/null
+#include <sys/cdefs.h>
+#include <lib.h>
+#include "namespace.h"
+
+#include <sys/time.h>
+
+#ifdef __weak_alias
+__weak_alias(clock_gettime, __clock_gettime50);
+#endif
+
+int clock_gettime(clockid_t clock_id, struct timespec *res)
+{
+ message m;
+
+ m.m2_l1 = (clockid_t) clock_id;
+
+ if (_syscall(PM_PROC_NR, CLOCK_GETTIME, &m) < 0)
+ return -1;
+
+ res->tv_sec = (time_t) m.m2_l1;
+ res->tv_nsec = (long) m.m2_l2;
+
+ return 0;
+}
+
{
/* returns the current clock tick */
myclock_t ret;
- getuptime(&ret);
+ getticks(&ret);
return ret;
}
{
clock_t ticks;
- if (getuptime(&ticks) == OK)
+ if (getticks(&ticks) == OK)
return ticks;
else
panic("getuptime() failed\n");
if (!hz)
hz = sys_hz();
+ /* use ticks not realtime as sys_now() is used to calculate timers */
jiffs = sys_jiffies();
return jiffs * (1000 / hz);
register int k;
clock_t uptime;
+ clock_t realtime;
time_t boottime;
- if ((k=getuptime2(&uptime, &boottime)) != OK)
+ if ((k=getuptime(&uptime, &realtime, &boottime)) != OK)
panic("clock_time: getuptme2 failed: %d", k);
- return( (time_t) (boottime + (uptime/sys_hz())));
+ return( (time_t) (boottime + (realtime/sys_hz())));
}
env_parse.c \
env_prefix.c \
fkey_ctl.c \
+ getticks.c \
getsysinfo.c \
getuptime.c \
- getuptime2.c \
input.c \
kernel_call.c \
kprintf.c \
if (micro_delta >= TSC_SPIN) {
s->s_usecs -= micro_delta;
- getuptime(&s->s_base_uptime);
+ getticks(&s->s_base_uptime);
s->s_state = STATE_UPTIME;
}
break;
case STATE_UPTIME:
- getuptime(&now);
+ getticks(&now);
/* We assume that sys_hz() caches its return value. */
micro_delta = ((now - s->s_base_uptime) * 1000 / sys_hz()) *
if (micro_delta >= TSC_SPIN) {
s->s_usecs -= micro_delta;
- getuptime(&s->s_base_uptime);
+ getticks(&s->s_base_uptime);
s->s_state = STATE_UPTIME;
}
break;
case STATE_UPTIME:
- getuptime(&now);
+ getticks(&now);
/* We assume that sys_hz() caches its return value. */
micro_delta = ((now - s->s_base_uptime) * 1000 / sys_hz()) *
#include "sysutil.h"
/*===========================================================================*
- * getuptime2 *
+ * getuptime *
*===========================================================================*/
-int getuptime2(ticks, boottime)
-clock_t *ticks; /* uptime in ticks */
-time_t *boottime;
+int getticks(ticks)
+clock_t *ticks; /* monotonic time in ticks */
{
message m;
int s;
m.T_ENDPT = NONE; /* ignore process times */
s = _kernel_call(SYS_TIMES, &m);
*ticks = m.T_BOOT_TICKS;
- *boottime = m.T_BOOTTIME;
return(s);
}
/*===========================================================================*
* getuptime *
*===========================================================================*/
-int getuptime(ticks)
-clock_t *ticks; /* uptime in ticks */
+int getuptime(ticks, realtime, boottime)
+clock_t *ticks; /* monotonic time in ticks */
+clock_t *realtime; /* wall time in ticks */
+time_t *boottime;
{
message m;
int s;
m.T_ENDPT = NONE; /* ignore process times */
s = _kernel_call(SYS_TIMES, &m);
*ticks = m.T_BOOT_TICKS;
+ *realtime = m.T_REAL_TICKS;
+ *boottime = m.T_BOOTTIME;
return(s);
}
int r;
clock_t now, prev_time = 0, next_time;
- if ((r = getuptime(&now)) != OK)
+ if ((r = getticks(&now)) != OK)
panic("set_timer: couldn't get uptime");
/* Set timer argument and add timer to the list. */
register int k;
clock_t uptime;
+ clock_t realtime;
time_t boottime;
- if ( (k=getuptime2(&uptime, &boottime)) != OK)
+ if ( (k=getuptime(&uptime, &realtime, &boottime)) != OK)
panic("clock_time: getuptme2 failed: %d", k);
- return( (time_t) (boottime + (uptime/sys_hz())));
+ return( (time_t) (boottime + (realtime/sys_hz())));
}
{
if (!curr_time)
{
- if (getuptime(&curr_time) != OK)
+ if (getticks(&curr_time) != OK)
ip_panic(("can't read clock"));
assert(curr_time >= prev_time);
}
printf("Error obtaining table from PM. Perhaps recompile IS?\n");
return;
}
- getuptime(&uptime);
+ getticks(&uptime);
printf("Process manager (PM) signal action dump\n");
printf("-process- -nr- --ignore- --catch- --block- -pending- -alarm---\n");
EXTERN dev_t fs_dev; /* the device that is handled by this FS proc */
EXTERN char fs_dev_label[16]; /* Name of the device driver that is handled */
-EXTERN int use_getuptime2; /* Should be removed togetherwith boottime */
register int k;
clock_t uptime;
+ clock_t realtime;
time_t boottime;
- if ( (k=getuptime2(&uptime, &boottime)) != OK)
+ if ( (k=getuptime(&uptime, &realtime, &boottime)) != OK)
panic("clock_time: getuptme2 failed: %d", k);
- return( (time_t) (boottime + (uptime/sys_hz())));
+ return( (time_t) (boottime + (realtime/sys_hz())));
}
int r;
clock_t uptime; /* Uptime in ticks */
+ clock_t realtime;
time_t boottime;
- if ((r = getuptime2(&uptime, &boottime)) != OK)
+ if ((r = getuptime(&uptime, &realtime, &boottime)) != OK)
panic("clock_time: getuptme2 failed: %d", r);
- return( (time_t) (boottime + (uptime/sys_hz())));
+ return( (time_t) (boottime + (realtime/sys_hz())));
}
/* First determine remaining time, in ticks, of previous alarm, if set. */
if (rmp->mp_flags & ALARM_ON) {
- if ( (s = getuptime(&uptime)) != OK)
+ if ( (s = getticks(&uptime)) != OK)
panic("get_realtimer couldn't get uptime: %d", s);
exptime = *tmr_exp_time(&rmp->mp_timer);
#define svrctl_req m2_i1
#define svrctl_argp m2_p1
#define stime m2_l1
+#define clk_id m2_l1
#define memsize m4_l1
#define membase m4_l2
#define sysuname_req m1_i1
#define reply_trace m2_l2
#define reply_time m2_l1
#define reply_utime m2_l2
+#define reply_ntime m2_l2
#define reply_t1 m4_l1
#define reply_t2 m4_l2
#define reply_t3 m4_l3
int do_stime(void);
int do_time(void);
int do_times(void);
+int do_getres(void);
+int do_gettime(void);
/* trace.c */
int do_trace(void);
do_srv_kill, /* 111 = srv_kill */
no_sys, /* 112 = gcov_flush */
do_get, /* 113 = getsid */
+ do_getres, /* 114 = clock_getres */
+ do_gettime, /* 115 = clock_gettime */
};
/* This should not fail with "array size is negative": */
extern int dummy[sizeof(call_vec) == NCALLS * sizeof(call_vec[0]) ? 1 : -1];
/* This file takes care of those system calls that deal with time.
*
* The entry points into this file are
+ * do_getres: perform the CLOCK_GETRES system call
+ * do_gettime: perform the CLOCK_GETTIME system call
* do_time: perform the TIME system call
* do_stime: perform the STIME system call
* do_times: perform the TIMES system call
#include <minix/callnr.h>
#include <minix/com.h>
#include <signal.h>
+#include <sys/time.h>
#include "mproc.h"
#include "param.h"
+/*===========================================================================*
+ * do_gettime *
+ *===========================================================================*/
+int do_gettime()
+{
+ clock_t ticks, realtime, clock;
+ time_t boottime;
+ int s;
+
+ if ( (s=getuptime(&ticks, &realtime, &boottime)) != OK)
+ panic("do_time couldn't get uptime: %d", s);
+
+ switch (m_in.clk_id) {
+ case CLOCK_REALTIME:
+ clock = realtime;
+ break;
+ case CLOCK_MONOTONIC:
+ clock = ticks;
+ break;
+ default:
+ return EINVAL; /* invalid/unsupported clock_id */
+ }
+
+ mp->mp_reply.reply_time = (time_t) (boottime + (clock / system_hz));
+ mp->mp_reply.reply_ntime = (clock % system_hz) * 1000000000 / system_hz;
+
+ return(OK);
+}
+
+/*===========================================================================*
+ * do_getres *
+ *===========================================================================*/
+int do_getres()
+{
+ switch (m_in.clk_id) {
+ case CLOCK_REALTIME:
+ case CLOCK_MONOTONIC:
+ /* tv_sec is always 0 since system_hz is an int */
+ mp->mp_reply.reply_time = (time_t) 0;
+ mp->mp_reply.reply_ntime = 1000000000 / system_hz;
+ return(OK);
+ default:
+ return EINVAL; /* invalid/unsupported clock_id */
+ }
+}
+
/*===========================================================================*
* do_time *
*===========================================================================*/
* rotates at a constant rate and that such things as leap seconds do not
* exist.
*/
- clock_t uptime, boottime;
+ clock_t ticks, realtime;
+ time_t boottime;
int s;
- if ( (s=getuptime2(&uptime, &boottime)) != OK)
+ if ( (s=getuptime(&ticks, &realtime, &boottime)) != OK)
panic("do_time couldn't get uptime: %d", s);
- mp->mp_reply.reply_time = (time_t) (boottime + (uptime/system_hz));
- mp->mp_reply.reply_utime = (uptime%system_hz)*1000000/system_hz;
+ mp->mp_reply.reply_time = (time_t) (boottime + (realtime / system_hz));
+ mp->mp_reply.reply_utime = (realtime % system_hz) * 1000000 / system_hz;
return(OK);
}
/* Perform the stime(tp) system call. Retrieve the system's uptime (ticks
* since boot) and pass the new time in seconds at system boot to the kernel.
*/
- clock_t uptime, boottime;
+ clock_t uptime, realtime;
+ time_t boottime;
int s;
if (mp->mp_effuid != SUPER_USER) {
return(EPERM);
}
- if ( (s=getuptime(&uptime)) != OK)
+ if ( (s=getuptime(&uptime, &realtime, &boottime)) != OK)
panic("do_stime couldn't get uptime: %d", s);
- boottime = (long) m_in.stime - (uptime/system_hz);
+ boottime = (long) m_in.stime - (realtime/system_hz);
s= sys_stime(boottime); /* Tell kernel about boottime */
if (s != OK)
clock_t ticks;
ldiv_t division;
- if (getuptime(&ticks) != OK)
+ if (getticks(&ticks) != OK)
return;
division = ldiv(100L * ticks / sys_hz(), 100L);
/* Update lazily for lookups, as this gets too expensive otherwise.
* Alternative: pull in only PM's table?
*/
- if ((r = getuptime(&now)) != OK)
+ if ((r = getticks(&now)) != OK)
panic(__FILE__, "unable to get uptime", r);
if (last_update != now) {
rp->r_next_rp = NULL; /* no next replica yet */
rp->r_uid = 0; /* root */
rp->r_check_tm = 0; /* not checked yet */
- getuptime(&rp->r_alive_tm); /* currently alive */
+ getticks(&rp->r_alive_tm); /* currently alive */
rp->r_stop_tm = 0; /* not exiting yet */
rp->r_restarts = 0; /* no restarts so far */
rp->r_period = 0; /* no period yet */
/* Mark the slot as no longer initializing. */
rp->r_flags &= ~RS_INITIALIZING;
rp->r_check_tm = 0;
- getuptime(&rp->r_alive_tm);
+ getticks(&rp->r_alive_tm);
}
/*===========================================================================*
rpub->endpoint = child_proc_nr_e; /* set child endpoint */
rp->r_pid = child_pid; /* set child pid */
rp->r_check_tm = 0; /* not checked yet */
- getuptime(&rp->r_alive_tm); /* currently alive */
+ getticks(&rp->r_alive_tm); /* currently alive */
rp->r_stop_tm = 0; /* not exiting yet */
rp->r_backoff = 0; /* not to be restarted */
rproc_ptr[child_proc_nr_n] = rp; /* mapping for fast access */
rp->r_flags |= how; /* what to on exit? */
sys_kill(rpub->endpoint, signo); /* first try friendly */
- getuptime(&rp->r_stop_tm); /* record current time */
+ getticks(&rp->r_stop_tm); /* record current time */
}
/*===========================================================================*
/* Mark the slot as no longer initializing. */
rp->r_flags &= ~RS_INITIALIZING;
rp->r_check_tm = 0;
- getuptime(&rp->r_alive_tm);
+ getticks(&rp->r_alive_tm);
/* Reply and unblock the service before doing anything else. */
m.m_type = OK;
rp->r_flags |= RS_UPDATING;
rp->r_new_rp->r_flags |= RS_UPDATING;
rupdate.flags |= RS_UPDATING;
- getuptime(&rupdate.prepare_tm);
+ getticks(&rupdate.prepare_tm);
rupdate.prepare_maxtime = prepare_maxtime;
rupdate.rp = rp;
no_sys, /* 111 = (srv_kill) */
do_gcov_flush, /* 112 = gcov_flush */
no_sys, /* 113 = (getsid) */
+ no_sys, /* 114 = (clock_getres) */
+ no_sys, /* 115 = (clock_gettime) */
};
/* This should not fail with "array size is negative": */
extern int dummy[sizeof(call_vec) == NCALLS * sizeof(call_vec[0]) ? 1 : -1];
register int r;
clock_t uptime;
+ clock_t realtime;
time_t boottime;
- r = getuptime2(&uptime, &boottime);
+ r = getuptime(&uptime, &realtime, &boottime);
if (r != OK)
panic("clock_time err: %d", r);
- return( (time_t) (boottime + (uptime/system_hz)));
+ return( (time_t) (boottime + (realtime/system_hz)));
}
/*===========================================================================*
clock_t ticks;
int s;
- s = getuptime(&ticks);
+ s = getticks(&ticks);
assert(s == OK);
struct timespec it_value;
};
-#ifndef __minix
#define CLOCK_REALTIME 0
+#define CLOCK_MONOTONIC 3
+
+#ifndef __minix
#define CLOCK_VIRTUAL 1
#define CLOCK_PROF 2
-#define CLOCK_MONOTONIC 3
#endif
#if defined(_NETBSD_SOURCE)
if (driver_minor > 255)
panic("invalid or no driver minor given");
- if ((r = getuptime(&now)) != OK)
+ if ((r = getticks(&now)) != OK)
panic("unable to get uptime: %d", r);
srand48(now);