@@ -148,6 +148,28 @@ tunable_parse_num (const char *strval, size_t len, tunable_num_t *val)
return true;
}
+/* Set *VAL to the position of the name STRVAL of length LEN in NAMES, as
+ returned by tunable_value_names. */
+static bool
+tunable_parse_name (const char *names, const char *strval, size_t len,
+ tunable_num_t *val)
+{
+ for (tunable_num_t i = 0; *names != '\0'; i++)
+ {
+ size_t j = 0;
+ while (j < len && names[j] == strval[j])
+ j++;
+ if (j == len && names[j] == '\0')
+ {
+ *val = i;
+ return true;
+ }
+ while (*names++ != '\0')
+ ;
+ }
+ return false;
+}
+
/* Validate range of the input value and initialize the tunable CUR if it looks
good. */
static bool
@@ -157,7 +179,13 @@ tunable_initialize (tunable_t *cur, const char *strval, size_t len)
if (cur->type.type_code != TUNABLE_TYPE_STRING)
{
- if (!tunable_parse_num (strval, len, &val.numval))
+ const char *names = tunable_value_names (cur - tunable_list);
+ if (names != NULL)
+ {
+ if (!tunable_parse_name (names, strval, len, &val.numval))
+ return false;
+ }
+ else if (!tunable_parse_num (strval, len, &val.numval))
return false;
}
else
@@ -456,7 +484,10 @@ __tunables_init (char **envp, char **argv)
else
{
tunable_val_t tval;
- if (tec->flags & TUNCONF_FLAG_PARSED)
+ /* ldconfig parses numbers, which a tunable with named values
+ does not accept. */
+ if ((tec->flags & TUNCONF_FLAG_PARSED)
+ && tunable_value_names (tid) == NULL)
{
tval.numval = tec->parsed_value;
do_tunable_update_val (& tunable_list[tid],
@@ -539,6 +570,23 @@ __tunables_init (char **envp, char **argv)
}
}
+/* Print the name of the value VAL of a tunable with the named values NAMES,
+ or VAL itself if it has no name, followed by all the names. */
+static void
+tunable_print_names (const char *names, tunable_num_t val)
+{
+ const char *name = names;
+ for (tunable_num_t i = 0; i < val && *name != '\0'; i++)
+ name += strlen (name) + 1;
+ if (*name != '\0')
+ _dl_printf ("%s (values:", name);
+ else
+ _dl_printf ("%d (values:", (int) val);
+ for (const char *p = names; *p != '\0'; p += strlen (p) + 1)
+ _dl_printf ("%s %s", p == names ? "" : ",", p);
+ _dl_printf (")\n");
+}
+
void
__tunables_print (void)
{
@@ -554,10 +602,14 @@ __tunables_print (void)
switch (cur->type.type_code)
{
case TUNABLE_TYPE_INT_32:
- _dl_printf ("%d (min: %d, max: %d)\n",
- (int) cur->val.numval,
- (int) cur->type.min,
- (int) cur->type.max);
+ if (tunable_value_names (i) != NULL)
+ tunable_print_names (tunable_value_names (i),
+ cur->val.numval);
+ else
+ _dl_printf ("%d (min: %d, max: %d)\n",
+ (int) cur->val.numval,
+ (int) cur->type.min,
+ (int) cur->type.max);
break;
case TUNABLE_TYPE_UINT_64:
_dl_printf ("0x%lx (min: 0x%lx, max: 0x%lx)\n",
@@ -45,6 +45,17 @@ typedef void (*tunable_callback_t) (tunable_val_t *);
#define TUNABLE_ENUM_NAME(__top,__ns,__id) TUNABLE_ENUM_NAME1 (__top,__ns,__id)
#define TUNABLE_ENUM_NAME1(__top,__ns,__id) __top ## _ ## __ns ## _ ## __id
+/* The enum type of a tunable with named values (see the values attribute in
+ dl-tunables.list), and the constant for its value VALUE. */
+#define TUNABLE_VALUE_TYPE(__top,__ns,__id) \
+ TUNABLE_VALUE_TYPE1 (__top,__ns,__id)
+#define TUNABLE_VALUE_TYPE1(__top,__ns,__id) \
+ enum __top ## _ ## __ns ## _ ## __id ## _value
+#define TUNABLE_VALUE(__top,__ns,__id,__value) \
+ TUNABLE_VALUE1 (__top,__ns,__id,__value)
+#define TUNABLE_VALUE1(__top,__ns,__id,__value) \
+ __top ## _ ## __ns ## _ ## __id ## _value_ ## __value
+
#include "dl-tunable-list.h"
extern void __tunables_init (char **, char **);
@@ -21,6 +21,10 @@
# minval: Optional minimum acceptable value
# maxval: Optional maximum acceptable value
# default: Optional default value (if not specified it will be 0 or "")
+# values: Optional names, separated by spaces, of the values 0 to maxval of
+# an INT_32 tunable with minval 0, which then only accepts the names.
+# The values are the constants TUNABLE_VALUE (top, ns, id, name) of
+# the enum type TUNABLE_VALUE_TYPE (top, ns, id).
# env_alias: An alias environment variable
glibc {
@@ -61,6 +61,29 @@ $1 == "}" {
if (!env_alias[top_ns,ns,tunable]) {
env_alias[top_ns,ns,tunable] = "{0}"
}
+ if (values[top_ns,ns,tunable] != "") {
+ nvalues = split(values[top_ns,ns,tunable], vnames, " ")
+ if (types[top_ns,ns,tunable] != "INT_32" \
+ || minvals[top_ns,ns,tunable] != 0 \
+ || maxvals[top_ns,ns,tunable] != nvalues - 1) {
+ printf ("%s:%d: values needs type INT_32, minval 0 and maxval %d\n",
+ FILENAME, FNR, nvalues - 1)
+ exit 1
+ }
+ for (i = 1; i <= nvalues; i++) {
+ if (vnames[i] !~ /^[a-z_][a-z0-9_]*$/) {
+ printf ("%s:%d: invalid value name: %s\n", FILENAME, FNR, vnames[i])
+ exit 1
+ }
+ }
+ # The default is not range checked at run time.
+ def = defaults[top_ns,ns,tunable]
+ if (def != "" && (def !~ /^[0-9]+$/ || def + 0 > nvalues - 1)) {
+ printf ("%s:%d: default needs to be between 0 and %d\n",
+ FILENAME, FNR, nvalues - 1)
+ exit 1
+ }
+ }
len = length(top_ns"."ns"."tunable)
if (len > max_name_len)
max_name_len = len
@@ -109,6 +132,9 @@ $1 == "}" {
else if (attr == "maxval") {
maxvals[top_ns,ns,tunable] = val
}
+ else if (attr == "values") {
+ values[top_ns,ns,tunable] = val
+ }
else if (attr == "env_alias") {
env_alias[top_ns,ns,tunable] = sprintf("\"%s\"", val)
len = length(val)
@@ -116,6 +142,7 @@ $1 == "}" {
max_alias_len = len
}
else if (attr == "default") {
+ defaults[top_ns,ns,tunable] = val
if (types[top_ns,ns,tunable] == "STRING") {
default_val[top_ns,ns,tunable] = sprintf(".strval = \"%s\"", val);
}
@@ -155,6 +182,23 @@ END {
}
print "} tunable_id_t;\n"
+ # The enum types of the tunables with named values.
+ for (i = 1; i <= typecount; i++) {
+ tnm = typesa[i];
+ split (tnm, indices, SUBSEP);
+ t = indices[1];
+ n = indices[2];
+ m = indices[3];
+ if (values[t,n,m] != "") {
+ nvalues = split (values[t,n,m], vnames, " ");
+ printf ("/* The values of %s.%s.%s. */\n", t, n, m);
+ printf ("TUNABLE_VALUE_TYPE(%s, %s, %s)\n{\n", t, n, m);
+ for (j = 1; j <= nvalues; j++)
+ printf (" TUNABLE_VALUE(%s, %s, %s, %s),\n", t, n, m, vnames[j]);
+ print "};\n"
+ }
+ }
+
print "\n#ifdef TUNABLES_INTERNAL"
# Internal definitions.
print "# define TUNABLE_NAME_MAX " (max_name_len + 1)
@@ -189,5 +233,31 @@ END {
}
}
printf "};\n"
+
+ # The names of the values of the tunables that have them.
+ print "\nstatic inline const char *"
+ print "tunable_value_names (tunable_id_t id)"
+ print "{"
+ print " switch (id)"
+ print " {"
+ for (i = 1; i <= typecount; i++) {
+ tnm = typesa[i];
+ split (tnm, indices, SUBSEP);
+ t = indices[1];
+ n = indices[2];
+ m = indices[3];
+ if (values[t,n,m] != "") {
+ nvalues = split (values[t,n,m], vnames, " ");
+ str = ""
+ for (j = 1; j <= nvalues; j++)
+ str = str vnames[j] "\\0"
+ printf (" case TUNABLE_ENUM_NAME(%s, %s, %s):\n", t, n, m);
+ printf (" return \"%s\";\n", str);
+ }
+ }
+ print " default:"
+ print " return NULL;"
+ print " }"
+ print "}"
print "#endif"
}