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

Commit f53fa6b5 authored by Siarhei Vishniakou's avatar Siarhei Vishniakou
Browse files

Only prioritize critical input threads

Input has several threads:
InputReader
InputClassifier (InputProcessor)
InputDispatcher
InputFilter
TraceProcessor

However, only two of them are in the critical path of the event
dispatch, and therefore, should be prioritized.

The others do not need to run with high priority.

In this CL, require that all InputThread's declare themselves as
critical or not, which would allow us to set their priority
appropriately.

Bug: 330719044
Test: perfetto trace
Flag: EXEMPT bugfix
Change-Id: Iaa7d7ed32557e1617884590562c3474b17d3a7f9
parent ec741152
Loading
Loading
Loading
Loading
+2 −1
Original line number Diff line number Diff line
@@ -44,7 +44,8 @@ public:
    InputFilterThread(std::shared_ptr<IInputThreadCallback> callback) : mCallback(callback) {
        mLooper = sp<Looper>::make(/*allowNonCallbacks=*/false);
        mThread = std::make_unique<InputThread>(
                "InputFilter", [this]() { loopOnce(); }, [this]() { mLooper->wake(); });
                "InputFilter", [this]() { loopOnce(); }, [this]() { mLooper->wake(); },
                /*isInCriticalPath=*/false);
    }

    ndk::ScopedAStatus finish() override {
+4 −3
Original line number Diff line number Diff line
@@ -45,11 +45,12 @@ private:

} // namespace

InputThread::InputThread(std::string name, std::function<void()> loop, std::function<void()> wake)
InputThread::InputThread(std::string name, std::function<void()> loop, std::function<void()> wake,
                         bool isInCriticalPath)
      : mName(name), mThreadWake(wake) {
    mThread = sp<InputThreadImpl>::make(loop);
    mThread->run(mName.c_str(), ANDROID_PRIORITY_URGENT_DISPLAY);
    if (input_flags::enable_input_policy_profile()) {
    if (input_flags::enable_input_policy_profile() && isInCriticalPath) {
        if (!applyInputEventProfile()) {
            LOG(ERROR) << "Couldn't apply input policy profile for " << name;
        }
+2 −1
Original line number Diff line number Diff line
@@ -981,7 +981,8 @@ status_t InputDispatcher::start() {
        return ALREADY_EXISTS;
    }
    mThread = std::make_unique<InputThread>(
            "InputDispatcher", [this]() { dispatchOnce(); }, [this]() { mLooper->wake(); });
            "InputDispatcher", [this]() { dispatchOnce(); }, [this]() { mLooper->wake(); },
            /*isInCriticalPath=*/true);
    return OK;
}

+1 −1
Original line number Diff line number Diff line
@@ -41,7 +41,7 @@ ThreadedBackend<Backend>::ThreadedBackend(Backend&& innerBackend)
      : mBackend(std::move(innerBackend)),
        mTracerThread(
                "InputTracer", [this]() { threadLoop(); },
                [this]() { mThreadWakeCondition.notify_all(); }) {}
                [this]() { mThreadWakeCondition.notify_all(); }, /*isInCriticalPath=*/false) {}

template <typename Backend>
ThreadedBackend<Backend>::~ThreadedBackend() {
+2 −2
Original line number Diff line number Diff line
@@ -28,8 +28,8 @@ namespace android {
 */
class InputThread {
public:
    explicit InputThread(std::string name, std::function<void()> loop,
                         std::function<void()> wake = nullptr);
    explicit InputThread(std::string name, std::function<void()> loop, std::function<void()> wake,
                         bool isInCriticalPath);
    virtual ~InputThread();

    bool isCallingThread();
Loading