]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
Determine number of workers if value is set to zero
authorArran Cudbard-Bell <a.cudbardb@freeradius.org>
Sat, 23 Sep 2023 04:02:31 +0000 (00:02 -0400)
committerArran Cudbard-Bell <a.cudbardb@freeradius.org>
Sat, 23 Sep 2023 04:02:39 +0000 (00:02 -0400)
src/lib/server/main_config.c

index 8fe1c685cddfee1daf9bb975a45129d407ee8d66..8e2deae6180c8c6fd79739fcfa39021e0bcde09e 100644 (file)
@@ -421,15 +421,47 @@ static int num_networks_parse(TALLOC_CTX *ctx, void *out, void *parent,
        return 0;
 }
 
+static inline CC_HINT(always_inline)
+uint32_t num_workers_auto(main_config_t *conf, CONF_ITEM *parent)
+{
+       uint32_t        value;
+
+       value = fr_hw_num_cores_active();
+       if (value == 0) {
+               cf_log_pwarn(parent, "Failed retrieving core count, defaulting to 1 worker");
+               value = 1;
+       }
+
+       /*
+        *      If we've got more than four times
+        *      the number of cores as we have
+        *      networks, then set the number of
+        *      workers to the number of cores
+        *      minus networks.
+        *
+        *      This ensures at a least a 4:1
+        *      ratio of workers to networks,
+        *      which seems like a sensible ratio.
+        */
+       else if (value > (conf->max_networks * 4)) {
+               value -= conf->max_networks;
+       }
+
+       return value;
+}
+
 static int num_workers_parse(TALLOC_CTX *ctx, void *out, void *parent, CONF_ITEM *ci, CONF_PARSER const *rule)
 {
        int             ret;
        uint32_t        value;
+       main_config_t   *conf = parent;
 
        if ((ret = cf_pair_parse_value(ctx, out, parent, ci, rule)) < 0) return ret;
 
        memcpy(&value, out, sizeof(value));
 
+       if (value == 0) value = num_workers_auto(conf, ci);
+
        /*
         *      If no value is specified, try and
         *      discover it automatically.
@@ -448,26 +480,7 @@ static int num_workers_dflt(CONF_PAIR **out, void *parent, CONF_SECTION *cs, fr_
        uint32_t        value;
        main_config_t   *conf = parent;
 
-       value = fr_hw_num_cores_active();
-       if (value == 0) {
-               cf_log_pwarn(parent, "Failed retrieving core count, defaulting to 1 worker");
-               value = 1;
-       }
-
-       /*
-        *      If we've got more than four times
-        *      the number of cores as we have
-        *      networks, then set the number of
-        *      workers to the number of cores
-        *      minus networks.
-        *
-        *      This ensures at a least a 4:1
-        *      ratio of workers to networks,
-        *      which seems like a sensible ratio.
-        */
-       else if (value > (conf->max_networks * 4)) {
-               value -= conf->max_networks;
-       }
+       value = num_workers_auto(conf, cf_section_to_item(cs));
        strvalue = talloc_asprintf(NULL, "%u", value);
        *out = cf_pair_alloc(cs, rule->name, strvalue, T_OP_EQ, T_BARE_WORD, quote);
        talloc_free(strvalue);