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 | |
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')
-rw-r--r-- | sys/kern/init_main.c | 12 | ||||
-rw-r--r-- | sys/kern/kern_acct.c | 27 | ||||
-rw-r--r-- | sys/kern/kern_clock.c | 29 | ||||
-rw-r--r-- | sys/kern/kern_exec.c | 13 | ||||
-rw-r--r-- | sys/kern/kern_exit.c | 54 | ||||
-rw-r--r-- | sys/kern/kern_fork.c | 13 | ||||
-rw-r--r-- | sys/kern/kern_resource.c | 91 | ||||
-rw-r--r-- | sys/kern/kern_sched.c | 4 | ||||
-rw-r--r-- | sys/kern/kern_sig.c | 6 | ||||
-rw-r--r-- | sys/kern/kern_synch.c | 4 | ||||
-rw-r--r-- | sys/kern/kern_sysctl.c | 6 | ||||
-rw-r--r-- | sys/kern/kern_time.c | 48 | ||||
-rw-r--r-- | sys/kern/sched_bsd.c | 18 | ||||
-rw-r--r-- | sys/kern/subr_prof.c | 12 | ||||
-rw-r--r-- | sys/kern/tty.c | 4 | ||||
-rw-r--r-- | sys/kern/uipc_socket.c | 6 | ||||
-rw-r--r-- | sys/kern/vfs_bio.c | 10 |
17 files changed, 196 insertions, 161 deletions
diff --git a/sys/kern/init_main.c b/sys/kern/init_main.c index a3b43e4ec28..341200012aa 100644 --- a/sys/kern/init_main.c +++ b/sys/kern/init_main.c @@ -1,4 +1,4 @@ -/* $OpenBSD: init_main.c,v 1.181 2012/01/01 12:17:33 fgsch Exp $ */ +/* $OpenBSD: init_main.c,v 1.182 2012/03/23 15:51:26 guenther Exp $ */ /* $NetBSD: init_main.c,v 1.84.4.1 1996/06/02 09:08:06 mrg Exp $ */ /* @@ -288,7 +288,7 @@ main(void *framep) /* Init timeouts. */ timeout_set(&p->p_sleep_to, endtsleep, p); - timeout_set(&p->p_realit_to, realitexpire, p); + timeout_set(&pr->ps_realit_to, realitexpire, pr); /* Create credentials. */ p->p_cred = &cred0; @@ -326,12 +326,6 @@ main(void *framep) p->p_addr = proc0paddr; /* XXX */ /* - * We continue to place resource usage info in the - * user struct so they're pageable. - */ - p->p_stats = &p->p_addr->u_stats; - - /* * Charge root for one process. */ (void)chgproccnt(0, 1); @@ -500,7 +494,7 @@ main(void *framep) boottime = mono_time = time; #endif LIST_FOREACH(p, &allproc, p_list) { - p->p_stats->p_start = boottime; + 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; } diff --git a/sys/kern/kern_acct.c b/sys/kern/kern_acct.c index 0051d4fe1c5..aa519740c5d 100644 --- a/sys/kern/kern_acct.c +++ b/sys/kern/kern_acct.c @@ -1,4 +1,4 @@ -/* $OpenBSD: kern_acct.c,v 1.23 2010/07/26 01:56:27 guenther Exp $ */ +/* $OpenBSD: kern_acct.c,v 1.24 2012/03/23 15:51:26 guenther Exp $ */ /* $NetBSD: kern_acct.c,v 1.42 1996/02/04 02:15:12 christos Exp $ */ /*- @@ -159,6 +159,7 @@ int acct_process(struct proc *p) { struct acct acct; + struct process *pr = p->p_p; struct rusage *r; struct timeval ut, st, tmp; int t; @@ -175,9 +176,9 @@ acct_process(struct proc *p) * Raise the file limit so that accounting can't be stopped by the * user. (XXX - we should think about the cpu limit too). */ - if (p->p_p->ps_limit->p_refcnt > 1) { - oplim = p->p_p->ps_limit; - p->p_p->ps_limit = limcopy(p->p_p->ps_limit); + if (pr->ps_limit->p_refcnt > 1) { + oplim = pr->ps_limit; + pr->ps_limit = limcopy(pr->ps_limit); } p->p_rlimit[RLIMIT_FSIZE].rlim_cur = RLIM_INFINITY; @@ -189,18 +190,18 @@ 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(p, &ut, &st, NULL); + 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); /* (3) The elapsed time the command ran (and its starting time) */ - acct.ac_btime = p->p_stats->p_start.tv_sec; + acct.ac_btime = pr->ps_start.tv_sec; getmicrotime(&tmp); - timersub(&tmp, &p->p_stats->p_start, &tmp); + timersub(&tmp, &pr->ps_start, &tmp); acct.ac_etime = encode_comp_t(tmp.tv_sec, tmp.tv_usec); /* (4) The average amount of memory used */ - r = &p->p_stats->p_ru; + r = &p->p_ru; timeradd(&ut, &st, &tmp); t = tmp.tv_sec * hz + tmp.tv_usec / tick; if (t) @@ -216,9 +217,9 @@ acct_process(struct proc *p) acct.ac_gid = p->p_cred->p_rgid; /* (7) The terminal from which the process was started */ - if ((p->p_p->ps_flags & PS_CONTROLT) && - p->p_p->ps_pgrp->pg_session->s_ttyp) - acct.ac_tty = p->p_p->ps_pgrp->pg_session->s_ttyp->t_dev; + if ((pr->ps_flags & PS_CONTROLT) && + pr->ps_pgrp->pg_session->s_ttyp) + acct.ac_tty = pr->ps_pgrp->pg_session->s_ttyp->t_dev; else acct.ac_tty = NODEV; @@ -232,8 +233,8 @@ acct_process(struct proc *p) (off_t)0, UIO_SYSSPACE, IO_APPEND|IO_UNIT, p->p_ucred, NULL, p); if (oplim) { - limfree(p->p_p->ps_limit); - p->p_p->ps_limit = oplim; + limfree(pr->ps_limit); + pr->ps_limit = oplim; } return error; diff --git a/sys/kern/kern_clock.c b/sys/kern/kern_clock.c index 7e85444d988..ab567332f37 100644 --- a/sys/kern/kern_clock.c +++ b/sys/kern/kern_clock.c @@ -1,4 +1,4 @@ -/* $OpenBSD: kern_clock.c,v 1.72 2011/03/07 07:07:13 guenther Exp $ */ +/* $OpenBSD: kern_clock.c,v 1.73 2012/03/23 15:51:26 guenther Exp $ */ /* $NetBSD: kern_clock.c,v 1.34 1996/06/09 04:51:03 briggs Exp $ */ /*- @@ -170,10 +170,6 @@ initclocks(void) * * hardclock detects that the itimer has expired, and schedules a timeout * to deliver the signal. This works because of the following reasons: - * - The timeout structures can be in struct pstats because the timers - * can be only activated on curproc (never swapped). Swapout can - * only happen from a kernel thread and softclock runs before threads - * are scheduled. * - The timeout can be scheduled with a 1 tick time because we're * doing it before the timeout processing in hardclock. So it will * be scheduled to run as soon as possible. @@ -189,17 +185,17 @@ initclocks(void) void virttimer_trampoline(void *v) { - struct proc *p = v; + struct process *pr = v; - psignal(p, SIGVTALRM); + psignal(pr->ps_mainproc, SIGVTALRM); } void proftimer_trampoline(void *v) { - struct proc *p = v; + struct process *pr = v; - psignal(p, SIGPROF); + psignal(pr->ps_mainproc, SIGPROF); } /* @@ -220,19 +216,18 @@ hardclock(struct clockframe *frame) p = curproc; if (p && ((p->p_flag & (P_SYSTEM | P_WEXIT)) == 0)) { - struct pstats *pstats; + struct process *pr = p->p_p; /* * Run current process's virtual and profile time, as needed. */ - pstats = p->p_stats; if (CLKF_USERMODE(frame) && - timerisset(&pstats->p_timer[ITIMER_VIRTUAL].it_value) && - itimerdecr(&pstats->p_timer[ITIMER_VIRTUAL], tick) == 0) - timeout_add(&pstats->p_virt_to, 1); - if (timerisset(&pstats->p_timer[ITIMER_PROF].it_value) && - itimerdecr(&pstats->p_timer[ITIMER_PROF], tick) == 0) - timeout_add(&pstats->p_prof_to, 1); + timerisset(&pr->ps_timer[ITIMER_VIRTUAL].it_value) && + itimerdecr(&pr->ps_timer[ITIMER_VIRTUAL], tick) == 0) + timeout_add(&pr->ps_virt_to, 1); + if (timerisset(&pr->ps_timer[ITIMER_PROF].it_value) && + itimerdecr(&pr->ps_timer[ITIMER_PROF], tick) == 0) + timeout_add(&pr->ps_prof_to, 1); } /* diff --git a/sys/kern/kern_exec.c b/sys/kern/kern_exec.c index 4fa96597e89..2cf05248187 100644 --- a/sys/kern/kern_exec.c +++ b/sys/kern/kern_exec.c @@ -1,4 +1,4 @@ -/* $OpenBSD: kern_exec.c,v 1.125 2012/03/09 13:01:28 ariane Exp $ */ +/* $OpenBSD: kern_exec.c,v 1.126 2012/03/23 15:51:26 guenther Exp $ */ /* $NetBSD: kern_exec.c,v 1.75 1996/02/09 18:59:28 christos Exp $ */ /*- @@ -600,13 +600,10 @@ sys_execve(struct proc *p, void *v, register_t *retval) if (pr->ps_flags & PS_SUGIDEXEC) { int i, s = splclock(); - timeout_del(&p->p_realit_to); - timerclear(&p->p_realtimer.it_interval); - timerclear(&p->p_realtimer.it_value); - for (i = 0; i < sizeof(p->p_stats->p_timer) / - sizeof(p->p_stats->p_timer[0]); i++) { - timerclear(&p->p_stats->p_timer[i].it_interval); - timerclear(&p->p_stats->p_timer[i].it_value); + timeout_del(&pr->ps_realit_to); + for (i = 0; i < nitems(pr->ps_timer); i++) { + timerclear(&pr->ps_timer[i].it_interval); + timerclear(&pr->ps_timer[i].it_value); } splx(s); } diff --git a/sys/kern/kern_exit.c b/sys/kern/kern_exit.c index c9a2a9c93f0..d3225d4e350 100644 --- a/sys/kern/kern_exit.c +++ b/sys/kern/kern_exit.c @@ -1,4 +1,4 @@ -/* $OpenBSD: kern_exit.c,v 1.108 2012/03/10 05:54:28 guenther Exp $ */ +/* $OpenBSD: kern_exit.c,v 1.109 2012/03/23 15:51:26 guenther Exp $ */ /* $NetBSD: kern_exit.c,v 1.39 1996/04/22 01:38:25 christos Exp $ */ /* @@ -120,6 +120,7 @@ void exit1(struct proc *p, int rv, int flags) { struct process *pr, *qr, *nqr; + struct rusage *rup; if (p->p_pid == 1) panic("init died (signal %d, exit %d)", @@ -166,11 +167,18 @@ exit1(struct proc *p, int rv, int flags) if (p->p_flag & P_PROFIL) stopprofclock(p); - p->p_ru = pool_get(&rusage_pool, PR_WAITOK); + rup = pr->ps_ru; + if (rup == NULL) { + rup = pool_get(&rusage_pool, PR_WAITOK | PR_ZERO); + + if (pr->ps_ru == NULL) + pr->ps_ru = rup; + else { + pool_put(&rusage_pool, rup); + rup = pr->ps_ru; + } + } p->p_siglist = 0; - timeout_del(&p->p_realit_to); - timeout_del(&p->p_stats->p_virt_to); - timeout_del(&p->p_stats->p_prof_to); /* * Close open files and release open-file table. @@ -178,6 +186,9 @@ exit1(struct proc *p, int rv, int flags) fdfree(p); if ((p->p_flag & P_THREAD) == 0) { + timeout_del(&pr->ps_realit_to); + timeout_del(&pr->ps_virt_to); + timeout_del(&pr->ps_prof_to); #ifdef SYSVSEM semexit(pr); #endif @@ -271,13 +282,8 @@ exit1(struct proc *p, int rv, int flags) } - /* - * Save exit status and final rusage info, adding in child rusage - * info and self times. - */ - *p->p_ru = p->p_stats->p_ru; - calcru(p, &p->p_ru->ru_utime, &p->p_ru->ru_stime, NULL); - ruadd(p->p_ru, &p->p_stats->p_cru); + /* add thread's accumulated rusage into the process's total */ + ruadd(rup, &p->p_ru); /* * clear %cpu usage during swap @@ -285,6 +291,15 @@ exit1(struct proc *p, int rv, int flags) p->p_pctcpu = 0; if ((p->p_flag & P_THREAD) == 0) { + /* + * Final thread has died, so add on our children's rusage + * and calculate the total times + */ + calcru(&pr->ps_tu, &rup->ru_utime, &rup->ru_stime, NULL); + ruadd(rup, &pr->ps_cru); + timeradd(&rup->ru_utime, &pr->ps_cru.ru_utime, &rup->ru_utime); + timeradd(&rup->ru_stime, &pr->ps_cru.ru_stime, &rup->ru_stime); + /* notify interested parties of our demise and clean up */ knote_processexit(pr); @@ -468,7 +483,7 @@ loop: return (error); } if (SCARG(uap, rusage) && - (error = copyout(p->p_ru, + (error = copyout(pr->ps_ru, SCARG(uap, rusage), sizeof(struct rusage)))) return (error); proc_finish_wait(q, p); @@ -517,6 +532,7 @@ void proc_finish_wait(struct proc *waiter, struct proc *p) { struct process *pr, *tr; + struct rusage *rup; /* * If we got the child via a ptrace 'attach', @@ -534,7 +550,10 @@ proc_finish_wait(struct proc *waiter, struct proc *p) } else { scheduler_wait_hook(waiter, p); p->p_xstat = 0; - ruadd(&waiter->p_stats->p_cru, p->p_ru); + rup = &waiter->p_p->ps_cru; + ruadd(rup, pr->ps_ru); + timeradd(&rup->ru_utime, &pr->ps_ru->ru_utime, &rup->ru_utime); + timeradd(&rup->ru_stime, &pr->ps_ru->ru_stime, &rup->ru_stime); proc_zap(p); } } @@ -562,10 +581,6 @@ proc_zap(struct proc *p) { struct process *pr = p->p_p; - pool_put(&rusage_pool, p->p_ru); - if ((p->p_flag & P_THREAD) == 0 && pr->ps_ptstat) - free(pr->ps_ptstat, M_SUBPROC); - /* * Finally finished with old proc entry. * Unlink it from its process group and free it. @@ -592,6 +607,9 @@ proc_zap(struct proc *p) * in the process (pun intended). */ if (--pr->ps_refcnt == 0) { + if (pr->ps_ptstat != NULL) + free(pr->ps_ptstat, M_SUBPROC); + pool_put(&rusage_pool, pr->ps_ru); KASSERT(TAILQ_EMPTY(&pr->ps_threads)); limfree(pr->ps_limit); crfree(pr->ps_cred->pc_ucred); diff --git a/sys/kern/kern_fork.c b/sys/kern/kern_fork.c index bf667d3b901..f7225155e47 100644 --- a/sys/kern/kern_fork.c +++ b/sys/kern/kern_fork.c @@ -1,4 +1,4 @@ -/* $OpenBSD: kern_fork.c,v 1.134 2012/02/20 22:23:39 guenther Exp $ */ +/* $OpenBSD: kern_fork.c,v 1.135 2012/03/23 15:51:26 guenther Exp $ */ /* $NetBSD: kern_fork.c,v 1.29 1996/02/09 18:59:34 christos Exp $ */ /* @@ -219,6 +219,10 @@ process_new(struct proc *p, struct process *parent) crhold(parent->ps_cred->pc_ucred); pr->ps_limit->p_refcnt++; + timeout_set(&pr->ps_realit_to, realitexpire, pr); + timeout_set(&pr->ps_virt_to, virttimer_trampoline, pr); + timeout_set(&pr->ps_prof_to, proftimer_trampoline, pr); + pr->ps_flags = parent->ps_flags & (PS_SUGID | PS_SUGIDEXEC); if (parent->ps_session->s_ttyvp != NULL && parent->ps_flags & PS_CONTROLT) @@ -331,12 +335,10 @@ fork1(struct proc *curp, int exitsig, int flags, void *stack, pid_t *tidptr, * Initialize the timeouts. */ timeout_set(&p->p_sleep_to, endtsleep, p); - timeout_set(&p->p_realit_to, realitexpire, p); /* * Duplicate sub-structures as needed. * Increase reference counts on shared objects. - * The p_stats and p_sigacts substructs are set in vm_fork. */ if (curp->p_flag & P_PROFIL) startprofclock(p); @@ -404,9 +406,6 @@ fork1(struct proc *curp, int exitsig, int flags, void *stack, pid_t *tidptr, uvm_fork(curp, p, ((flags & FORK_SHAREVM) ? TRUE : FALSE), stack, 0, func ? func : child_return, arg ? arg : p); - timeout_set(&p->p_stats->p_virt_to, virttimer_trampoline, p); - timeout_set(&p->p_stats->p_prof_to, proftimer_trampoline, p); - vm = p->p_vmspace; if (flags & FORK_FORK) { @@ -481,7 +480,7 @@ fork1(struct proc *curp, int exitsig, int flags, void *stack, pid_t *tidptr, * Make child runnable, set start time, and add to run queue. */ SCHED_LOCK(s); - getmicrotime(&p->p_stats->p_start); + getmicrotime(&pr->ps_start); p->p_acflag = AFORK; p->p_stat = SRUN; p->p_cpu = sched_choosecpu_fork(curp, flags); diff --git a/sys/kern/kern_resource.c b/sys/kern/kern_resource.c index ce3dfea9fdf..ab199d4401e 100644 --- a/sys/kern/kern_resource.c +++ b/sys/kern/kern_resource.c @@ -1,4 +1,4 @@ -/* $OpenBSD: kern_resource.c,v 1.38 2012/03/19 09:05:39 guenther Exp $ */ +/* $OpenBSD: kern_resource.c,v 1.39 2012/03/23 15:51:26 guenther Exp $ */ /* $NetBSD: kern_resource.c,v 1.38 1996/10/23 07:19:38 matthias Exp $ */ /*- @@ -52,6 +52,9 @@ #include <uvm/uvm_extern.h> +void tuagg_sub(struct tusage *, struct proc *); +void tuagg(struct process *, struct proc *); + /* * Patchable maximum data and stack limits. */ @@ -334,23 +337,54 @@ sys_getrlimit(struct proc *p, void *v, register_t *retval) return (error); } +void +tuagg_sub(struct tusage *tup, struct proc *p) +{ + timeradd(&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; +} + /* - * Transform the running time and tick information in proc p into user, - * system, and interrupt time usage. + * Aggregate a single thread's immediate time counts into the running + * totals for the thread and process */ void -calcru(struct proc *p, struct timeval *up, struct timeval *sp, +tuagg_unlocked(struct process *pr, struct proc *p) +{ + tuagg_sub(&pr->ps_tu, p); + tuagg_sub(&p->p_tu, p); + timerclear(&p->p_rtime); + p->p_uticks = 0; + p->p_sticks = 0; + p->p_iticks = 0; +} + +void +tuagg(struct process *pr, struct proc *p) +{ + int s; + + SCHED_LOCK(s); + tuagg_unlocked(pr, p); + SCHED_UNLOCK(s); +} + +/* + * Transform the running time and tick information in a struct tusage + * into user, system, and interrupt time usage. + */ +void +calcru(struct tusage *tup, struct timeval *up, struct timeval *sp, struct timeval *ip) { u_quad_t st, ut, it; int freq; - int s; - s = splstatclock(); - st = p->p_sticks; - ut = p->p_uticks; - it = p->p_iticks; - splx(s); + st = tup->tu_sticks; + ut = tup->tu_uticks; + it = tup->tu_iticks; if (st + ut + it == 0) { timerclear(up); @@ -384,43 +418,36 @@ sys_getrusage(struct proc *p, void *v, register_t *retval) syscallarg(struct rusage *) rusage; } */ *uap = v; struct process *pr = p->p_p; + struct proc *q; struct rusage ru; struct rusage *rup; switch (SCARG(uap, who)) { case RUSAGE_SELF: - calcru(p, &p->p_stats->p_ru.ru_utime, - &p->p_stats->p_ru.ru_stime, NULL); - ru = p->p_stats->p_ru; + /* start with the sum of dead threads, if any */ + if (pr->ps_ru != NULL) + ru = *pr->ps_ru; + else + bzero(&ru, sizeof(ru)); rup = &ru; - /* XXX add on already dead threads */ - - /* add on other living threads */ - { - struct proc *q; - - TAILQ_FOREACH(q, &pr->ps_threads, p_thr_link) { - if (q == p || P_ZOMBIE(q)) - continue; - /* - * XXX this is approximate: no call - * to calcru in other running threads - */ - ruadd(rup, &q->p_stats->p_ru); - } + /* add on all living threads */ + TAILQ_FOREACH(q, &pr->ps_threads, p_thr_link) { + ruadd(rup, &q->p_ru); + tuagg(pr, q); } + + calcru(&pr->ps_tu, &rup->ru_utime, &rup->ru_stime, NULL); break; case RUSAGE_THREAD: - rup = &p->p_stats->p_ru; - calcru(p, &rup->ru_utime, &rup->ru_stime, NULL); - ru = *rup; + rup = &p->p_ru; + calcru(&p->p_tu, &rup->ru_utime, &rup->ru_stime, NULL); break; case RUSAGE_CHILDREN: - rup = &p->p_stats->p_cru; + rup = &pr->ps_cru; break; default: diff --git a/sys/kern/kern_sched.c b/sys/kern/kern_sched.c index 1c2c30f924a..0ddfe498dbb 100644 --- a/sys/kern/kern_sched.c +++ b/sys/kern/kern_sched.c @@ -1,4 +1,4 @@ -/* $OpenBSD: kern_sched.c,v 1.25 2012/03/10 22:02:32 haesbaert Exp $ */ +/* $OpenBSD: kern_sched.c,v 1.26 2012/03/23 15:51:26 guenther Exp $ */ /* * Copyright (c) 2007, 2008 Artur Grabowski <art@openbsd.org> * @@ -556,7 +556,7 @@ sched_peg_curproc(struct cpu_info *ci) p->p_cpu = ci; atomic_setbits_int(&p->p_flag, P_CPUPEG); setrunqueue(p); - p->p_stats->p_ru.ru_nvcsw++; + p->p_ru.ru_nvcsw++; mi_switch(); SCHED_UNLOCK(s); } diff --git a/sys/kern/kern_sig.c b/sys/kern/kern_sig.c index 5171bd7323e..936d04c8e70 100644 --- a/sys/kern/kern_sig.c +++ b/sys/kern/kern_sig.c @@ -1,4 +1,4 @@ -/* $OpenBSD: kern_sig.c,v 1.137 2012/03/19 09:05:39 guenther Exp $ */ +/* $OpenBSD: kern_sig.c,v 1.138 2012/03/23 15:51:26 guenther Exp $ */ /* $NetBSD: kern_sig.c,v 1.54 1996/04/22 01:38:32 christos Exp $ */ /* @@ -721,7 +721,7 @@ trapsignal(struct proc *p, int signum, u_long trapno, int code, p->p_sigmask, code, &si); } #endif - p->p_stats->p_ru.ru_nsignals++; + p->p_ru.ru_nsignals++; (*p->p_emul->e_sendsig)(ps->ps_sigact[signum], signum, p->p_sigmask, trapno, code, sigval); p->p_sigmask |= ps->ps_catchmask[signum]; @@ -1316,7 +1316,7 @@ postsig(int signum) ps->ps_sigact[signum] = SIG_DFL; } splx(s); - p->p_stats->p_ru.ru_nsignals++; + p->p_ru.ru_nsignals++; if (p->p_sisig == signum) { p->p_sisig = 0; p->p_sitrapno = 0; diff --git a/sys/kern/kern_synch.c b/sys/kern/kern_synch.c index 031a46dfaee..6b10a95e5b9 100644 --- a/sys/kern/kern_synch.c +++ b/sys/kern/kern_synch.c @@ -1,4 +1,4 @@ -/* $OpenBSD: kern_synch.c,v 1.100 2012/03/19 09:05:39 guenther Exp $ */ +/* $OpenBSD: kern_synch.c,v 1.101 2012/03/23 15:51:26 guenther Exp $ */ /* $NetBSD: kern_synch.c,v 1.37 1996/04/22 01:38:37 christos Exp $ */ /* @@ -215,7 +215,7 @@ sleep_finish(struct sleep_state *sls, int do_sleep) if (sls->sls_do_sleep && do_sleep) { p->p_stat = SSLEEP; - p->p_stats->p_ru.ru_nvcsw++; + p->p_ru.ru_nvcsw++; SCHED_ASSERT_LOCKED(); mi_switch(); } else if (!do_sleep) { diff --git a/sys/kern/kern_sysctl.c b/sys/kern/kern_sysctl.c index 6d0880d6033..3d34ce34fff 100644 --- a/sys/kern/kern_sysctl.c +++ b/sys/kern/kern_sysctl.c @@ -1,4 +1,4 @@ -/* $OpenBSD: kern_sysctl.c,v 1.216 2012/03/13 17:28:32 tedu Exp $ */ +/* $OpenBSD: kern_sysctl.c,v 1.217 2012/03/23 15:51:26 guenther Exp $ */ /* $NetBSD: kern_sysctl.c,v 1.17 1996/05/20 17:49:05 mrg Exp $ */ /*- @@ -1498,7 +1498,7 @@ fill_kproc(struct proc *p, struct kinfo_proc *ki) struct timeval 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_stats, p->p_sigacts); + p, pr, s, p->p_vmspace, pr->ps_limit, p->p_sigacts); /* stuff that's too painful to generalize into the macros */ ki->p_pid = pr->ps_pid; @@ -1521,7 +1521,7 @@ fill_kproc(struct proc *p, struct kinfo_proc *ki) if (p->p_stat != SIDL) ki->p_vm_rssize = vm_resident_count(p->p_vmspace); - calcru(p, &ut, &st, NULL); + calcru(&p->p_tu, &ut, &st, NULL); ki->p_uutime_sec = ut.tv_sec; ki->p_uutime_usec = ut.tv_usec; ki->p_ustime_sec = st.tv_sec; 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; } } diff --git a/sys/kern/sched_bsd.c b/sys/kern/sched_bsd.c index 6fb2772e5ce..1bc1034ae22 100644 --- a/sys/kern/sched_bsd.c +++ b/sys/kern/sched_bsd.c @@ -1,4 +1,4 @@ -/* $OpenBSD: sched_bsd.c,v 1.28 2012/02/20 22:23:39 guenther Exp $ */ +/* $OpenBSD: sched_bsd.c,v 1.29 2012/03/23 15:51:26 guenther Exp $ */ /* $NetBSD: kern_synch.c,v 1.37 1996/04/22 01:38:37 christos Exp $ */ /*- @@ -305,7 +305,7 @@ yield(void) p->p_priority = p->p_usrpri; p->p_stat = SRUN; setrunqueue(p); - p->p_stats->p_ru.ru_nvcsw++; + p->p_ru.ru_nvcsw++; mi_switch(); SCHED_UNLOCK(s); } @@ -333,7 +333,7 @@ preempt(struct proc *newp) p->p_stat = SRUN; p->p_cpu = sched_choosecpu(p); setrunqueue(p); - p->p_stats->p_ru.ru_nivcsw++; + p->p_ru.ru_nivcsw++; mi_switch(); SCHED_UNLOCK(s); } @@ -344,7 +344,9 @@ mi_switch(void) struct schedstate_percpu *spc = &curcpu()->ci_schedstate; struct proc *p = curproc; struct proc *nextproc; + struct process *pr = p->p_p; struct rlimit *rlim; + rlim_t secs; struct timeval tv; #ifdef MULTIPROCESSOR int hold_count; @@ -384,13 +386,17 @@ mi_switch(void) timeradd(&p->p_rtime, &tv, &p->p_rtime); } + /* add the time counts for this thread to the process's total */ + tuagg_unlocked(pr, p); + /* * Check if the process exceeds its cpu resource allocation. * If over max, kill it. */ - rlim = &p->p_rlimit[RLIMIT_CPU]; - if ((rlim_t)p->p_rtime.tv_sec >= rlim->rlim_cur) { - if ((rlim_t)p->p_rtime.tv_sec >= rlim->rlim_max) { + rlim = &pr->ps_limit->pl_rlimit[RLIMIT_CPU]; + secs = pr->ps_tu.tu_runtime.tv_sec; + if (secs >= rlim->rlim_cur) { + if (secs >= rlim->rlim_max) { psignal(p, SIGKILL); } else { psignal(p, SIGXCPU); diff --git a/sys/kern/subr_prof.c b/sys/kern/subr_prof.c index f1475420df0..070c632bc1a 100644 --- a/sys/kern/subr_prof.c +++ b/sys/kern/subr_prof.c @@ -1,4 +1,4 @@ -/* $OpenBSD: subr_prof.c,v 1.19 2010/07/09 20:30:48 deraadt Exp $ */ +/* $OpenBSD: subr_prof.c,v 1.20 2012/03/23 15:51:26 guenther Exp $ */ /* $NetBSD: subr_prof.c,v 1.12 1996/04/22 01:38:50 christos Exp $ */ /*- @@ -161,7 +161,7 @@ sys_profil(struct proc *p, void *v, register_t *retval) stopprofclock(p); return (0); } - upp = &p->p_stats->p_prof; + upp = &p->p_p->ps_prof; /* Block profile interrupts while changing state. */ s = splstatclock(); @@ -196,12 +196,12 @@ addupc_intr(struct proc *p, u_long pc) { struct uprof *prof; - prof = &p->p_stats->p_prof; + prof = &p->p_p->ps_prof; if (pc < prof->pr_off || PC_TO_INDEX(pc, prof) >= prof->pr_size) return; /* out of range; ignore */ - prof->pr_addr = pc; - prof->pr_ticks++; + p->p_prof_addr = pc; + p->p_prof_ticks++; atomic_setbits_int(&p->p_flag, P_OWEUPC); need_proftick(p); } @@ -223,7 +223,7 @@ addupc_task(struct proc *p, u_long pc, u_int nticks) if ((p->p_flag & P_PROFIL) == 0 || nticks == 0) return; - prof = &p->p_stats->p_prof; + prof = &p->p_p->ps_prof; if (pc < prof->pr_off || (i = PC_TO_INDEX(pc, prof)) >= prof->pr_size) return; diff --git a/sys/kern/tty.c b/sys/kern/tty.c index 1a918c29714..df0c72e498c 100644 --- a/sys/kern/tty.c +++ b/sys/kern/tty.c @@ -1,4 +1,4 @@ -/* $OpenBSD: tty.c,v 1.93 2011/07/05 04:48:02 guenther Exp $ */ +/* $OpenBSD: tty.c,v 1.94 2012/03/23 15:51:26 guenther Exp $ */ /* $NetBSD: tty.c,v 1.68.4.2 1996/06/06 16:04:52 thorpej Exp $ */ /*- @@ -2115,7 +2115,7 @@ ttyinfo(struct tty *tp) rss = pick->p_stat == SIDL || P_ZOMBIE(pick) ? 0 : vm_resident_count(pick->p_vmspace); - calcru(pick, &utime, &stime, NULL); + calcru(&pick->p_p->ps_tu, &utime, &stime, NULL); /* Round up and print user time. */ utime.tv_usec += 5000; diff --git a/sys/kern/uipc_socket.c b/sys/kern/uipc_socket.c index 5375e11220d..6749f4c56c5 100644 --- a/sys/kern/uipc_socket.c +++ b/sys/kern/uipc_socket.c @@ -1,4 +1,4 @@ -/* $OpenBSD: uipc_socket.c,v 1.97 2012/03/17 10:16:41 dlg Exp $ */ +/* $OpenBSD: uipc_socket.c,v 1.98 2012/03/23 15:51:26 guenther Exp $ */ /* $NetBSD: uipc_socket.c,v 1.21 1996/02/04 02:17:52 christos Exp $ */ /* @@ -406,7 +406,7 @@ sosend(struct socket *so, struct mbuf *addr, struct uio *uio, struct mbuf *top, (flags & MSG_DONTROUTE) && (so->so_options & SO_DONTROUTE) == 0 && (so->so_proto->pr_flags & PR_ATOMIC); if (uio && uio->uio_procp) - uio->uio_procp->p_stats->p_ru.ru_msgsnd++; + uio->uio_procp->p_ru.ru_msgsnd++; if (control) clen = control->m_len; #define snderr(errno) { error = errno; splx(s); goto release; } @@ -725,7 +725,7 @@ dontblock: * corruption. */ if (uio->uio_procp) - uio->uio_procp->p_stats->p_ru.ru_msgrcv++; + uio->uio_procp->p_ru.ru_msgrcv++; KASSERT(m == so->so_rcv.sb_mb); SBLASTRECORDCHK(&so->so_rcv, "soreceive 1"); SBLASTMBUFCHK(&so->so_rcv, "soreceive 1"); diff --git a/sys/kern/vfs_bio.c b/sys/kern/vfs_bio.c index 1b589974153..bd1cd91fc24 100644 --- a/sys/kern/vfs_bio.c +++ b/sys/kern/vfs_bio.c @@ -1,4 +1,4 @@ -/* $OpenBSD: vfs_bio.c,v 1.134 2011/09/19 14:48:04 beck Exp $ */ +/* $OpenBSD: vfs_bio.c,v 1.135 2012/03/23 15:51:26 guenther Exp $ */ /* $NetBSD: vfs_bio.c,v 1.44 1996/06/11 11:15:36 pk Exp $ */ /* @@ -375,7 +375,7 @@ bio_doread(struct vnode *vp, daddr64_t blkno, int size, int async) bcstats.numreads++; VOP_STRATEGY(bp); /* Pay for the read. */ - curproc->p_stats->p_ru.ru_inblock++; /* XXX */ + curproc->p_ru.ru_inblock++; /* XXX */ } else if (async) { brelse(bp); } @@ -554,7 +554,7 @@ bread_cluster(struct vnode *vp, daddr64_t blkno, int size, struct buf **rbpp) bcstats.pendingreads++; bcstats.numreads++; VOP_STRATEGY(bp); - curproc->p_stats->p_ru.ru_inblock++; + curproc->p_ru.ru_inblock++; out: return (biowait(*rbpp)); @@ -617,7 +617,7 @@ bwrite(struct buf *bp) if (wasdelayed) { reassignbuf(bp); } else - curproc->p_stats->p_ru.ru_oublock++; + curproc->p_ru.ru_oublock++; /* Initiate disk write. Make sure the appropriate party is charged. */ @@ -671,7 +671,7 @@ bdwrite(struct buf *bp) s = splbio(); reassignbuf(bp); splx(s); - curproc->p_stats->p_ru.ru_oublock++; /* XXX */ + curproc->p_ru.ru_oublock++; /* XXX */ } /* If this is a tape block, write the block now. */ |