From owner-svn-src-all@freebsd.org Sat May 26 08:43:04 2018 Return-Path: Delivered-To: svn-src-all@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 ED3FBF6E0B7; Sat, 26 May 2018 08:43:03 +0000 (UTC) (envelope-from brde@optusnet.com.au) Received: from mail105.syd.optusnet.com.au (mail105.syd.optusnet.com.au [211.29.132.249]) by mx1.freebsd.org (Postfix) with ESMTP id 2FA7087E08; Sat, 26 May 2018 08:43:02 +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 mail105.syd.optusnet.com.au (Postfix) with ESMTPS id 32B4D104C4AE; Sat, 26 May 2018 18:42:54 +1000 (AEST) Date: Sat, 26 May 2018 18:42:53 +1000 (EST) From: Bruce Evans X-X-Sender: bde@besplex.bde.org To: Eitan Adler cc: Alexey Dokuchaev , Bruce Evans , svn-src-head@freebsd.org, svn-src-all@freebsd.org, src-committers Subject: Re: svn commit: r333945 - head/usr.bin/top In-Reply-To: Message-ID: <20180526175225.Y2558@besplex.bde.org> References: <201805202319.w4KNJ9hj038452@repo.freebsd.org> <20180521094344.Q1053@besplex.bde.org> <20180521063953.GA70671@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=FNpr/6gs c=1 sm=1 tr=0 a=PalzARQSbocsUSjMRkwAPg==:117 a=PalzARQSbocsUSjMRkwAPg==:17 a=kj9zAlcOel0A:10 a=6I5d2MoRAAAA:8 a=uyavkMrdAAAA:8 a=2Zs28DNd_5JVJXk8RF0A:9 a=LgjS_5B3MOc4BwW_:21 a=bYBxrsk4H7JLRLFv:21 a=CjuIK1q_8ugA:10 a=IjZwj45LgO3ly-622nXo:22 a=j2_G595jqNHTxQgNwHU2:22 X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.26 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 26 May 2018 08:43:04 -0000 On Fri, 25 May 2018, Eitan Adler wrote: > On 20 May 2018 at 23:39, Alexey Dokuchaev wrote: >> On Mon, May 21, 2018 at 10:32:30AM +1000, Bruce Evans wrote: >>> ... >>>> if (smpmode && namelength > SMPUNAMELEN) >>>> namelength = SMPUNAMELEN; >>>> else if (namelength > UPUNAMELEN) >>> > ... > > what about this? It is now too simple. > commit 7d041879b4d0ad11818b5f5875b1198a722841d7 > Author: Eitan Adler > Date: Sat May 26 04:30:48 2018 +0000 > > top(1): allow to configure the max username length > > Some users prefer shorter names, and MAXLOGNAME is not a perfect method > of coming up with a default. Use 8, by request, and allow users to > configure it. 8 was the (default) minimum name length, but this makes it the (default) maximum. This is a surprising change... > diff --git a/usr.bin/top/machine.c b/usr.bin/top/machine.c > index 0f31d87..d6a9b41 100644 > --- a/usr.bin/top/machine.c > +++ b/usr.bin/top/machine.c > @@ -50,8 +50,9 @@ > #include "layout.h" > > #define GETSYSCTL(name, var) getsysctl(name, &(var), sizeof(var)) > -#define SMPUNAMELEN 13 > -#define UPUNAMELEN 15 > +#ifndef MAXTOPNAMELEN > +#define MAXTOPNAMELEN 8 > +#endif 13 was not too bad as a default maximum. 15 was bogus. Most users use SMP so would never see 15 being used. The extra 2 for UP is to waste space made available by not having a column for the CPU number. But width 2 for this field broke a year or 2 ago on large systems with more than 99 CPUs. The format string for the CPU number is still hard-coded to " %2d". Several fields are formatted correctly with variable width. The USER field is one of these. > > extern struct timeval timeout; > static int smpmode; > @@ -329,11 +330,7 @@ machine_init(struct statics *statics) > NULL, 0) == 0 && carc_en == 1) > carc_enabled = 1; > > - namelength = MAXLOGNAME; > - if (smpmode && namelength > SMPUNAMELEN) > - namelength = SMPUNAMELEN; > - else if (namelength > UPUNAMELEN) > - namelength = UPUNAMELEN; > + namelength = MAXTOPNAMELEN; > > kd = kvm_open(NULL, _PATH_DEVNULL, NULL, O_RDONLY, "kvm_open"); > if (kd == NULL) I don't like having many run-time configuration options, but one for this would work well. Default to either 8 or 13 so as to not surprise too many users. But have a runtime option to set change the default. This is almost as easy as having a compile-time option (don't have both). It takes just 1 letter in the getopt string and 3 lines in a case statement for top's usual sloppy arg parsing (case X; namelength = atoi(optarg); break;). Documentation takes about the same as for a compile-time option. The old code would have been efficient enough on most systems it it had stopped trying to find the longest name after finding one that is as long as the maximum. To avoid long scans on large systems with a silly order of user name (like sorting the shortest ones first), stop after about 100 names. I think adjusting the format to match the width of the USER field is done correctly. Thus dynamically reducing the width to much less than 8 is already useful for getting more columns in the COMMAND field. AFAIK there is no way to control the widths of the other fields. Certainly not the CPU number field. Bruce