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

2016-03-20 Thread Gleb Smirnoff
On Wed, Mar 16, 2016 at 08:37:52AM +, Hans Petter Selasky wrote:
H> Author: hselasky
H> Date: Wed Mar 16 08:37:52 2016
H> New Revision: 296933
H> URL: https://svnweb.freebsd.org/changeset/base/296933
H> 
H> Log:
H>   Improve the implementation and documentation of the
H>   SYSCTL_COUNTER_U64_ARRAY() macro.
H>   
H>   - Add proper asserts to the SYSCTL_COUNTER_U64_ARRAY() macro that checks
H> the size of the first element of the array.
H>   - Add an example to the counter(9) manual page how to use the
H> SYSCTL_COUNTER_U64_ARRAY() macro.
H>   - Add some missing symbolic links for counter(9) while at it.

...

H> +.Sh EXAMPLES
H> +The following example creates a static counter array exported to
H> +userspace through a sysctl:
H> +.Bd -literal -offset indent
H> +#define MY_SIZE 8
H> +static counter_u64_t array[MY_SIZE];
H> +SYSCTL_COUNTER_U64_ARRAY(_debug, OID_AUTO, counter_array, CTLFLAG_RW,
H> +[0], MY_SIZE, "Test counter array");

I always wondered what is stylistically better: array or [0]? I
usually prefer the former.

-- 
Totus tuus, Glebius.
___
svn-src-head@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"


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

2016-03-19 Thread Hans Petter Selasky

On 03/16/16 21:36, Gleb Smirnoff wrote:

On Wed, Mar 16, 2016 at 08:37:52AM +, Hans Petter Selasky wrote:
H> Modified: head/sys/sys/sysctl.h
H> 
==
H> --- head/sys/sys/sysctl.h Wed Mar 16 06:42:15 2016(r296932)
H> +++ head/sys/sys/sysctl.h Wed Mar 16 08:37:52 2016(r296933)
H> @@ -654,8 +654,10 @@ TAILQ_HEAD(sysctl_ctx_list, sysctl_ctx_e
H>   SYSCTL_OID(parent, nbr, name,   \
H>   CTLTYPE_OPAQUE | CTLFLAG_MPSAFE | (access), \
H>   (ptr), (len), sysctl_handle_counter_u64_array, "S", descr);   \
H> - CTASSERT(((access) & CTLTYPE) == 0 ||   \
H> - ((access) & SYSCTL_CT_ASSERT_MASK) == CTLTYPE_OPAQUE)
H> + CTASSERTaccess) & CTLTYPE) == 0 ||  \
H> + ((access) & SYSCTL_CT_ASSERT_MASK) == CTLTYPE_OPAQUE) &&\
H> + sizeof(counter_u64_t) == sizeof(*(ptr)) &&  \
H> + sizeof(uint64_t) == sizeof(**(ptr)))

I don't agree with the last line. Does it assert that counter_u64_t is
implemented using uint64_t? That is true, but that is internal detail,
that might be changed in future.



Yes, it asserts that counter_u64_t is a 64-bit counter, as the name of 
the typedef hints at.


From the past experience there has been several cases where someone has 
changed a field in structure which is exported as a sysctl, and then the 
sysctls were never updated.


--HPS
___
svn-src-head@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"


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

2016-03-19 Thread Hans Petter Selasky

On 03/16/16 21:32, Gleb Smirnoff wrote:

On Wed, Mar 16, 2016 at 08:37:52AM +, Hans Petter Selasky wrote:
H> Author: hselasky
H> Date: Wed Mar 16 08:37:52 2016
H> New Revision: 296933
H> URL: https://svnweb.freebsd.org/changeset/base/296933
H>
H> Log:
H>   Improve the implementation and documentation of the
H>   SYSCTL_COUNTER_U64_ARRAY() macro.
H>
H>   - Add proper asserts to the SYSCTL_COUNTER_U64_ARRAY() macro that checks
H> the size of the first element of the array.
H>   - Add an example to the counter(9) manual page how to use the
H> SYSCTL_COUNTER_U64_ARRAY() macro.
H>   - Add some missing symbolic links for counter(9) while at it.

...

