Date: Sat, 16 Oct 2010 16:07:59 -0700 From: Garrett Cooper <gcooper@FreeBSD.org> To: =?ISO-8859-1?Q?Dag=2DErling_Sm=F8rgrav?= <des@des.no> Cc: freebsd-hackers@freebsd.org, Ivan Voras <ivoras@freebsd.org> Subject: Re: Why is TUNABLE_INT discouraged? Message-ID: <AANLkTim1E94qWq1TF1111-sYo2dj35Y-XnPq3DT4kpoL@mail.gmail.com> In-Reply-To: <8662zg586z.fsf@ds4.des.no> References: <AANLkTinKaiGFhKRgqQ%2BFjm=02VfWCxULe0a68y-PkJx6@mail.gmail.com> <86fwyq8rsc.fsf@ds4.des.no> <i3kbis$73l$1@dough.gmane.org> <86d3tujh72.fsf@ds4.des.no> <AANLkTi=puD%2B-WeZ%2BFGdtZtw1v%2BNnGD_htwNa%2BEn9fcML@mail.gmail.com> <864of680wv.fsf@ds4.des.no> <AANLkTinraF50O%2Bcp_h1m6TODnoz_7R3WXfjTanh-86mn@mail.gmail.com> <AANLkTikU6fLzWL-n6fCtvaTsXWGis7ydKM1qJaV=WRJ%2B@mail.gmail.com> <8662zkurx9.fsf@ds4.des.no> <AANLkTimbkTQiNgYCYFnTXMpRe9koJGrq1%2BYoq5-fVmFD@mail.gmail.com> <8662zg586z.fsf@ds4.des.no>
index | next in thread | previous in thread | raw e-mail
[-- Attachment #1 --]
2010/8/12 Dag-Erling Smørgrav <des@des.no>:
> Garrett Cooper <gcooper@FreeBSD.org> writes:
>> Dag-Erling Smørgrav <des@des.no> writes:
>> > It might be a good idea to introduce TUNABLE_POINTER and TUNABLE_SIZE.
>> I would actually argue against doing that because it would only create
>> divergence between sysctl and tunable KPIs...
>
> Not if we also introduce corresponding SYSCTLs. Note that my idea is to
> have these as aliases for the correct primitive types.
>
>> (BTW, when you say TUNABLE_SIZE, I assume it would be a size_t quantity?)
>
> Yes.
>
>> Something might need to be done to the values returned by the tunables
>> though, because they don't respect boundaries, and can overflow right
>> now (which exacerbates the issue with values crammed into smaller
>> datatypes)...
>
> Yes. How about this:
>
> - rename getenv_quad() to getenv_signed() and getenv_unsigned()
> - add min / max arguments
> - implement getenv_quad() (and all the others) in terms of
> getenv_number()
>
> e.g.
>
> int
> getenv_uint(const char *name, unsigned int *data)
> {
> unsigned long long tmp;
> int rval;
>
> if ((rval = getenv_unsigned(name, &tmp, 0, UINT_MAX)) == 0)
> *data = (unsigned int)tmp;
> return (rval);
> }
>
> (note that due to the min / max arguments, the complexity of handling
> both signed and unsigned values in the same function probably exceeds
> the complexity of having two very similar functions)
Here's a draft of this work des@ challenged me to a while back. It
works well as demonstrated with my tests. The only catch with
detecting bounds is that if it's the minimum in the case of signed or
maximum representable value in the case of unsigned, then strtoq, etc
will clamp the value to the maximum representable value.
Other than that it works well, and now tunables represented by
unsigned values should work better.
Please let me know what you all think.
Thanks!
-Garrett
PS I added uquad_t for consistency in the APIs, even though quad_t was
deprecated, but I didn't bump __FreeBSD_version__ -- wasn't sure if I
should have done that).
[-- Attachment #2 --]
# Console output
# for i in */; do (cd $i && sh test*.sh 2>/dev/null); done
test_int_tunable.tunable="-1"
test_int_tunable.tunable="0"
test_int_tunable.tunable="42"
test_int_tunable.tunable="asdf1234"
test_int_tunable.tunable="-2147483647"
test_int_tunable.tunable="-2147483649"
test_int_tunable.tunable="2147483646"
test_int_tunable.tunable="2147483648"
test_long_tunable.tunable="0"
test_long_tunable.tunable="42"
test_long_tunable.tunable="asdf1234"
test_long_tunable.tunable="-9223372036854775809"
test_long_tunable.tunable="-9223372036854775807"
test_long_tunable.tunable="9223372036854775806"
test_long_tunable.tunable="9223372036854775808"
test_pointer_tunable.tunable="-1"
test_pointer_tunable.tunable="0"
test_pointer_tunable.tunable="42"
test_pointer_tunable.tunable="3735928559"
test_pointer_tunable.tunable="asdf1234"
test_pointer_tunable.tunable="8580481023"
test_pointer_tunable.tunable="8580481025"
test_quad_tunable.tunable="0"
test_quad_tunable.tunable="42"
test_quad_tunable.tunable="asdf1234"
test_quad_tunable.tunable="-9223372036854775809"
test_quad_tunable.tunable="-9223372036854775807"
test_quad_tunable.tunable="9223372036854775806"
test_quad_tunable.tunable="9223372036854775808"
test_size_tunable.tunable="-1"
test_size_tunable.tunable="0"
test_size_tunable.tunable="42"
test_size_tunable.tunable="asdf1234"
test_size_tunable.tunable="9223372036854775808"
test_size_tunable.tunable="18446744073709551614"
test_size_tunable.tunable="18446744073709551616"
test_string_tunable.tunable=""
test_string_tunable.tunable="asdf1234"
test_string_tunable.tunable="character"
test_string_tunable.tunable="asortoflongishstring"
test_tunable_suffixes.tunable="-1"
test_tunable_suffixes.tunable="-1g"
test_tunable_suffixes.tunable="-1G"
test_tunable_suffixes.tunable="-1k"
test_tunable_suffixes.tunable="-1K"
test_tunable_suffixes.tunable="-1m"
test_tunable_suffixes.tunable="-1M"
test_tunable_suffixes.tunable="-1t"
test_tunable_suffixes.tunable="-1T"
test_tunable_suffixes.tunable="-1z"
test_tunable_suffixes.tunable="-1Z"
test_tunable_suffixes.tunable="0"
test_tunable_suffixes.tunable="0g"
test_tunable_suffixes.tunable="0G"
test_tunable_suffixes.tunable="0k"
test_tunable_suffixes.tunable="0K"
test_tunable_suffixes.tunable="0m"
test_tunable_suffixes.tunable="0M"
test_tunable_suffixes.tunable="0t"
test_tunable_suffixes.tunable="0T"
test_tunable_suffixes.tunable="0z"
test_tunable_suffixes.tunable="0Z"
test_tunable_suffixes.tunable="1"
test_tunable_suffixes.tunable="1g"
test_tunable_suffixes.tunable="1G"
test_tunable_suffixes.tunable="1k"
test_tunable_suffixes.tunable="1K"
test_tunable_suffixes.tunable="1m"
test_tunable_suffixes.tunable="1M"
test_tunable_suffixes.tunable="1t"
test_tunable_suffixes.tunable="1T"
test_tunable_suffixes.tunable="1z"
test_tunable_suffixes.tunable="1Z"
test_uint_tunable.tunable="-1"
test_uint_tunable.tunable="0"
test_uint_tunable.tunable="42"
test_uint_tunable.tunable="asdf1234"
test_uint_tunable.tunable="2147483648"
test_uint_tunable.tunable="4294967294"
test_uint_tunable.tunable="4294967296"
test_ulong_tunable.tunable="-1"
test_ulong_tunable.tunable="0"
test_ulong_tunable.tunable="42"
test_ulong_tunable.tunable="asdf1234"
test_ulong_tunable.tunable="9223372036854775808"
test_ulong_tunable.tunable="18446744073709551614"
test_ulong_tunable.tunable="18446744073709551616"
test_uquad_tunable.tunable="-1"
test_uquad_tunable.tunable="0"
test_uquad_tunable.tunable="42"
test_uquad_tunable.tunable="asdf1234"
test_uquad_tunable.tunable="9223372036854775808"
test_uquad_tunable.tunable="18446744073709551614"
test_uquad_tunable.tunable="18446744073709551616"
# Dmesg output
test_int_tunable: 0
test_int_tunable: -1
test_int_tunable: 0
test_int_tunable: 42
test_int_tunable: 0
test_int_tunable: -2147483647
test_int_tunable: 0
test_int_tunable: 2147483646
test_int_tunable: 0
test_long_tunable: 0
test_long_tunable: 0
test_long_tunable: 42
test_long_tunable: 0
test_long_tunable: -9223372036854775808
test_long_tunable: -9223372036854775807
test_long_tunable: 9223372036854775806
test_long_tunable: 9223372036854775807
test_pointer_tunable: ffffffffffffffff
test_pointer_tunable: 0
test_pointer_tunable: 2a
test_pointer_tunable: deadbeef
test_pointer_tunable: 0
test_pointer_tunable: 1ff6fbfff
test_pointer_tunable: 1ff6fc001
test_quad_tunable: 0
test_quad_tunable: 0
test_quad_tunable: 42
test_quad_tunable: 0
test_quad_tunable: -9223372036854775808
test_quad_tunable: -9223372036854775807
test_quad_tunable: 9223372036854775806
test_quad_tunable: 9223372036854775807
test_size_tunable: 0
test_size_tunable: 18446744073709551615
test_size_tunable: 0
test_size_tunable: 42
test_size_tunable: 0
test_size_tunable: 9223372036854775808
test_size_tunable: 18446744073709551614
test_size_tunable: 18446744073709551615
test_string_tunable:
test_string_tunable:
test_string_tunable: asdf1234
test_string_tunable: character
test_string_tunable: asortoflo
test_tunable_suffixes: 0
test_tunable_suffixes: -1
test_tunable_suffixes: -1073741824
test_tunable_suffixes: -1073741824
test_tunable_suffixes: -1024
test_tunable_suffixes: -1024
test_tunable_suffixes: -1048576
test_tunable_suffixes: -1048576
test_tunable_suffixes: -1099511627776
test_tunable_suffixes: -1099511627776
test_tunable_suffixes: 0
test_tunable_suffixes: 0
test_tunable_suffixes: 0
test_tunable_suffixes: 0
test_tunable_suffixes: 0
test_tunable_suffixes: 0
test_tunable_suffixes: 0
test_tunable_suffixes: 0
test_tunable_suffixes: 0
test_tunable_suffixes: 0
test_tunable_suffixes: 0
test_tunable_suffixes: 0
test_tunable_suffixes: 0
test_tunable_suffixes: 1
test_tunable_suffixes: 1073741824
test_tunable_suffixes: 1073741824
test_tunable_suffixes: 1024
test_tunable_suffixes: 1024
test_tunable_suffixes: 1048576
test_tunable_suffixes: 1048576
test_tunable_suffixes: 1099511627776
test_tunable_suffixes: 1099511627776
test_tunable_suffixes: 0
test_tunable_suffixes: 0
test_uint_tunable: 0
test_uint_tunable: 0
test_uint_tunable: 0
test_uint_tunable: 42
test_uint_tunable: 0
test_uint_tunable: 2147483648
test_uint_tunable: 4294967294
test_uint_tunable: 0
test_ulong_tunable: 0
test_ulong_tunable: 18446744073709551615
test_ulong_tunable: 0
test_ulong_tunable: 42
test_ulong_tunable: 0
test_ulong_tunable: 9223372036854775808
test_ulong_tunable: 18446744073709551614
test_ulong_tunable: 18446744073709551615
test_uquad_tunable: 0
test_uquad_tunable: 18446744073709551615
test_uquad_tunable: 0
test_uquad_tunable: 42
test_uquad_tunable: 0
test_uquad_tunable: 9223372036854775808
test_uquad_tunable: 18446744073709551614
test_uquad_tunable: 18446744073709551615
help
Want to link to this message? Use this
URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?AANLkTim1E94qWq1TF1111-sYo2dj35Y-XnPq3DT4kpoL>
