Introduce a minor math helper 14/240814/2
authorMichal Bloch <m.bloch@samsung.com>
Tue, 11 Aug 2020 14:44:10 +0000 (16:44 +0200)
committerMichal Bloch <m.bloch@samsung.com>
Wed, 12 Aug 2020 12:51:35 +0000 (14:51 +0200)
Change-Id: Ie4da8c6a962314a11e8ace65cde8f99105f9524a
Signed-off-by: Michal Bloch <m.bloch@samsung.com>
src/logger/qos.c

index 6eb7331..c0949c7 100644 (file)
 
 void (*qos_distribution_func)(struct qos_module *qos, struct metrics_pid_aggr_info *infos, int count);
 
+static inline int divide_rounding_upwards(int dividend, int divisor)
+{
+       return (dividend + (divisor - 1)) / (divisor ?: 1);
+}
+
 void qos_distribution_proportional(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);
@@ -28,7 +33,7 @@ void qos_distribution_equal(struct qos_module *qos, struct metrics_pid_aggr_info
 {
        /* 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) */
-       const int equal_limit_for_everybody = (qos->max_throughput + (count - 1)) / count;
+       const int equal_limit_for_everybody = divide_rounding_upwards(qos->max_throughput, count);
 
        for (int i = 0; i < count; ++i)
                infos[i].count = equal_limit_for_everybody;