#include "qos.h"
+#include <logcommon.h>
+
#include <assert.h>
#include <stdlib.h>
return lhs->count - rhs->count;
}
-void qos_distribution_proportional_raw(struct qos_module *qos, struct metrics_pid_aggr_info *infos, int count)
+static void qos_distribution_proportional_raw(struct qos_module *qos, struct metrics_pid_aggr_info *infos, int count)
{
const double proportion = (double) qos->max_throughput / (metrics_get_total(qos->log_metrics) ?: 1);
infos[i].count = (int) (infos[i].count * proportion + 0.5);
}
-void qos_distribution_equal(struct qos_module *qos, struct metrics_pid_aggr_info *infos, int count)
+static void qos_distribution_equal(struct qos_module *qos, struct metrics_pid_aggr_info *infos, int count)
{
/* round upwards so that it's never 0, to give all clients a chance
* to log at least something (so a developer can tell it's alive) */
}
-void qos_distribution_equal_dual(struct qos_module *qos, struct metrics_pid_aggr_info *infos, int count)
+static void qos_distribution_equal_dual(struct qos_module *qos, struct metrics_pid_aggr_info *infos, int count)
{
/* Anything below the "equal" threshold is unlimited.
* The ones above this limit get leftovers distributed
infos[i].count = -1;
}
-void qos_distribution_equal_multi(struct qos_module *qos, struct metrics_pid_aggr_info *infos, int count)
+static void qos_distribution_equal_multi(struct qos_module *qos, struct metrics_pid_aggr_info *infos, int count)
{
/* Similar to 'dual', except anything not reaching the higher
* threshold also gets an unlimited pass (which increases the
infos[i].count = -1;
}
-void qos_distribution_proportional_talmud(struct qos_module *qos, struct metrics_pid_aggr_info *infos, int count)
+static void qos_distribution_proportional_talmud(struct qos_module *qos, struct metrics_pid_aggr_info *infos, int count)
{
/* As proscribed by the talmudic contested garment rule.
* Probably makes little sense given how our QoS works but
infos[i].count = upper_half ? infos[i].count - final_level : final_level;
}
+qos_distribution_func qos_get_distribution_func_by_name(const char *name)
+{
+ if (!name)
+ return qos_distribution_equal_multi;
+
+ static struct {
+ void (*func)(struct qos_module *qos, struct metrics_pid_aggr_info *infos, int count);
+ const char *name;
+ } qos_methods[] = {
+ { qos_distribution_proportional_raw , "proportional_raw" },
+ { qos_distribution_proportional_talmud, "proportional_talmud" },
+ { qos_distribution_equal , "equal" },
+ { qos_distribution_equal_dual , "equal_dual" },
+ { qos_distribution_equal_multi , "equal_multi" },
+ };
+
+ for (int i = 0; i < NELEMS(qos_methods); ++i)
+ if (!strcmp(name, qos_methods[i].name))
+ return qos_methods[i].func;
+
+ return qos_distribution_equal_multi;
+}
+