H> +.Sh EXAMPLES
H> +The following example creates a static counter array exported to
H> +userspace through a sysctl:
H> +.Bd -literal -offset indent
H> +#define MY_SIZE 8
H> +static counter_u64_t array[MY_SIZE];
H> +SYSCTL_COUNTER_U64_ARRAY(_debug, OID_AUTO, counter_array, CTLFLAG_RW,
H> +[0], MY_SIZE, "Test counter array");

I always wondered what is stylistically better: array or [0]? I
usually prefer the former.



A question: If you pass "array" why do you need a length argument in the 
SYSCTL macro. Can't you get the length of the array like 
sizeof(array)/sizeof((array)[0]) inside the macro?


--HPS
___
svn-src-head@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"


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

2016-03-19 Thread Gleb Smirnoff
On Thu, Mar 17, 2016 at 08:21:12AM +0100, Hans Petter Selasky wrote:
H> On 03/16/16 21:32, Gleb Smirnoff wrote:
H> > On Wed, Mar 16, 2016 at 08:37:52AM +, Hans Petter Selasky wrote:
H> > H> Author: hselasky
H> > H> Date: Wed Mar 16 08:37:52 2016
H> > H> New Revision: 296933
H> > H> URL: https://svnweb.freebsd.org/changeset/base/296933
H> > H>
H> > H> Log:
H> > H>   Improve the implementation and documentation of the
H> > H>   SYSCTL_COUNTER_U64_ARRAY() macro.
H> > H>
H> > H>   - Add proper asserts to the SYSCTL_COUNTER_U64_ARRAY() macro that 
checks
H> > H> the size of the first element of the array.
H> > H>   - Add an example to the counter(9) manual page how to use the
H> > H> SYSCTL_COUNTER_U64_ARRAY() macro.
H> > H>   - Add some missing symbolic links for counter(9) while at it.
H> >
H> > ...
H> >
H> > H> +.Sh EXAMPLES
H> > H> +The following example creates a static counter array exported to
H> > H> +userspace through a sysctl:
H> > H> +.Bd -literal -offset indent
H> > H> +#define MY_SIZE 8
H> > H> +static counter_u64_t array[MY_SIZE];
H> > H> +SYSCTL_COUNTER_U64_ARRAY(_debug, OID_AUTO, counter_array, CTLFLAG_RW,
H> > H> +[0], MY_SIZE, "Test counter array");
H> >
H> > I always wondered what is stylistically better: array or [0]? I
H> > usually prefer the former.
H> >
H> 
H> A question: If you pass "array" why do you need a length argument in the 
H> SYSCTL macro. Can't you get the length of the array like 
H> sizeof(array)/sizeof((array)[0]) inside the macro?

IMHO, that's a good idea for the static sysctl declaration. I can't imagine
a good case when size in array declaration and in the SYSCTL declaration
would differ.

-- 
Totus tuus, Glebius.
___
svn-src-head@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"


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

2016-03-19 Thread Gleb Smirnoff
On Thu, Mar 17, 2016 at 08:19:50AM +0100, Hans Petter Selasky wrote:
H> On 03/16/16 21:36, Gleb Smirnoff wrote:
H> > On Wed, Mar 16, 2016 at 08:37:52AM +, Hans Petter Selasky wrote:
H> > H> Modified: head/sys/sys/sysctl.h
H> > H> 
==
H> > H> --- head/sys/sys/sysctl.h   Wed Mar 16 06:42:15 2016
(r296932)
H> > H> +++ head/sys/sys/sysctl.h   Wed Mar 16 08:37:52 2016
(r296933)
H> > H> @@ -654,8 +654,10 @@ TAILQ_HEAD(sysctl_ctx_list, sysctl_ctx_e
H> > H> SYSCTL_OID(parent, nbr, name,   
\
H> > H> CTLTYPE_OPAQUE | CTLFLAG_MPSAFE | (access), 
\
H> > H> (ptr), (len), sysctl_handle_counter_u64_array, "S", descr); 
\
H> > H> -   CTASSERT(((access) & CTLTYPE) == 0 ||   
\
H> > H> -   ((access) & SYSCTL_CT_ASSERT_MASK) == CTLTYPE_OPAQUE)
H> > H> +   CTASSERTaccess) & CTLTYPE) == 0 ||  
\
H> > H> +   ((access) & SYSCTL_CT_ASSERT_MASK) == CTLTYPE_OPAQUE) &&
\
H> > H> +   sizeof(counter_u64_t) == sizeof(*(ptr)) &&  
\
H> > H> +   sizeof(uint64_t) == sizeof(**(ptr)))
H> >
H> > I don't agree with the last line. Does it assert that counter_u64_t is
H> > implemented using uint64_t? That is true, but that is internal detail,
H> > that might be changed in future.
H> >
H> 
H> Yes, it asserts that counter_u64_t is a 64-bit counter, as the name of 
H> the typedef hints at.
H> 
H>  From the past experience there has been several cases where someone has 
H> changed a field in structure which is exported as a sysctl, and then the 
H> sysctls were never updated.

