sysctl questions
Milan Obuch
freebsd-hackers at dino.sk
Sat Oct 19 11:45:29 UTC 2019
Hi,
I am working on AXI XADC driver on Zynq based Zybo Z7 board. I created
simple PL design to be able to use this core IP. Looking in some other
ADC driver I desided to use sysctl API to report measurements. So I did
create mib entry in attach function like this
snprintf(pinbuf, sizeof(inum), "%d", i);
inpN_node = SYSCTL_ADD_NODE(ctx, inp_tree, OID_AUTO, inum,
CTLFLAG_RD, NULL, "ADC input");
inpN_tree = SYSCTL_CHILDREN(inpN_node);
SYSCTL_ADD_PROC(ctx, inpN_tree, OID_AUTO, "read",
CTLFLAG_RD | CTLTYPE_UINT, &axi_xadc_inputs[i], 0,
axi_xadc_read_proc, "IU", "Read ADC input");
where inum is string, i is integer - input number. Top node for my
mib entries is dev.adc.0.ain. When the above snippet is run for i from
0 up to Ninputs - 1, sysctl shows them in opposite order, i. e.
# sysctl dev.adc.0.ain
dev.adc.0.ain.3.read: <some value>
dev.adc.0.ain.2.read: <some value>
dev.adc.0.ain.1.read: <some value>
dev.adc.0.ain.0.read: <some value>
Why it is so? It looks for me a bit counter intuitive, I like the nodes
be ordered the way I decide, not the other way so... so I am just
calling the initialisation snippet for i starting with Ninput - 1 down
to 0 and it works the way I want.
Other thing I do not understand is my axi_xadc_read_proc is called
*twice* per node. My procedure is short:
static int
axi_xadc_read_proc(SYSCTL_HANDLER_ARGS)
{
int error;
int32_t status, value;
long cvalue;
struct axi_xadc_softc *sc;
struct axi_xadc_input *input;
input = (struct axi_xadc_input *)arg1;
sc = input->sc;
XADC_LOCK(sc);
status = RD4(sc, AXI_XADC_SR);
value = RD4(sc, input->reg);
cvalue = some_conversion(value);
device_printf(sc->dev, "status %.4X raw %.4X conv %ld\n",
status, value, cvalue);
XADC_UNLOCK(sc);
error = sysctl_handle_int(oidp, &value, sizeof(value), req);
if (error != 0 || req->newptr == NULL)
return (error);
return (0);
}
Doing 'sysctl dev.adc.0.ain.0.read' prints one line in my login
session, but two lines on console, example is
adc0: status 00F7 raw A1B6 in 45
adc0: status 00F7 raw A1D6 in 45
Naturally, these are just debug outputs, but still it makes me a bit
surprised.
Also, do we have somewhere documented sysctl api usage? I did not find
much, just three or so man pages, all somewhat short...
Regards,
Milan
More information about the freebsd-hackers
mailing list