diff options
author | phk <phk@FreeBSD.org> | 1999-11-29 11:29:04 +0000 |
---|---|---|
committer | phk <phk@FreeBSD.org> | 1999-11-29 11:29:04 +0000 |
commit | 8da3ba86dcb25f842958179693b5d802d91ae681 (patch) | |
tree | 4868f81c1c195acf2e065944af8bede54779fd0c /sys/kern | |
parent | d1d5bef80771c347e974ca1f996e28808a4077a7 (diff) | |
download | FreeBSD-src-8da3ba86dcb25f842958179693b5d802d91ae681.zip FreeBSD-src-8da3ba86dcb25f842958179693b5d802d91ae681.tar.gz |
Add a bit of sanity checking and problem avoidance in case the
timecounter hardware is bogus.
This will produce a new warning "microuptime() went backwards"
and try to not screw up the process resource accounting.
Diffstat (limited to 'sys/kern')
-rw-r--r-- | sys/kern/kern_resource.c | 10 | ||||
-rw-r--r-- | sys/kern/kern_synch.c | 11 |
2 files changed, 17 insertions, 4 deletions
diff --git a/sys/kern/kern_resource.c b/sys/kern/kern_resource.c index fde934e..495175e 100644 --- a/sys/kern/kern_resource.c +++ b/sys/kern/kern_resource.c @@ -49,6 +49,7 @@ #include <sys/resourcevar.h> #include <sys/malloc.h> #include <sys/proc.h> +#include <sys/time.h> #include <vm/vm.h> #include <vm/vm_param.h> @@ -519,8 +520,13 @@ calcru(p, up, sp, ip) * quantum, which is much greater than the sampling error. */ microuptime(&tv); - tu += (tv.tv_usec - switchtime.tv_usec) + - (tv.tv_sec - switchtime.tv_sec) * (int64_t)1000000; + if (timevalcmp(&tv, &switchtime, <)) + printf("microuptime() went backwards (%ld.%06ld -> %ld,%06ld)\n", + switchtime.tv_sec, switchtime.tv_usec, + tv.tv_sec, tv.tv_usec); + else + tu += (tv.tv_usec - switchtime.tv_usec) + + (tv.tv_sec - switchtime.tv_sec) * (int64_t)1000000; } ptu = p->p_stats->p_uu + p->p_stats->p_su + p->p_stats->p_iu; if (tu < ptu || (int64_t)tu < 0) { diff --git a/sys/kern/kern_synch.c b/sys/kern/kern_synch.c index 597f5e6..16699e0 100644 --- a/sys/kern/kern_synch.c +++ b/sys/kern/kern_synch.c @@ -791,8 +791,15 @@ mi_switch() * process was running, and add that to its total so far. */ microuptime(&new_switchtime); - p->p_runtime += (new_switchtime.tv_usec - switchtime.tv_usec) + - (new_switchtime.tv_sec - switchtime.tv_sec) * (int64_t)1000000; + if (timevalcmp(&new_switchtime, &switchtime, <)) { + printf("microuptime() went backwards (%ld.%06ld -> %ld,%06ld)\n", + switchtime.tv_sec, switchtime.tv_usec, + new_switchtime.tv_sec, new_switchtime.tv_usec); + new_switchtime = switchtime; + } else { + p->p_runtime += (new_switchtime.tv_usec - switchtime.tv_usec) + + (new_switchtime.tv_sec - switchtime.tv_sec) * (int64_t)1000000; + } /* * Check if the process exceeds its cpu resource allocation. |