Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 283854bb authored by Peng Xu's avatar Peng Xu Committed by Android (Google) Code Review
Browse files

Merge "Tune SensorService thread priority, lower sensor event latency" into nyc-mr1-dev

parents 6d7d099b 98d30f62
Loading
Loading
Loading
Loading
+14 −0
Original line number Diff line number Diff line
@@ -47,6 +47,7 @@

#include <inttypes.h>
#include <math.h>
#include <sched.h>
#include <stdint.h>
#include <sys/socket.h>
#include <sys/stat.h>
@@ -71,6 +72,7 @@ bool SensorService::sHmacGlobalKeyIsValid = false;

#define SENSOR_SERVICE_DIR "/data/system/sensor_service"
#define SENSOR_SERVICE_HMAC_KEY_FILE  SENSOR_SERVICE_DIR "/hmac_key"
#define SENSOR_SERVICE_SCHED_FIFO_PRIORITY 10

// Permissions.
static const String16 sDump("android.permission.DUMP");
@@ -117,6 +119,15 @@ bool SensorService::initializeHmacKey() {
    return true;
}

// Set main thread to SCHED_FIFO to lower sensor event latency when system is under load
void SensorService::enableSchedFifoMode() {
    struct sched_param param = {0};
    param.sched_priority = SENSOR_SERVICE_SCHED_FIFO_PRIORITY;
    if (sched_setscheduler(getTid(), SCHED_FIFO | SCHED_RESET_ON_FORK, &param) != 0) {
        ALOGE("Couldn't set SCHED_FIFO for SensorService thread");
    }
}

void SensorService::onFirstRef() {
    ALOGD("nuSensorService starting...");
    SensorDevice& dev(SensorDevice::getInstance());
@@ -261,6 +272,9 @@ void SensorService::onFirstRef() {
            mAckReceiver = new SensorEventAckReceiver(this);
            mAckReceiver->run("SensorEventAckReceiver", PRIORITY_URGENT_DISPLAY);
            run("SensorService", PRIORITY_URGENT_DISPLAY);

            // priority can only be changed after run
            enableSchedFifoMode();
        }
    }
}
+2 −0
Original line number Diff line number Diff line
@@ -215,6 +215,8 @@ private:
    // Either read from storage or create a new one.
    static bool initializeHmacKey();

    // Enable SCHED_FIFO priority for thread
    void enableSchedFifoMode();

    static uint8_t sHmacGlobalKey[128];
    static bool sHmacGlobalKeyIsValid;