Merge "Revert "Revert "Increase HidRawSensor thread priority to reduce latency""" into main am: 095c6960f8

Original change: https://android-review.googlesource.com/c/platform/hardware/libhardware/+/2755006

Change-Id: Ibdee07646502b1b4f494486d23bab55d1b567894
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
This commit is contained in:
Treehugger Robot 2023-09-18 22:21:39 +00:00 committed by Automerger Merge Worker
commit 60b7e3a576
2 changed files with 12 additions and 1 deletions

View file

@ -35,6 +35,15 @@ using namespace Hid::Sensor::PropertyUsage;
const std::unordered_set<unsigned int> HidRawSensorDevice::sInterested{ const std::unordered_set<unsigned int> HidRawSensorDevice::sInterested{
ACCELEROMETER_3D, GYROMETER_3D, COMPASS_3D, CUSTOM}; ACCELEROMETER_3D, GYROMETER_3D, COMPASS_3D, CUSTOM};
void HidRawSensorDevice::enableSchedFifoMode() {
constexpr int kHidRawSensorPriority = 10; // Matches with sensor service priority
struct sched_param param = {0};
param.sched_priority = kHidRawSensorPriority;
if (sched_setscheduler(getTid(), SCHED_FIFO | SCHED_RESET_ON_FORK, &param) != 0) {
ALOGE("Couldn't set SCHED_FIFO for HidRawSensor thread: %s", strerror(errno));
}
}
sp<HidRawSensorDevice> HidRawSensorDevice::create(const std::string &devName) { sp<HidRawSensorDevice> HidRawSensorDevice::create(const std::string &devName) {
sp<HidRawSensorDevice> device(new HidRawSensorDevice(devName)); sp<HidRawSensorDevice> device(new HidRawSensorDevice(devName));
// offset +1 strong count added by constructor // offset +1 strong count added by constructor
@ -74,7 +83,8 @@ HidRawSensorDevice::HidRawSensorDevice(const std::string &devName)
return; return;
} }
run("HidRawSensor"); run("HidRawSensor", PRIORITY_URGENT_DISPLAY);
enableSchedFifoMode();
mValid = true; mValid = true;
} }

View file

@ -41,6 +41,7 @@ private:
// constructor will result in +1 strong count // constructor will result in +1 strong count
explicit HidRawSensorDevice(const std::string &devName); explicit HidRawSensorDevice(const std::string &devName);
void enableSchedFifoMode();
// implement function of Thread // implement function of Thread
virtual bool threadLoop() override; virtual bool threadLoop() override;
std::unordered_map<unsigned int/*reportId*/, sp<HidRawSensor>> mSensors; std::unordered_map<unsigned int/*reportId*/, sp<HidRawSensor>> mSensors;