From: g0dil Date: Tue, 3 Feb 2009 09:31:02 +0000 (+0000) Subject: Scheduler: Implement timer source switching API X-Git-Url: http://g0dil.de/git?a=commitdiff_plain;h=c48abca75a9bb62c31d0f2651a00ddf4ce79c7f2;p=senf.git Scheduler: Implement timer source switching API Scheduler: Switch default timer source to lores / epoll() git-svn-id: https://svn.berlios.de/svnroot/repos/senf/trunk@1092 270642c3-0616-0410-b53a-bc976706d245 --- diff --git a/Scheduler/Scheduler.cci b/Scheduler/Scheduler.cci index 1e69ee1..6f87861 100644 --- a/Scheduler/Scheduler.cci +++ b/Scheduler/Scheduler.cci @@ -54,6 +54,23 @@ prefix_ unsigned senf::scheduler::hangCount() return scheduler::detail::FIFORunner::instance().hangCount(); } +prefix_ void senf::scheduler::hiresTimers() +{ + detail::TimerDispatcher::instance().setTimerSource( + std::auto_ptr(new POSIXTimerSource())); +} + +prefix_ void senf::scheduler::loresTimers() +{ + detail::TimerDispatcher::instance().setTimerSource( + std::auto_ptr(new PollTimerSource())); +} + +prefix_ bool senf::scheduler::haveScalableHiresTimers() +{ + return false; +} + ///////////////////////////////cci.e/////////////////////////////////////// #undef prefix_ diff --git a/Scheduler/Scheduler.hh b/Scheduler/Scheduler.hh index a8cfe59..fdd5f59 100644 --- a/Scheduler/Scheduler.hh +++ b/Scheduler/Scheduler.hh @@ -232,6 +232,32 @@ namespace scheduler { /** \brief Number of watchdog events */ unsigned hangCount(); + /** \brief Switch to using hi resolution timers + + By default, timers are implemented directly using epoll. This however restricts the timer + resolution to that of the kernel HZ value. + + High resolution timers are implemented either using POSIX timers or, when available, using + the Linux special \c timerfd() syscall. + + POSIX timers are delivered using signals. A high timer load this increases the signal load + considerably. \c timerfd()'s are delivered on a file descriptor and thus don't have such a + scalability issue. + + \warning The timer source must not be switched from a scheduler callback + */ + void hiresTimers(); + + /** \brief Switch back to using epoll for timing + \see hiresTimers() + */ + void loresTimers(); + + /** \brief return \c true, if \c timerfd() timing is available, \c false otherwise + \see hiresTimers() + */ + bool haveScalableHiresTimers(); + /** \brief Restart scheduler This call will restart all scheduler dispatchers (timers, signals, file descriptors). This diff --git a/Scheduler/TimerEvent.cc b/Scheduler/TimerEvent.cc index 38ad03a..437aae3 100644 --- a/Scheduler/TimerEvent.cc +++ b/Scheduler/TimerEvent.cc @@ -34,7 +34,7 @@ ///////////////////////////////cc.p//////////////////////////////////////// prefix_ senf::scheduler::detail::TimerDispatcher::TimerDispatcher() - : source_ (new POSIXTimerSource()) + : source_ (new PollTimerSource()) {} prefix_ senf::scheduler::detail::TimerDispatcher::~TimerDispatcher() diff --git a/Scheduler/TimerEvent.cci b/Scheduler/TimerEvent.cci index 5fcf5ef..e2bf3fb 100644 --- a/Scheduler/TimerEvent.cci +++ b/Scheduler/TimerEvent.cci @@ -98,6 +98,12 @@ prefix_ bool senf::scheduler::detail::TimerDispatcher::empty() return timers_.empty(); } +prefix_ void senf::scheduler::detail::TimerDispatcher:: +setTimerSource(std::auto_ptr timerSource) +{ + source_.reset(timerSource.release()); +} + ///////////////////////////////cci.e/////////////////////////////////////// #undef prefix_ diff --git a/Scheduler/TimerEvent.ih b/Scheduler/TimerEvent.ih index af9c104..a6ecf9b 100644 --- a/Scheduler/TimerEvent.ih +++ b/Scheduler/TimerEvent.ih @@ -65,6 +65,8 @@ namespace detail { bool empty() const; + void setTimerSource(std::auto_ptr timerSource); + protected: private: