Skip to content
Snippets Groups Projects
Commit 13cc6b65 authored by g0dil's avatar g0dil
Browse files

Scheduler: Add scheduler timer latency test

parent 4565a260
No related branches found
No related tags found
No related merge requests found
...@@ -89,6 +89,8 @@ prefix_ void senf::scheduler::detail::FIFORunner::startWatchdog() ...@@ -89,6 +89,8 @@ prefix_ void senf::scheduler::detail::FIFORunner::startWatchdog()
watchdogRunning_ = true; watchdogRunning_ = true;
} }
else
stopWatchdog();
} }
prefix_ void senf::scheduler::detail::FIFORunner::stopWatchdog() prefix_ void senf::scheduler::detail::FIFORunner::stopWatchdog()
......
...@@ -116,6 +116,7 @@ namespace scheduler { ...@@ -116,6 +116,7 @@ namespace scheduler {
\param[in] initiallyEnabled if set \c false, do not \param[in] initiallyEnabled if set \c false, do not
enable callback automatically. */ enable callback automatically. */
ClockService::clock_type timeout() const; ClockService::clock_type timeout() const;
///< Get current/last timeout value
private: private:
virtual void v_run(); virtual void v_run();
......
...@@ -29,9 +29,11 @@ ...@@ -29,9 +29,11 @@
// Custom includes // Custom includes
#include "TimerEvent.hh" #include "TimerEvent.hh"
#include "Scheduler.hh" #include "Scheduler.hh"
#include <boost/bind.hpp>
#include "../Utils//auto_unit_test.hh" #include "../Utils//auto_unit_test.hh"
#include <boost/test/test_tools.hpp> #include <boost/test/test_tools.hpp>
#include <boost/random.hpp>
#define prefix_ #define prefix_
///////////////////////////////cc.p//////////////////////////////////////// ///////////////////////////////cc.p////////////////////////////////////////
...@@ -83,6 +85,67 @@ BOOST_AUTO_UNIT_TEST(timerDispatcher) ...@@ -83,6 +85,67 @@ BOOST_AUTO_UNIT_TEST(timerDispatcher)
} }
} }
namespace {
senf::ClockService::clock_type randomDelay()
{
static boost::uniform_smallint<> random (100,300);
static boost::mt19937 generator;
return senf::scheduler::now() + senf::ClockService::milliseconds(random(generator));
}
unsigned count (0);
senf::ClockService::clock_type delay (0);
void jitterCb(senf::scheduler::TimerEvent & tm)
{
std::cerr << senf::scheduler::now() << ' ' << tm.timeout() << '\n';
count ++;
delay += senf::scheduler::now() - tm.timeout();
tm.timeout(randomDelay());
}
void logSchedulerTime()
{
std::cerr << senf::scheduler::now() << '\n';
}
void jitterTest()
{
count = 0;
delay = 0;
senf::scheduler::TimerEvent tm1 ("jitterTest::tm1", boost::bind(&jitterCb, boost::ref(tm1)),
randomDelay());
senf::scheduler::TimerEvent tm2 ("jitterTest::tm2", boost::bind(&jitterCb, boost::ref(tm2)),
randomDelay());
senf::scheduler::TimerEvent tm3 ("jitterTest::tm3", boost::bind(&jitterCb, boost::ref(tm3)),
randomDelay());
senf::scheduler::TimerEvent timeout("jitterTest::timeout", &senf::scheduler::terminate,
senf::scheduler::now() + senf::ClockService::seconds(5));
senf::scheduler::EventHook timerCalled ("jitterTest::logSchedulerTime", &logSchedulerTime,
senf::scheduler::EventHook::PRE);
senf::scheduler::process();
std::cerr << "Average scheduling delay: " << delay/count << "\n";
}
}
BOOST_AUTO_UNIT_TEST(timerJitter)
{
senf::scheduler::watchdogTimeout(0);
std::cerr << "Epoll timers\n";
senf::scheduler::loresTimers();
jitterTest();
std::cerr << "Hires timers\n";
senf::scheduler::hiresTimers();
jitterTest();
senf::scheduler::watchdogTimeout(1000);
}
///////////////////////////////cc.e//////////////////////////////////////// ///////////////////////////////cc.e////////////////////////////////////////
#undef prefix_ #undef prefix_
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment