Provide sysctl(9) macro to deal with array of counter(9).
This commit is contained in:
parent
33eb7d8e7f
commit
0cafb74055
@ -25,7 +25,7 @@
|
||||
.\"
|
||||
.\" $FreeBSD$
|
||||
.\"
|
||||
.Dd February 7, 2014
|
||||
.Dd March 14, 2016
|
||||
.Dt COUNTER 9
|
||||
.Os
|
||||
.Sh NAME
|
||||
@ -54,6 +54,8 @@
|
||||
.In sys/sysctl.h
|
||||
.Fn SYSCTL_COUNTER_U64 parent nbr name access ptr descr
|
||||
.Fn SYSCTL_ADD_COUNTER_U64 ctx parent nbr name access ptr descr
|
||||
.Fn SYSCTL_COUNTER_U64_ARRAY parent nbr name access ptr len descr
|
||||
.Fn SYSCTL_ADD_COUNTER_U64_ARRAY ctx parent nbr name access ptr len descr
|
||||
.Sh DESCRIPTION
|
||||
.Nm
|
||||
is a generic facility to create counters
|
||||
@ -150,6 +152,40 @@ argument should be a pointer to allocated
|
||||
A read of the oid returns value obtained through
|
||||
.Fn counter_u64_fetch .
|
||||
Any write to the oid zeroes it.
|
||||
.It Fn SYSCTL_COUNTER_U64_ARRAY parent nbr name access ptr len descr
|
||||
Declare a static
|
||||
.Xr sysctl
|
||||
oid that would represent an array of
|
||||
.Nm .
|
||||
The
|
||||
.Fa ptr
|
||||
argument should be a pointer to allocated array of
|
||||
.Vt counter_u64_t's .
|
||||
The
|
||||
.Fa len
|
||||
argument should specify number of elements in the array.
|
||||
A read of the oid returns len-sized array of
|
||||
.Vt uint64_t
|
||||
values obtained through
|
||||
.Fn counter_u64_fetch .
|
||||
Any write to the oid zeroes all array elements.
|
||||
.It Fn SYSCTL_ADD_COUNTER_U64_ARRAY ctx parent nbr name access ptr len descr
|
||||
Create a
|
||||
.Xr sysctl
|
||||
oid that would represent an array of
|
||||
.Nm .
|
||||
The
|
||||
.Fa ptr
|
||||
argument should be a pointer to allocated array of
|
||||
.Vt counter_u64_t's .
|
||||
The
|
||||
.Fa len
|
||||
argument should specify number of elements in the array.
|
||||
A read of the oid returns len-sized array of
|
||||
.Vt uint64_t
|
||||
values obtained through
|
||||
.Fn counter_u64_fetch .
|
||||
Any write to the oid zeroes all array elements.
|
||||
.El
|
||||
.Sh IMPLEMENTATION DETAILS
|
||||
On all architectures
|
||||
|
@ -94,3 +94,27 @@ sysctl_handle_counter_u64(SYSCTL_HANDLER_ARGS)
|
||||
|
||||
return (0);
|
||||
}
|
||||
|
||||
int
|
||||
sysctl_handle_counter_u64_array(SYSCTL_HANDLER_ARGS)
|
||||
{
|
||||
uint64_t *out;
|
||||
int error;
|
||||
|
||||
out = malloc(arg2 * sizeof(uint64_t), M_TEMP, M_WAITOK);
|
||||
for (int i = 0; i < arg2; i++)
|
||||
out[i] = counter_u64_fetch(((counter_u64_t *)arg1)[i]);
|
||||
|
||||
error = SYSCTL_OUT(req, out, arg2 * sizeof(uint64_t));
|
||||
|
||||
if (error || !req->newptr)
|
||||
return (error);
|
||||
|
||||
/*
|
||||
* Any write attempt to a counter zeroes it.
|
||||
*/
|
||||
for (int i = 0; i < arg2; i++)
|
||||
counter_u64_zero(((counter_u64_t *)arg1)[i]);
|
||||
|
||||
return (0);
|
||||
}
|
||||
|
@ -204,6 +204,7 @@ int sysctl_handle_long(SYSCTL_HANDLER_ARGS);
|
||||
int sysctl_handle_string(SYSCTL_HANDLER_ARGS);
|
||||
int sysctl_handle_opaque(SYSCTL_HANDLER_ARGS);
|
||||
int sysctl_handle_counter_u64(SYSCTL_HANDLER_ARGS);
|
||||
int sysctl_handle_counter_u64_array(SYSCTL_HANDLER_ARGS);
|
||||
|
||||
int sysctl_handle_uma_zone_max(SYSCTL_HANDLER_ARGS);
|
||||
int sysctl_handle_uma_zone_cur(SYSCTL_HANDLER_ARGS);
|
||||
@ -648,6 +649,26 @@ TAILQ_HEAD(sysctl_ctx_list, sysctl_ctx_entry);
|
||||
__ptr, 0, sysctl_handle_counter_u64, "QU", __DESCR(descr)); \
|
||||
})
|
||||
|
||||
/* Oid for an array of counter(9)s. The pointer and length must be non zero. */
|
||||
#define SYSCTL_COUNTER_U64_ARRAY(parent, nbr, name, access, ptr, len, descr) \
|
||||
SYSCTL_OID(parent, nbr, name, \
|
||||
CTLTYPE_OPAQUE | CTLFLAG_MPSAFE | (access), \
|
||||
(ptr), (len), sysctl_handle_counter_u64_array, "S", descr); \
|
||||
CTASSERT(((access) & CTLTYPE) == 0 || \
|
||||
((access) & SYSCTL_CT_ASSERT_MASK) == CTLTYPE_OPAQUE)
|
||||
|
||||
#define SYSCTL_ADD_COUNTER_U64_ARRAY(ctx, parent, nbr, name, access, \
|
||||
ptr, len, descr) \
|
||||
({ \
|
||||
counter_u64_t *__ptr = (ptr); \
|
||||
CTASSERT(((access) & CTLTYPE) == 0 || \
|
||||
((access) & SYSCTL_CT_ASSERT_MASK) == CTLTYPE_OPAQUE); \
|
||||
sysctl_add_oid(ctx, parent, nbr, name, \
|
||||
CTLTYPE_OPAQUE | CTLFLAG_MPSAFE | (access), \
|
||||
__ptr, len, sysctl_handle_counter_u64_array, "S", \
|
||||
__DESCR(descr)); \
|
||||
})
|
||||
|
||||
/* Oid for an opaque object. Specified by a pointer and a length. */
|
||||
#define SYSCTL_OPAQUE(parent, nbr, name, access, ptr, len, fmt, descr) \
|
||||
SYSCTL_OID(parent, nbr, name, CTLTYPE_OPAQUE|(access), \
|
||||
|
Loading…
Reference in New Issue
Block a user