Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 06 Apr 2015 15:29:22 -0700
From:      Chris Torek <torek@torek.net>
To:        freebsd-arch@freebsd.org
Subject:   sysctl output formatting
Message-ID:  <201504062229.t36MTMlJ024359@elf.torek.net>

next in thread | raw e-mail | index | archive | help
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



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201504062229.t36MTMlJ024359>