summaryrefslogtreecommitdiffstats
path: root/sys/kern
diff options
context:
space:
mode:
authordes <des@FreeBSD.org>2003-05-01 16:59:23 +0000
committerdes <des@FreeBSD.org>2003-05-01 16:59:23 +0000
commit8ed712ead15fc26b5070dcac9458f31fc6ecf0fa (patch)
treed8221c44ce99320f82809d2b7504a757957a47c4 /sys/kern
parenteaf3fff90a28f606675fd3c1610d0def28d6be67 (diff)
downloadFreeBSD-src-8ed712ead15fc26b5070dcac9458f31fc6ecf0fa.zip
FreeBSD-src-8ed712ead15fc26b5070dcac9458f31fc6ecf0fa.tar.gz
Instead of recording the Unix time in a process when it starts, record the
uptime. Where necessary, convert it back to Unix time by adding boottime to it. This fixes a potential problem in the accounting code, which would compute the elapsed time incorrectly if the Unix time was stepped during the lifetime of the process.
Diffstat (limited to 'sys/kern')
-rw-r--r--sys/kern/init_main.c2
-rw-r--r--sys/kern/kern_acct.c6
-rw-r--r--sys/kern/kern_fork.c2
-rw-r--r--sys/kern/kern_kthread.c2
-rw-r--r--sys/kern/kern_proc.c3
5 files changed, 8 insertions, 7 deletions
diff --git a/sys/kern/init_main.c b/sys/kern/init_main.c
index d0cfa52..83fca78 100644
--- a/sys/kern/init_main.c
+++ b/sys/kern/init_main.c
@@ -467,7 +467,7 @@ proc0_post(void *dummy __unused)
*/
sx_slock(&allproc_lock);
LIST_FOREACH(p, &allproc, p_list) {
- microtime(&p->p_stats->p_start);
+ microuptime(&p->p_stats->p_start);
p->p_runtime.sec = 0;
p->p_runtime.frac = 0;
}
diff --git a/sys/kern/kern_acct.c b/sys/kern/kern_acct.c
index 9de4641..19e5b1c 100644
--- a/sys/kern/kern_acct.c
+++ b/sys/kern/kern_acct.c
@@ -250,8 +250,10 @@ acct_process(td)
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;
- microtime(&tmp);
+ tmp = boottime;
+ timevaladd(&tmp, &p->p_stats->p_start);
+ acct.ac_btime = tmp.tv_sec;
+ microuptime(&tmp);
timevalsub(&tmp, &p->p_stats->p_start);
acct.ac_etime = encode_comp_t(tmp.tv_sec, tmp.tv_usec);
diff --git a/sys/kern/kern_fork.c b/sys/kern/kern_fork.c
index 1cc9580..7d2c65c 100644
--- a/sys/kern/kern_fork.c
+++ b/sys/kern/kern_fork.c
@@ -686,7 +686,7 @@ again:
* If RFSTOPPED not requested, make child runnable and add to
* run queue.
*/
- microtime(&(p2->p_stats->p_start));
+ microuptime(&p2->p_stats->p_start);
if ((flags & RFSTOPPED) == 0) {
mtx_lock_spin(&sched_lock);
p2->p_state = PRS_NORMAL;
diff --git a/sys/kern/kern_kthread.c b/sys/kern/kern_kthread.c
index 46fa97c..d4846dd 100644
--- a/sys/kern/kern_kthread.c
+++ b/sys/kern/kern_kthread.c
@@ -79,7 +79,7 @@ kthread_create(void (*func)(void *), void *arg,
struct thread *td;
struct proc *p2;
- if (!proc0.p_stats /* || proc0.p_stats->p_start.tv_sec == 0 */)
+ if (!proc0.p_stats)
panic("kthread_create called too soon");
error = fork1(&thread0, RFMEM | RFFDG | RFPROC | RFSTOPPED | flags,
diff --git a/sys/kern/kern_proc.c b/sys/kern/kern_proc.c
index 111c0f2..5ad7882 100644
--- a/sys/kern/kern_proc.c
+++ b/sys/kern/kern_proc.c
@@ -677,8 +677,7 @@ fill_kinfo_proc(p, kp)
}
if ((p->p_sflag & PS_INMEM) && p->p_stats) {
kp->ki_start = p->p_stats->p_start;
- if (kp->ki_start.tv_sec < 3600)
- kp->ki_start.tv_sec += boottime.tv_sec;
+ timevaladd(&kp->ki_start, &boottime);
kp->ki_rusage = p->p_stats->p_ru;
kp->ki_childtime.tv_sec = p->p_stats->p_cru.ru_utime.tv_sec +
p->p_stats->p_cru.ru_stime.tv_sec;
OpenPOWER on IntegriCloud