From 61117bfa1b08ca048e6512c0652c568300fedf6a Mon Sep 17 00:00:00 2001 From: Siddhesh Poyarekar Date: Fri, 5 Feb 2021 13:18:58 +0530 Subject: tunables: Simplify TUNABLE_SET interface The TUNABLE_SET interface took a primitive C type argument, which resulted in inconsistent type conversions internally due to incorrect dereferencing of types, especialy on 32-bit architectures. This change simplifies the TUNABLE setting logic along with the interfaces. Now all numeric tunable values are stored as signed numbers in tunable_num_t, which is intmax_t. All calls to set tunables cast the input value to its primitive type and then to tunable_num_t for storage. This relies on gcc-specific (although I suspect other compilers woul also do the same) unsigned to signed integer conversion semantics, i.e. the bit pattern is conserved. The reverse conversion is guaranteed by the standard. --- manual/README.tunables | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) (limited to 'manual') diff --git a/manual/README.tunables b/manual/README.tunables index d8c768a..605ddd7 100644 --- a/manual/README.tunables +++ b/manual/README.tunables @@ -98,17 +98,16 @@ where it can expect the tunable value to be passed in VALP. Tunables in the module can be updated using: - TUNABLE_SET (check, int32_t, val) + TUNABLE_SET (check, val) -where 'check' is the tunable name, 'int32_t' is the C type of the tunable and -'val' is a value of same type. +where 'check' is the tunable name and 'val' is a value of same type. To get and set tunables in a different namespace from that module, use the full form of the macros as follows: val = TUNABLE_GET_FULL (glibc, cpu, hwcap_mask, uint64_t, NULL) - TUNABLE_SET_FULL (glibc, cpu, hwcap_mask, uint64_t, val) + TUNABLE_SET_FULL (glibc, cpu, hwcap_mask, val) where 'glibc' is the top namespace, 'cpu' is the tunable namespace and the remaining arguments are the same as the short form macros. @@ -116,18 +115,17 @@ remaining arguments are the same as the short form macros. The minimum and maximum values can updated together with the tunable value using: - TUNABLE_SET_WITH_BOUNDS (check, int32_t, val, min, max) + TUNABLE_SET_WITH_BOUNDS (check, val, min, max) -where 'check' is the tunable name, 'int32_t' is the C type of the tunable, -'val' is a value of same type, 'min' and 'max' are the minimum and maximum -values of the tunable. +where 'check' is the tunable name, 'val' is a value of same type, 'min' and +'max' are the minimum and maximum values of the tunable. To set the minimum and maximum values of tunables in a different namespace from that module, use the full form of the macros as follows: val = TUNABLE_GET_FULL (glibc, cpu, hwcap_mask, uint64_t, NULL) - TUNABLE_SET_WITH_BOUNDS_FULL (glibc, cpu, hwcap_mask, uint64_t, val, min, max) + TUNABLE_SET_WITH_BOUNDS_FULL (glibc, cpu, hwcap_mask, val, min, max) where 'glibc' is the top namespace, 'cpu' is the tunable namespace and the remaining arguments are the same as the short form macros. -- cgit v1.1