Tune IRQs on the new roboRIO for lower latency

This pulls peak wakeup latency down from 800 uS or more to 150 uS.  Most
of this is changing ktimersoftd/* to be high priority.

While we are here, most of the IRQs, including MMC are running at RT
priority 15.  Anything we want to run needs to be higher than 15.  Move
the networking stack and message_bridge up above that so we get low
latency communications.

Change-Id: I14ede0fdeb2a008f482feae75fa04cabc3f5abeb
Signed-off-by: Austin Schuh <austin.linux@gmail.com>
diff --git a/frc971/wpilib/ADIS16448.cc b/frc971/wpilib/ADIS16448.cc
index b479970..c047cf9 100644
--- a/frc971/wpilib/ADIS16448.cc
+++ b/frc971/wpilib/ADIS16448.cc
@@ -137,9 +137,9 @@
 
   // NI's SPI driver defaults to SCHED_OTHER.  Find it's PID with ps, and change
   // it to a RT priority of 33.
-  AOS_PCHECK(system("busybox ps -ef | grep '\\[spi0\\]' | awk '{print $1}' | "
-                    "xargs chrt -f -p "
-                    "33") == 0);
+  PCHECK(system("busybox ps -ef | grep '\\[spi0\\]' | awk '{print $1}' | "
+                "xargs chrt -f -p "
+                "33") == 0);
 
   event_loop->set_name("IMU");
   event_loop_->SetRuntimeRealtimePriority(33);
diff --git a/frc971/wpilib/sensor_reader.cc b/frc971/wpilib/sensor_reader.cc
index 2a40128..f476e71 100644
--- a/frc971/wpilib/sensor_reader.cc
+++ b/frc971/wpilib/sensor_reader.cc
@@ -6,6 +6,7 @@
 
 #include "aos/init.h"
 #include "aos/logging/logging.h"
+#include "aos/realtime.h"
 #include "aos/util/compiler_memory_barrier.h"
 #include "frc971/wpilib/ahal/DigitalInput.h"
 #include "frc971/wpilib/ahal/DriverStation.h"
@@ -27,6 +28,10 @@
   ds_ = &::frc::DriverStation::GetInstance();
 
   event_loop->SetRuntimeRealtimePriority(40);
+  // The timer interrupt fires on CPU1.  Since nothing else is pinned, it will
+  // be cheapest to pin this there so it transitions directly and doesn't
+  // need to ever migrate.
+  event_loop->SetRuntimeAffinity(aos::MakeCpusetFromCpus({1}));
 
   // Fill in the no pwm trigger defaults.
   timer_handler_ = event_loop_->AddTimer([this]() { Loop(); });
diff --git a/frc971/wpilib/wpilib_robot_base.h b/frc971/wpilib/wpilib_robot_base.h
index 33a17bc..bcde100 100644
--- a/frc971/wpilib/wpilib_robot_base.h
+++ b/frc971/wpilib/wpilib_robot_base.h
@@ -54,6 +54,12 @@
     // it. This is in here instead of starter.sh because starter.sh doesn't run
     // with permissions on a roboRIO.
     PCHECK(system("echo 0 > /proc/sys/vm/overcommit_memory") == 0);
+    PCHECK(system("busybox ps -ef | grep '\\[ktimersoftd/0\\]' | awk '{print "
+                  "$1}' | xargs chrt -f -p 70") == 0);
+    PCHECK(system("busybox ps -ef | grep '\\[ktimersoftd/1\\]' | awk '{print "
+                  "$1}' | xargs chrt -f -p 70") == 0);
+    PCHECK(system("busybox ps -ef | grep '\\[irq/54-eth0\\]' | awk '{print "
+                  "$1}' | xargs chrt -f -p 17") == 0);
 
     // Configure throttling so we reserve 5% of the CPU for non-rt work.
     // This makes things significantly more stable when work explodes.
diff --git a/y2020/y2020_roborio.json b/y2020/y2020_roborio.json
index 505eb1c..fc3063e 100644
--- a/y2020/y2020_roborio.json
+++ b/y2020/y2020_roborio.json
@@ -412,7 +412,7 @@
     {
       "name": "message_bridge_client",
       "executable_name": "message_bridge_client",
-      "args": ["--rt_priority=5"],
+      "args": ["--rt_priority=16"],
       "nodes": [
         "roborio"
       ]
@@ -420,7 +420,7 @@
     {
       "name": "message_bridge_server",
       "executable_name": "message_bridge_server",
-      "args": ["--rt_priority=5"],
+      "args": ["--rt_priority=16"],
       "nodes": [
         "roborio"
       ]