diff options
author | Philip Guenthe <guenther@cvs.openbsd.org> | 2012-03-23 15:51:27 +0000 |
---|---|---|
committer | Philip Guenthe <guenther@cvs.openbsd.org> | 2012-03-23 15:51:27 +0000 |
commit | 3a829b1c12609aae928c035b8f17ae238f6e809b (patch) | |
tree | 5ad109cbb6d1159db7d5a8d765f4995f015b7155 | |
parent | fe805d3568ba38f32e5785ef64ed5e07e2d1df00 (diff) |
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@
38 files changed, 322 insertions, 303 deletions
diff --git a/lib/libkvm/kvm_proc2.c b/lib/libkvm/kvm_proc2.c index f98c7db2ebc..f4306bf691b 100644 --- a/lib/libkvm/kvm_proc2.c +++ b/lib/libkvm/kvm_proc2.c @@ -1,4 +1,4 @@ -/* $OpenBSD: kvm_proc2.c,v 1.9 2012/01/07 05:38:12 guenther Exp $ */ +/* $OpenBSD: kvm_proc2.c,v 1.10 2012/03/23 15:51:25 guenther Exp $ */ /* $NetBSD: kvm_proc.c,v 1.30 1999/03/24 05:50:50 mrg Exp $ */ /*- * Copyright (c) 1998 The NetBSD Foundation, Inc. @@ -117,7 +117,6 @@ kvm_proclist(kvm_t *kd, int op, int arg, struct proc *p, struct sigacts sa, *sap; struct vmspace vm, *vmp; struct plimit limits, *limp; - struct pstats pstats, *ps; pid_t process_pid, parent_pid, leader_pid; int cnt = 0; @@ -282,14 +281,9 @@ kvm_proclist(kvm_t *kd, int op, int arg, struct proc *p, KREAD(kd, (u_long)process.ps_limit, &limits)) limp = NULL; - ps = &pstats; - if (P_ZOMBIE(&proc) || - KREAD(kd, (u_long)proc.p_stats, &pstats)) - ps = NULL; - #define do_copy_str(_d, _s, _l) kvm_read(kd, (u_long)(_s), (_d), (_l)-1) FILL_KPROC(&kp, do_copy_str, &proc, &process, &pcred, &ucred, - &pgrp, p, proc.p_p, &sess, vmp, limp, ps, sap); + &pgrp, p, proc.p_p, &sess, vmp, limp, sap); #undef do_copy_str /* stuff that's too painful to generalize into the macros */ diff --git a/sys/arch/alpha/alpha/clock.c b/sys/arch/alpha/alpha/clock.c index 9f4fbeb4fd7..e8c8db02f79 100644 --- a/sys/arch/alpha/alpha/clock.c +++ b/sys/arch/alpha/alpha/clock.c @@ -1,4 +1,4 @@ -/* $OpenBSD: clock.c,v 1.20 2010/09/20 06:33:46 matthew Exp $ */ +/* $OpenBSD: clock.c,v 1.21 2012/03/23 15:51:25 guenther Exp $ */ /* $NetBSD: clock.c,v 1.29 2000/06/05 21:47:10 thorpej Exp $ */ /* @@ -126,8 +126,8 @@ cpu_initclocks(void) * PALcode save a clock interrupt, which would get delivered * when we spl0() in autoconf.c. If established the clock * interrupt handler earlier, that interrupt would go to - * hardclock, which would then fall over because p->p_stats - * isn't set at that time. + * hardclock, which would then fall over because the pointer + * to the virtual timers wasn't set at that time. */ platform.clockintr = hardclock; schedhz = 16; diff --git a/sys/arch/i386/i386/machdep.c b/sys/arch/i386/i386/machdep.c index 1e07d7bc885..4dba2b20078 100644 --- a/sys/arch/i386/i386/machdep.c +++ b/sys/arch/i386/i386/machdep.c @@ -1,4 +1,4 @@ -/* $OpenBSD: machdep.c,v 1.507 2012/03/19 00:49:08 jsg Exp $ */ +/* $OpenBSD: machdep.c,v 1.508 2012/03/23 15:51:25 guenther Exp $ */ /* $NetBSD: machdep.c,v 1.214 1996/11/10 03:16:17 thorpej Exp $ */ /*- @@ -2458,7 +2458,7 @@ boot(int howto) if ((howto & RB_NOSYNC) == 0 && waittime < 0) { extern struct proc proc0; - /* protect against curproc->p_stats.foo refs in sync() XXX */ + /* make sure there's a process to charge for I/O in sync() */ if (curproc == NULL) curproc = &proc0; diff --git a/sys/arch/m88k/m88k/m88k_machdep.c b/sys/arch/m88k/m88k/m88k_machdep.c index 89ddb045343..8b94310e7dc 100644 --- a/sys/arch/m88k/m88k/m88k_machdep.c +++ b/sys/arch/m88k/m88k/m88k_machdep.c @@ -1,4 +1,4 @@ -/* $OpenBSD: m88k_machdep.c,v 1.51 2010/12/23 20:05:08 miod Exp $ */ +/* $OpenBSD: m88k_machdep.c,v 1.52 2012/03/23 15:51:26 guenther Exp $ */ /* * Copyright (c) 1998, 1999, 2000, 2001 Steve Murphree, Jr. * Copyright (c) 1996 Nivas Madhur @@ -560,7 +560,7 @@ cpu_emergency_disable() p->p_priority = p->p_usrpri; p->p_stat = SRUN; setrunqueue(p); - p->p_stats->p_ru.ru_nvcsw++; + p->p_ru.ru_nvcsw++; SCHED_UNLOCK(s); } diff --git a/sys/arch/solbourne/solbourne/machdep.c b/sys/arch/solbourne/solbourne/machdep.c index d0a3ffe2d4a..ca9b8b7f812 100644 --- a/sys/arch/solbourne/solbourne/machdep.c +++ b/sys/arch/solbourne/solbourne/machdep.c @@ -1,4 +1,4 @@ -/* $OpenBSD: machdep.c,v 1.21 2011/07/05 04:48:02 guenther Exp $ */ +/* $OpenBSD: machdep.c,v 1.22 2012/03/23 15:51:26 guenther Exp $ */ /* OpenBSD: machdep.c,v 1.105 2005/04/11 15:13:01 deraadt Exp */ /* @@ -538,7 +538,7 @@ boot(howto) if ((howto & RB_NOSYNC) == 0 && waittime < 0) { extern struct proc proc0; - /* XXX protect against curproc->p_stats.foo refs in sync() */ + /* make sure there's a process to charge for I/O in sync() */ if (curproc == NULL) curproc = &proc0; waittime = 0; diff --git a/sys/arch/sparc/sparc/machdep.c b/sys/arch/sparc/sparc/machdep.c index 379b7d50c03..718ef15df43 100644 --- a/sys/arch/sparc/sparc/machdep.c +++ b/sys/arch/sparc/sparc/machdep.c @@ -1,4 +1,4 @@ -/* $OpenBSD: machdep.c,v 1.137 2011/07/05 04:48:02 guenther Exp $ */ +/* $OpenBSD: machdep.c,v 1.138 2012/03/23 15:51:26 guenther Exp $ */ /* $NetBSD: machdep.c,v 1.85 1997/09/12 08:55:02 pk Exp $ */ /* @@ -551,7 +551,7 @@ boot(howto) if ((howto & RB_NOSYNC) == 0 && waittime < 0) { extern struct proc proc0; - /* XXX protect against curproc->p_stats.foo refs in sync() */ + /* make sure there's a process to charge for I/O in sync() */ if (curproc == NULL) curproc = &proc0; waittime = 0; diff --git a/sys/arch/sparc64/sparc64/db_interface.c b/sys/arch/sparc64/sparc64/db_interface.c index a68f7aa52b3..96d351fe992 100644 --- a/sys/arch/sparc64/sparc64/db_interface.c +++ b/sys/arch/sparc64/sparc64/db_interface.c @@ -1,4 +1,4 @@ -/* $OpenBSD: db_interface.c,v 1.31 2011/07/03 18:34:14 oga Exp $ */ +/* $OpenBSD: db_interface.c,v 1.32 2012/03/23 15:51:26 guenther Exp $ */ /* $NetBSD: db_interface.c,v 1.61 2001/07/31 06:55:47 eeh Exp $ */ /* @@ -802,8 +802,8 @@ db_proc_cmd(addr, have_addr, count, modif) p->p_vmspace->vm_maxsaddr, p->p_vmspace->vm_ssize, (unsigned long long)ptoa(p->p_vmspace->vm_ssize)); db_printf("profile timer: %ld sec %ld usec\n", - p->p_stats->p_timer[ITIMER_PROF].it_value.tv_sec, - p->p_stats->p_timer[ITIMER_PROF].it_value.tv_usec); + p->p_p->ps_timer[ITIMER_PROF].it_value.tv_sec, + p->p_p->ps_timer[ITIMER_PROF].it_value.tv_usec); db_printf("pcb: %p tf: %p fpstate: %p\n", &p->p_addr->u_pcb, p->p_md.md_tf, p->p_md.md_fpstate); return; diff --git a/sys/arch/sparc64/sparc64/machdep.c b/sys/arch/sparc64/sparc64/machdep.c index 2130f5d4818..6b30d4b1b4f 100644 --- a/sys/arch/sparc64/sparc64/machdep.c +++ b/sys/arch/sparc64/sparc64/machdep.c @@ -1,4 +1,4 @@ -/* $OpenBSD: machdep.c,v 1.136 2011/07/05 04:48:02 guenther Exp $ */ +/* $OpenBSD: machdep.c,v 1.137 2012/03/23 15:51:26 guenther Exp $ */ /* $NetBSD: machdep.c,v 1.108 2001/07/24 19:30:14 eeh Exp $ */ /*- @@ -639,7 +639,7 @@ boot(howto) extern struct proc proc0; extern int sparc_clock_time_is_ok; - /* XXX protect against curproc->p_stats.foo refs in sync() */ + /* make sure there's a process to charge for I/O in sync() */ if (curproc == NULL) curproc = &proc0; waittime = 0; diff --git a/sys/compat/linux/linux_misc.c b/sys/compat/linux/linux_misc.c index ffa718dc1be..9d300d33a1e 100644 --- a/sys/compat/linux/linux_misc.c +++ b/sys/compat/linux/linux_misc.c @@ -1,4 +1,4 @@ -/* $OpenBSD: linux_misc.c,v 1.73 2011/12/14 08:33:18 robert Exp $ */ +/* $OpenBSD: linux_misc.c,v 1.74 2012/03/23 15:51:26 guenther Exp $ */ /* $NetBSD: linux_misc.c,v 1.27 1996/05/20 01:59:21 fvdl Exp $ */ /*- @@ -744,17 +744,16 @@ linux_sys_times(p, v, retval) struct linux_sys_times_args /* { syscallarg(struct times *) tms; } */ *uap = v; - struct timeval t; + struct timeval t, ut, st; struct linux_tms ltms; - struct rusage ru; int error; - calcru(p, &ru.ru_utime, &ru.ru_stime, NULL); - ltms.ltms_utime = CONVTCK(ru.ru_utime); - ltms.ltms_stime = CONVTCK(ru.ru_stime); + calcru(&p->p_p->ps_tu, &ut, &st, NULL); + ltms.ltms_utime = CONVTCK(ut); + ltms.ltms_stime = CONVTCK(st); - ltms.ltms_cutime = CONVTCK(p->p_stats->p_cru.ru_utime); - ltms.ltms_cstime = CONVTCK(p->p_stats->p_cru.ru_stime); + ltms.ltms_cutime = CONVTCK(p->p_p->ps_cru.ru_utime); + ltms.ltms_cstime = CONVTCK(p->p_p->ps_cru.ru_stime); if ((error = copyout(<ms, SCARG(uap, tms), sizeof ltms))) return error; @@ -778,18 +777,20 @@ linux_sys_alarm(p, v, retval) struct linux_sys_alarm_args /* { syscallarg(unsigned int) secs; } */ *uap = v; - int s; + struct process *pr; struct itimerval *itp, it; struct timeval tv; + int s; int timo; - itp = &p->p_realtimer; + pr = p->p_p; + itp = &pr->ps_timer[ITIMER_REAL]; s = splclock(); /* * Clear any pending timer alarms. */ getmicrouptime(&tv); - timeout_del(&p->p_realit_to); + timeout_del(&pr->ps_realit_to); timerclear(&itp->it_interval); if (timerisset(&itp->it_value) && timercmp(&itp->it_value, &tv, >)) @@ -816,7 +817,7 @@ linux_sys_alarm(p, v, retval) timerclear(&it.it_interval); it.it_value.tv_sec = SCARG(uap, secs); it.it_value.tv_usec = 0; - if (itimerfix(&it.it_value) || itimerfix(&it.it_interval)) { + if (itimerfix(&it.it_value)) { splx(s); return (EINVAL); } @@ -824,9 +825,9 @@ linux_sys_alarm(p, v, retval) if (timerisset(&it.it_value)) { timo = tvtohz(&it.it_value); timeradd(&it.it_value, &tv, &it.it_value); - timeout_add(&p->p_realit_to, timo); + timeout_add(&pr->ps_realit_to, timo); } - p->p_realtimer = it; + pr->ps_timer[ITIMER_REAL] = it; splx(s); return 0; 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. */ diff --git a/sys/miscfs/procfs/procfs_status.c b/sys/miscfs/procfs/procfs_status.c index 0a629e92a04..c19175825ef 100644 --- a/sys/miscfs/procfs/procfs_status.c +++ b/sys/miscfs/procfs/procfs_status.c @@ -1,4 +1,4 @@ -/* $OpenBSD: procfs_status.c,v 1.11 2010/07/26 01:56:27 guenther Exp $ */ +/* $OpenBSD: procfs_status.c,v 1.12 2012/03/23 15:51:26 guenther Exp $ */ /* $NetBSD: procfs_status.c,v 1.11 1996/03/16 23:52:50 christos Exp $ */ /* @@ -118,10 +118,10 @@ procfs_stat_gen(struct proc *p, char *s, int l) } snprintf(ps, sizeof(ps), " %ld,%ld", - p->p_stats->p_start.tv_sec, p->p_stats->p_start.tv_usec); + pr->ps_start.tv_sec, pr->ps_start.tv_usec); COUNTORCAT(s, l, ps, n); - calcru(p, &ut, &st, (void *) 0); + calcru(&pr->ps_tu, &ut, &st, (void *) 0); snprintf(ps, sizeof(ps), " %ld,%ld %ld,%ld", ut.tv_sec, ut.tv_usec, st.tv_sec, st.tv_usec); COUNTORCAT(s, l, ps, n); diff --git a/sys/nfs/nfs_vnops.c b/sys/nfs/nfs_vnops.c index 3380669cbad..4a314a0368e 100644 --- a/sys/nfs/nfs_vnops.c +++ b/sys/nfs/nfs_vnops.c @@ -1,4 +1,4 @@ -/* $OpenBSD: nfs_vnops.c,v 1.138 2011/07/09 00:24:44 beck Exp $ */ +/* $OpenBSD: nfs_vnops.c,v 1.139 2012/03/23 15:51:26 guenther Exp $ */ /* $NetBSD: nfs_vnops.c,v 1.62.4.1 1996/07/08 20:26:52 jtc Exp $ */ /* @@ -3020,7 +3020,7 @@ nfs_writebp(struct buf *bp, int force) buf_undirty(bp); if ((oldflags & B_ASYNC) && !(oldflags & B_DELWRI) && p) - ++p->p_stats->p_ru.ru_oublock; + ++p->p_ru.ru_oublock; bp->b_vp->v_numoutput++; splx(s); @@ -3095,7 +3095,7 @@ nfs_writebp(struct buf *bp, int force) bp->b_flags |= B_RAW; rtval = biowait(bp); if (!(oldflags & B_DELWRI) && p) { - ++p->p_stats->p_ru.ru_oublock; + ++p->p_ru.ru_oublock; } brelse(bp); return (rtval); diff --git a/sys/sys/proc.h b/sys/sys/proc.h index ac06c6ae9b5..1af10a61667 100644 --- a/sys/sys/proc.h +++ b/sys/sys/proc.h @@ -1,4 +1,4 @@ -/* $OpenBSD: proc.h,v 1.152 2012/03/10 05:54:28 guenther Exp $ */ +/* $OpenBSD: proc.h,v 1.153 2012/03/23 15:51:26 guenther Exp $ */ /* $NetBSD: proc.h,v 1.44 1996/04/22 01:23:21 christos Exp $ */ /*- @@ -46,6 +46,7 @@ #include <sys/timeout.h> /* For struct timeout */ #include <sys/event.h> /* For struct klist */ #include <sys/mutex.h> /* For struct mutex */ +#include <sys/resource.h> /* For struct rusage */ #include <machine/atomic.h> #ifdef _KERNEL @@ -119,6 +120,18 @@ extern struct emul *emulsw[]; /* All emuls in system */ extern int nemuls; /* Number of emuls */ /* + * time usage: accumulated times in ticks + * One a second, each thread's immediate counts (p_[usi]ticks) are + * accumulated into these. + */ +struct tusage { + struct timeval tu_runtime; /* Realtime. */ + uint64_t tu_uticks; /* Statclock hits in user mode. */ + uint64_t tu_sticks; /* Statclock hits in system mode. */ + uint64_t tu_iticks; /* Statclock hits processing intr. */ +}; + +/* * Description of a process. * * These structures contain the information needed to manage a thread of @@ -166,6 +179,11 @@ struct process { int ps_ptmask; /* Ptrace event mask */ struct ptrace_state *ps_ptstat;/* Ptrace state */ + struct rusage *ps_ru; /* sum of stats for dead threads. */ + struct tusage ps_tu; /* accumulated times. */ + struct rusage ps_cru; /* sum of stats for reaped children */ + struct itimerval ps_timer[3]; /* timers, indexed by ITIMER_* */ + /* End area that is zeroed on creation. */ #define ps_endzero ps_startcopy @@ -177,9 +195,21 @@ struct process { u_int ps_rtableid; /* Process routing table/domain. */ char ps_nice; /* Process "nice" value. */ + struct uprof { /* profile arguments */ + caddr_t pr_base; /* buffer base */ + size_t pr_size; /* buffer size */ + u_long pr_off; /* pc offset */ + u_int pr_scale; /* pc scaling */ + } ps_prof; + /* End area that is copied on creation. */ #define ps_endcopy ps_refcnt + struct timeval ps_start; /* starting time. */ + struct timeout ps_realit_to; /* real-time itimer trampoline. */ + struct timeout ps_virt_to; /* virtual itimer trampoline. */ + struct timeout ps_prof_to; /* prof itimer trampoline. */ + int ps_refcnt; /* Number of references. */ }; @@ -223,7 +253,6 @@ struct proc { /* substructures: */ struct filedesc *p_fd; /* Ptr to open files structure. */ - struct pstats *p_stats; /* Accounting/statistics */ struct vmspace *p_vmspace; /* Address space. */ struct sigacts *p_sigacts; /* Signal actions, state */ #define p_cred p_p->ps_cred @@ -259,12 +288,12 @@ struct proc { u_int p_slptime; /* Time since last blocked. */ struct cpu_info * __volatile p_cpu; /* CPU we're running on. */ - struct itimerval p_realtimer; /* Alarm timer. */ - struct timeout p_realit_to; /* Alarm timeout. */ + struct rusage p_ru; /* Statistics */ + struct tusage p_tu; /* accumulated times. */ struct timeval p_rtime; /* Real time. */ - u_quad_t p_uticks; /* Statclock hits in user mode. */ - u_quad_t p_sticks; /* Statclock hits in system mode. */ - u_quad_t p_iticks; /* Statclock hits processing intr. */ + u_int p_uticks; /* Statclock hits in user mode. */ + u_int p_sticks; /* Statclock hits in system mode. */ + u_int p_iticks; /* Statclock hits processing intr. */ void *p_systrace; /* Back pointer to systrace */ @@ -311,9 +340,11 @@ struct proc { int p_sicode; /* For core dump/debugger XXX */ long p_sitrapno; /* For core dump/debugger XXX */ + u_long p_prof_addr; /* temp storage for profiling addr util AST */ + u_long p_prof_ticks; /* temp storage for profiling ticks util AST */ + u_short p_xstat; /* Exit status for wait; also stop signal. */ u_short p_acflag; /* Accounting flags. */ - struct rusage *p_ru; /* Exit information. XXX */ }; /* Status values. */ diff --git a/sys/sys/resourcevar.h b/sys/sys/resourcevar.h index 7fe5f6c8324..3dc7a2af309 100644 --- a/sys/sys/resourcevar.h +++ b/sys/sys/resourcevar.h @@ -1,4 +1,4 @@ -/* $OpenBSD: resourcevar.h,v 1.14 2011/07/11 15:40:47 guenther Exp $ */ +/* $OpenBSD: resourcevar.h,v 1.15 2012/03/23 15:51:26 guenther Exp $ */ /* $NetBSD: resourcevar.h,v 1.12 1995/11/22 23:01:53 cgd Exp $ */ /* @@ -38,32 +38,6 @@ #include <sys/timeout.h> /* - * Kernel per-process accounting / statistics - * (not necessarily resident except when running). - */ -struct pstats { -#define pstat_startzero p_ru - struct rusage p_ru; /* stats for this proc */ - struct rusage p_cru; /* sum of stats for reaped children */ - struct itimerval p_timer[3]; /* virtual-time timers */ -#define pstat_endzero pstat_startcopy - -#define pstat_startcopy p_prof - struct uprof { /* profile arguments */ - caddr_t pr_base; /* buffer base */ - size_t pr_size; /* buffer size */ - u_long pr_off; /* pc offset */ - u_int pr_scale; /* pc scaling */ - u_long pr_addr; /* temp storage for addr until AST */ - u_long pr_ticks; /* temp storage for ticks until AST */ - } p_prof; -#define pstat_endcopy p_start - struct timeval p_start; /* starting time */ - struct timeout p_virt_to; /* virtual itimer trampoline. */ - struct timeout p_prof_to; /* prof itimer trampoline. */ -}; - -/* * Kernel shareable process resource limits. Because this structure * is moderately large but changes infrequently, it is shared * copy-on-write after forks. @@ -77,15 +51,16 @@ struct plimit { #define ADDUPROF(p) \ do { \ atomic_clearbits_int(&(p)->p_flag, P_OWEUPC); \ - addupc_task((p), (p)->p_stats->p_prof.pr_addr, \ - (p)->p_stats->p_prof.pr_ticks); \ - (p)->p_stats->p_prof.pr_ticks = 0; \ + addupc_task((p), (p)->p_prof_addr, (p)->p_prof_ticks); \ + (p)->p_prof_ticks = 0; \ } while (0) #ifdef _KERNEL void addupc_intr(struct proc *p, u_long pc); void addupc_task(struct proc *p, u_long pc, u_int ticks); -void calcru(struct proc *p, struct timeval *up, struct timeval *sp, +void tuagg_unlocked(struct process *, struct proc *); +struct tusage; +void calcru(struct tusage *, struct timeval *up, struct timeval *sp, struct timeval *ip); struct plimit *limcopy(struct plimit *lim); void limfree(struct plimit *); diff --git a/sys/sys/sysctl.h b/sys/sys/sysctl.h index 8c2d7a730bd..dcb12fedf16 100644 --- a/sys/sys/sysctl.h +++ b/sys/sys/sysctl.h @@ -1,4 +1,4 @@ -/* $OpenBSD: sysctl.h,v 1.120 2012/01/07 05:38:12 guenther Exp $ */ +/* $OpenBSD: sysctl.h,v 1.121 2012/03/23 15:51:26 guenther Exp $ */ /* $NetBSD: sysctl.h,v 1.16 1996/04/09 20:55:36 cgd Exp $ */ /* @@ -325,7 +325,7 @@ struct kinfo_proc { u_int64_t p_addr; /* PTR: Kernel virtual addr of u-area */ u_int64_t p_fd; /* PTR: Ptr to open files structure. */ - u_int64_t p_stats; /* PTR: Accounting/statistics */ + u_int64_t p_stats; /* unused, always zero. */ u_int64_t p_limit; /* PTR: Process limits. */ u_int64_t p_vmspace; /* PTR: Address space. */ u_int64_t p_sigacts; /* PTR: Signal actions, state */ @@ -458,7 +458,6 @@ struct kinfo_proc { * sess - source struct session * vm - source struct vmspace * lim - source struct plimits - * ps - source struct pstats * sa - source struct sigacts * There are some members that are not handled by these macros * because they're too painful to generalize: p_pid, p_ppid, p_sid, p_tdev, @@ -467,18 +466,18 @@ struct kinfo_proc { #define PTRTOINT64(_x) ((u_int64_t)(u_long)(_x)) -#define FILL_KPROC(kp, copy_str, p, pr, pc, uc, pg, paddr, praddr, sess, vm, lim, ps, sa) \ +#define FILL_KPROC(kp, copy_str, p, pr, pc, uc, pg, paddr, praddr, sess, vm, lim, sa) \ do { \ memset((kp), 0, sizeof(*(kp))); \ \ (kp)->p_paddr = PTRTOINT64(paddr); \ (kp)->p_fd = PTRTOINT64((p)->p_fd); \ - (kp)->p_stats = PTRTOINT64((p)->p_stats); \ + (kp)->p_stats = 0; \ (kp)->p_limit = PTRTOINT64((pr)->ps_limit); \ (kp)->p_vmspace = PTRTOINT64((p)->p_vmspace); \ (kp)->p_sigacts = PTRTOINT64((p)->p_sigacts); \ (kp)->p_sess = PTRTOINT64((pg)->pg_session); \ - (kp)->p_ru = PTRTOINT64((p)->p_ru); \ + (kp)->p_ru = PTRTOINT64((pr)->ps_ru); \ \ (kp)->p_exitsig = (p)->p_exitsig; \ (kp)->p_flag = (p)->p_flag | (pr)->ps_flags | P_INMEM; \ @@ -499,8 +498,8 @@ do { \ (kp)->p_jobc = (pg)->pg_jobc; \ \ (kp)->p_estcpu = (p)->p_estcpu; \ - (kp)->p_rtime_sec = (p)->p_rtime.tv_sec; \ - (kp)->p_rtime_usec = (p)->p_rtime.tv_usec; \ + (kp)->p_rtime_sec = (pr)->ps_tu.tu_runtime.tv_sec; \ + (kp)->p_rtime_usec = (pr)->ps_tu.tu_runtime.tv_usec; \ (kp)->p_cpticks = (p)->p_cpticks; \ (kp)->p_pctcpu = (p)->p_pctcpu; \ \ @@ -558,31 +557,31 @@ do { \ (kp)->p_rlim_rss_cur = \ (lim)->pl_rlimit[RLIMIT_RSS].rlim_cur; \ \ - if (!P_ZOMBIE(p) && (ps) != NULL) { \ + if (!P_ZOMBIE(p)) { \ struct timeval tv; \ \ (kp)->p_uvalid = 1; \ \ - (kp)->p_ustart_sec = (ps)->p_start.tv_sec; \ - (kp)->p_ustart_usec = (ps)->p_start.tv_usec; \ + (kp)->p_ustart_sec = (pr)->ps_start.tv_sec; \ + (kp)->p_ustart_usec = (pr)->ps_start.tv_usec; \ \ - (kp)->p_uru_maxrss = (ps)->p_ru.ru_maxrss; \ - (kp)->p_uru_ixrss = (ps)->p_ru.ru_ixrss; \ - (kp)->p_uru_idrss = (ps)->p_ru.ru_idrss; \ - (kp)->p_uru_isrss = (ps)->p_ru.ru_isrss; \ - (kp)->p_uru_minflt = (ps)->p_ru.ru_minflt; \ - (kp)->p_uru_majflt = (ps)->p_ru.ru_majflt; \ - (kp)->p_uru_nswap = (ps)->p_ru.ru_nswap; \ - (kp)->p_uru_inblock = (ps)->p_ru.ru_inblock; \ - (kp)->p_uru_oublock = (ps)->p_ru.ru_oublock; \ - (kp)->p_uru_msgsnd = (ps)->p_ru.ru_msgsnd; \ - (kp)->p_uru_msgrcv = (ps)->p_ru.ru_msgrcv; \ - (kp)->p_uru_nsignals = (ps)->p_ru.ru_nsignals; \ - (kp)->p_uru_nvcsw = (ps)->p_ru.ru_nvcsw; \ - (kp)->p_uru_nivcsw = (ps)->p_ru.ru_nivcsw; \ + (kp)->p_uru_maxrss = (p)->p_ru.ru_maxrss; \ + (kp)->p_uru_ixrss = (p)->p_ru.ru_ixrss; \ + (kp)->p_uru_idrss = (p)->p_ru.ru_idrss; \ + (kp)->p_uru_isrss = (p)->p_ru.ru_isrss; \ + (kp)->p_uru_minflt = (p)->p_ru.ru_minflt; \ + (kp)->p_uru_majflt = (p)->p_ru.ru_majflt; \ + (kp)->p_uru_nswap = (p)->p_ru.ru_nswap; \ + (kp)->p_uru_inblock = (p)->p_ru.ru_inblock; \ + (kp)->p_uru_oublock = (p)->p_ru.ru_oublock; \ + (kp)->p_uru_msgsnd = (p)->p_ru.ru_msgsnd; \ + (kp)->p_uru_msgrcv = (p)->p_ru.ru_msgrcv; \ + (kp)->p_uru_nsignals = (p)->p_ru.ru_nsignals; \ + (kp)->p_uru_nvcsw = (p)->p_ru.ru_nvcsw; \ + (kp)->p_uru_nivcsw = (p)->p_ru.ru_nivcsw; \ \ - timeradd(&(ps)->p_cru.ru_utime, \ - &(ps)->p_cru.ru_stime, &tv); \ + timeradd(&(pr)->ps_cru.ru_utime, \ + &(pr)->ps_cru.ru_stime, &tv); \ (kp)->p_uctime_sec = tv.tv_sec; \ (kp)->p_uctime_usec = tv.tv_usec; \ } \ diff --git a/sys/sys/user.h b/sys/sys/user.h index aebafb72943..b057508e5bf 100644 --- a/sys/sys/user.h +++ b/sys/sys/user.h @@ -1,4 +1,4 @@ -/* $OpenBSD: user.h,v 1.7 2010/06/29 20:48:50 guenther Exp $ */ +/* $OpenBSD: user.h,v 1.8 2012/03/23 15:51:26 guenther Exp $ */ /* $NetBSD: user.h,v 1.10 1996/04/09 20:55:49 cgd Exp $ */ /* @@ -55,6 +55,4 @@ struct user { struct pcb u_pcb; - - struct pstats u_stats; /* p_stats points here (use it!) */ }; diff --git a/sys/ufs/ext2fs/ext2fs_bmap.c b/sys/ufs/ext2fs/ext2fs_bmap.c index f685d496984..ec77ae33ec5 100644 --- a/sys/ufs/ext2fs/ext2fs_bmap.c +++ b/sys/ufs/ext2fs/ext2fs_bmap.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ext2fs_bmap.c,v 1.19 2011/07/04 20:35:35 deraadt Exp $ */ +/* $OpenBSD: ext2fs_bmap.c,v 1.20 2012/03/23 15:51:26 guenther Exp $ */ /* $NetBSD: ext2fs_bmap.c,v 1.5 2000/03/30 12:41:11 augustss Exp $ */ /* @@ -188,7 +188,7 @@ ext2fs_bmaparray(struct vnode *vp, int32_t bn, daddr64_t *bnp, bp->b_blkno = blkptrtodb(ump, daddr); bp->b_flags |= B_READ; VOP_STRATEGY(bp); - curproc->p_stats->p_ru.ru_inblock++; /* XXX */ + curproc->p_ru.ru_inblock++; /* XXX */ bcstats.pendingreads++; if ((error = biowait(bp)) != 0) { brelse(bp); diff --git a/sys/ufs/ext2fs/ext2fs_inode.c b/sys/ufs/ext2fs/ext2fs_inode.c index a1e467fc038..3158a0a70ce 100644 --- a/sys/ufs/ext2fs/ext2fs_inode.c +++ b/sys/ufs/ext2fs/ext2fs_inode.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ext2fs_inode.c,v 1.44 2011/07/04 04:30:41 tedu Exp $ */ +/* $OpenBSD: ext2fs_inode.c,v 1.45 2012/03/23 15:51:26 guenther Exp $ */ /* $NetBSD: ext2fs_inode.c,v 1.24 2001/06/19 12:59:18 wiz Exp $ */ /* @@ -465,7 +465,7 @@ ext2fs_indirtrunc(struct inode *ip, int32_t lbn, int32_t dbn, int32_t lastbn, in vp = ITOV(ip); bp = getblk(vp, lbn, (int)fs->e2fs_bsize, 0, 0); if (!(bp->b_flags & (B_DONE | B_DELWRI))) { - curproc->p_stats->p_ru.ru_inblock++; /* pay for read */ + curproc->p_ru.ru_inblock++; /* pay for read */ bcstats.pendingreads++; bcstats.numreads++; bp->b_flags |= B_READ; diff --git a/sys/ufs/ffs/ffs_inode.c b/sys/ufs/ffs/ffs_inode.c index 597bd4ecca4..3ecd74c2e0e 100644 --- a/sys/ufs/ffs/ffs_inode.c +++ b/sys/ufs/ffs/ffs_inode.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ffs_inode.c,v 1.60 2011/08/16 14:36:39 thib Exp $ */ +/* $OpenBSD: ffs_inode.c,v 1.61 2012/03/23 15:51:26 guenther Exp $ */ /* $NetBSD: ffs_inode.c,v 1.10 1996/05/11 18:27:19 mycroft Exp $ */ /* @@ -525,7 +525,7 @@ ffs_indirtrunc(struct inode *ip, daddr64_t lbn, daddr64_t dbn, vp = ITOV(ip); bp = getblk(vp, lbn, (int)fs->fs_bsize, 0, 0); if (!(bp->b_flags & (B_DONE | B_DELWRI))) { - curproc->p_stats->p_ru.ru_inblock++; /* pay for read */ + curproc->p_ru.ru_inblock++; /* pay for read */ bcstats.pendingreads++; bcstats.numreads++; bp->b_flags |= B_READ; diff --git a/sys/ufs/ufs/ufs_bmap.c b/sys/ufs/ufs/ufs_bmap.c index ef72bd84c81..86a49ff93c5 100644 --- a/sys/ufs/ufs/ufs_bmap.c +++ b/sys/ufs/ufs/ufs_bmap.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ufs_bmap.c,v 1.31 2011/09/18 11:18:28 miod Exp $ */ +/* $OpenBSD: ufs_bmap.c,v 1.32 2012/03/23 15:51:26 guenther Exp $ */ /* $NetBSD: ufs_bmap.c,v 1.3 1996/02/09 22:36:00 christos Exp $ */ /* @@ -175,7 +175,7 @@ ufs_bmaparray(struct vnode *vp, daddr64_t bn, daddr64_t *bnp, struct indir *ap, bcstats.pendingreads++; bcstats.numreads++; VOP_STRATEGY(bp); - curproc->p_stats->p_ru.ru_inblock++; /* XXX */ + curproc->p_ru.ru_inblock++; /* XXX */ if ((error = biowait(bp)) != 0) { brelse(bp); return (error); diff --git a/sys/uvm/uvm_fault.c b/sys/uvm/uvm_fault.c index 03a4418dac6..ba8ea7c5cc7 100644 --- a/sys/uvm/uvm_fault.c +++ b/sys/uvm/uvm_fault.c @@ -1,4 +1,4 @@ -/* $OpenBSD: uvm_fault.c,v 1.63 2012/03/09 13:01:29 ariane Exp $ */ +/* $OpenBSD: uvm_fault.c,v 1.64 2012/03/23 15:51:26 guenther Exp $ */ /* $NetBSD: uvm_fault.c,v 1.51 2000/08/06 00:22:53 thorpej Exp $ */ /* @@ -302,9 +302,9 @@ uvmfault_anonget(struct uvm_faultinfo *ufi, struct vm_amap *amap, uvmexp.fltanget++; /* bump rusage counters */ if (anon->an_page) - curproc->p_addr->u_stats.p_ru.ru_minflt++; + curproc->p_ru.ru_minflt++; else - curproc->p_addr->u_stats.p_ru.ru_majflt++; + curproc->p_ru.ru_majflt++; /* * loop until we get it, or fail. @@ -1268,10 +1268,10 @@ Case2: if (uobjpage) { /* update rusage counters */ - curproc->p_addr->u_stats.p_ru.ru_minflt++; + curproc->p_ru.ru_minflt++; } else { /* update rusage counters */ - curproc->p_addr->u_stats.p_ru.ru_majflt++; + curproc->p_ru.ru_majflt++; /* locked: maps(read), amap(if there), uobj */ uvmfault_unlockall(&ufi, amap, NULL, NULL); diff --git a/sys/uvm/uvm_glue.c b/sys/uvm/uvm_glue.c index aa55afbd07d..c2d205ce656 100644 --- a/sys/uvm/uvm_glue.c +++ b/sys/uvm/uvm_glue.c @@ -1,4 +1,4 @@ -/* $OpenBSD: uvm_glue.c,v 1.58 2011/04/15 21:47:24 oga Exp $ */ +/* $OpenBSD: uvm_glue.c,v 1.59 2012/03/23 15:51:26 guenther Exp $ */ /* $NetBSD: uvm_glue.c,v 1.44 2001/02/06 19:54:44 eeh Exp $ */ /* @@ -315,8 +315,6 @@ void uvm_fork(struct proc *p1, struct proc *p2, boolean_t shared, void *stack, size_t stacksize, void (*func)(void *), void * arg) { - struct user *up = p2->p_addr; - if (shared == TRUE) { p2->p_vmspace = NULL; uvmspace_share(p1, p2); /* share vmspace */ @@ -325,22 +323,10 @@ uvm_fork(struct proc *p1, struct proc *p2, boolean_t shared, void *stack, #ifdef PMAP_UAREA /* Tell the pmap this is a u-area mapping */ - PMAP_UAREA((vaddr_t)up); + PMAP_UAREA((vaddr_t)p2->p_addr); #endif /* - * p_stats currently points at a field in the user struct. Copy - * parts of p_stats, and zero out the rest. - */ - p2->p_stats = &up->u_stats; - memset(&up->u_stats.pstat_startzero, 0, - ((caddr_t)&up->u_stats.pstat_endzero - - (caddr_t)&up->u_stats.pstat_startzero)); - memcpy(&up->u_stats.pstat_startcopy, &p1->p_stats->pstat_startcopy, - ((caddr_t)&up->u_stats.pstat_endcopy - - (caddr_t)&up->u_stats.pstat_startcopy)); - - /* * cpu_fork() copy and update the pcb, and make the child ready * to run. If this is a normal user fork, the child will exit * directly to user mode via child_return() on its first time |