Speed up LocklessQueueWakeUpper::Wakeup by inlining sched_setscheduler
We were checking and updating the soft limits (and taking no action...)
every time we sent a message which needed PI boosting (sender is lower
priority than the receiver).
Stop checking everything else and only do the sched_setscheduler call
inline. This takes ~50% CPU to ~25% CPU for our CAN processing code
processing 8k wakeups/sec.
Change-Id: I92fb5a89f6edcfaa9a47257eda401b5c05b3226a
Signed-off-by: Austin Schuh <austin.linux@gmail.com>
diff --git a/aos/ipc_lib/lockless_queue.cc b/aos/ipc_lib/lockless_queue.cc
index a26b564..9d14d8f 100644
--- a/aos/ipc_lib/lockless_queue.cc
+++ b/aos/ipc_lib/lockless_queue.cc
@@ -21,6 +21,7 @@
DEFINE_bool(dump_lockless_queue_data, false,
"If true, print the data out when dumping the queue.");
+DECLARE_bool(skip_realtime_scheduler);
namespace aos::ipc_lib {
namespace {
@@ -813,7 +814,19 @@
// Boost if we are RT and there is a higher priority sender out there.
// Otherwise we might run into priority inversions.
if (max_priority > current_priority && current_priority > 0) {
- SetCurrentThreadRealtimePriority(max_priority);
+ // Inline the setscheduler call rather than using aos/realtime.h. This is
+ // quite performance sensitive, and halves the time needed to send a
+ // message when pi boosting is in effect.
+ if (!FLAGS_skip_realtime_scheduler) {
+ // TODO(austin): Do we need to boost the soft limit here too like we
+ // were before?
+ struct sched_param param;
+ param.sched_priority = max_priority;
+ PCHECK(sched_setscheduler(0, SCHED_FIFO, ¶m) == 0)
+ << ": changing to SCHED_FIFO with " << max_priority
+ << ", if you want to bypass this check for testing, use "
+ "--skip_realtime_scheduler";
+ }
}
// Build up the siginfo to send.
@@ -842,7 +855,14 @@
// Drop back down if we were boosted.
if (max_priority > current_priority && current_priority > 0) {
- SetCurrentThreadRealtimePriority(current_priority);
+ if (!FLAGS_skip_realtime_scheduler) {
+ struct sched_param param;
+ param.sched_priority = current_priority;
+ PCHECK(sched_setscheduler(0, SCHED_FIFO, ¶m) == 0)
+ << ": changing to SCHED_FIFO with " << max_priority
+ << ", if you want to bypass this check for testing, use "
+ "--skip_realtime_scheduler";
+ }
}
}