]> git.ipfire.org Git - thirdparty/glibc.git/blame - manual/README.tunables
<sys/platform/x86.h>: Add SGX-KEYS support
[thirdparty/glibc.git] / manual / README.tunables
CommitLineData
67e58f39
SP
1 TUNABLE FRAMEWORK
2 =================
3
4Tunables is a feature in the GNU C Library that allows application authors and
5distribution maintainers to alter the runtime library behaviour to match their
6workload.
7
8The tunable framework allows modules within glibc to register variables that
9may be tweaked through an environment variable. It aims to enforce a strict
10namespace rule to bring consistency to naming of these tunable environment
11variables across the project. This document is a guide for glibc developers to
12add tunables to the framework.
13
14ADDING A NEW TUNABLE
15--------------------
16
17The TOP_NAMESPACE macro is defined by default as 'glibc'. If distributions
18intend to add their own tunables, they should do so in a different top
19namespace by overriding the TOP_NAMESPACE macro for that tunable. Downstream
20implementations are discouraged from using the 'glibc' top namespace for
21tunables they don't already have consensus to push upstream.
22
44330b6d 23There are three steps to adding a tunable:
67e58f39 24
44330b6d 251. Add a tunable to the list and fully specify its properties:
67e58f39 26
44330b6d
SP
27For each tunable you want to add, make an entry in elf/dl-tunables.list. The
28format of the file is as follows:
67e58f39
SP
29
30TOP_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 }
44}
45
46The list of allowed attributes are:
47
48- type: Data type. Defaults to STRING. Allowed types are:
ad2f35cb
SP
49 INT_32, UINT_64, SIZE_T and STRING. Numeric types may
50 be in octal or hexadecimal format too.
67e58f39
SP
51
52- minval: Optional minimum acceptable value. For a string type
53 this is the minimum length of the value.
54
55- maxval: Optional maximum acceptable value. For a string type
56 this is the maximum length of the value.
57
d1310307
SP
58- default: Specify an optional default value for the tunable.
59
67e58f39
SP
60- env_alias: An alias environment variable
61
6c2b5799
SP
62- security_level: Specify security level of the tunable for AT_SECURE
63 binaries. Valid values are:
65eff7fb 64
6c2b5799
SP
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.
65eff7fb 69 NONE: Read all the time.
67e58f39 70
dfb8e514 712. Use TUNABLE_GET/TUNABLE_SET/TUNABLE_SET_WITH_BOUNDS to get and set tunables.
44330b6d
SP
72
733. 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.
76
77GETTING AND SETTING TUNABLES
78----------------------------
79
80When the TUNABLE_NAMESPACE macro is defined, one may get tunables in that
81module using the TUNABLE_GET macro as follows:
82
83 val = TUNABLE_GET (check, int32_t, TUNABLE_CALLBACK (check_callback))
84
85where '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
87non-default value. The macro returns the value as type 'int32_t'.
88
89The callback function should be defined as follows:
90
91 void
92 TUNABLE_CALLBACK (check_callback) (int32_t *valp)
93 {
94 ...
95 }
96
97where it can expect the tunable value to be passed in VALP.
98
99Tunables in the module can be updated using:
100
61117bfa 101 TUNABLE_SET (check, val)
44330b6d 102
61117bfa 103where 'check' is the tunable name and 'val' is a value of same type.
44330b6d
SP
104
105To get and set tunables in a different namespace from that module, use the full
106form of the macros as follows:
107
dce452dc 108 val = TUNABLE_GET_FULL (glibc, cpu, hwcap_mask, uint64_t, NULL)
44330b6d 109
61117bfa 110 TUNABLE_SET_FULL (glibc, cpu, hwcap_mask, val)
44330b6d 111
dce452dc 112where 'glibc' is the top namespace, 'cpu' is the tunable namespace and the
44330b6d
SP
113remaining arguments are the same as the short form macros.
114
dfb8e514
L
115The minimum and maximum values can updated together with the tunable value
116using:
117
61117bfa 118 TUNABLE_SET_WITH_BOUNDS (check, val, min, max)
dfb8e514 119
61117bfa
SP
120where 'check' is the tunable name, 'val' is a value of same type, 'min' and
121'max' are the minimum and maximum values of the tunable.
dfb8e514
L
122
123To set the minimum and maximum values of tunables in a different namespace
124from that module, use the full form of the macros as follows:
125
126 val = TUNABLE_GET_FULL (glibc, cpu, hwcap_mask, uint64_t, NULL)
127
61117bfa 128 TUNABLE_SET_WITH_BOUNDS_FULL (glibc, cpu, hwcap_mask, val, min, max)
dfb8e514
L
129
130where 'glibc' is the top namespace, 'cpu' is the tunable namespace and the
131remaining arguments are the same as the short form macros.
132
44330b6d
SP
133When TUNABLE_NAMESPACE is not defined in a module, TUNABLE_GET is equivalent to
134TUNABLE_GET_FULL, so you will need to provide full namespace information for
dfb8e514
L
135both macros. Likewise for TUNABLE_SET, TUNABLE_SET_FULL,
136TUNABLE_SET_WITH_BOUNDS and TUNABLE_SET_WITH_BOUNDS_FULL.
44330b6d
SP
137
138** IMPORTANT NOTE **
139
140The tunable list is set as read-only after the dynamic linker relocates itself,
141so setting tunable values must be limited only to tunables within the dynamic
142linker, that too before relocation.
67e58f39
SP
143
144FUTURE WORK
145-----------
146
147The framework currently only allows a one-time initialization of variables
148through environment variables and in some cases, modification of variables via
149an API call. A future goals for this project include:
150
151- Setting system-wide and user-wide defaults for tunables through some
152 mechanism like a configuration file.
153
154- Allow tweaking of some tunables at runtime