From owner-svn-src-head@freebsd.org Tue Jun 5 05:32:11 2018 Return-Path: Delivered-To: svn-src-head@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 8569EFD3A96; Tue, 5 Jun 2018 05:32:11 +0000 (UTC) (envelope-from brde@optusnet.com.au) Received: from mail110.syd.optusnet.com.au (mail110.syd.optusnet.com.au [211.29.132.97]) by mx1.freebsd.org (Postfix) with ESMTP id 6EA3B8101F; Tue, 5 Jun 2018 05:32:10 +0000 (UTC) (envelope-from brde@optusnet.com.au) Received: from [192.168.0.102] (c110-21-101-228.carlnfd1.nsw.optusnet.com.au [110.21.101.228]) by mail110.syd.optusnet.com.au (Postfix) with ESMTPS id BC5B31048A4; Tue, 5 Jun 2018 15:32:01 +1000 (AEST) Date: Tue, 5 Jun 2018 15:32:00 +1000 (EST) From: Bruce Evans X-X-Sender: bde@besplex.bde.org To: Ian Lepore cc: Eitan Adler , src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: Re: svn commit: r334604 - head/usr.bin/top In-Reply-To: <1528128032.32688.218.camel@freebsd.org> Message-ID: <20180605141442.Y1370@besplex.bde.org> References: <201806040527.w545R1UA075420@repo.freebsd.org> <1528128032.32688.218.camel@freebsd.org> MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII; format=flowed X-Optus-CM-Score: 0 X-Optus-CM-Analysis: v=2.2 cv=I9sVfJog c=1 sm=1 tr=0 a=PalzARQSbocsUSjMRkwAPg==:117 a=PalzARQSbocsUSjMRkwAPg==:17 a=kj9zAlcOel0A:10 a=LulXne3407rxXn8zq4sA:9 a=CjuIK1q_8ugA:10 X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.26 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: Tue, 05 Jun 2018 05:32:11 -0000 On Mon, 4 Jun 2018, Ian Lepore wrote: > On Mon, 2018-06-04 at 05:27 +0000, Eitan Adler wrote: >> ... >> Log: >> \xa0 top(1): some nitpicks >> \xa0\xa0 >> \xa0 - prefer fully spelled names to "u_long" > > Why? I though we preferred the u_char, u_int, u_long spellings in BSD > code? (I certainly prefer them, and I thought style(9) did too, but I > seem to be remembering that wrong). u_foo is only prefered in system-y code (like top and the kernel). However, top used to be portable and using u_foo in it just breaks portability. However2, u_foo was only used in the MD parts of top, and was only used twice, and 1 of these uses is wrong (*). Top doesn't suffer much from unsigned poisoning, so it has little need for u_foo. It mostly uses int, and that is mostly correct. In the old MD code (just machine.c), it used 'unsigned xxx' just 3 times, and all 3 were wrong: - unsigned int swap_delay. swap_delay is boolean, but should have been int and not churned to bool. It has not been churned. - casts of len and nlen to unsigned long to print them in getsysctl(). Although the values in these variables are or should be small, the variables need to have type size_t to use them conveniently with APIs like sysctl(3). Then to print them, we bogusly cast them to unsigned long. Old versions used the wrong format %d so were broken on non-32-bit arches, and instead of fixing this properly using %zu, the warning was broken by changing the format to %lu and casting to unsigned long. unsigned long of course works unless the values are preposterous, and unsigned long is large enough for even preposterous values on all supported arches, but verifying this is more work than using %zu. Casting to int to match the old format would also work for non-preposterous values. The bogus fix was committed in 2001. I think libc supported %zu then theough this was not long after C99 standardized %zu. top/machine.c is FreeBSD-only, so it should have used the unportable %zu. (*) The use of u_long for swap_maxpages is correct. This variable is read from a kernel variable with type u_long using SYSCTL_ULONG(). The use of u_long for cpumask is now very wrong. Originally, the correct type was cpumask_t. This was u_int even on amd64. u_long was originally only slightly wrong since it is larger than u_int and cpumask is populated without asking the kernel what the CPUs are. (This method was OK. It checks for activity on all CPU numbers between 0 and ncpus - 1.) FreeBSD had fancy cpusets implemented as of arrays of (signed) long when this was new, but the kernel also used simple masks of type cpumask_t or worse, so it was limited to 32 CPUs too. Now the kernel can handle many more than 32 CPUs, but top can only handle 8 * sizeof(u_long) CPUs. top's display is also limited to 2-digit CPU numbers. style(9) says nothing about this. Its only literal match for either u_ or unsigned is in a rule saying that the C99 spelling [for fixed-width types] of uintXX_t should be used instead of the BSD spelling u_intXX_t. It hasn't suffered from unsigned poisoning and uses plain int in most examples. It doesn't even have much typedef poisoning or any examples or many rules for foo_t. Its only matches for _t are for u*_t as above, and in a rule that allows churning bool_t to bool, and in a rule that says to not use [private] typedefs ending in _t [because POSIX reserves names ending in _t]. Bruce