Fix a ticks comparison in sched_pctcpu_update().

We may fail to reset the %CPU tracking window if a thread does not run
for over half of the ticks rollover period, resulting in a bogus %CPU
value for the thread until ticks fully rolls over. Handle this by comparing
the unsigned difference ticks - ts_ltick with SCHED_TICK_TARG instead.

Reviewed by:	cem, jeff
MFC after:	1 week
Sponsored by:	Dell EMC Isilon
This commit is contained in:
markj 2017-03-03 20:57:40 +00:00
parent aee44fc238
commit 8b1baed602

View File

@ -1662,7 +1662,11 @@ sched_pctcpu_update(struct td_sched *ts, int run)
{
int t = ticks;
if (t - ts->ts_ltick >= SCHED_TICK_TARG) {
/*
* The signed difference may be negative if the thread hasn't run for
* over half of the ticks rollover period.
*/
if ((u_int)(t - ts->ts_ltick) >= SCHED_TICK_TARG) {
ts->ts_ticks = 0;
ts->ts_ftick = t - SCHED_TICK_TARG;
} else if (t - ts->ts_ftick >= SCHED_TICK_MAX) {