From 7db617e10ec7539544e046eb672d70606df7ed27 Mon Sep 17 00:00:00 2001 From: Otto Date: Wed, 13 Oct 2021 11:12:28 +0200 Subject: [PATCH] Convert more atomics to stat_t and eliminate AtomicCounter form the recursor (except in cases that are shared by with auth). I changed two AtomicCounters to atomic; their range is limited and they are not updated very frequently. --- pdns/histogram.hh | 7 ++++--- pdns/pdns_recursor.cc | 4 ++-- pdns/responsestats.hh | 3 ++- pdns/syncres.hh | 6 +++--- 4 files changed, 11 insertions(+), 9 deletions(-) diff --git a/pdns/histogram.hh b/pdns/histogram.hh index beaaf795755f..7cfbcac343e2 100644 --- a/pdns/histogram.hh +++ b/pdns/histogram.hh @@ -22,12 +22,13 @@ #pragma once #include -#include #include #include #include #include +#include "stat_t.hh" + namespace pdns { @@ -50,7 +51,7 @@ struct AtomicBucket const std::string d_name; const uint64_t d_boundary{0}; - mutable std::atomic d_count{0}; + mutable stat_t d_count{0}; }; template @@ -178,6 +179,6 @@ private: using Histogram = BaseHistogram; -using AtomicHistogram = BaseHistogram>; +using AtomicHistogram = BaseHistogram; } // namespace pdns diff --git a/pdns/pdns_recursor.cc b/pdns/pdns_recursor.cc index 280f93674442..c63a79926757 100644 --- a/pdns/pdns_recursor.cc +++ b/pdns/pdns_recursor.cc @@ -199,7 +199,7 @@ enum class PaddingMode { Always, PaddedQueries }; static listenSocketsAddresses_t g_listenSocketsAddresses; // is shared across all threads right now static set g_fromtosockets; // listen sockets that use 'sendfromto()' mechanism (without actually using sendfromto()) -static AtomicCounter counter; +static std::atomic counter; static std::shared_ptr g_initialDomainMap; // new threads needs this to be setup static std::shared_ptr g_initialAllowFrom; // new thread needs to be setup with this static NetmaskGroup g_XPFAcl; @@ -854,7 +854,7 @@ TCPConnection::~TCPConnection() --s_currentConnections; } -AtomicCounter TCPConnection::s_currentConnections; +std::atomic TCPConnection::s_currentConnections; static void terminateTCPConnection(int fd) { diff --git a/pdns/responsestats.hh b/pdns/responsestats.hh index 0d89ca88ac7b..cb24c284bab2 100644 --- a/pdns/responsestats.hh +++ b/pdns/responsestats.hh @@ -23,6 +23,7 @@ #include #include "histogram.hh" +#include "stat_t.hh" #include "dnspacket.hh" @@ -42,7 +43,7 @@ public: private: struct Counter { - mutable std::atomic value; + mutable pdns::stat_t value; }; std::array d_qtypecounters; diff --git a/pdns/syncres.hh b/pdns/syncres.hh index 2ace9e6b43bb..e3382e5597c0 100644 --- a/pdns/syncres.hh +++ b/pdns/syncres.hh @@ -1034,8 +1034,8 @@ struct RecursorStats pdns::AtomicHistogram cumulativeAnswers; pdns::AtomicHistogram cumulativeAuth4Answers; pdns::AtomicHistogram cumulativeAuth6Answers; - std::atomic avgLatencyUsec; - std::atomic avgLatencyOursUsec; + pdns::stat_t_trait avgLatencyUsec; + pdns::stat_t_trait avgLatencyOursUsec; pdns::stat_t qcounter; // not increased for unauth packets pdns::stat_t ipv6qcounter; pdns::stat_t tcpqcounter; @@ -1121,7 +1121,7 @@ public: static unsigned int getCurrentConnections() { return s_currentConnections; } private: const int d_fd; - static AtomicCounter s_currentConnections; //!< total number of current TCP connections + static std::atomic s_currentConnections; //!< total number of current TCP connections }; class ImmediateServFailException