From owner-freebsd-current@FreeBSD.ORG Wed May 28 15:59:11 2014 Return-Path: Delivered-To: freebsd-current@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id 3DF6DE5D; Wed, 28 May 2014 15:59:11 +0000 (UTC) Received: from bigwig.baldwin.cx (bigwig.baldwin.cx [IPv6:2001:470:1f11:75::1]) (using TLSv1 with cipher DHE-RSA-CAMELLIA256-SHA (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 1692D25D8; Wed, 28 May 2014 15:59:11 +0000 (UTC) Received: from jhbbsd.localnet (unknown [209.249.190.124]) by bigwig.baldwin.cx (Postfix) with ESMTPSA id 4FA46B917; Wed, 28 May 2014 11:59:09 -0400 (EDT) From: John Baldwin To: "Jamie Landeg-Jones" Subject: Re: Change top's notion of idle processes / threads Date: Wed, 28 May 2014 10:54:04 -0400 User-Agent: KMail/1.13.5 (FreeBSD/8.4-CBSD-20140415; KDE/4.5.5; amd64; ; ) References: <201405231605.26312.jhb@freebsd.org> <201405271637.23332.jhb@freebsd.org> <201405281220.s4SCKZcn023546@catnip.dyslexicfish.net> In-Reply-To: <201405281220.s4SCKZcn023546@catnip.dyslexicfish.net> MIME-Version: 1.0 Content-Type: Text/Plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit Message-Id: <201405281054.04691.jhb@freebsd.org> X-Greylist: Sender succeeded SMTP AUTH, not delayed by milter-greylist-4.2.7 (bigwig.baldwin.cx); Wed, 28 May 2014 11:59:09 -0400 (EDT) Cc: freebsd-current@freebsd.org, emaste@freebsd.org X-BeenThere: freebsd-current@freebsd.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Discussions about the use of FreeBSD-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 28 May 2014 15:59:11 -0000 On Wednesday, May 28, 2014 8:20:35 am Jamie Landeg-Jones wrote: > John, the changes are good. > > The "'trickling' but still not idle" processes now show up as they should. > > However, it has exposed one quirk in the display: > > Sorting is done by WCPU followed by total processor time. > > Processes which aren't idle (but are using so little cpu it shows as 0.00%) > show below processes which are truely idle, but have totaled more processor > time overall. > > This is more noticable with your new patch, as toggling between idle-only > and full now shows processes appearing higher in the list than some which > only appear in the non-idle view! > > Ideally, processes where cpu "is virtually 0.00% but really a smidgen higher" > should be display higher. > > I realise the pctcpu granularity is at fault here. > > Basically, what I'm saying is that truely idle processes should appear below > other processes reporting 0.00% cpu. > > In other words, what I'm asking is: shouldn't the cpu sort priority not > simply be keyed on 'ki_pctcpu', but on a primary key based on > "if cur->ki_runtime == old->ki_runtime ?" followed by secondary key ki_pctcpu. > > Or even easier, shouldn't simply sorting on (cur->ki_runtime - old->ki_runtime) > suffice? > > Is this a valid point, and if it is, is it practical, and/or easy enough to > achieve? I'll even have a stab at it myself tomorrow, after hopefully getting > some sleep (32 hours without sleep - sorry for incoherency - insomnia is a PITA) Yes, I actually started by sorting on the raw delta and ended up going back and fixing pctcpu instead. However, there is a problem in this case which is that you still want to fall back to ki_pctcpu if you don't have a valid previous delta to compare against. It's a lot simpler to just fixup ki_pctcpu and not have to go change the sorting code explicitly. :( I actually started out having a function that returned a double for the pctcpu, but that would mean recalculating the raw pctcpu many, many times during the sort. Just updating ki_pctcpu once per each process/thread per fetch scales a bit better. I could perhaps use an array to cache raw percentages as doubles. Ok, try people.freebsd.org/~jhb/patches/top_pctcpu2.patch -- John Baldwin