summaryrefslogtreecommitdiffstats
path: root/sys/kern
diff options
context:
space:
mode:
authorguenther <guenther@openbsd.org>2013-06-03 16:55:21 +0000
committerguenther <guenther@openbsd.org>2013-06-03 16:55:21 +0000
commit08be1c182fbd154e4a9fe23d2f7954d0b00a3b1d (patch)
treec4804a28a8f9e84c1f24ccefb4fe9d4d7f61f5e6 /sys/kern
parentImplement support for multiple addresses per interface. (diff)
downloadwireguard-openbsd-08be1c182fbd154e4a9fe23d2f7954d0b00a3b1d.tar.xz
wireguard-openbsd-08be1c182fbd154e4a9fe23d2f7954d0b00a3b1d.zip
Convert some internal APIs to use timespecs instead of timevals
ok matthew@ deraadt@
Diffstat (limited to 'sys/kern')
-rw-r--r--sys/kern/init_main.c10
-rw-r--r--sys/kern/kern_acct.c24
-rw-r--r--sys/kern/kern_fork.c4
-rw-r--r--sys/kern/kern_resource.c48
-rw-r--r--sys/kern/kern_sched.c10
-rw-r--r--sys/kern/kern_sysctl.c18
-rw-r--r--sys/kern/kern_tc.c4
-rw-r--r--sys/kern/kern_time.c12
-rw-r--r--sys/kern/sched_bsd.c20
-rw-r--r--sys/kern/tty.c22
10 files changed, 92 insertions, 80 deletions
diff --git a/sys/kern/init_main.c b/sys/kern/init_main.c
index 51067dfae20..a7b4c43c512 100644
--- a/sys/kern/init_main.c
+++ b/sys/kern/init_main.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: init_main.c,v 1.188 2013/03/28 16:55:25 deraadt Exp $ */
+/* $OpenBSD: init_main.c,v 1.189 2013/06/03 16:55:22 guenther Exp $ */
/* $NetBSD: init_main.c,v 1.84.4.1 1996/06/02 09:08:06 mrg Exp $ */
/*
@@ -125,7 +125,7 @@ extern struct user *proc0paddr;
struct vnode *rootvp, *swapdev_vp;
int boothowto;
-struct timeval boottime;
+struct timespec boottime;
int ncpus = 1;
int ncpusfound = 1; /* number of cpus we find */
__volatile int start_init_exec; /* semaphore for start_init() */
@@ -496,11 +496,11 @@ main(void *framep)
* from the file system. Reset p->p_rtime as it may have been
* munched in mi_switch() after the time got set.
*/
- microtime(&boottime);
+ nanotime(&boottime);
LIST_FOREACH(p, &allproc, p_list) {
p->p_p->ps_start = boottime;
- microuptime(&p->p_cpu->ci_schedstate.spc_runtime);
- p->p_rtime.tv_sec = p->p_rtime.tv_usec = 0;
+ nanouptime(&p->p_cpu->ci_schedstate.spc_runtime);
+ timespecclear(&p->p_rtime);
}
uvm_swap_init();
diff --git a/sys/kern/kern_acct.c b/sys/kern/kern_acct.c
index acab061862d..4edf52736ca 100644
--- a/sys/kern/kern_acct.c
+++ b/sys/kern/kern_acct.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: kern_acct.c,v 1.26 2012/07/08 17:14:39 guenther Exp $ */
+/* $OpenBSD: kern_acct.c,v 1.27 2013/06/03 16:55:22 guenther Exp $ */
/* $NetBSD: kern_acct.c,v 1.42 1996/02/04 02:15:12 christos Exp $ */
/*-
@@ -161,7 +161,7 @@ acct_process(struct proc *p)
struct acct acct;
struct process *pr = p->p_p;
struct rusage *r;
- struct timeval ut, st, tmp;
+ struct timespec ut, st, tmp;
int t;
struct vnode *vp;
int error;
@@ -179,20 +179,20 @@ acct_process(struct proc *p)
bcopy(p->p_comm, acct.ac_comm, sizeof acct.ac_comm);
/* (2) The amount of user and system time that was used */
- calcru(&pr->ps_tu, &ut, &st, NULL);
- acct.ac_utime = encode_comp_t(ut.tv_sec, ut.tv_usec);
- acct.ac_stime = encode_comp_t(st.tv_sec, st.tv_usec);
+ calctsru(&pr->ps_tu, &ut, &st, NULL);
+ acct.ac_utime = encode_comp_t(ut.tv_sec, ut.tv_nsec);
+ acct.ac_stime = encode_comp_t(st.tv_sec, st.tv_nsec);
/* (3) The elapsed time the command ran (and its starting time) */
acct.ac_btime = pr->ps_start.tv_sec;
- getmicrotime(&tmp);
- timersub(&tmp, &pr->ps_start, &tmp);
- acct.ac_etime = encode_comp_t(tmp.tv_sec, tmp.tv_usec);
+ getnanotime(&tmp);
+ timespecsub(&tmp, &pr->ps_start, &tmp);
+ acct.ac_etime = encode_comp_t(tmp.tv_sec, tmp.tv_nsec);
/* (4) The average amount of memory used */
r = &p->p_ru;
- timeradd(&ut, &st, &tmp);
- t = tmp.tv_sec * hz + tmp.tv_usec / tick;
+ timespecadd(&ut, &st, &tmp);
+ t = tmp.tv_sec * hz + tmp.tv_nsec / (1000 * tick);
if (t)
acct.ac_mem = (r->ru_ixrss + r->ru_idrss + r->ru_isrss) / t;
else
@@ -236,14 +236,14 @@ acct_process(struct proc *p)
#define MAXFRACT ((1 << MANTSIZE) - 1) /* Maximum fractional value. */
comp_t
-encode_comp_t(u_long s, u_long us)
+encode_comp_t(u_long s, u_long ns)
{
int exp, rnd;
exp = 0;
rnd = 0;
s *= AHZ;
- s += us / (1000000 / AHZ); /* Maximize precision. */
+ s += ns / (1000000000 / AHZ); /* Maximize precision. */
while (s > MAXFRACT) {
rnd = s & (1 << (EXPSIZE - 1)); /* Round up? */
diff --git a/sys/kern/kern_fork.c b/sys/kern/kern_fork.c
index dd4de7f0c9b..5d3ee5312c6 100644
--- a/sys/kern/kern_fork.c
+++ b/sys/kern/kern_fork.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: kern_fork.c,v 1.147 2013/06/01 16:04:46 tedu Exp $ */
+/* $OpenBSD: kern_fork.c,v 1.148 2013/06/03 16:55:22 guenther Exp $ */
/* $NetBSD: kern_fork.c,v 1.29 1996/02/09 18:59:34 christos Exp $ */
/*
@@ -492,7 +492,7 @@ fork1(struct proc *curp, int exitsig, int flags, void *stack, pid_t *tidptr,
* For new processes, set accounting bits
*/
if ((flags & FORK_THREAD) == 0) {
- getmicrotime(&pr->ps_start);
+ getnanotime(&pr->ps_start);
pr->ps_acflag = AFORK;
}
diff --git a/sys/kern/kern_resource.c b/sys/kern/kern_resource.c
index ea4f8bf512b..272f2b99533 100644
--- a/sys/kern/kern_resource.c
+++ b/sys/kern/kern_resource.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: kern_resource.c,v 1.41 2013/04/01 01:07:34 guenther Exp $ */
+/* $OpenBSD: kern_resource.c,v 1.42 2013/06/03 16:55:22 guenther Exp $ */
/* $NetBSD: kern_resource.c,v 1.38 1996/10/23 07:19:38 matthias Exp $ */
/*-
@@ -339,7 +339,7 @@ sys_getrlimit(struct proc *p, void *v, register_t *retval)
void
tuagg_sub(struct tusage *tup, struct proc *p)
{
- timeradd(&tup->tu_runtime, &p->p_rtime, &tup->tu_runtime);
+ timespecadd(&tup->tu_runtime, &p->p_rtime, &tup->tu_runtime);
tup->tu_uticks += p->p_uticks;
tup->tu_sticks += p->p_sticks;
tup->tu_iticks += p->p_iticks;
@@ -354,7 +354,7 @@ tuagg_unlocked(struct process *pr, struct proc *p)
{
tuagg_sub(&pr->ps_tu, p);
tuagg_sub(&p->p_tu, p);
- timerclear(&p->p_rtime);
+ timespecclear(&p->p_rtime);
p->p_uticks = 0;
p->p_sticks = 0;
p->p_iticks = 0;
@@ -375,8 +375,8 @@ tuagg(struct process *pr, struct proc *p)
* into user, system, and interrupt time usage.
*/
void
-calcru(struct tusage *tup, struct timeval *up, struct timeval *sp,
- struct timeval *ip)
+calctsru(struct tusage *tup, struct timespec *up, struct timespec *sp,
+ struct timespec *ip)
{
u_quad_t st, ut, it;
int freq;
@@ -386,28 +386,42 @@ calcru(struct tusage *tup, struct timeval *up, struct timeval *sp,
it = tup->tu_iticks;
if (st + ut + it == 0) {
- timerclear(up);
- timerclear(sp);
+ timespecclear(up);
+ timespecclear(sp);
if (ip != NULL)
- timerclear(ip);
+ timespecclear(ip);
return;
}
freq = stathz ? stathz : hz;
- st = st * 1000000 / freq;
- sp->tv_sec = st / 1000000;
- sp->tv_usec = st % 1000000;
- ut = ut * 1000000 / freq;
- up->tv_sec = ut / 1000000;
- up->tv_usec = ut % 1000000;
+ st = st * 1000000000 / freq;
+ sp->tv_sec = st / 1000000000;
+ sp->tv_nsec = st % 1000000000;
+ ut = ut * 1000000000 / freq;
+ up->tv_sec = ut / 1000000000;
+ up->tv_nsec = ut % 1000000000;
if (ip != NULL) {
- it = it * 1000000 / freq;
- ip->tv_sec = it / 1000000;
- ip->tv_usec = it % 1000000;
+ it = it * 1000000000 / freq;
+ ip->tv_sec = it / 1000000000;
+ ip->tv_nsec = it % 1000000000;
}
}
+void
+calcru(struct tusage *tup, struct timeval *up, struct timeval *sp,
+ struct timeval *ip)
+{
+ struct timespec u, s, i;
+
+ calctsru(tup, &u, &s, ip != NULL ? &i : NULL);
+ TIMESPEC_TO_TIMEVAL(up, &u);
+ TIMESPEC_TO_TIMEVAL(sp, &s);
+ if (ip != NULL)
+ TIMESPEC_TO_TIMEVAL(ip, &i);
+}
+
+
/* ARGSUSED */
int
sys_getrusage(struct proc *p, void *v, register_t *retval)
diff --git a/sys/kern/kern_sched.c b/sys/kern/kern_sched.c
index 40aa5c8c163..dad6291081e 100644
--- a/sys/kern/kern_sched.c
+++ b/sys/kern/kern_sched.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: kern_sched.c,v 1.28 2013/04/19 21:44:08 tedu Exp $ */
+/* $OpenBSD: kern_sched.c,v 1.29 2013/06/03 16:55:22 guenther Exp $ */
/*
* Copyright (c) 2007, 2008 Artur Grabowski <art@openbsd.org>
*
@@ -190,13 +190,13 @@ void
sched_exit(struct proc *p)
{
struct schedstate_percpu *spc = &curcpu()->ci_schedstate;
- struct timeval tv;
+ struct timespec ts;
struct proc *idle;
int s;
- microuptime(&tv);
- timersub(&tv, &spc->spc_runtime, &tv);
- timeradd(&p->p_rtime, &tv, &p->p_rtime);
+ nanouptime(&ts);
+ timespecsub(&ts, &spc->spc_runtime, &ts);
+ timespecadd(&p->p_rtime, &ts, &p->p_rtime);
LIST_INSERT_HEAD(&spc->spc_deadproc, p, p_hash);
diff --git a/sys/kern/kern_sysctl.c b/sys/kern/kern_sysctl.c
index 00967454af0..d7bbfd4a4ba 100644
--- a/sys/kern/kern_sysctl.c
+++ b/sys/kern/kern_sysctl.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: kern_sysctl.c,v 1.234 2013/04/06 03:44:34 tedu Exp $ */
+/* $OpenBSD: kern_sysctl.c,v 1.235 2013/06/03 16:55:22 guenther Exp $ */
/* $NetBSD: kern_sysctl.c,v 1.17 1996/05/20 17:49:05 mrg Exp $ */
/*-
@@ -356,9 +356,11 @@ kern_sysctl(int *name, u_int namelen, void *oldp, size_t *oldlenp, void *newp,
return (error);
case KERN_CLOCKRATE:
return (sysctl_clockrate(oldp, oldlenp, newp));
- case KERN_BOOTTIME:
- return (sysctl_rdstruct(oldp, oldlenp, newp, &boottime,
- sizeof(struct timeval)));
+ case KERN_BOOTTIME: {
+ struct timeval bt;
+ TIMESPEC_TO_TIMEVAL(&bt, &boottime);
+ return (sysctl_rdstruct(oldp, oldlenp, newp, &bt, sizeof bt));
+ }
case KERN_VNODE:
return (sysctl_vnode(oldp, oldlenp, p));
#ifndef SMALL_KERNEL
@@ -1543,7 +1545,7 @@ fill_kproc(struct proc *p, struct kinfo_proc *ki, int isthread,
struct process *pr = p->p_p;
struct session *s = pr->ps_session;
struct tty *tp;
- struct timeval ut, st;
+ struct timespec ut, st;
FILL_KPROC(ki, strlcpy, p, pr, p->p_cred, p->p_ucred, pr->ps_pgrp,
p, pr, s, p->p_vmspace, pr->ps_limit, p->p_sigacts, isthread,
@@ -1571,11 +1573,11 @@ fill_kproc(struct proc *p, struct kinfo_proc *ki, int isthread,
if (p->p_stat != SIDL)
ki->p_vm_rssize = vm_resident_count(p->p_vmspace);
- calcru(&p->p_tu, &ut, &st, NULL);
+ calctsru(&p->p_tu, &ut, &st, NULL);
ki->p_uutime_sec = ut.tv_sec;
- ki->p_uutime_usec = ut.tv_usec;
+ ki->p_uutime_usec = ut.tv_nsec/1000;
ki->p_ustime_sec = st.tv_sec;
- ki->p_ustime_usec = st.tv_usec;
+ ki->p_ustime_usec = st.tv_nsec/1000;
#ifdef MULTIPROCESSOR
if (p->p_cpu != NULL)
diff --git a/sys/kern/kern_tc.c b/sys/kern/kern_tc.c
index cf8a9484a81..7b988a33dfc 100644
--- a/sys/kern/kern_tc.c
+++ b/sys/kern/kern_tc.c
@@ -6,7 +6,7 @@
* this stuff is worth it, you can buy me a beer in return. Poul-Henning Kamp
* ----------------------------------------------------------------------------
*
- * $OpenBSD: kern_tc.c,v 1.19 2013/06/02 20:59:09 guenther Exp $
+ * $OpenBSD: kern_tc.c,v 1.20 2013/06/03 16:55:22 guenther Exp $
* $FreeBSD: src/sys/kern/kern_tc.c,v 1.148 2003/03/18 08:45:23 phk Exp $
*/
@@ -296,7 +296,7 @@ tc_setrealtimeclock(struct timespec *ts)
bintime_sub(&bt, &bt2);
bintime_add(&bt2, &boottimebin);
boottimebin = bt;
- bintime2timeval(&bt, &boottime);
+ bintime2timespec(&bt, &boottime);
add_timer_randomness(ts->tv_sec);
/* XXX fiddle all the little crinkly bits around the fiords... */
diff --git a/sys/kern/kern_time.c b/sys/kern/kern_time.c
index fec84fbf5b4..dcb878639fd 100644
--- a/sys/kern/kern_time.c
+++ b/sys/kern/kern_time.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: kern_time.c,v 1.78 2013/06/02 20:59:09 guenther Exp $ */
+/* $OpenBSD: kern_time.c,v 1.79 2013/06/03 16:55:22 guenther Exp $ */
/* $NetBSD: kern_time.c,v 1.20 1996/02/18 11:57:06 fvdl Exp $ */
/*
@@ -112,8 +112,6 @@ settime(struct timespec *ts)
int
clock_gettime(struct proc *p, clockid_t clock_id, struct timespec *tp)
{
- struct timeval tv;
-
switch (clock_id) {
case CLOCK_REALTIME:
nanotime(tp);
@@ -122,11 +120,9 @@ clock_gettime(struct proc *p, clockid_t clock_id, struct timespec *tp)
nanouptime(tp);
break;
case CLOCK_PROF:
- microuptime(&tv);
- timersub(&tv, &curcpu()->ci_schedstate.spc_runtime, &tv);
- timeradd(&tv, &p->p_rtime, &tv);
- tp->tv_sec = tv.tv_sec;
- tp->tv_nsec = tv.tv_usec * 1000;
+ nanouptime(tp);
+ timespecsub(tp, &curcpu()->ci_schedstate.spc_runtime, tp);
+ timespecadd(tp, &p->p_rtime, tp);
break;
default:
return (EINVAL);
diff --git a/sys/kern/sched_bsd.c b/sys/kern/sched_bsd.c
index ff7a1d2c966..ed512c2af29 100644
--- a/sys/kern/sched_bsd.c
+++ b/sys/kern/sched_bsd.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: sched_bsd.c,v 1.32 2013/06/02 20:59:09 guenther Exp $ */
+/* $OpenBSD: sched_bsd.c,v 1.33 2013/06/03 16:55:22 guenther Exp $ */
/* $NetBSD: kern_synch.c,v 1.37 1996/04/22 01:38:37 christos Exp $ */
/*-
@@ -346,7 +346,7 @@ mi_switch(void)
struct process *pr = p->p_p;
struct rlimit *rlim;
rlim_t secs;
- struct timeval tv;
+ struct timespec ts;
#ifdef MULTIPROCESSOR
int hold_count;
int sched_count;
@@ -372,18 +372,18 @@ mi_switch(void)
* Compute the amount of time during which the current
* process was running, and add that to its total so far.
*/
- microuptime(&tv);
- if (timercmp(&tv, &spc->spc_runtime, <)) {
+ nanouptime(&ts);
+ if (timespeccmp(&ts, &spc->spc_runtime, <)) {
#if 0
printf("uptime is not monotonic! "
- "tv=%lld.%06lu, runtime=%lld.%06lu\n",
- (long long)tv.tv_sec, tv.tv_usec,
+ "ts=%lld.%09lu, runtime=%lld.%09lu\n",
+ (long long)tv.tv_sec, tv.tv_nsec,
(long long)spc->spc_runtime.tv_sec,
- spc->spc_runtime.tv_usec);
+ spc->spc_runtime.tv_nsec);
#endif
} else {
- timersub(&tv, &spc->spc_runtime, &tv);
- timeradd(&p->p_rtime, &tv, &p->p_rtime);
+ timespecsub(&ts, &spc->spc_runtime, &ts);
+ timespecadd(&p->p_rtime, &ts, &p->p_rtime);
}
/* add the time counts for this thread to the process's total */
@@ -443,7 +443,7 @@ mi_switch(void)
*/
KASSERT(p->p_cpu == curcpu());
- microuptime(&p->p_cpu->ci_schedstate.spc_runtime);
+ nanouptime(&p->p_cpu->ci_schedstate.spc_runtime);
#ifdef MULTIPROCESSOR
/*
diff --git a/sys/kern/tty.c b/sys/kern/tty.c
index 48e3ed66f7d..b3f87146101 100644
--- a/sys/kern/tty.c
+++ b/sys/kern/tty.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: tty.c,v 1.97 2013/04/24 09:52:54 nicm Exp $ */
+/* $OpenBSD: tty.c,v 1.98 2013/06/03 16:55:22 guenther Exp $ */
/* $NetBSD: tty.c,v 1.68.4.2 1996/06/06 16:04:52 thorpej Exp $ */
/*-
@@ -2122,7 +2122,7 @@ ttyinfo(struct tty *tp)
{
struct process *pr;
struct proc *pick;
- struct timeval utime, stime;
+ struct timespec utime, stime;
int tmp;
if (ttycheckoutq(tp,0) == 0)
@@ -2152,20 +2152,20 @@ ttyinfo(struct tty *tp)
rss = pick->p_stat == SIDL || P_ZOMBIE(pick) ? 0 :
vm_resident_count(pick->p_vmspace);
- calcru(&pick->p_p->ps_tu, &utime, &stime, NULL);
+ calctsru(&pick->p_p->ps_tu, &utime, &stime, NULL);
/* Round up and print user time. */
- utime.tv_usec += 5000;
- if (utime.tv_usec >= 1000000) {
+ utime.tv_nsec += 5000000;
+ if (utime.tv_nsec >= 1000000000) {
utime.tv_sec += 1;
- utime.tv_usec -= 1000000;
+ utime.tv_nsec -= 1000000000;
}
/* Round up and print system time. */
- stime.tv_usec += 5000;
- if (stime.tv_usec >= 1000000) {
+ stime.tv_nsec += 5000000;
+ if (stime.tv_nsec >= 1000000000) {
stime.tv_sec += 1;
- stime.tv_usec -= 1000000;
+ stime.tv_nsec -= 1000000000;
}
ttyprintf(tp,
@@ -2174,8 +2174,8 @@ ttyinfo(struct tty *tp)
pick->p_stat == SONPROC ? "running" :
pick->p_stat == SRUN ? "runnable" :
pick->p_wmesg ? pick->p_wmesg : "iowait",
- utime.tv_sec, utime.tv_usec / 10000,
- stime.tv_sec, stime.tv_usec / 10000, pctcpu / 100, rss);
+ utime.tv_sec, utime.tv_nsec / 10000000,
+ stime.tv_sec, stime.tv_nsec / 10000000, pctcpu / 100, rss);
}
tp->t_rocount = 0; /* so pending input will be retyped if BS */
}