Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 7 Apr 2015 01:07:07 +0200
From:      Luigi Rizzo <rizzo@iet.unipi.it>
To:        Chris Torek <torek@torek.net>
Cc:        "freebsd-arch@freebsd.org" <freebsd-arch@freebsd.org>
Subject:   Re: sysctl output formatting
Message-ID:  <CA%2BhQ2%2BgXByFkHuSs8ZY_ceezekfU3GfnmrfA-uaW6xQnqHKm3w@mail.gmail.com>
In-Reply-To: <201504062229.t36MTMlJ024359@elf.torek.net>
References:  <201504062229.t36MTMlJ024359@elf.torek.net>

next in thread | previous in thread | raw e-mail | index | archive | help
On Tue, Apr 7, 2015 at 12:29 AM, Chris Torek <torek@torek.net> 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



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?CA%2BhQ2%2BgXByFkHuSs8ZY_ceezekfU3GfnmrfA-uaW6xQnqHKm3w>