From c6d04bdc6d5608f15a9a5ac97d08f516580a142a Mon Sep 17 00:00:00 2001 From: bert hubert Date: Thu, 15 Jan 2015 13:43:28 +0100 Subject: [PATCH] remove old tsc based timer infrastructure, beef up #ifdef to prevent using the high-end per thread cpu timers on OSX --- pdns/Makefile.am | 1 - pdns/htimer.cc | 140 ------------------------------------------ pdns/htimer.hh | 77 ----------------------- pdns/misc.hh | 22 +------ pdns/pdns_recursor.cc | 1 + 5 files changed, 2 insertions(+), 239 deletions(-) delete mode 100644 pdns/htimer.cc delete mode 100644 pdns/htimer.hh diff --git a/pdns/Makefile.am b/pdns/Makefile.am index db9db8d69..9dfe05428 100644 --- a/pdns/Makefile.am +++ b/pdns/Makefile.am @@ -927,7 +927,6 @@ pdns_recursor_SOURCES = \ dnsrecords.cc dnsrecords.hh \ dnswriter.cc dnswriter.hh \ epollmplexer.cc \ - htimer.cc htimer.hh \ iputils.cc \ json.cc json.hh \ logger.cc \ diff --git a/pdns/htimer.cc b/pdns/htimer.cc deleted file mode 100644 index 1f4533df0..000000000 --- a/pdns/htimer.cc +++ /dev/null @@ -1,140 +0,0 @@ -#include -#include "htimer.hh" -#include - -HTimer::timers_t HTimer::s_timers; - -#include "namespaces.hh" -#include "namespaces.hh" - - -/* idea: nested timers, where the hierarchy of nesting is constructed at runtime. Each timer can have multiple - positions in the hierarchy, and might conceivable nest within itself. - - Desired result: - - Processing incoming questions - Rest - Parsing question - Rest - MOADNSParser - Searching cache - Processing Server Answers - Rest - MOADNSParser - Waiting for packets - - Parsing question - Rest - MOADDNSParser - - Processing Server Answers - Rest - MOADNSParser - - Waiting for packets -*/ - -#define RDTSC(qp) \ -do { \ - unsigned long lowPart, highPart; \ - __asm__ __volatile__("rdtsc" : "=a" (lowPart), "=d" (highPart)); \ - qp = (((unsigned long long) highPart) << 32) | lowPart; \ -} while (0) - -HTimer::HTimer(const std::string& name) : d_accumulated(0), d_started(0) -{ - s_timers[name]=this; -} - -HTimer::~HTimer() -{ - for(timers_t::iterator iter = s_timers.begin(); iter != s_timers.end() ; ++iter) { - if(iter->second == this) { - s_timers.erase(iter); - break; - } - } -} - -void HTimer::start() -{ - if(d_started) - throw runtime_error("HTimer restarted!"); - RDTSC(d_started); -} - -void HTimer::stop() -{ - if(!d_started) - throw runtime_error("HTimer stopped that wasn't started!"); - uint64_t stopped; - RDTSC(stopped); - - d_accumulated += stopped - d_started; - d_started=0; -} - -uint64_t HTimer::getAccumulated() const -{ - uint64_t accumulated = d_accumulated; - if(d_started) { - uint64_t midterm; - RDTSC(midterm); - - accumulated += midterm - d_started; - } - return accumulated; -} - -uint64_t HTimer::getAccumulatedReset() -{ - uint64_t accumulated = d_accumulated; - if(d_started) { - uint64_t midterm; - RDTSC(midterm); - - accumulated += midterm - d_started; - d_started=midterm; - } - d_accumulated=0; - return accumulated; -} - - -HTimerSentinel HTimer::getSentinel() -{ - return HTimerSentinel(this); -} - -void HTimer::listAll() -{ - for(timers_t::iterator iter = s_timers.begin(); iter != s_timers.end() ; ++iter) { - cerr << iter->first <<": " << iter->second->getAccumulatedReset()/3000.0 <<"usec\n"; - } -} - -#if 0 -int main() -{ - char *q = new char; - delete q; - - HTimer htmain("main"); - htmain.start(); - - HTimer htloop("loop"); - { - HTimerSentinel hts=htloop.getSentinel(); - for(int i=0; i < 1000; ++i) - { - shared_ptr p(shared_ptr(new char)); - } - } - - htloop.listAll(); - - cerr<<"accumulated: "<< htmain.getAccumulated() < -#include -#include -#include - -class HTimerSentinel; -// typedef boost::shared_ptr HTimerSentinel; - -class HTimer : public boost::noncopyable -{ -public: - HTimer(){}; - explicit HTimer(const std::string& name); - ~HTimer(); - void start(); - void stop(); - uint64_t getAccumulated() const; - uint64_t getAccumulatedReset(); - - HTimerSentinel getSentinel(); - static void listAll(); - -private: - typedef std::map timers_t; - static timers_t s_timers; - uint64_t d_accumulated; - uint64_t d_started; -}; - -class HTimerSentinel -{ -public: - explicit HTimerSentinel(class HTimer* parent) : d_parent(parent) - { - d_rc=1; - d_parent->start(); - } - - HTimerSentinel(const HTimerSentinel& orig) - { - d_parent = orig.d_parent; - orig.d_rc++; - } - - ~HTimerSentinel() - { - if(!--d_rc) - d_parent->stop(); - } - -private: - HTimerSentinel& operator=(const HTimerSentinel& rhs); - HTimer* d_parent; - - mutable unsigned int d_rc; -}; - -class HTimerSentinelImp : public boost::noncopyable -{ -public: - explicit HTimerSentinelImp(class HTimer* parent) : d_parent(parent) - { - d_parent->start(); - } - - ~HTimerSentinelImp() - { - d_parent->stop(); - } - -private: - HTimer* d_parent; -}; - -#endif diff --git a/pdns/misc.hh b/pdns/misc.hh index e7c72e0de..515e35fe5 100644 --- a/pdns/misc.hh +++ b/pdns/misc.hh @@ -33,26 +33,6 @@ #include #include using namespace ::boost::multi_index; -#if 0 -#include -using std::cout; -using std::endl; - -struct TSCTimer -{ - TSCTimer() - { - RDTSC(d_tsc1); - } - ~TSCTimer() - { - uint64_t tsc2; - RDTSC(tsc2); - cout<<"Timer: "<< (tsc2 - d_tsc1)/3000.0 << endl; - } - uint64_t d_tsc1; -}; -#endif #include "utility.hh" #include "dns.hh" @@ -181,7 +161,7 @@ int makeGidNumeric(const string &group); int makeUidNumeric(const string &user); void cleanSlashes(string &str); -#ifdef _POSIX_THREAD_CPUTIME +#if defined(_POSIX_THREAD_CPUTIME) && defined(CLOCK_THREAD_CPUTIME_ID) /** CPUTime measurements */ class CPUTime { diff --git a/pdns/pdns_recursor.cc b/pdns/pdns_recursor.cc index 5cda0f0f4..1c8480a07 100644 --- a/pdns/pdns_recursor.cc +++ b/pdns/pdns_recursor.cc @@ -755,6 +755,7 @@ void startDoResolve(void *p) newLat = min(newLat,(uint64_t)(g_networkTimeoutMsec*1000)); // outliers of several minutes exist.. g_stats.avgLatencyUsec=(1-1.0/g_latencyStatSize)*g_stats.avgLatencyUsec + (float)newLat/g_latencyStatSize; // no worries, we do this for packet cache hits elsewhere + // cout<d_mdp.d_qname<<"\t"<getUsec()<<"\t"<