From owner-freebsd-arch@FreeBSD.ORG Mon Apr 6 23:07:10 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 94E65306 for ; Mon, 6 Apr 2015 23:07:10 +0000 (UTC) Received: from mail-la0-x229.google.com (mail-la0-x229.google.com [IPv6:2a00:1450:4010:c03::229]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (Client CN "smtp.gmail.com", Issuer "Google Internet Authority G2" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 03F1236F for ; Mon, 6 Apr 2015 23:07:10 +0000 (UTC) Received: by labbd9 with SMTP id bd9so18422177lab.2 for ; Mon, 06 Apr 2015 16:07:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:sender:in-reply-to:references:date:message-id:subject :from:to:cc:content-type; bh=gcFiBw/w6GAUJwaCowdF2NJuA+qbzBoH48XRIo/ztcs=; b=pnWULs/ZiAxKk0qUWLIi3wMyyi4Roz9PQp83FtEcA5yraxewCX/k2SZ2MO1irjD7o6 tkcrazitTp8zOOcyJG9Bh/pyeRqqdRWH9HB9HKA0j/zMd/1ug0rQg1EgbHPKomAapLav MMYEFcS/t410Aq96Y/sJbm9wOIhH0+ZrIC3bL5GGoKDs0ErNqu8k35osy44+E8I0z9Z3 8NzwCR+1G5pjK3aaX49Vk69Ir9s0zF8Kfyrp13f0TqZmDWFSmW9HLdkh+GGq6FqemDj9 ycP10Lm2U06HJysqJGgjgrWm3bJwJnwB0YzXujMkxPcz1mWSZ72uOZGWhgg7+Bt8Sb7T eQ0Q== MIME-Version: 1.0 X-Received: by 10.153.5.8 with SMTP id ci8mr11095678lad.62.1428361627227; Mon, 06 Apr 2015 16:07:07 -0700 (PDT) Sender: rizzo.unipi@gmail.com Received: by 10.114.180.4 with HTTP; Mon, 6 Apr 2015 16:07:07 -0700 (PDT) In-Reply-To: <201504062229.t36MTMlJ024359@elf.torek.net> References: <201504062229.t36MTMlJ024359@elf.torek.net> Date: Tue, 7 Apr 2015 01:07:07 +0200 X-Google-Sender-Auth: sytoRLkgYUfMXiMICZqQ79vDirA Message-ID: Subject: Re: sysctl output formatting From: Luigi Rizzo To: Chris Torek Content-Type: text/plain; charset=ISO-8859-1 X-Content-Filtered-By: Mailman/MimeDel 2.1.18-1 Cc: "freebsd-arch@freebsd.org" 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 23:07:10 -0000 On Tue, Apr 7, 2015 at 12:29 AM, Chris Torek wrote: > 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). > > since we are in bikeshed territory how about instead (or in addition) building a small wrapper/sysctl extension that eats sysctl's output, an exception list that specifies which variables should be converted and to what format, and does the conversion. I understand that this is potentially N*M complexity (N sysctl variables times M entries in the exception list) if we allow exceptions to be regexp, but for the numbers at hand it is probably acceptable. The advantage is that you can run it on existing kernels and can be easily customized. c heers luigi