Skip to content
Snippets Groups Projects
Commit 0671b483 authored by Nicolas Pope's avatar Nicolas Pope
Browse files

Resolves #309 reduce unwanted timer precision

parent 12522ca3
No related branches found
No related tags found
No related merge requests found
......@@ -29,7 +29,7 @@ set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake/")
include(Findglog)
find_package( OpenCV REQUIRED )
find_package( OpenCV REQUIRED COMPONENTS core imgproc highgui cudaimgproc calib3d imgcodecs videoio aruco cudaarithm cudastereo cudaoptflow face tracking quality)
find_package( Threads REQUIRED )
find_package( URIParser REQUIRED )
find_package( MsgPack REQUIRED )
......
......@@ -55,6 +55,8 @@ static void run(ftl::Configurable *root) {
Universe *net = ftl::create<Universe>(root, "net");
ftl::ctrl::Master ctrl(root, net);
ftl::timer::setHighPrecision(true);
auto paths = root->get<vector<string>>("paths");
string file = "";
if (paths && (*paths).size() > 0) file = (*paths)[(*paths).size()-1];
......
......@@ -69,9 +69,20 @@ int64_t get_time();
*/
void setInterval(int ms);
/**
* The highprec parameter sets whether or not this
* timer should be high precision on the calling interval. A high precision
* timer involves spinning the cpu to achieve millisecond accuracy.
*/
void setHighPrecision(bool hp);
int getInterval();
/**
* Get current (monotonic) time in milliseconds.
*/
int64_t get_time();
int64_t get_time_micro();
double get_time_seconds();
......
......@@ -20,6 +20,7 @@ using namespace ftl::timer;
static int64_t last_frame = 0;
static int64_t mspf = 50;
static bool hprec_ = false;
static int64_t clock_adjust = 0;
static bool active = false;
static std::atomic<int> active_jobs = 0;
......@@ -59,7 +60,7 @@ static void waitTimePoint() {
int64_t msdelay = mspf - (now % mspf);
int64_t sincelast = now - last_frame*mspf;
if (sincelast > mspf) LOG(WARNING) << "Frame " << "(" << (target-last_frame) << ") dropped by " << sincelast << "ms";
if (hprec_ && sincelast > mspf) LOG(WARNING) << "Frame " << "(" << (target-last_frame) << ") dropped by " << (sincelast-mspf) << "ms";
// Use sleep_for for larger delays
......@@ -89,15 +90,21 @@ static void waitTimePoint() {
}
}
// Spin loop until exact grab time
//LOG(INFO) << "Spin Delay: " << (now / 40) << " = " << (40 - (now%40));
if (sincelast != mspf) {
target = now / mspf;
while ((now/mspf) == target) {
_mm_pause(); // SSE2 nano pause intrinsic
now = get_time();
};
if (hprec_) {
// Spin loop until exact grab time
// Accurate to around 4 micro seconds.
if (sincelast != mspf) {
// TODO: Try using sleep_for for msdelay-1
target = now / mspf;
while ((now/mspf) == target) {
_mm_pause(); // SSE2 nano pause intrinsic
now = get_time();
};
}
} else {
// Accurate to just under 1 millisecond usually
if (sincelast != mspf) sleep_for(milliseconds(msdelay));
now = get_time();
}
last_frame = now/mspf;
}
......@@ -106,6 +113,10 @@ void ftl::timer::setInterval(int ms) {
mspf = ms;
}
void ftl::timer::setHighPrecision(bool hp) {
hprec_ = hp;
}
int ftl::timer::getInterval() {
return mspf;
}
......
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