]> git.ipfire.org Git - thirdparty/knot-dns.git/commitdiff
kxdpgun: stats_period overflow bugfix
authorJan Doskočil <jan.doskocil@nic.cz>
Fri, 18 Oct 2024 09:36:37 +0000 (11:36 +0200)
committerDaniel Salzman <daniel.salzman@nic.cz>
Wed, 30 Oct 2024 14:03:13 +0000 (15:03 +0100)
src/utils/kxdpgun/main.c
src/utils/kxdpgun/main.h
src/utils/kxdpgun/stats.c

index 5e10b6d07912e88fc63d584d3f2e21897b1f8efa..3c036034ae623e409c8eb2fd1e00326888827b48 100644 (file)
@@ -77,7 +77,7 @@ const static xdp_gun_ctx_t ctx_defaults = {
        .flags = KNOT_XDP_FILTER_UDP | KNOT_XDP_FILTER_PASS,
        .xdp_config = { .ring_size = 2048 },
        .jw = NULL,
-       .stats_period = 0,
+       .stats_period_ns = 0,
 };
 
 static void sigterm_handler(int signo)
@@ -742,8 +742,8 @@ void *xdp_gun_thread(void *_ctx)
                uint64_t duration_ns = timer_end_ns(&timer);
                duration_us = duration_ns / 1000;
                uint64_t dura_exp = ((local_stats.qry_sent + periodic_stats.qry_sent) * 1000000) / ctx->qps;
-               if (ctx->thread_id == 0 && ctx->stats_period != 0 && global_stats.collected == 0
-                   && (duration_ns - (periodic_stats.since - local_stats.since)) >= ctx->stats_period) {
+               if (ctx->thread_id == 0 && ctx->stats_period_ns != 0 && global_stats.collected == 0
+                   && (duration_ns - (periodic_stats.since - local_stats.since)) >= ctx->stats_period_ns) {
                        ATOMIC_SET(stats_switch, STATS_PERIODIC);
                        ATOMIC_ADD(stats_trigger, 1);
                }
@@ -1299,7 +1299,7 @@ static bool get_opts(int argc, char *argv[], xdp_gun_ctx_t *ctx)
                        assert(optarg);
                        arg = atoi(optarg);
                        if (arg > 0) {
-                               ctx->stats_period = arg * 1000000; // convert to ns
+                               ctx->stats_period_ns = arg * 1000000ull; // convert to ns
                        } else {
                                ERR2("period must be a positive integer\n");
                                return false;
index d87aee8804afb82303d751753841583b1d923cde..d560709570cf80bc4ee6e8c7e0e4952871d3e042 100644 (file)
@@ -62,7 +62,7 @@ typedef struct xdp_gun_ctx {
        uint64_t               qps, duration;
        uint64_t               runid;
        uint64_t               stats_start_us;
-       uint32_t               stats_period; // 0 means no periodic stats
+       uint64_t               stats_period_ns; // 0 means no periodic stats
        unsigned               at_once;
        uint16_t               msgid;
        uint16_t               edns_size;
index f1e4f4349745cda3e02b59fb2f6f38b63654f573..84b7c0d376fe0c2f68bca65d50f2ef37eca9aa9d 100644 (file)
@@ -111,8 +111,8 @@ void json_stats_header(const xdp_gun_ctx_t *ctx)
                jsonw_end(w);
 
                jsonw_ulong(w, "time_units_per_sec", 1000000000);
-               if (ctx->stats_period > 0) {
-                       jsonw_double(w, "stats_interval", ctx->stats_period / 1000.0);
+               if (ctx->stats_period_ns > 0) {
+                       jsonw_double(w, "stats_interval", ctx->stats_period_ns / 1000000000.0);
                }
                // TODO: timeout