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.
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);