From: David VaĊĦek Date: Sat, 4 Nov 2023 00:54:21 +0000 (+0100) Subject: stats: convert to universal atomics (variable stats_vals) X-Git-Tag: v3.4.0~257^2~4 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=44b3dedd87f0c4cce7e7e3efc44b23877acbba2e;p=thirdparty%2Fknot-dns.git stats: convert to universal atomics (variable stats_vals) --- diff --git a/src/knot/common/stats.c b/src/knot/common/stats.c index 79c0f239ee..f94742bed7 100644 --- a/src/knot/common/stats.c +++ b/src/knot/common/stats.c @@ -77,7 +77,8 @@ const stats_item_t zone_contents_stats[] = { { 0 } }; -uint64_t stats_get_counter(uint64_t **stats_vals, uint32_t offset, unsigned threads) +uint64_t stats_get_counter(knot_atomic_uint64_t **stats_vals, uint32_t offset, + unsigned threads) { uint64_t res = 0; for (unsigned i = 0; i < threads; i++) { diff --git a/src/knot/common/stats.h b/src/knot/common/stats.h index 5cb51ca362..acfd1ca8a8 100644 --- a/src/knot/common/stats.h +++ b/src/knot/common/stats.h @@ -20,6 +20,7 @@ #pragma once +#include "contrib/atomic.h" #include "knot/server/server.h" typedef uint64_t (*stats_server_val_f)(server_t *server); @@ -49,7 +50,8 @@ extern const stats_item_t zone_contents_stats[]; /*! * \brief Read out value of single counter summed across threads. */ -uint64_t stats_get_counter(uint64_t **stats_vals, uint32_t offset, unsigned threads); +uint64_t stats_get_counter(knot_atomic_uint64_t **stats_vals, uint32_t offset, + unsigned threads); /*! * \brief Reconfigures the statistics facility. diff --git a/src/knot/ctl/commands.c b/src/knot/ctl/commands.c index 5fbd202fdf..6ea8aae967 100644 --- a/src/knot/ctl/commands.c +++ b/src/knot/ctl/commands.c @@ -36,6 +36,7 @@ #include "knot/zone/zonefile.h" #include "libknot/libknot.h" #include "libknot/yparser/yptrafo.h" +#include "contrib/atomic.h" #include "contrib/files.h" #include "contrib/string.h" #include "contrib/strtonum.h" @@ -1597,7 +1598,7 @@ static int zone_purge(zone_t *zone, ctl_args_t *args) return selective_zone_purge(conf(), zone, params); } -static int send_stats_ctr(mod_ctr_t *ctr, uint64_t **stats_vals, unsigned threads, +static int send_stats_ctr(mod_ctr_t *ctr, knot_atomic_uint64_t **stats_vals, unsigned threads, ctl_args_t *args, knot_ctl_data_t *data) { char index[128]; diff --git a/src/knot/nameserver/query_module.c b/src/knot/nameserver/query_module.c index 54a982bb89..13fa5da4e1 100644 --- a/src/knot/nameserver/query_module.c +++ b/src/knot/nameserver/query_module.c @@ -32,17 +32,6 @@ #include "knot/nameserver/query_module.h" #include "knot/nameserver/process_query.h" -#ifdef HAVE_ATOMIC - #define ATOMIC_ADD(dst, val) __atomic_add_fetch(&(dst), (val), __ATOMIC_RELAXED) - #define ATOMIC_SUB(dst, val) __atomic_sub_fetch(&(dst), (val), __ATOMIC_RELAXED) - #define ATOMIC_SET(dst, val) __atomic_store_n(&(dst), (val), __ATOMIC_RELAXED) -#else - #warning "Statistics data can be inaccurate" - #define ATOMIC_ADD(dst, val) ((dst) += (val)) - #define ATOMIC_SUB(dst, val) ((dst) -= (val)) - #define ATOMIC_SET(dst, val) ((dst) = (val)) -#endif - _public_ int knotd_conf_check_ref(knotd_conf_check_args_t *args) { @@ -313,8 +302,8 @@ int knotd_mod_stats_add(knotd_mod_t *mod, const char *ctr_name, uint32_t idx_cou stats += mod->stats_count; for (unsigned i = 0; i < threads; i++) { - uint64_t *new_vals = realloc(mod->stats_vals[i], - (offset + idx_count) * sizeof(*new_vals)); + knot_atomic_uint64_t *new_vals = realloc(mod->stats_vals[i], + (offset + idx_count) * sizeof(*new_vals)); if (new_vals == NULL) { knotd_mod_stats_free(mod); return KNOT_ENOMEM; diff --git a/src/knot/nameserver/query_module.h b/src/knot/nameserver/query_module.h index 5cc905b909..65957c4bc6 100644 --- a/src/knot/nameserver/query_module.h +++ b/src/knot/nameserver/query_module.h @@ -1,4 +1,4 @@ -/* Copyright (C) 2020 CZ.NIC, z.s.p.o. +/* Copyright (C) 2023 CZ.NIC, z.s.p.o. This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -22,14 +22,9 @@ #include "knot/dnssec/zone-keys.h" #include "knot/include/module.h" #include "knot/server/server.h" +#include "contrib/atomic.h" #include "contrib/ucw/lists.h" -#ifdef HAVE_ATOMIC - #define ATOMIC_GET(src) __atomic_load_n(&(src), __ATOMIC_RELAXED) -#else - #define ATOMIC_GET(src) (src) -#endif - #define KNOTD_STAGES (KNOTD_STAGE_END + 1) typedef unsigned (*query_step_process_f) @@ -91,7 +86,7 @@ struct knotd_mod { zone_keyset_t *keyset; zone_sign_ctx_t *sign_ctx; mod_ctr_t *stats_info; - uint64_t **stats_vals; + knot_atomic_uint64_t **stats_vals; uint32_t stats_count; void *ctx; };