From f53fa6b562d6608197329b94e796012e18d11dc7 Mon Sep 17 00:00:00 2001 From: Siarhei Vishniakou Date: Thu, 19 Sep 2024 17:42:42 -0700 Subject: 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 --- services/inputflinger/InputThread.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'services/inputflinger/InputThread.cpp') diff --git a/services/inputflinger/InputThread.cpp b/services/inputflinger/InputThread.cpp index 449eb45b4b..bd4b192e22 100644 --- a/services/inputflinger/InputThread.cpp +++ b/services/inputflinger/InputThread.cpp @@ -45,11 +45,12 @@ private: } // namespace -InputThread::InputThread(std::string name, std::function loop, std::function wake) +InputThread::InputThread(std::string name, std::function loop, std::function wake, + bool isInCriticalPath) : mName(name), mThreadWake(wake) { mThread = sp::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; } @@ -84,4 +85,4 @@ bool InputThread::applyInputEventProfile() { #endif } -} // namespace android \ No newline at end of file +} // namespace android -- cgit v1.2.3-59-g8ed1b From a925de1e1487c1f08e690fd1390163b5ceaf7bd6 Mon Sep 17 00:00:00 2001 From: Siarhei Vishniakou Date: Thu, 19 Sep 2024 19:02:24 -0700 Subject: Move applyInputEventProfile to cpp file This is an implementation detail, so it doesn't need to be exposed in the header file at all. Bug: 330719044 Flag: EXEMPT refactor Test: none Change-Id: I54b0bac26f1a3a77a2b5c5a43a3d3e7f5a42a20d --- services/inputflinger/InputThread.cpp | 26 +++++++++++++------------- services/inputflinger/include/InputThread.h | 2 -- 2 files changed, 13 insertions(+), 15 deletions(-) (limited to 'services/inputflinger/InputThread.cpp') diff --git a/services/inputflinger/InputThread.cpp b/services/inputflinger/InputThread.cpp index bd4b192e22..7cf4e397f9 100644 --- a/services/inputflinger/InputThread.cpp +++ b/services/inputflinger/InputThread.cpp @@ -26,6 +26,16 @@ namespace input_flags = com::android::input::flags; namespace { +bool applyInputEventProfile(const Thread& thread) { +#if defined(__ANDROID__) + return SetTaskProfiles(thread.getTid(), {"InputPolicy"}); +#else + // Since thread information is not available and there's no benefit of + // applying the task profile on host, return directly. + return true; +#endif +} + // Implementation of Thread from libutils. class InputThreadImpl : public Thread { public: @@ -47,11 +57,11 @@ private: InputThread::InputThread(std::string name, std::function loop, std::function wake, bool isInCriticalPath) - : mName(name), mThreadWake(wake) { + : mThreadWake(wake) { mThread = sp::make(loop); - mThread->run(mName.c_str(), ANDROID_PRIORITY_URGENT_DISPLAY); + mThread->run(name.c_str(), ANDROID_PRIORITY_URGENT_DISPLAY); if (input_flags::enable_input_policy_profile() && isInCriticalPath) { - if (!applyInputEventProfile()) { + if (!applyInputEventProfile(*mThread)) { LOG(ERROR) << "Couldn't apply input policy profile for " << name; } } @@ -75,14 +85,4 @@ bool InputThread::isCallingThread() { #endif } -bool InputThread::applyInputEventProfile() { -#if defined(__ANDROID__) - return SetTaskProfiles(mThread->getTid(), {"InputPolicy"}); -#else - // Since thread information is not available and there's no benefit of - // applying the task profile on host, return directly. - return true; -#endif -} - } // namespace android diff --git a/services/inputflinger/include/InputThread.h b/services/inputflinger/include/InputThread.h index 595f5a2b9e..ed92b8f949 100644 --- a/services/inputflinger/include/InputThread.h +++ b/services/inputflinger/include/InputThread.h @@ -35,10 +35,8 @@ public: bool isCallingThread(); private: - std::string mName; std::function mThreadWake; sp mThread; - bool applyInputEventProfile(); }; } // namespace android -- cgit v1.2.3-59-g8ed1b