svn commit: r296933 - in head: share/man/man9 sys/sys

Hans Petter Selasky hselasky at FreeBSD.org
Wed Mar 16 08:37:54 UTC 2016


Author: hselasky
Date: Wed Mar 16 08:37:52 2016
New Revision: 296933
URL: https://svnweb.freebsd.org/changeset/base/296933

Log:
  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.

Modified:
  head/share/man/man9/Makefile
  head/share/man/man9/counter.9
  head/sys/sys/sysctl.h

Modified: head/share/man/man9/Makefile
==============================================================================
--- head/share/man/man9/Makefile	Wed Mar 16 06:42:15 2016	(r296932)
+++ head/share/man/man9/Makefile	Wed Mar 16 08:37:52 2016	(r296933)
@@ -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 \

Modified: head/share/man/man9/counter.9
==============================================================================
--- head/share/man/man9/counter.9	Wed Mar 16 06:42:15 2016	(r296932)
+++ head/share/man/man9/counter.9	Wed Mar 16 08:37:52 2016	(r296933)
@@ -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 ,

Modified: head/sys/sys/sysctl.h
==============================================================================
--- head/sys/sys/sysctl.h	Wed Mar 16 06:42:15 2016	(r296932)
+++ head/sys/sys/sysctl.h	Wed Mar 16 08:37:52 2016	(r296933)
@@ -654,8 +654,10 @@ TAILQ_HEAD(sysctl_ctx_list, sysctl_ctx_e
 	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)							\


More information about the svn-src-all mailing list