android.frameworks.sensorservice@1.0: Looper thread SCHED_FIFO
Looper thread uses SCHED_FIFO with a priority 10.
Test: sensor works (sanity checks with camera app), logcat
doesn't show SCHED_FIFO could not be used
b/34386025 [Treble] Identify and fix Binder usage by camera HALs that isn't NDK-based
b/35219747 [Treble] Figure out the new interface between camera and sensor
b/36651814 [QCOM Treble] [REDACTED] Camera HAL uses Binder
b/36651420 [QCOM Treble] [REDACTED] location daemon uses Binder
Change-Id: I0f236a77cccdc8d67a933daf7d5046947c82a3cf
diff --git a/services/sensorservice/hidl/SensorManager.cpp b/services/sensorservice/hidl/SensorManager.cpp
index 0743fc3..06ff95c 100644
--- a/services/sensorservice/hidl/SensorManager.cpp
+++ b/services/sensorservice/hidl/SensorManager.cpp
@@ -22,12 +22,14 @@
#include "SensorManager.h"
+#include <sched.h>
+
+#include <thread>
+
#include "EventQueue.h"
#include "DirectReportChannel.h"
#include "utils.h"
-#include <thread>
-
namespace android {
namespace frameworks {
namespace sensorservice {
@@ -131,6 +133,14 @@
std::condition_variable looperSet;
std::thread{[&mutex = mLooperMutex, &looper = mLooper, &looperSet] {
+
+ struct sched_param p = {0};
+ p.sched_priority = 10;
+ if (sched_setscheduler(0 /* current thread*/, SCHED_FIFO, &p) != 0) {
+ LOG(WARNING) << "Could not use SCHED_FIFO for looper thread: "
+ << strerror(errno);
+ }
+
std::unique_lock<std::mutex> lock(mutex);
looper = Looper::prepare(ALOOPER_PREPARE_ALLOW_NON_CALLBACKS /* opts */);
lock.unlock();