argp: fix pointer-subtraction bug
[glibc.git] / manual / README.tunables
blobd8c768abcc70b5a4968d45298ccf0e99cd02c357
1                         TUNABLE FRAMEWORK
2                         =================
4 Tunables is a feature in the GNU C Library that allows application authors and
5 distribution maintainers to alter the runtime library behaviour to match their
6 workload.
8 The tunable framework allows modules within glibc to register variables that
9 may be tweaked through an environment variable.  It aims to enforce a strict
10 namespace rule to bring consistency to naming of these tunable environment
11 variables across the project.  This document is a guide for glibc developers to
12 add tunables to the framework.
14 ADDING A NEW TUNABLE
15 --------------------
17 The TOP_NAMESPACE macro is defined by default as 'glibc'.  If distributions
18 intend to add their own tunables, they should do so in a different top
19 namespace by overriding the TOP_NAMESPACE macro for that tunable.  Downstream
20 implementations are discouraged from using the 'glibc' top namespace for
21 tunables they don't already have consensus to push upstream.
23 There are three steps to adding a tunable:
25 1. Add a tunable to the list and fully specify its properties:
27 For each tunable you want to add, make an entry in elf/dl-tunables.list.  The
28 format of the file is as follows:
30 TOP_NAMESPACE {
31   NAMESPACE1 {
32     TUNABLE1 {
33       # tunable attributes, one per line
34     }
35     # A tunable with default attributes, i.e. string variable.
36     TUNABLE2
37     TUNABLE3 {
38       # its attributes
39     }
40   }
41   NAMESPACE2 {
42     ...
43   }
46 The list of allowed attributes are:
48 - type:                 Data type.  Defaults to STRING.  Allowed types are:
49                         INT_32, UINT_64, SIZE_T and STRING.  Numeric types may
50                         be in octal or hexadecimal format too.
52 - minval:               Optional minimum acceptable value.  For a string type
53                         this is the minimum length of the value.
55 - maxval:               Optional maximum acceptable value.  For a string type
56                         this is the maximum length of the value.
58 - default:              Specify an optional default value for the tunable.
60 - env_alias:            An alias environment variable
62 - security_level:       Specify security level of the tunable for AT_SECURE
63                         binaries.  Valid values are:
65                         SXID_ERASE: (default) Do not read and do not pass on to
66                         child processes.
67                         SXID_IGNORE: Do not read, but retain for non-AT_SECURE
68                         child processes.
69                         NONE: Read all the time.
71 2. Use TUNABLE_GET/TUNABLE_SET/TUNABLE_SET_WITH_BOUNDS to get and set tunables.
73 3. OPTIONAL: If tunables in a namespace are being used multiple times within a
74    specific module, set the TUNABLE_NAMESPACE macro to reduce the amount of
75    typing.
77 GETTING AND SETTING TUNABLES
78 ----------------------------
80 When the TUNABLE_NAMESPACE macro is defined, one may get tunables in that
81 module using the TUNABLE_GET macro as follows:
83   val = TUNABLE_GET (check, int32_t, TUNABLE_CALLBACK (check_callback))
85 where 'check' is the tunable name, 'int32_t' is the C type of the tunable and
86 'check_callback' is the function to call if the tunable got initialized to a
87 non-default value.  The macro returns the value as type 'int32_t'.
89 The callback function should be defined as follows:
91   void
92   TUNABLE_CALLBACK (check_callback) (int32_t *valp)
93   {
94   ...
95   }
97 where it can expect the tunable value to be passed in VALP.
99 Tunables in the module can be updated using:
101   TUNABLE_SET (check, int32_t, val)
103 where 'check' is the tunable name, 'int32_t' is the C type of the tunable and
104 'val' is a value of same type.
106 To get and set tunables in a different namespace from that module, use the full
107 form of the macros as follows:
109   val = TUNABLE_GET_FULL (glibc, cpu, hwcap_mask, uint64_t, NULL)
111   TUNABLE_SET_FULL (glibc, cpu, hwcap_mask, uint64_t, val)
113 where 'glibc' is the top namespace, 'cpu' is the tunable namespace and the
114 remaining arguments are the same as the short form macros.
116 The minimum and maximum values can updated together with the tunable value
117 using:
119   TUNABLE_SET_WITH_BOUNDS (check, int32_t, val, min, max)
121 where 'check' is the tunable name, 'int32_t' is the C type of the tunable,
122 'val' is a value of same type, 'min' and 'max' are the minimum and maximum
123 values of the tunable.
125 To set the minimum and maximum values of tunables in a different namespace
126 from that module, use the full form of the macros as follows:
128   val = TUNABLE_GET_FULL (glibc, cpu, hwcap_mask, uint64_t, NULL)
130   TUNABLE_SET_WITH_BOUNDS_FULL (glibc, cpu, hwcap_mask, uint64_t, val, min, max)
132 where 'glibc' is the top namespace, 'cpu' is the tunable namespace and the
133 remaining arguments are the same as the short form macros.
135 When TUNABLE_NAMESPACE is not defined in a module, TUNABLE_GET is equivalent to
136 TUNABLE_GET_FULL, so you will need to provide full namespace information for
137 both macros.  Likewise for TUNABLE_SET, TUNABLE_SET_FULL,
138 TUNABLE_SET_WITH_BOUNDS and TUNABLE_SET_WITH_BOUNDS_FULL.
140 ** IMPORTANT NOTE **
142 The tunable list is set as read-only after the dynamic linker relocates itself,
143 so setting tunable values must be limited only to tunables within the dynamic
144 linker, that too before relocation.
146 FUTURE WORK
147 -----------
149 The framework currently only allows a one-time initialization of variables
150 through environment variables and in some cases, modification of variables via
151 an API call.  A future goals for this project include:
153 - Setting system-wide and user-wide defaults for tunables through some
154   mechanism like a configuration file.
156 - Allow tweaking of some tunables at runtime