Date: Tue, 15 Mar 2016 00:05:00 +0000 (UTC) From: Gleb Smirnoff <glebius@FreeBSD.org> To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r296880 - in head: share/man/man9 sys/kern sys/sys Message-ID: <201603150005.u2F050ps086390@repo.freebsd.org>
next in thread | raw e-mail | index | archive | help
Author: glebius Date: Tue Mar 15 00:05:00 2016 New Revision: 296880 URL: https://svnweb.freebsd.org/changeset/base/296880 Log: Provide sysctl(9) macro to deal with array of counter(9). Modified: head/share/man/man9/counter.9 head/sys/kern/subr_counter.c head/sys/sys/sysctl.h Modified: head/share/man/man9/counter.9 ============================================================================== --- head/share/man/man9/counter.9 Mon Mar 14 23:49:16 2016 (r296879) +++ head/share/man/man9/counter.9 Tue Mar 15 00:05:00 2016 (r296880) @@ -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 allocate 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 Modified: head/sys/kern/subr_counter.c ============================================================================== --- head/sys/kern/subr_counter.c Mon Mar 14 23:49:16 2016 (r296879) +++ head/sys/kern/subr_counter.c Tue Mar 15 00:05:00 2016 (r296880) @@ -94,3 +94,27 @@ sysctl_handle_counter_u64(SYSCTL_HANDLER 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); +} Modified: head/sys/sys/sysctl.h ============================================================================== --- head/sys/sys/sysctl.h Mon Mar 14 23:49:16 2016 (r296879) +++ head/sys/sys/sysctl.h Tue Mar 15 00:05:00 2016 (r296880) @@ -204,6 +204,7 @@ int sysctl_handle_long(SYSCTL_HANDLER_AR 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_e __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), \
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201603150005.u2F050ps086390>