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/aos/util/top.h b/aos/util/top.h
index e8e0d57..a71873a 100644
--- a/aos/util/top.h
+++ b/aos/util/top.h
@@ -11,7 +11,7 @@
namespace aos::util {
// ProcStat is a struct to hold all the fields available in /proc/[pid]/stat.
-// Currently we only use a small subset of the feilds. See man 5 proc for
+// Currently we only use a small subset of the fields. See man 5 proc for
// details on what the fields are--these are in the same order as they appear in
// the stat file.
//
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";
diff --git a/frc971/orin/build_rootfs.py b/frc971/orin/build_rootfs.py
index e0559a1..9ae0a72 100755
--- a/frc971/orin/build_rootfs.py
+++ b/frc971/orin/build_rootfs.py
@@ -1253,6 +1253,8 @@
copyfile("root:root", "644", "etc/systemd/network/80-canc.network")
copyfile("root:root", "644", "etc/udev/rules.d/nvidia.rules")
copyfile("root:root", "644", "etc/udev/rules.d/can.rules")
+ copyfile("root:root", "644",
+ "lib/systemd/system/nvargus-daemon.service")
target(["/root/bin/change_hostname.sh", "orin-971-1"])
target(["systemctl", "enable", "systemd-networkd"])
diff --git a/frc971/orin/contents/lib/systemd/system/nvargus-daemon.service b/frc971/orin/contents/lib/systemd/system/nvargus-daemon.service
new file mode 100644
index 0000000..36b9e4e
--- /dev/null
+++ b/frc971/orin/contents/lib/systemd/system/nvargus-daemon.service
@@ -0,0 +1,16 @@
+[Unit]
+Description=NVIDIA Argus daemon
+After=local-fs.target network.target nvpmodel.service
+
+[Service]
+Type=simple
+ExecStart=/usr/sbin/nvargus-daemon
+StandardOutput=journal
+Restart=on-failure
+CPUSchedulingPolicy=fifo
+CPUSchedulingPriority=51
+#Environment=enableCamPclLogs=5
+#Environment=enableCamScfLogs=5
+
+[Install]
+WantedBy=multi-user.target
diff --git a/frc971/orin/orin_irq_config.json b/frc971/orin/orin_irq_config.json
index 8ead6ba..c067e20 100644
--- a/frc971/orin/orin_irq_config.json
+++ b/frc971/orin/orin_irq_config.json
@@ -306,6 +306,11 @@
"nice": -20
},
{
+ "name": "ivc/bc00000.rtc",
+ "scheduler": "SCHEDULER_FIFO",
+ "priority": 55
+ },
+ {
"name": "irq/*-aerdrv",
"scheduler": "SCHEDULER_OTHER",
"nice": -20
@@ -319,7 +324,7 @@
"name": "irq/*-host_sy",
"scheduler": "SCHEDULER_FIFO",
"affinity": [2, 3],
- "priority": 51
+ "priority": 58
},
{
"name": "irq/*-b950000",