]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
Convert more atomics to stat_t and eliminate AtomicCounter form the recursor
authorOtto <otto.moerbeek@open-xchange.com>
Wed, 13 Oct 2021 09:12:28 +0000 (11:12 +0200)
committerOtto <otto.moerbeek@open-xchange.com>
Wed, 13 Oct 2021 09:12:28 +0000 (11:12 +0200)
(except in cases that are shared by with auth).

I changed two AtomicCounters to atomic<int32>; their range is limited and
they are not updated very frequently.

pdns/histogram.hh
pdns/pdns_recursor.cc
pdns/responsestats.hh
pdns/syncres.hh

index beaaf795755f27b8dd91dfa7963d1d1ea5335eff..7cfbcac343e27905ea03b6f9f69822c977903efc 100644 (file)
 #pragma once
 
 #include <algorithm>
-#include <atomic>
 #include <limits>
 #include <stdexcept>
 #include <string>
 #include <vector>
 
+#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<uint64_t> d_count{0};
+  mutable stat_t d_count{0};
 };
 
 template <class B, class SumType>
@@ -178,6 +179,6 @@ private:
 
 using Histogram = BaseHistogram<Bucket, uint64_t>;
 
-using AtomicHistogram = BaseHistogram<AtomicBucket, std::atomic<uint64_t>>;
+using AtomicHistogram = BaseHistogram<AtomicBucket, pdns::stat_t>;
 
 } // namespace pdns
index 280f93674442b25d9aee32354543d45021f38473..c63a79926757a15709be29a72b7c06b7ced36193 100644 (file)
@@ -199,7 +199,7 @@ enum class PaddingMode { Always, PaddedQueries };
 
 static listenSocketsAddresses_t g_listenSocketsAddresses; // is shared across all threads right now
 static set<int> g_fromtosockets; // listen sockets that use 'sendfromto()' mechanism (without actually using sendfromto())
-static AtomicCounter counter;
+static std::atomic<uint32_t> counter;
 static std::shared_ptr<SyncRes::domainmap_t> g_initialDomainMap; // new threads needs this to be setup
 static std::shared_ptr<NetmaskGroup> 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<uint32_t> TCPConnection::s_currentConnections;
 
 static void terminateTCPConnection(int fd)
 {
index 0d89ca88ac7b97c2013171b8887ef55ee611205a..cb24c284bab2b9d3b65f5f4331a6350decb526c5 100644 (file)
@@ -23,6 +23,7 @@
 
 #include <array>
 #include "histogram.hh"
+#include "stat_t.hh"
 
 #include "dnspacket.hh"
 
@@ -42,7 +43,7 @@ public:
 private:
   struct Counter
   {
-    mutable std::atomic<uint64_t> value;
+    mutable pdns::stat_t value;
   };
 
   std::array<Counter, 65536> d_qtypecounters;
index 2ace9e6b43bbb04a5976fca4479a7e0263c1d83d..e3382e5597c09b6570fb3ebcb4f01d54532cd2c9 100644 (file)
@@ -1034,8 +1034,8 @@ struct RecursorStats
   pdns::AtomicHistogram cumulativeAnswers;
   pdns::AtomicHistogram cumulativeAuth4Answers;
   pdns::AtomicHistogram cumulativeAuth6Answers;
-  std::atomic<double> avgLatencyUsec;
-  std::atomic<double> avgLatencyOursUsec;
+  pdns::stat_t_trait<double> avgLatencyUsec;
+  pdns::stat_t_trait<double> 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<uint32_t> s_currentConnections; //!< total number of current TCP connections
 };
 
 class ImmediateServFailException