README.tunables 4.5 KB

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