It could be that counter_u64_t becomes a machine dependent typedef, being
different size on different machines. Unlikely, but possible.

-- 
Totus tuus, Glebius.
___
svn-src-head@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"


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

2016-03-18 Thread Gleb Smirnoff
On Wed, Mar 16, 2016 at 01:32:41PM -0700, Gleb Smirnoff wrote:
T> H> +.Sh EXAMPLES
T> H> +The following example creates a static counter array exported to
T> H> +userspace through a sysctl:
T> H> +.Bd -literal -offset indent
T> H> +#define MY_SIZE 8
T> H> +static counter_u64_t array[MY_SIZE];
T> H> +SYSCTL_COUNTER_U64_ARRAY(_debug, OID_AUTO, counter_array, CTLFLAG_RW,
T> H> +[0], MY_SIZE, "Test counter array");
T> 
T> I always wondered what is stylistically better: array or [0]? I
T> usually prefer the former.

And now your assertion forces to do the latter.

-- 
Totus tuus, Glebius.
___
svn-src-head@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"


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

2016-03-18 Thread Gleb Smirnoff
On Wed, Mar 16, 2016 at 08:37:52AM +, Hans Petter Selasky wrote:
H> Modified: head/sys/sys/sysctl.h
H> 
==
H> --- head/sys/sys/sysctl.hWed Mar 16 06:42:15 2016(r296932)
H> +++ head/sys/sys/sysctl.hWed Mar 16 08:37:52 2016(r296933)
H> @@ -654,8 +654,10 @@ TAILQ_HEAD(sysctl_ctx_list, sysctl_ctx_e
H>  SYSCTL_OID(parent, nbr, name,   \
H>  CTLTYPE_OPAQUE | CTLFLAG_MPSAFE | (access), \
H>  (ptr), (len), sysctl_handle_counter_u64_array, "S", descr); \
H> -CTASSERT(((access) & CTLTYPE) == 0 ||   \
H> -((access) & SYSCTL_CT_ASSERT_MASK) == CTLTYPE_OPAQUE)
H> +CTASSERTaccess) & CTLTYPE) == 0 ||  \
H> +((access) & SYSCTL_CT_ASSERT_MASK) == CTLTYPE_OPAQUE) &&\
H> +sizeof(counter_u64_t) == sizeof(*(ptr)) &&  \
H> +sizeof(uint64_t) == sizeof(**(ptr)))

I don't agree with the last line. Does it assert that counter_u64_t is
implemented using uint64_t? That is true, but that is internal detail,
that might be changed in future.

-- 
Totus tuus, Glebius.
___
svn-src-head@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"


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

2016-03-16 Thread Hans Petter Selasky
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/MakefileWed Mar 16 06:42:15 2016
(r296932)
+++ head/share/man/man9/MakefileWed 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,
+[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)
+   CTASSERTaccess) & CTLTYPE) == 0 ||  \
+   ((access) & SYSCTL_CT_ASSERT_MASK) == CTLTYPE_OPAQUE) &&\
+   sizeof(counter_u64_t) == sizeof(*(ptr)) &&  \
+   sizeof(uint64_t) == sizeof(**(ptr)))
 
 #defineSYSCTL_ADD_COUNTER_U64_ARRAY(ctx, parent, nbr, name, access,
\
 ptr, len, descr)   \
___
svn-src-head@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"