On Wed, 16 Oct 2019 10:23:52 -0500, Scott Cheloha wrote:
> Tracking the process starting time as an uptime fixes the classic
> "init(8) started in 1969" bug in ps(1) when your CMOS battery dies.
>
> In general it lets us track how long a process has been running
> correctly regardless of whether or not the kernel UTC clock has
> jumped.
One comment inline.
> NetBSD and FreeBSD have already done this.
>
> For kernel core dumps we need to do a bit of shuffling in libkvm to
> determine the approximate starting time. The granularity is much more
> limited in this case, but it's a start.
>
> I have added nanoboottime(9) here because it simplifies the math
> in kern_acct.c. I can commit that first in a separate patch.
>
> ok?
>
> Index: sys/kern/kern_sysctl.c
> ===================================================================
> RCS file: /cvs/src/sys/kern/kern_sysctl.c,v
> retrieving revision 1.366
> diff -u -p -r1.366 kern_sysctl.c
> --- sys/kern/kern_sysctl.c 21 Aug 2019 20:44:09 -0000 1.366
> +++ sys/kern/kern_sysctl.c 16 Oct 2019 15:15:31 -0000
> @@ -1637,7 +1637,8 @@ fill_kproc(struct process *pr, struct ki
> struct session *s = pr->ps_session;
> struct tty *tp;
> struct vmspace *vm = pr->ps_vmspace;
> - struct timespec ut, st;
> + struct timespec st, ut;
> + struct timeval booted, starting_uptime, starting_utc;
> int isthread;
>
> isthread = p != NULL;
> @@ -1679,6 +1680,13 @@ fill_kproc(struct process *pr, struct ki
> ki->p_cpuid = CPU_INFO_UNIT(p->p_cpu);
> #endif
> }
> +
> + /* Convert starting uptime to a starting UTC time. */
> + TIMESPEC_TO_TIMEVAL(&starting_uptime, &pr->ps_start);
> + microboottime(&booted);
> + timeradd(&booted, &starting_uptime, &starting_utc);
> + ki->p_ustart_sec = starting_utc.tv_sec;
> + ki->p_ustart_usec = starting_utc.tv_usec;
FILL_KPROC only fills in p_ustart_sec and p_ustart_usec for non-zombie
processes. You probably want to do the same. You are also missing
a diff to sys/sysctl.h to remove p_ustart_sec and p_ustart_usec from
FILL_KPROC.
> /* get %cpu and schedule state: just one thread or sum of all? */
> if (isthread) {
The rest looks fine, modulo the nlist issue bluhm@ noticed.
- todd