From f1fdbd94a37f930ff87f0e0001ea6933e8029343 Mon Sep 17 00:00:00 2001 From: hselasky Date: Wed, 16 Mar 2016 08:37:52 +0000 Subject: Improve the implementation and documentation of the SYSCTL_COUNTER_U64_ARRAY() macro. - Add proper asserts to the SYSCTL_COUNTER_U64_ARRAY() macro that checks the size of the first element of the array. - Add an example to the counter(9) manual page how to use the SYSCTL_COUNTER_U64_ARRAY() macro. - Add some missing symbolic links for counter(9) while at it. --- share/man/man9/Makefile | 6 +++++- share/man/man9/counter.9 | 10 ++++++++++ sys/sys/sysctl.h | 6 ++++-- 3 files changed, 19 insertions(+), 3 deletions(-) diff --git a/share/man/man9/Makefile b/share/man/man9/Makefile index 66c16d7..26f230c 100644 --- a/share/man/man9/Makefile +++ b/share/man/man9/Makefile @@ -639,7 +639,11 @@ MLINKS+=counter.9 counter_u64_alloc.9 \ counter.9 counter_exit.9 \ counter.9 counter_u64_add_protected.9 \ counter.9 counter_u64_fetch.9 \ - counter.9 counter_u64_zero.9 + counter.9 counter_u64_zero.9 \ + counter.9 SYSCTL_COUNTER_U64.9 \ + counter.9 SYSCTL_ADD_COUNTER_U64.9 \ + counter.9 SYSCTL_COUNTER_U64_ARRAY.9 \ + counter.9 SYSCTL_ADD_COUNTER_U64_ARRAY.9 MLINKS+=cpuset.9 CPUSET_T_INITIALIZER.9 \ cpuset.9 CPUSET_FSET.9 \ cpuset.9 CPU_CLR.9 \ diff --git a/share/man/man9/counter.9 b/share/man/man9/counter.9 index 85bc9fe..0fcf2ad 100644 --- a/share/man/man9/counter.9 +++ b/share/man/man9/counter.9 @@ -215,6 +215,16 @@ amd64 single-instruction implementation. On some architectures updating a counter require a .Xr critical 9 section. +.Sh EXAMPLES +The following example creates a static counter array exported to +userspace through a sysctl: +.Bd -literal -offset indent +#define MY_SIZE 8 +static counter_u64_t array[MY_SIZE]; +SYSCTL_COUNTER_U64_ARRAY(_debug, OID_AUTO, counter_array, CTLFLAG_RW, + &array[0], MY_SIZE, "Test counter array"); +.Ed +.Pp .Sh SEE ALSO .Xr atomic 9 , .Xr critical 9 , diff --git a/sys/sys/sysctl.h b/sys/sys/sysctl.h index 34ee03c..eb5eef0 100644 --- a/sys/sys/sysctl.h +++ b/sys/sys/sysctl.h @@ -654,8 +654,10 @@ TAILQ_HEAD(sysctl_ctx_list, sysctl_ctx_entry); 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) + CTASSERT((((access) & CTLTYPE) == 0 || \ + ((access) & SYSCTL_CT_ASSERT_MASK) == CTLTYPE_OPAQUE) && \ + sizeof(counter_u64_t) == sizeof(*(ptr)) && \ + sizeof(uint64_t) == sizeof(**(ptr))) #define SYSCTL_ADD_COUNTER_U64_ARRAY(ctx, parent, nbr, name, access, \ ptr, len, descr) \ -- cgit v1.1