Loading services/surfaceflinger/Android.bp +1 −2 Original line number Diff line number Diff line Loading @@ -42,12 +42,12 @@ cc_defaults { name: "libsurfaceflinger_defaults", defaults: [ "android.hardware.graphics.composer3-ndk_shared", "android.hardware.power-ndk_shared", "librenderengine_deps", "libtimestats_deps", "libsurfaceflinger_common_deps", "surfaceflinger_defaults", "libsurfaceflinger_proto_deps", "poweradvisor_deps", ], cflags: [ "-DLOG_TAG=\"SurfaceFlinger\"", Loading Loading @@ -79,7 +79,6 @@ cc_defaults { "libhidlbase", "liblog", "libnativewindow", "libpowermanager", "libprocessgroup", "libprotobuf-cpp-lite", "libstatslog_surfaceflinger", Loading services/surfaceflinger/CompositionEngine/Android.bp +1 −1 Original line number Diff line number Diff line Loading @@ -13,11 +13,11 @@ cc_defaults { defaults: [ "aconfig_lib_cc_static_link.defaults", "android.hardware.graphics.composer3-ndk_shared", "android.hardware.power-ndk_shared", "librenderengine_deps", "libtimestats_deps", "surfaceflinger_defaults", "libsurfaceflinger_proto_deps", "poweradvisor_deps", ], cflags: [ "-DLOG_TAG=\"CompositionEngine\"", Loading services/surfaceflinger/PowerAdvisor/Common.h 0 → 100644 +28 −0 Original line number Diff line number Diff line /* * Copyright 2024 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #pragma once #pragma clang diagnostic push #pragma clang diagnostic ignored "-Wconversion" #include <aidl/android/adpf/ISessionManager.h> #include <aidl/android/hardware/power/CompositionData.h> #pragma clang diagnostic pop namespace android::adpf { using namespace ::aidl::android::adpf; namespace hal = ::aidl::android::hardware::power; } // namespace android::adpf services/surfaceflinger/PowerAdvisor/PowerAdvisor.cpp +14 −5 Original line number Diff line number Diff line Loading @@ -28,22 +28,19 @@ #include <optional> #include <android-base/properties.h> #include <android/binder_libbinder.h> #include <common/trace.h> #include <utils/Log.h> #include <utils/Mutex.h> #include <binder/IServiceManager.h> #pragma clang diagnostic push #pragma clang diagnostic ignored "-Wconversion" #include <powermanager/PowerHalController.h> #include <powermanager/PowerHintSessionWrapper.h> #pragma clang diagnostic pop #include <common/FlagManager.h> #include "PowerAdvisor.h" namespace hal = aidl::android::hardware::power; #include "SessionManager.h" namespace android::adpf::impl { Loading Loading @@ -545,6 +542,18 @@ void PowerAdvisor::setTotalFrameTargetWorkDuration(Duration targetDuration) { mTotalFrameTargetDuration = targetDuration; } std::shared_ptr<SessionManager> PowerAdvisor::getSessionManager() { return mSessionManager; } sp<IBinder> PowerAdvisor::getOrCreateSessionManagerForBinder(uid_t uid) { // Flag guards the creation of SessionManager if (mSessionManager == nullptr && FlagManager::getInstance().adpf_native_session_manager()) { mSessionManager = ndk::SharedRefBase::make<SessionManager>(uid); } return AIBinder_toPlatformBinder(mSessionManager->asBinder().get()); } std::vector<DisplayId> PowerAdvisor::getOrderedDisplayIds( std::optional<TimePoint> DisplayTimingData::*sortBy) { std::vector<DisplayId> sortedDisplays; Loading services/surfaceflinger/PowerAdvisor/PowerAdvisor.h +16 −0 Original line number Diff line number Diff line Loading @@ -36,6 +36,8 @@ #include <ui/DisplayIdentification.h> #include "../Scheduler/OneShotTimer.h" #include "SessionManager.h" using namespace std::chrono_literals; namespace android { Loading @@ -47,6 +49,8 @@ class PowerHintSessionWrapper; namespace adpf { namespace hal = aidl::android::hardware::power; class PowerAdvisor { public: virtual ~PowerAdvisor() = default; Loading Loading @@ -102,12 +106,18 @@ public: virtual void setDisplays(std::vector<DisplayId>& displayIds) = 0; // Sets the target duration for the entire pipeline including the gpu virtual void setTotalFrameTargetWorkDuration(Duration targetDuration) = 0; // Get the session manager, if it exists virtual std::shared_ptr<SessionManager> getSessionManager() = 0; // --- The following methods may run on threads besides SF main --- // Send a hint about an upcoming increase in the CPU workload virtual void notifyCpuLoadUp() = 0; // Send a hint about the imminent start of a new CPU workload virtual void notifyDisplayUpdateImminentAndCpuReset() = 0; // --- The following methods specifically run on binder threads --- // Retrieve a SessionManager for HintManagerService to call virtual sp<IBinder> getOrCreateSessionManagerForBinder(uid_t uid) = 0; }; namespace impl { Loading Loading @@ -146,11 +156,15 @@ public: void setCompositeEnd(TimePoint compositeEndTime) override; void setDisplays(std::vector<DisplayId>& displayIds) override; void setTotalFrameTargetWorkDuration(Duration targetDuration) override; std::shared_ptr<SessionManager> getSessionManager() override; // --- The following methods may run on threads besides SF main --- void notifyCpuLoadUp() override; void notifyDisplayUpdateImminentAndCpuReset() override; // --- The following methods specifically run on binder threads --- sp<IBinder> getOrCreateSessionManagerForBinder(uid_t uid) override; private: friend class PowerAdvisorTest; Loading Loading @@ -323,6 +337,8 @@ private: template <aidl::android::hardware::power::ChannelMessage::ChannelMessageContents::Tag T, class In> bool writeHintSessionMessage(In* elements, size_t count) REQUIRES(mHintSessionMutex); std::shared_ptr<SessionManager> mSessionManager; }; } // namespace impl Loading Loading
services/surfaceflinger/Android.bp +1 −2 Original line number Diff line number Diff line Loading @@ -42,12 +42,12 @@ cc_defaults { name: "libsurfaceflinger_defaults", defaults: [ "android.hardware.graphics.composer3-ndk_shared", "android.hardware.power-ndk_shared", "librenderengine_deps", "libtimestats_deps", "libsurfaceflinger_common_deps", "surfaceflinger_defaults", "libsurfaceflinger_proto_deps", "poweradvisor_deps", ], cflags: [ "-DLOG_TAG=\"SurfaceFlinger\"", Loading Loading @@ -79,7 +79,6 @@ cc_defaults { "libhidlbase", "liblog", "libnativewindow", "libpowermanager", "libprocessgroup", "libprotobuf-cpp-lite", "libstatslog_surfaceflinger", Loading
services/surfaceflinger/CompositionEngine/Android.bp +1 −1 Original line number Diff line number Diff line Loading @@ -13,11 +13,11 @@ cc_defaults { defaults: [ "aconfig_lib_cc_static_link.defaults", "android.hardware.graphics.composer3-ndk_shared", "android.hardware.power-ndk_shared", "librenderengine_deps", "libtimestats_deps", "surfaceflinger_defaults", "libsurfaceflinger_proto_deps", "poweradvisor_deps", ], cflags: [ "-DLOG_TAG=\"CompositionEngine\"", Loading
services/surfaceflinger/PowerAdvisor/Common.h 0 → 100644 +28 −0 Original line number Diff line number Diff line /* * Copyright 2024 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #pragma once #pragma clang diagnostic push #pragma clang diagnostic ignored "-Wconversion" #include <aidl/android/adpf/ISessionManager.h> #include <aidl/android/hardware/power/CompositionData.h> #pragma clang diagnostic pop namespace android::adpf { using namespace ::aidl::android::adpf; namespace hal = ::aidl::android::hardware::power; } // namespace android::adpf
services/surfaceflinger/PowerAdvisor/PowerAdvisor.cpp +14 −5 Original line number Diff line number Diff line Loading @@ -28,22 +28,19 @@ #include <optional> #include <android-base/properties.h> #include <android/binder_libbinder.h> #include <common/trace.h> #include <utils/Log.h> #include <utils/Mutex.h> #include <binder/IServiceManager.h> #pragma clang diagnostic push #pragma clang diagnostic ignored "-Wconversion" #include <powermanager/PowerHalController.h> #include <powermanager/PowerHintSessionWrapper.h> #pragma clang diagnostic pop #include <common/FlagManager.h> #include "PowerAdvisor.h" namespace hal = aidl::android::hardware::power; #include "SessionManager.h" namespace android::adpf::impl { Loading Loading @@ -545,6 +542,18 @@ void PowerAdvisor::setTotalFrameTargetWorkDuration(Duration targetDuration) { mTotalFrameTargetDuration = targetDuration; } std::shared_ptr<SessionManager> PowerAdvisor::getSessionManager() { return mSessionManager; } sp<IBinder> PowerAdvisor::getOrCreateSessionManagerForBinder(uid_t uid) { // Flag guards the creation of SessionManager if (mSessionManager == nullptr && FlagManager::getInstance().adpf_native_session_manager()) { mSessionManager = ndk::SharedRefBase::make<SessionManager>(uid); } return AIBinder_toPlatformBinder(mSessionManager->asBinder().get()); } std::vector<DisplayId> PowerAdvisor::getOrderedDisplayIds( std::optional<TimePoint> DisplayTimingData::*sortBy) { std::vector<DisplayId> sortedDisplays; Loading
services/surfaceflinger/PowerAdvisor/PowerAdvisor.h +16 −0 Original line number Diff line number Diff line Loading @@ -36,6 +36,8 @@ #include <ui/DisplayIdentification.h> #include "../Scheduler/OneShotTimer.h" #include "SessionManager.h" using namespace std::chrono_literals; namespace android { Loading @@ -47,6 +49,8 @@ class PowerHintSessionWrapper; namespace adpf { namespace hal = aidl::android::hardware::power; class PowerAdvisor { public: virtual ~PowerAdvisor() = default; Loading Loading @@ -102,12 +106,18 @@ public: virtual void setDisplays(std::vector<DisplayId>& displayIds) = 0; // Sets the target duration for the entire pipeline including the gpu virtual void setTotalFrameTargetWorkDuration(Duration targetDuration) = 0; // Get the session manager, if it exists virtual std::shared_ptr<SessionManager> getSessionManager() = 0; // --- The following methods may run on threads besides SF main --- // Send a hint about an upcoming increase in the CPU workload virtual void notifyCpuLoadUp() = 0; // Send a hint about the imminent start of a new CPU workload virtual void notifyDisplayUpdateImminentAndCpuReset() = 0; // --- The following methods specifically run on binder threads --- // Retrieve a SessionManager for HintManagerService to call virtual sp<IBinder> getOrCreateSessionManagerForBinder(uid_t uid) = 0; }; namespace impl { Loading Loading @@ -146,11 +156,15 @@ public: void setCompositeEnd(TimePoint compositeEndTime) override; void setDisplays(std::vector<DisplayId>& displayIds) override; void setTotalFrameTargetWorkDuration(Duration targetDuration) override; std::shared_ptr<SessionManager> getSessionManager() override; // --- The following methods may run on threads besides SF main --- void notifyCpuLoadUp() override; void notifyDisplayUpdateImminentAndCpuReset() override; // --- The following methods specifically run on binder threads --- sp<IBinder> getOrCreateSessionManagerForBinder(uid_t uid) override; private: friend class PowerAdvisorTest; Loading Loading @@ -323,6 +337,8 @@ private: template <aidl::android::hardware::power::ChannelMessage::ChannelMessageContents::Tag T, class In> bool writeHintSessionMessage(In* elements, size_t count) REQUIRES(mHintSessionMutex); std::shared_ptr<SessionManager> mSessionManager; }; } // namespace impl Loading