From owner-svn-src-head@FreeBSD.ORG Fri Jun 20 19:54:24 2014 Return-Path: Delivered-To: svn-src-head@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id 65B7FBC0; Fri, 20 Jun 2014 19:54:24 +0000 (UTC) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:1900:2254:2068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 52C1024F3; Fri, 20 Jun 2014 19:54:24 +0000 (UTC) Received: from svn.freebsd.org ([127.0.1.70]) by svn.freebsd.org (8.14.8/8.14.8) with ESMTP id s5KJsOiv096157; Fri, 20 Jun 2014 19:54:24 GMT (envelope-from jhb@svn.freebsd.org) Received: (from jhb@localhost) by svn.freebsd.org (8.14.8/8.14.8/Submit) id s5KJsOa7096156; Fri, 20 Jun 2014 19:54:24 GMT (envelope-from jhb@svn.freebsd.org) Message-Id: <201406201954.s5KJsOa7096156@svn.freebsd.org> From: John Baldwin Date: Fri, 20 Jun 2014 19:54:24 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r267685 - head/usr.bin/top X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 20 Jun 2014 19:54:24 -0000 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))