diff options
author | hselasky <hselasky@FreeBSD.org> | 2016-03-16 08:37:52 +0000 |
---|---|---|
committer | hselasky <hselasky@FreeBSD.org> | 2016-03-16 08:37:52 +0000 |
commit | f1fdbd94a37f930ff87f0e0001ea6933e8029343 (patch) | |
tree | 55757d948c119239c5f08c93e3f0d24d5ac38bec | |
parent | f0149ff4ac175b42adabe6e41da09574d6e552e5 (diff) | |
download | FreeBSD-src-f1fdbd94a37f930ff87f0e0001ea6933e8029343.zip FreeBSD-src-f1fdbd94a37f930ff87f0e0001ea6933e8029343.tar.gz |
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.
-rw-r--r-- | share/man/man9/Makefile | 6 | ||||
-rw-r--r-- | share/man/man9/counter.9 | 10 | ||||
-rw-r--r-- | 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) \ |