]>
Commit | Line | Data |
---|---|---|
67e58f39 SP |
1 | TUNABLE FRAMEWORK |
2 | ================= | |
3 | ||
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. | |
7 | ||
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. | |
13 | ||
14 | ADDING A NEW TUNABLE | |
15 | -------------------- | |
16 | ||
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. | |
22 | ||
44330b6d | 23 | There are three steps to adding a tunable: |
67e58f39 | 24 | |
44330b6d | 25 | 1. Add a tunable to the list and fully specify its properties: |
67e58f39 | 26 | |
44330b6d SP |
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: | |
67e58f39 SP |
29 | |
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 | } | |
44 | } | |
45 | ||
46 | The 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 | ||
65eff7fb SL |
62 | - security_level: Specify security level of the tunable. Valid values: |
63 | ||
64 | SXID_ERASE: (default) Don't read for AT_SECURE binaries and | |
65 | removed so that child processes can't read it. | |
66 | SXID_IGNORE: Don't read for AT_SECURE binaries, but retained for | |
67 | non-AT_SECURE subprocesses. | |
68 | NONE: Read all the time. | |
67e58f39 | 69 | |
44330b6d SP |
70 | 2. Use TUNABLE_GET/TUNABLE_SET to get and set tunables. |
71 | ||
72 | 3. OPTIONAL: If tunables in a namespace are being used multiple times within a | |
73 | specific module, set the TUNABLE_NAMESPACE macro to reduce the amount of | |
74 | typing. | |
75 | ||
76 | GETTING AND SETTING TUNABLES | |
77 | ---------------------------- | |
78 | ||
79 | When the TUNABLE_NAMESPACE macro is defined, one may get tunables in that | |
80 | module using the TUNABLE_GET macro as follows: | |
81 | ||
82 | val = TUNABLE_GET (check, int32_t, TUNABLE_CALLBACK (check_callback)) | |
83 | ||
84 | where 'check' is the tunable name, 'int32_t' is the C type of the tunable and | |
85 | 'check_callback' is the function to call if the tunable got initialized to a | |
86 | non-default value. The macro returns the value as type 'int32_t'. | |
87 | ||
88 | The callback function should be defined as follows: | |
89 | ||
90 | void | |
91 | TUNABLE_CALLBACK (check_callback) (int32_t *valp) | |
92 | { | |
93 | ... | |
94 | } | |
95 | ||
96 | where it can expect the tunable value to be passed in VALP. | |
97 | ||
98 | Tunables in the module can be updated using: | |
99 | ||
100 | TUNABLE_SET (check, int32_t, val) | |
101 | ||
102 | where 'check' is the tunable name, 'int32_t' is the C type of the tunable and | |
103 | 'val' is a value of same type. | |
104 | ||
105 | To get and set tunables in a different namespace from that module, use the full | |
106 | form of the macros as follows: | |
107 | ||
108 | val = TUNABLE_GET_FULL (glibc, tune, hwcap_mask, uint64_t, NULL) | |
109 | ||
110 | TUNABLE_SET_FULL (glibc, tune, hwcap_mask, uint64_t, val) | |
111 | ||
112 | where 'glibc' is the top namespace, 'tune' is the tunable namespace and the | |
113 | remaining arguments are the same as the short form macros. | |
114 | ||
115 | When TUNABLE_NAMESPACE is not defined in a module, TUNABLE_GET is equivalent to | |
116 | TUNABLE_GET_FULL, so you will need to provide full namespace information for | |
117 | both macros. Likewise for TUNABLE_SET and TUNABLE_SET_FULL. | |
118 | ||
119 | ** IMPORTANT NOTE ** | |
120 | ||
121 | The tunable list is set as read-only after the dynamic linker relocates itself, | |
122 | so setting tunable values must be limited only to tunables within the dynamic | |
123 | linker, that too before relocation. | |
67e58f39 SP |
124 | |
125 | FUTURE WORK | |
126 | ----------- | |
127 | ||
128 | The framework currently only allows a one-time initialization of variables | |
129 | through environment variables and in some cases, modification of variables via | |
130 | an API call. A future goals for this project include: | |
131 | ||
132 | - Setting system-wide and user-wide defaults for tunables through some | |
133 | mechanism like a configuration file. | |
134 | ||
135 | - Allow tweaking of some tunables at runtime |