mirror of
https://git.hardenedbsd.org/hardenedbsd/HardenedBSD.git
synced 2025-01-01 00:18:15 +01:00
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.
This commit is contained in:
parent
ab1c0de5ed
commit
8f04f6c729
@ -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) {
|
||||
|
@ -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.
|
||||
|
Loading…
Reference in New Issue
Block a user