Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 3 Mar 2017 20:57:40 +0000 (UTC)
From:      Mark Johnston <markj@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r314625 - head/sys/kern
Message-ID:  <201703032057.v23KveoK075973@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
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) {



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201703032057.v23KveoK075973>