Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 20 Jun 2014 19:54:24 +0000 (UTC)
From:      John Baldwin <jhb@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r267685 - head/usr.bin/top
Message-ID:  <201406201954.s5KJsOa7096156@svn.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: jhb
Date: Fri Jun 20 19:54:23 2014
New Revision: 267685
URL: http://svnweb.freebsd.org/changeset/base/267685

Log:
  Cap the percent CPU of individual threads at 100% to fix some of the
  more obvious imprecision in the previous top changes.
  
  Specifically, top uses a delta of clock_gettime() calls right after
  invoking the kern.proc sysctl to fetch the process/thread list to
  compute the time delta between the fetches.  However, the kern.proc
  sysctl handler does not run in constant time.  It can spin on locks,
  be preempted by an interrupt handler, etc.  As a result, the time
  between the gathering of stats for individual processes or threads
  between subsequent kern.proc handlers can vary.  If a "slow" kern.proc
  run is followed by a "fast" kern.proc run, then the threads/processes
  at the start of the "slow" run will have a longer time delta than the
  threads/processes at the end.  If the clock_gettime() time delta is
  not itself skewed by preemption, then the delta may be too short for
  a given thread/process resulting in a higher percent CPU than actual.
  However, there is no good way to calculate the exact amount of overage,
  nor to know which threads to subtract the overage from.  Instead, just
  punt and fix the definitely-wrong case of an individual thread having
  more than 100% CPU.
  
  Discussed with:	zonk

Modified:
  head/usr.bin/top/machine.c

Modified: head/usr.bin/top/machine.c
==============================================================================
--- head/usr.bin/top/machine.c	Fri Jun 20 18:07:04 2014	(r267684)
+++ head/usr.bin/top/machine.c	Fri Jun 20 19:54:23 2014	(r267685)
@@ -850,6 +850,8 @@ get_process_info(struct system_info *si,
 			continue;
 
 		PCTCPU(pp) = proc_calc_pctcpu(pp);
+		if (sel->thread && PCTCPU(pp) > 1.0)
+			PCTCPU(pp) = 1.0;
 		if (displaymode == DISP_CPU && !show_idle &&
 		    (!proc_used_cpu(pp) ||
 		     pp->ki_stat == SSTOP || pp->ki_stat == SIDL))



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