Add support for nice to irq_affinity and reprioritize mmc driver

This lets us move things to sched_other, but make them important easily.
The most important one here is the MMC driver, which should be
important, but not be on the RT scheduler.

Change-Id: I763c230e910daf05162774ba888366aa37bef115
Signed-off-by: Austin Schuh <austin.linux@gmail.com>
diff --git a/aos/starter/irq_affinity.cc b/aos/starter/irq_affinity.cc
index 5c70e9e..08cd5a6 100644
--- a/aos/starter/irq_affinity.cc
+++ b/aos/starter/irq_affinity.cc
@@ -1,6 +1,7 @@
 #include <linux/securebits.h>
 #include <pwd.h>
 #include <sys/prctl.h>
+#include <sys/resource.h>
 #include <sys/types.h>
 
 #include "aos/events/shm_event_loop.h"
@@ -86,6 +87,7 @@
   std::string postfix;
   starter::Scheduler scheduler;
   int priority;
+  std::optional<int> nice;
   cpu_set_t affinity;
 
   bool Matches(std::string_view candidate) const {
@@ -107,25 +109,29 @@
   }
 
   void ConfigurePid(pid_t pid) const {
-    {
-      struct sched_param param;
-      param.sched_priority = priority;
-      int new_scheduler;
-      switch (scheduler) {
-        case starter::Scheduler::SCHEDULER_OTHER:
-          new_scheduler = SCHED_OTHER;
-          break;
-        case starter::Scheduler::SCHEDULER_RR:
-          new_scheduler = SCHED_RR;
-          break;
-        case starter::Scheduler::SCHEDULER_FIFO:
-          new_scheduler = SCHED_FIFO;
-          break;
-        default:
-          LOG(FATAL) << "Unknown scheduler";
-      }
-      PCHECK(sched_setscheduler(pid, new_scheduler, &param) == 0);
+    struct sched_param param;
+    param.sched_priority = priority;
+    int new_scheduler;
+    switch (scheduler) {
+      case starter::Scheduler::SCHEDULER_OTHER:
+        new_scheduler = SCHED_OTHER;
+        break;
+      case starter::Scheduler::SCHEDULER_RR:
+        new_scheduler = SCHED_RR;
+        break;
+      case starter::Scheduler::SCHEDULER_FIFO:
+        new_scheduler = SCHED_FIFO;
+        break;
+      default:
+        LOG(FATAL) << "Unknown scheduler";
     }
+    PCHECK(sched_setscheduler(pid, new_scheduler, &param) == 0);
+
+    if (scheduler == starter::Scheduler::SCHEDULER_OTHER && nice.has_value()) {
+      PCHECK(setpriority(PRIO_PROCESS, pid, *nice) == 0)
+          << ": Failed to set priority";
+    }
+
     PCHECK(sched_setaffinity(pid, sizeof(affinity), &affinity) == 0);
   }
 };
@@ -160,6 +166,7 @@
                                 star_position + 1)),
             .scheduler = kthread_config->scheduler(),
             .priority = kthread_config->priority(),
+            .nice = kthread_config->nice(),
             .affinity = AffinityFromFlatbuffer(kthread_config->affinity()),
         });
       }
diff --git a/aos/starter/kthread.fbs b/aos/starter/kthread.fbs
index e76185d..69f2b0e 100644
--- a/aos/starter/kthread.fbs
+++ b/aos/starter/kthread.fbs
@@ -16,6 +16,7 @@
   priority: int8 (id: 1);
   scheduler: Scheduler = SCHEDULER_OTHER (id: 2);
   affinity: [uint8] (id: 3);
+  nice: int8 = 0 (id: 4);
 }
 
 table IrqAffinityConfig {
diff --git a/aos/starter/roborio_irq_config.json b/aos/starter/roborio_irq_config.json
index d6ea0db..af9a315 100644
--- a/aos/starter/roborio_irq_config.json
+++ b/aos/starter/roborio_irq_config.json
@@ -19,6 +19,16 @@
       "scheduler": "SCHEDULER_FIFO",
       "priority": 45,
       "affinity": [1]
+    },
+    {
+      "name": "irq/*-s-mmc0",
+      "scheduler": "SCHEDULER_OTHER",
+      "nice": -20
+    },
+    {
+      "name": "irq/*-mmc0",
+      "scheduler": "SCHEDULER_OTHER",
+      "nice": -20
     }
   ]
 }