From 54b9dd9cf5831fb91eebb37310440d46cb39e2ee Mon Sep 17 00:00:00 2001 From: cheloha Date: Tue, 22 Oct 2019 21:19:23 +0000 Subject: struct proc: change ps_start from utc time to uptime Allows us to determine how long a process has been running, even if the UTC clock jumps. With help from bluhm@ and millert@, who squashed several bugs. ok bluhm@ millert@ --- sys/kern/kern_acct.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) (limited to 'sys/kern/kern_acct.c') diff --git a/sys/kern/kern_acct.c b/sys/kern/kern_acct.c index 6d85501d26a..f46ebf61d88 100644 --- a/sys/kern/kern_acct.c +++ b/sys/kern/kern_acct.c @@ -1,4 +1,4 @@ -/* $OpenBSD: kern_acct.c,v 1.41 2019/10/06 16:24:14 beck Exp $ */ +/* $OpenBSD: kern_acct.c,v 1.42 2019/10/22 21:19:22 cheloha Exp $ */ /* $NetBSD: kern_acct.c,v 1.42 1996/02/04 02:15:12 christos Exp $ */ /*- @@ -171,7 +171,7 @@ acct_process(struct proc *p) struct acct acct; struct process *pr = p->p_p; struct rusage *r; - struct timespec ut, st, tmp; + struct timespec booted, elapsed, realstart, st, tmp, uptime, ut; int t; struct vnode *vp; int error = 0; @@ -203,10 +203,12 @@ acct_process(struct proc *p) 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; - getnanotime(&tmp); - timespecsub(&tmp, &pr->ps_start, &tmp); - acct.ac_etime = encode_comp_t(tmp.tv_sec, tmp.tv_nsec); + nanouptime(&uptime); + nanoboottime(&booted); + timespecadd(&booted, &pr->ps_start, &realstart); + acct.ac_btime = realstart.tv_sec; + timespecsub(&uptime, &pr->ps_start, &elapsed); + acct.ac_etime = encode_comp_t(elapsed.tv_sec, elapsed.tv_nsec); /* (4) The average amount of memory used */ r = &p->p_ru; -- cgit v1.2.3