Prioritize nvargus-daemon and other threads
A large part of our critical path work in libargus was running at
SCHED_OTHER. Move this to SCHED_FIFO so it will run. This reduces
outliers to down in the 8ms from 16+.
Change-Id: Ib86a07f70f3715328b86d83ee91aada4ab441cd7
Signed-off-by: Austin Schuh <austin.linux@gmail.com>
diff --git a/frc971/orin/argus_camera.cc b/frc971/orin/argus_camera.cc
index 62ae36e..42686a1 100644
--- a/frc971/orin/argus_camera.cc
+++ b/frc971/orin/argus_camera.cc
@@ -1,3 +1,5 @@
+#include <dirent.h>
+
#include <chrono>
#include <filesystem>
#include <thread>
@@ -631,6 +633,25 @@
camera.Start();
+ // Set the libargus threads which got spawned to RT priority.
+ {
+ DIR *dirp = opendir("/proc/self/task");
+ PCHECK(dirp != nullptr);
+ const int main_pid = getpid();
+ struct dirent *directory_entry;
+ while ((directory_entry = readdir(dirp)) != NULL) {
+ const int thread_id = std::atoi(directory_entry->d_name);
+
+ // ignore . and .. which are zeroes for some reason
+ if (thread_id != 0 && thread_id != main_pid) {
+ struct sched_param param;
+ param.sched_priority = 56;
+ sched_setscheduler(thread_id, SCHED_FIFO, ¶m);
+ }
+ }
+ closedir(dirp);
+ }
+
event_loop.Run();
LOG(INFO) << "Event loop shutting down";