svn commit: r314625 - head/sys/kern

Mark Johnston markj at FreeBSD.org
Fri Mar 3 20:57:41 UTC 2017


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) {


More information about the svn-src-all mailing list