Author: markj
Date: Fri Mar  3 20:57:40 2017
New Revision: 314625
URL: https://svnweb.freebsd.org/changeset/base/314625

Log:
  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

Modified:
  head/sys/kern/sched_ule.c

Modified: head/sys/kern/sched_ule.c
==============================================================================
--- head/sys/kern/sched_ule.c   Fri Mar  3 20:51:57 2017        (r314624)
+++ head/sys/kern/sched_ule.c   Fri Mar  3 20:57:40 2017        (r314625)
@@ -1662,7 +1662,11 @@ sched_pctcpu_update(struct td_sched *ts,
 {
        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) {
_______________________________________________
svn-src-head@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"

Reply via email to