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

Commit a9464874 authored by Matt Buckley's avatar Matt Buckley Committed by Android (Google) Code Review
Browse files

Merge "Create SessionManager in ADPF PowerAdvisor" into main

parents 125c5f3a c1b8d763
Loading
Loading
Loading
Loading
+1 −2
Original line number Diff line number Diff line
@@ -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\"",
@@ -79,7 +79,6 @@ cc_defaults {
        "libhidlbase",
        "liblog",
        "libnativewindow",
        "libpowermanager",
        "libprocessgroup",
        "libprotobuf-cpp-lite",
        "libstatslog_surfaceflinger",
+1 −1
Original line number Diff line number Diff line
@@ -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\"",
+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
+14 −5
Original line number Diff line number Diff line
@@ -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 {

@@ -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;
+16 −0
Original line number Diff line number Diff line
@@ -36,6 +36,8 @@
#include <ui/DisplayIdentification.h>
#include "../Scheduler/OneShotTimer.h"

#include "SessionManager.h"

using namespace std::chrono_literals;

namespace android {
@@ -47,6 +49,8 @@ class PowerHintSessionWrapper;

namespace adpf {

namespace hal = aidl::android::hardware::power;

class PowerAdvisor {
public:
    virtual ~PowerAdvisor() = default;
@@ -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 {
@@ -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;

@@ -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