diff options
author | 2012-03-23 15:51:25 +0000 | |
---|---|---|
committer | 2012-03-23 15:51:25 +0000 | |
commit | 8f15e6a4ddcf78e1c1320bc27380937fb93b1657 (patch) | |
tree | 6054f67bdb157eefd93c058e5b63bde14012ea3b /sys/kern/kern_time.c | |
parent | rollback r1.76 since it may break some tools (diff) | |
download | wireguard-openbsd-8f15e6a4ddcf78e1c1320bc27380937fb93b1657.tar.xz wireguard-openbsd-8f15e6a4ddcf78e1c1320bc27380937fb93b1657.zip |
Make rusage totals, itimers, and profile settings per-process instead
of per-rthread. Handling of per-thread tick and runtime counters
inspired by how FreeBSD does it.
ok kettenis@
Diffstat (limited to 'sys/kern/kern_time.c')
-rw-r--r-- | sys/kern/kern_time.c | 48 |
1 files changed, 23 insertions, 25 deletions
diff --git a/sys/kern/kern_time.c b/sys/kern/kern_time.c index 180e76178fb..3ed6a7d53eb 100644 --- a/sys/kern/kern_time.c +++ b/sys/kern/kern_time.c @@ -1,4 +1,4 @@ -/* $OpenBSD: kern_time.c,v 1.73 2012/03/19 09:05:39 guenther Exp $ */ +/* $OpenBSD: kern_time.c,v 1.74 2012/03/23 15:51:26 guenther Exp $ */ /* $NetBSD: kern_time.c,v 1.20 1996/02/18 11:57:06 fvdl Exp $ */ /* @@ -588,12 +588,10 @@ out: /* * Get value of an interval timer. The process virtual and - * profiling virtual time timers are kept in the p_stats area, since - * they can be swapped out. These are kept internally in the + * profiling virtual time timers are kept internally in the * way they are specified externally: in time until they expire. * - * The real time interval timer is kept in the process table slot - * for the process, and its value (it_value) is kept as an + * The real time interval timer's it_value, in contast, is kept as an * absolute time rather than as a delta, so that it is easy to keep * periodic real-time signals from drifting. * @@ -624,6 +622,8 @@ sys_getitimer(struct proc *p, void *v, register_t *retval) if (which < ITIMER_REAL || which > ITIMER_PROF) return (EINVAL); s = splclock(); + aitv = p->p_p->ps_timer[which]; + if (which == ITIMER_REAL) { struct timeval now; @@ -634,7 +634,6 @@ sys_getitimer(struct proc *p, void *v, register_t *retval) * has passed return 0, else return difference between * current time and time for the timer to go off. */ - aitv = p->p_realtimer; if (timerisset(&aitv.it_value)) { if (timercmp(&aitv.it_value, &now, <)) timerclear(&aitv.it_value); @@ -642,8 +641,7 @@ sys_getitimer(struct proc *p, void *v, register_t *retval) timersub(&aitv.it_value, &now, &aitv.it_value); } - } else - aitv = p->p_stats->p_timer[which]; + } splx(s); return (copyout(&aitv, SCARG(uap, itv), sizeof (struct itimerval))); } @@ -661,6 +659,7 @@ sys_setitimer(struct proc *p, void *v, register_t *retval) struct itimerval aitv; const struct itimerval *itvp; struct itimerval *oitv; + struct process *pr = p->p_p; int error; int timo; int which; @@ -687,24 +686,24 @@ sys_setitimer(struct proc *p, void *v, register_t *retval) if (which == ITIMER_REAL) { struct timeval ctv; - timeout_del(&p->p_realit_to); + timeout_del(&pr->ps_realit_to); getmicrouptime(&ctv); if (timerisset(&aitv.it_value)) { timo = tvtohz(&aitv.it_value); - timeout_add(&p->p_realit_to, timo); + timeout_add(&pr->ps_realit_to, timo); timeradd(&aitv.it_value, &ctv, &aitv.it_value); } - p->p_realtimer = aitv; + pr->ps_timer[ITIMER_REAL] = aitv; } else { int s; itimerround(&aitv.it_interval); s = splclock(); - p->p_stats->p_timer[which] = aitv; + pr->ps_timer[which] = aitv; if (which == ITIMER_VIRTUAL) - timeout_del(&p->p_stats->p_virt_to); + timeout_del(&pr->ps_virt_to); if (which == ITIMER_PROF) - timeout_del(&p->p_stats->p_prof_to); + timeout_del(&pr->ps_prof_to); splx(s); } @@ -722,29 +721,28 @@ sys_setitimer(struct proc *p, void *v, register_t *retval) void realitexpire(void *arg) { - struct proc *p; + struct process *pr = arg; + struct itimerval *tp = &pr->ps_timer[ITIMER_REAL]; - p = (struct proc *)arg; - psignal(p, SIGALRM); - if (!timerisset(&p->p_realtimer.it_interval)) { - timerclear(&p->p_realtimer.it_value); + psignal(pr->ps_mainproc, SIGALRM); + if (!timerisset(&tp->it_interval)) { + timerclear(&tp->it_value); return; } for (;;) { struct timeval ctv, ntv; int timo; - timeradd(&p->p_realtimer.it_value, - &p->p_realtimer.it_interval, &p->p_realtimer.it_value); + timeradd(&tp->it_value, &tp->it_interval, &tp->it_value); getmicrouptime(&ctv); - if (timercmp(&p->p_realtimer.it_value, &ctv, >)) { - ntv = p->p_realtimer.it_value; + if (timercmp(&tp->it_value, &ctv, >)) { + ntv = tp->it_value; timersub(&ntv, &ctv, &ntv); timo = tvtohz(&ntv) - 1; if (timo <= 0) timo = 1; - if ((p->p_p->ps_flags & PS_EXITING) == 0) - timeout_add(&p->p_realit_to, timo); + if ((pr->ps_flags & PS_EXITING) == 0) + timeout_add(&pr->ps_realit_to, timo); return; } } |