From owner-freebsd-arch@FreeBSD.ORG Mon Apr 6 22:29:30 2015 Return-Path: Delivered-To: freebsd-arch@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id 86738B66 for ; Mon, 6 Apr 2015 22:29:30 +0000 (UTC) Received: from elf.torek.net (mail.torek.net [96.90.199.121]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 694B0F2C for ; Mon, 6 Apr 2015 22:29:29 +0000 (UTC) Received: from elf.torek.net (localhost [127.0.0.1]) by elf.torek.net (8.14.5/8.14.5) with ESMTP id t36MTMlJ024359 for ; Mon, 6 Apr 2015 16:29:22 -0600 (MDT) (envelope-from torek@torek.net) Message-Id: <201504062229.t36MTMlJ024359@elf.torek.net> From: Chris Torek To: freebsd-arch@freebsd.org Subject: sysctl output formatting MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <24357.1428359362.1@elf.torek.net> Date: Mon, 06 Apr 2015 15:29:22 -0700 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.4.3 (elf.torek.net [127.0.0.1]); Mon, 06 Apr 2015 16:29:22 -0600 (MDT) X-BeenThere: freebsd-arch@freebsd.org X-Mailman-Version: 2.1.18-1 Precedence: list List-Id: Discussion related to FreeBSD architecture List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 06 Apr 2015 22:29:30 -0000 We had a side discussion at $work about a private sysctl emulation (so our side thing doesn't actually affect sysctl itself at all) where it was suggested that some simple numeric sysctls are "best displayed in hex". Consider, e.g.: $ sysctl kern.timecounter.tc.i8254 kern.timecounter.tc.i8254.mask: 65535 kern.timecounter.tc.i8254.counter: 25822 kern.timecounter.tc.i8254.frequency: 1193182 kern.timecounter.tc.i8254.quality: 0 The "mask" here actually makes more sense displayed in hex. One can of course use: $ sysctl -x kern.timecounter.tc.i8254 kern.timecounter.tc.i8254.mask: 0x0000ffff kern.timecounter.tc.i8254.counter: 0x0000786c kern.timecounter.tc.i8254.frequency: 0x00000000001234de kern.timecounter.tc.i8254.quality: 0000000000 but now the mask is shown in hex (yay) but the others are shown in hex too (boo). The suggestion made (note that I'm carefully filing off names via passive voice :-) ) is that there could be a sysctl flag: #define CTLFLAG_DEFHEX 0x00000800 that says that, without any additional formatting directive, the user-level "sysctl" command should output this particular value in hex. Obviously this eats up another flag bit (but there are a few left) and might require a new argument to the sysctl command ("force output to be decimal", for compatibility or whatever). Then someone said "but what about suggesting that the output be in octal, or binary, or ..." in which case this would have to be a bit-field rather than a single bit (a la the CTLMASK_SECURE field). Anyway, I volunteered to send in the idea to be bikeshedded :-) here. It does seem like a reasonable special case to add, though I admit it buys much more with certain huge 64-bit byte-grouped values we have (0x0303030103030300 reads so much nicer than 217020509924295424 for instance). If people like the idea, I could code it up as well. Chris