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

Improve timer efficiency

parent acbd0d94
No related branches found
No related tags found
1 merge request!316Resolves #343 GUI and Frame Refactor
......@@ -155,6 +155,9 @@ int main(int argc, char **argv) {
Pylon::PylonAutoInitTerm autoInitTerm;
#endif
// Note: This causes 100% CPU use but prevents the random frame drops.
ftl::timer::setHighPrecision(true);
{
nanogui::init();
......
......@@ -89,6 +89,30 @@ static void waitTimePoint() {
}
}
/*while (msdelay >= 10 && sincelast != mspf) {
sleep_for(milliseconds(5));
now = get_time();
msdelay = mspf - (now % mspf);
}*/
if (msdelay >= 2 && sincelast != mspf) {
UNIQUE_LOCK(mtx, lk);
auto idle_job = jobs[kTimerIdle1].begin();
while (idle_job != jobs[kTimerIdle1].end() && msdelay >= 2 && sincelast != mspf) {
(*idle_job).active = true;
bool doremove = !(*idle_job).job.trigger(now);
if (doremove) {
idle_job = jobs[kTimerIdle1].erase(idle_job);
LOG(INFO) << "Timer job removed";
} else {
(*idle_job++).active = false;
}
now = get_time();
msdelay = mspf - (now % mspf);
}
}
if (hprec_) {
// Spin loop until exact grab time
// Accurate to around 4 micro seconds.
......@@ -194,6 +218,13 @@ static void trigger_jobs() {
auto *pj = &j;
// If last job in list then do in this thread
if (active_jobs == jobs[kTimerMain].size()+1) {
bool doremove = !pj->job.trigger(ts);
pj->active = false;
active_jobs--;
if (doremove) removeJob(pj->id);
} else {
ftl::pool.push([pj,ts](int id) {
bool doremove = !pj->job.trigger(ts);
pj->active = false;
......@@ -201,6 +232,7 @@ static void trigger_jobs() {
if (doremove) removeJob(pj->id);
});
}
}
// Final cleanup of stale jobs
for (size_t j=0; j<kTimerMAXLEVEL; ++j) {
......
......@@ -92,7 +92,7 @@ class Source : public ftl::Configurable, public ftl::data::DiscreteSource {
BaseSourceImpl *impl_;
SHARED_MUTEX mutex_;
cudaStream_t stream_;
bool is_retrieving;
std::atomic_bool is_retrieving;
void _swap();
};
......
......@@ -138,7 +138,7 @@ void IntervalSourceBuilder::start() {
// TODO: Do in parallel...
for (auto *s : srcs_) {
if (!s->retrieve(fs->firstFrame())) {
LOG(WARNING) << "Frame was skipping";
LOG(WARNING) << "Frame is being skipped: " << ts;
}
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment