Protect update of the per processor switchtime variable against
interrupts. Protect usage of the per processor switchtime variable against interrupts in calcru(). This seem to eliminate the "microuptime() went backwards" warnings.
This commit is contained in:
parent
e6c77250ef
commit
0d139b3741
@ -118,6 +118,7 @@ exit1(p, rv)
|
||||
register struct proc *q, *nq;
|
||||
register struct vmspace *vm;
|
||||
struct exitlist *ep;
|
||||
struct timeval new_switchtime;
|
||||
|
||||
if (p->p_pid == 1) {
|
||||
printf("init died (signal %d, exit %d)\n",
|
||||
@ -325,7 +326,10 @@ exit1(p, rv)
|
||||
* directly. Set it now so that the rest of the exit time gets
|
||||
* counted somewhere if possible.
|
||||
*/
|
||||
microuptime(PCPU_PTR(switchtime));
|
||||
mtx_lock_spin(&sched_lock);
|
||||
microuptime(&new_switchtime);
|
||||
PCPU_SET(switchtime, new_switchtime);
|
||||
mtx_unlock_spin(&sched_lock);
|
||||
PCPU_SET(switchticks, ticks);
|
||||
|
||||
/*
|
||||
|
@ -567,19 +567,27 @@ calcru(p, up, sp, ip)
|
||||
|
||||
tu = p->p_runtime;
|
||||
if (p == curproc) {
|
||||
struct timeval old_switchtime;
|
||||
/*
|
||||
* Adjust for the current time slice. This is actually fairly
|
||||
* important since the error here is on the order of a time
|
||||
* quantum, which is much greater than the sampling error.
|
||||
*/
|
||||
microuptime(&tv);
|
||||
if (timevalcmp(&tv, PCPU_PTR(switchtime), <))
|
||||
do {
|
||||
old_switchtime = PCPU_GET(switchtime);
|
||||
microuptime(&tv);
|
||||
} while (old_switchtime.tv_sec !=
|
||||
PCPU_GET(switchtime.tv_sec) ||
|
||||
old_switchtime.tv_usec !=
|
||||
PCPU_GET(switchtime.tv_usec));
|
||||
if (timevalcmp(&tv, &old_switchtime, <))
|
||||
printf("microuptime() went backwards (%ld.%06ld -> %ld.%06ld)\n",
|
||||
PCPU_GET(switchtime.tv_sec), PCPU_GET(switchtime.tv_usec),
|
||||
tv.tv_sec, tv.tv_usec);
|
||||
old_switchtime.tv_sec,
|
||||
old_switchtime.tv_usec,
|
||||
tv.tv_sec, tv.tv_usec);
|
||||
else
|
||||
tu += (tv.tv_usec - PCPU_GET(switchtime.tv_usec)) +
|
||||
(tv.tv_sec - PCPU_GET(switchtime.tv_sec)) *
|
||||
tu += (tv.tv_usec - old_switchtime.tv_usec) +
|
||||
(tv.tv_sec - old_switchtime.tv_sec) *
|
||||
(int64_t)1000000;
|
||||
}
|
||||
ptu = p->p_uu + p->p_su + p->p_iu;
|
||||
|
Loading…
x
Reference in New Issue
Block a user