sm6375-common: power-libperfmgr: improve adpf logic
Cache active state and reduce log spam Add value tracing into libperfmgr Use adaptive stale timeout based on rate limit Bug: 191331719 Bug: 191296994 Bug: 177493042 Test: boot Signed-off-by: Wei Wang <wvw@google.com> Change-Id: I1c1484c9277209bf68bd287ceae83e2b37684c62
This commit is contained in:
parent
7b56c41f2d
commit
36addfaf7c
6 changed files with 84 additions and 73 deletions
|
@ -55,7 +55,8 @@ Power::Power(std::shared_ptr<HintManager> hm)
|
||||||
: mHintManager(hm),
|
: mHintManager(hm),
|
||||||
mInteractionHandler(nullptr),
|
mInteractionHandler(nullptr),
|
||||||
mSustainedPerfModeOn(false),
|
mSustainedPerfModeOn(false),
|
||||||
mAdpfRate(::android::base::GetIntProperty(kPowerHalAdpfRateProp, kPowerHalAdpfRateDefault)) {
|
mAdpfRateNs(
|
||||||
|
::android::base::GetIntProperty(kPowerHalAdpfRateProp, kPowerHalAdpfRateDefault)) {
|
||||||
mInteractionHandler = std::make_unique<InteractionHandler>(mHintManager);
|
mInteractionHandler = std::make_unique<InteractionHandler>(mHintManager);
|
||||||
mInteractionHandler->Init();
|
mInteractionHandler->Init();
|
||||||
|
|
||||||
|
@ -81,7 +82,7 @@ Power::Power(std::shared_ptr<HintManager> hm)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Now start to take powerhint
|
// Now start to take powerhint
|
||||||
LOG(INFO) << "PowerHAL ready to take hints, Adpf update rate: " << mAdpfRate;
|
LOG(INFO) << "PowerHAL ready to take hints, Adpf update rate: " << mAdpfRateNs;
|
||||||
}
|
}
|
||||||
|
|
||||||
ndk::ScopedAStatus Power::setMode(Mode type, bool enabled) {
|
ndk::ScopedAStatus Power::setMode(Mode type, bool enabled) {
|
||||||
|
@ -200,7 +201,6 @@ binder_status_t Power::dump(int fd, const char **, uint32_t) {
|
||||||
if (!::android::base::WriteStringToFd(buf, fd)) {
|
if (!::android::base::WriteStringToFd(buf, fd)) {
|
||||||
PLOG(ERROR) << "Failed to dump state to fd";
|
PLOG(ERROR) << "Failed to dump state to fd";
|
||||||
}
|
}
|
||||||
// TODO(jimmyshiu@): dump weak_ptr of PowerHintSession
|
|
||||||
fsync(fd);
|
fsync(fd);
|
||||||
return STATUS_OK;
|
return STATUS_OK;
|
||||||
}
|
}
|
||||||
|
@ -209,7 +209,7 @@ ndk::ScopedAStatus Power::createHintSession(int32_t tgid, int32_t uid,
|
||||||
const std::vector<int32_t> &threadIds,
|
const std::vector<int32_t> &threadIds,
|
||||||
int64_t durationNanos,
|
int64_t durationNanos,
|
||||||
std::shared_ptr<IPowerHintSession> *_aidl_return) {
|
std::shared_ptr<IPowerHintSession> *_aidl_return) {
|
||||||
if (mAdpfRate == -1) {
|
if (mAdpfRateNs <= 0) {
|
||||||
*_aidl_return = nullptr;
|
*_aidl_return = nullptr;
|
||||||
return ndk::ScopedAStatus::fromExceptionCode(EX_UNSUPPORTED_OPERATION);
|
return ndk::ScopedAStatus::fromExceptionCode(EX_UNSUPPORTED_OPERATION);
|
||||||
}
|
}
|
||||||
|
@ -218,15 +218,15 @@ ndk::ScopedAStatus Power::createHintSession(int32_t tgid, int32_t uid,
|
||||||
*_aidl_return = nullptr;
|
*_aidl_return = nullptr;
|
||||||
return ndk::ScopedAStatus::fromExceptionCode(EX_ILLEGAL_ARGUMENT);
|
return ndk::ScopedAStatus::fromExceptionCode(EX_ILLEGAL_ARGUMENT);
|
||||||
}
|
}
|
||||||
std::shared_ptr<IPowerHintSession> session =
|
std::shared_ptr<IPowerHintSession> session = ndk::SharedRefBase::make<PowerHintSession>(
|
||||||
ndk::SharedRefBase::make<PowerHintSession>(tgid, uid, threadIds, durationNanos);
|
tgid, uid, threadIds, durationNanos, nanoseconds(mAdpfRateNs));
|
||||||
*_aidl_return = session;
|
*_aidl_return = session;
|
||||||
return ndk::ScopedAStatus::ok();
|
return ndk::ScopedAStatus::ok();
|
||||||
}
|
}
|
||||||
|
|
||||||
ndk::ScopedAStatus Power::getHintSessionPreferredRate(int64_t *outNanoseconds) {
|
ndk::ScopedAStatus Power::getHintSessionPreferredRate(int64_t *outNanoseconds) {
|
||||||
*outNanoseconds = mAdpfRate;
|
*outNanoseconds = mAdpfRateNs;
|
||||||
if (mAdpfRate == -1) {
|
if (mAdpfRateNs <= 0) {
|
||||||
return ndk::ScopedAStatus::fromExceptionCode(EX_UNSUPPORTED_OPERATION);
|
return ndk::ScopedAStatus::fromExceptionCode(EX_UNSUPPORTED_OPERATION);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -55,7 +55,7 @@ class Power : public ::aidl::android::hardware::power::BnPower {
|
||||||
std::shared_ptr<HintManager> mHintManager;
|
std::shared_ptr<HintManager> mHintManager;
|
||||||
std::unique_ptr<InteractionHandler> mInteractionHandler;
|
std::unique_ptr<InteractionHandler> mInteractionHandler;
|
||||||
std::atomic<bool> mSustainedPerfModeOn;
|
std::atomic<bool> mSustainedPerfModeOn;
|
||||||
const int64_t mAdpfRate;
|
const int64_t mAdpfRateNs;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace pixel
|
} // namespace pixel
|
||||||
|
|
|
@ -51,7 +51,7 @@ constexpr char kPowerHalAdpfPidInitialIntegral[] = "vendor.powerhal.adpf.pid.i_i
|
||||||
constexpr char kPowerHalAdpfUclampEnable[] = "vendor.powerhal.adpf.uclamp";
|
constexpr char kPowerHalAdpfUclampEnable[] = "vendor.powerhal.adpf.uclamp";
|
||||||
constexpr char kPowerHalAdpfUclampCapRatio[] = "vendor.powerhal.adpf.uclamp.cap_ratio";
|
constexpr char kPowerHalAdpfUclampCapRatio[] = "vendor.powerhal.adpf.uclamp.cap_ratio";
|
||||||
constexpr char kPowerHalAdpfUclampGranularity[] = "vendor.powerhal.adpf.uclamp.granularity";
|
constexpr char kPowerHalAdpfUclampGranularity[] = "vendor.powerhal.adpf.uclamp.granularity";
|
||||||
constexpr char kPowerHalAdpfStaleTimeout[] = "vendor.powerhal.adpf.stale_timeout_ms";
|
constexpr char kPowerHalAdpfStaleTimeFactor[] = "vendor.powerhal.adpf.stale_timeout_factor";
|
||||||
constexpr char kPowerHalAdpfSamplingWindow[] = "vendor.powerhal.adpf.sampling_window";
|
constexpr char kPowerHalAdpfSamplingWindow[] = "vendor.powerhal.adpf.sampling_window";
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
@ -83,8 +83,8 @@ static inline void TRACE_ADPF_PID(uintptr_t session_id, int32_t uid, int32_t tgi
|
||||||
int64_t err, int64_t integral, int64_t previous, int64_t p,
|
int64_t err, int64_t integral, int64_t previous, int64_t p,
|
||||||
int64_t i, int64_t d, int32_t output) {
|
int64_t i, int64_t d, int32_t output) {
|
||||||
if (ATRACE_ENABLED()) {
|
if (ATRACE_ENABLED()) {
|
||||||
std::string idstr = StringPrintf("adpf.%" PRId32 "-%" PRId32 "-%" PRIxPTR, tgid, uid,
|
const std::string idstr = StringPrintf("adpf.%" PRId32 "-%" PRId32 "-%" PRIxPTR, tgid, uid,
|
||||||
session_id & 0xffff);
|
session_id & 0xffff);
|
||||||
std::string sz = StringPrintf("%s-pid.count", idstr.c_str());
|
std::string sz = StringPrintf("%s-pid.count", idstr.c_str());
|
||||||
ATRACE_INT(sz.c_str(), count);
|
ATRACE_INT(sz.c_str(), count);
|
||||||
sz = StringPrintf("%s-pid.err", idstr.c_str());
|
sz = StringPrintf("%s-pid.err", idstr.c_str());
|
||||||
|
@ -104,11 +104,11 @@ static inline void TRACE_ADPF_PID(uintptr_t session_id, int32_t uid, int32_t tgi
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static int64_t ns_to_100us(int64_t ns) {
|
static inline int64_t ns_to_100us(int64_t ns) {
|
||||||
return ns / 100000;
|
return ns / 100000;
|
||||||
}
|
}
|
||||||
|
|
||||||
double getDoubleProperty(const char *prop, double value) {
|
static double getDoubleProperty(const char *prop, double value) {
|
||||||
std::string result = ::android::base::GetProperty(prop, std::to_string(value).c_str());
|
std::string result = ::android::base::GetProperty(prop, std::to_string(value).c_str());
|
||||||
if (!::android::base::ParseDouble(result.c_str(), &value)) {
|
if (!::android::base::ParseDouble(result.c_str(), &value)) {
|
||||||
ALOGE("PowerHintSession : failed to parse double in %s", prop);
|
ALOGE("PowerHintSession : failed to parse double in %s", prop);
|
||||||
|
@ -134,51 +134,53 @@ static const int sUclampCap =
|
||||||
static_cast<int>(getDoubleProperty(kPowerHalAdpfUclampCapRatio, 0.5) * 1024);
|
static_cast<int>(getDoubleProperty(kPowerHalAdpfUclampCapRatio, 0.5) * 1024);
|
||||||
static const uint32_t sUclampGranularity =
|
static const uint32_t sUclampGranularity =
|
||||||
::android::base::GetUintProperty<uint32_t>(kPowerHalAdpfUclampGranularity, 5);
|
::android::base::GetUintProperty<uint32_t>(kPowerHalAdpfUclampGranularity, 5);
|
||||||
static const int64_t sStaleTimeoutMs =
|
static const int64_t sStaleTimeFactor =
|
||||||
::android::base::GetIntProperty<int64_t>(kPowerHalAdpfStaleTimeout, 3000);
|
::android::base::GetIntProperty<int64_t>(kPowerHalAdpfStaleTimeFactor, 20);
|
||||||
static const size_t sSamplingWindow =
|
static const size_t sSamplingWindow =
|
||||||
::android::base::GetUintProperty<size_t>(kPowerHalAdpfSamplingWindow, 1);
|
::android::base::GetUintProperty<size_t>(kPowerHalAdpfSamplingWindow, 1);
|
||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
PowerHintSession::PowerHintSession(int32_t tgid, int32_t uid, const std::vector<int32_t> &threadIds,
|
PowerHintSession::PowerHintSession(int32_t tgid, int32_t uid, const std::vector<int32_t> &threadIds,
|
||||||
int64_t durationNanos) {
|
int64_t durationNanos, const nanoseconds adpfRate)
|
||||||
|
: kAdpfRate(adpfRate) {
|
||||||
mDescriptor = new AppHintDesc(tgid, uid, threadIds, sUclampCap);
|
mDescriptor = new AppHintDesc(tgid, uid, threadIds, sUclampCap);
|
||||||
mDescriptor->duration = std::chrono::nanoseconds(durationNanos);
|
mDescriptor->duration = std::chrono::nanoseconds(durationNanos);
|
||||||
mStaleHandler = sp<StaleHandler>(new StaleHandler(this, sStaleTimeoutMs));
|
mStaleHandler = sp<StaleHandler>(new StaleHandler(this));
|
||||||
mPowerManagerHandler = PowerSessionManager::getInstance();
|
mPowerManagerHandler = PowerSessionManager::getInstance();
|
||||||
|
|
||||||
if (ATRACE_ENABLED()) {
|
if (ATRACE_ENABLED()) {
|
||||||
std::string sz =
|
const std::string idstr = getIdString();
|
||||||
StringPrintf("adpf.%" PRId32 "-%" PRId32 "-%" PRIxPTR "-target", mDescriptor->tgid,
|
std::string sz = StringPrintf("%s-target", idstr.c_str());
|
||||||
mDescriptor->uid, reinterpret_cast<uintptr_t>(this) & 0xffff);
|
|
||||||
ATRACE_INT(sz.c_str(), (int64_t)mDescriptor->duration.count());
|
ATRACE_INT(sz.c_str(), (int64_t)mDescriptor->duration.count());
|
||||||
sz = StringPrintf("adpf.%" PRId32 "-%" PRId32 "-%" PRIxPTR "-active", mDescriptor->tgid,
|
sz = StringPrintf("%s-active", idstr.c_str());
|
||||||
mDescriptor->uid, reinterpret_cast<uintptr_t>(this) & 0xffff);
|
|
||||||
ATRACE_INT(sz.c_str(), mDescriptor->is_active.load());
|
ATRACE_INT(sz.c_str(), mDescriptor->is_active.load());
|
||||||
}
|
}
|
||||||
PowerSessionManager::getInstance()->addPowerSession(this);
|
PowerSessionManager::getInstance()->addPowerSession(this);
|
||||||
ALOGD("PowerHintSession created: %s", mDescriptor->toString().c_str());
|
ALOGV("PowerHintSession created: %s", mDescriptor->toString().c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
PowerHintSession::~PowerHintSession() {
|
PowerHintSession::~PowerHintSession() {
|
||||||
close();
|
close();
|
||||||
ALOGD("PowerHintSession deleted: %s", mDescriptor->toString().c_str());
|
ALOGV("PowerHintSession deleted: %s", mDescriptor->toString().c_str());
|
||||||
if (ATRACE_ENABLED()) {
|
if (ATRACE_ENABLED()) {
|
||||||
std::string sz =
|
const std::string idstr = getIdString();
|
||||||
StringPrintf("adpf.%" PRId32 "-%" PRId32 "-%" PRIxPTR "-target", mDescriptor->tgid,
|
std::string sz = StringPrintf("%s-target", idstr.c_str());
|
||||||
mDescriptor->uid, reinterpret_cast<uintptr_t>(this) & 0xffff);
|
|
||||||
ATRACE_INT(sz.c_str(), 0);
|
ATRACE_INT(sz.c_str(), 0);
|
||||||
sz = StringPrintf("adpf.%" PRId32 "-%" PRId32 "-%" PRIxPTR "-actl_last", mDescriptor->tgid,
|
sz = StringPrintf("%s-actl_last", idstr.c_str());
|
||||||
mDescriptor->uid, reinterpret_cast<uintptr_t>(this) & 0xffff);
|
|
||||||
ATRACE_INT(sz.c_str(), 0);
|
ATRACE_INT(sz.c_str(), 0);
|
||||||
sz = StringPrintf("adpf.%" PRId32 "-%" PRId32 "-%" PRIxPTR "-active", mDescriptor->tgid,
|
sz = sz = StringPrintf("%s-active", idstr.c_str());
|
||||||
mDescriptor->uid, reinterpret_cast<uintptr_t>(this) & 0xffff);
|
|
||||||
ATRACE_INT(sz.c_str(), 0);
|
ATRACE_INT(sz.c_str(), 0);
|
||||||
}
|
}
|
||||||
delete mDescriptor;
|
delete mDescriptor;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::string PowerHintSession::getIdString() const {
|
||||||
|
std::string idstr = StringPrintf("%" PRId32 "-%" PRId32 "-%" PRIxPTR, mDescriptor->tgid,
|
||||||
|
mDescriptor->uid, reinterpret_cast<uintptr_t>(this) & 0xffff);
|
||||||
|
return idstr;
|
||||||
|
}
|
||||||
|
|
||||||
void PowerHintSession::updateUniveralBoostMode() {
|
void PowerHintSession::updateUniveralBoostMode() {
|
||||||
PowerHintMonitor::getInstance()->getLooper()->sendMessage(mPowerManagerHandler, NULL);
|
PowerHintMonitor::getInstance()->getLooper()->sendMessage(mPowerManagerHandler, NULL);
|
||||||
}
|
}
|
||||||
|
@ -194,9 +196,6 @@ int PowerHintSession::setUclamp(int32_t min, int32_t max) {
|
||||||
StringPrintf("adpf.%" PRId32 "-%" PRId32 "-%" PRIxPTR "-min", mDescriptor->tgid,
|
StringPrintf("adpf.%" PRId32 "-%" PRId32 "-%" PRIxPTR "-min", mDescriptor->tgid,
|
||||||
mDescriptor->uid, reinterpret_cast<uintptr_t>(this) & 0xffff);
|
mDescriptor->uid, reinterpret_cast<uintptr_t>(this) & 0xffff);
|
||||||
ATRACE_INT(sz.c_str(), min);
|
ATRACE_INT(sz.c_str(), min);
|
||||||
sz = StringPrintf("adpf.%" PRId32 "-%" PRId32 "-%" PRIxPTR "-max", mDescriptor->tgid,
|
|
||||||
mDescriptor->uid, reinterpret_cast<uintptr_t>(this) & 0xffff);
|
|
||||||
ATRACE_INT(sz.c_str(), max);
|
|
||||||
}
|
}
|
||||||
for (const auto tid : mDescriptor->threadIds) {
|
for (const auto tid : mDescriptor->threadIds) {
|
||||||
sched_attr attr = {};
|
sched_attr attr = {};
|
||||||
|
@ -223,7 +222,7 @@ ndk::ScopedAStatus PowerHintSession::pause() {
|
||||||
mDescriptor->is_active.store(false);
|
mDescriptor->is_active.store(false);
|
||||||
if (ATRACE_ENABLED()) {
|
if (ATRACE_ENABLED()) {
|
||||||
std::string sz =
|
std::string sz =
|
||||||
StringPrintf("%" PRId32 "-%" PRId32 "-%" PRIxPTR "-active", mDescriptor->tgid,
|
StringPrintf("adpf.%" PRId32 "-%" PRId32 "-%" PRIxPTR "-active", mDescriptor->tgid,
|
||||||
mDescriptor->uid, reinterpret_cast<uintptr_t>(this) & 0xffff);
|
mDescriptor->uid, reinterpret_cast<uintptr_t>(this) & 0xffff);
|
||||||
ATRACE_INT(sz.c_str(), mDescriptor->is_active.load());
|
ATRACE_INT(sz.c_str(), mDescriptor->is_active.load());
|
||||||
}
|
}
|
||||||
|
@ -238,7 +237,7 @@ ndk::ScopedAStatus PowerHintSession::resume() {
|
||||||
mDescriptor->integral_error = std::max(sPidIInit, mDescriptor->integral_error);
|
mDescriptor->integral_error = std::max(sPidIInit, mDescriptor->integral_error);
|
||||||
if (ATRACE_ENABLED()) {
|
if (ATRACE_ENABLED()) {
|
||||||
std::string sz =
|
std::string sz =
|
||||||
StringPrintf("%" PRId32 "-%" PRId32 "-%" PRIxPTR "-active", mDescriptor->tgid,
|
StringPrintf("adpf.%" PRId32 "-%" PRId32 "-%" PRIxPTR "-active", mDescriptor->tgid,
|
||||||
mDescriptor->uid, reinterpret_cast<uintptr_t>(this) & 0xffff);
|
mDescriptor->uid, reinterpret_cast<uintptr_t>(this) & 0xffff);
|
||||||
ATRACE_INT(sz.c_str(), mDescriptor->is_active.load());
|
ATRACE_INT(sz.c_str(), mDescriptor->is_active.load());
|
||||||
}
|
}
|
||||||
|
@ -303,25 +302,15 @@ ndk::ScopedAStatus PowerHintSession::reportActualWorkDuration(
|
||||||
int64_t targetDurationNanos = (int64_t)mDescriptor->duration.count();
|
int64_t targetDurationNanos = (int64_t)mDescriptor->duration.count();
|
||||||
size_t length = actualDurations.size();
|
size_t length = actualDurations.size();
|
||||||
size_t start = sSamplingWindow == 0 || sSamplingWindow > length ? 0 : length - sSamplingWindow;
|
size_t start = sSamplingWindow == 0 || sSamplingWindow > length ? 0 : length - sSamplingWindow;
|
||||||
int64_t actualDurationNanos = 0;
|
|
||||||
int64_t dt = ns_to_100us(targetDurationNanos);
|
int64_t dt = ns_to_100us(targetDurationNanos);
|
||||||
int64_t error = 0;
|
int64_t error = 0;
|
||||||
int64_t derivative = 0;
|
int64_t derivative = 0;
|
||||||
for (size_t i = start; i < length; i++) {
|
for (size_t i = start; i < length; i++) {
|
||||||
actualDurationNanos = actualDurations[i].durationNanos;
|
int64_t actualDurationNanos = actualDurations[i].durationNanos;
|
||||||
if (std::abs(actualDurationNanos) > targetDurationNanos * 20) {
|
if (std::abs(actualDurationNanos) > targetDurationNanos * 20) {
|
||||||
ALOGW("The actual duration is way far from the target (%" PRId64 " >> %" PRId64 ")",
|
ALOGW("The actual duration is way far from the target (%" PRId64 " >> %" PRId64 ")",
|
||||||
actualDurationNanos, targetDurationNanos);
|
actualDurationNanos, targetDurationNanos);
|
||||||
}
|
}
|
||||||
if (ATRACE_ENABLED()) {
|
|
||||||
std::string sz = StringPrintf("adpf.%" PRId32 "-%" PRId32 "-%" PRIxPTR "-actl_last",
|
|
||||||
mDescriptor->tgid, mDescriptor->uid,
|
|
||||||
reinterpret_cast<uintptr_t>(this) & 0xffff);
|
|
||||||
ATRACE_INT(sz.c_str(), actualDurationNanos);
|
|
||||||
sz = StringPrintf("adpf.%" PRId32 "-%" PRId32 "-%" PRIxPTR "-target", mDescriptor->tgid,
|
|
||||||
mDescriptor->uid, reinterpret_cast<uintptr_t>(this) & 0xffff);
|
|
||||||
ATRACE_INT(sz.c_str(), (int64_t)mDescriptor->duration.count());
|
|
||||||
}
|
|
||||||
// PID control algorithm
|
// PID control algorithm
|
||||||
error = ns_to_100us(actualDurationNanos - targetDurationNanos) +
|
error = ns_to_100us(actualDurationNanos - targetDurationNanos) +
|
||||||
static_cast<int64_t>(sPidOffset);
|
static_cast<int64_t>(sPidOffset);
|
||||||
|
@ -331,6 +320,19 @@ ndk::ScopedAStatus PowerHintSession::reportActualWorkDuration(
|
||||||
derivative = (error - mDescriptor->previous_error) / dt;
|
derivative = (error - mDescriptor->previous_error) / dt;
|
||||||
mDescriptor->previous_error = error;
|
mDescriptor->previous_error = error;
|
||||||
}
|
}
|
||||||
|
if (ATRACE_ENABLED()) {
|
||||||
|
std::string sz = StringPrintf("adpf.%" PRId32 "-%" PRId32 "-%" PRIxPTR "-actl_last",
|
||||||
|
mDescriptor->tgid, mDescriptor->uid,
|
||||||
|
reinterpret_cast<uintptr_t>(this) & 0xffff);
|
||||||
|
ATRACE_INT(sz.c_str(), actualDurations[length - 1].durationNanos);
|
||||||
|
sz = StringPrintf("adpf.%" PRId32 "-%" PRId32 "-%" PRIxPTR "-target", mDescriptor->tgid,
|
||||||
|
mDescriptor->uid, reinterpret_cast<uintptr_t>(this) & 0xffff);
|
||||||
|
ATRACE_INT(sz.c_str(), (int64_t)mDescriptor->duration.count());
|
||||||
|
sz = StringPrintf("adpf.%" PRId32 "-%" PRId32 "-%" PRIxPTR "-sample_size",
|
||||||
|
mDescriptor->tgid, mDescriptor->uid,
|
||||||
|
reinterpret_cast<uintptr_t>(this) & 0xffff);
|
||||||
|
ATRACE_INT(sz.c_str(), length);
|
||||||
|
}
|
||||||
int64_t pOut = static_cast<int64_t>(sPidP * error);
|
int64_t pOut = static_cast<int64_t>(sPidP * error);
|
||||||
int64_t iOut = static_cast<int64_t>(sPidI * mDescriptor->integral_error);
|
int64_t iOut = static_cast<int64_t>(sPidI * mDescriptor->integral_error);
|
||||||
int64_t dOut = static_cast<int64_t>(sPidD * derivative);
|
int64_t dOut = static_cast<int64_t>(sPidD * derivative);
|
||||||
|
@ -418,7 +420,8 @@ void PowerHintSession::StaleHandler::updateStaleTimer() {
|
||||||
}
|
}
|
||||||
|
|
||||||
time_point<steady_clock> PowerHintSession::StaleHandler::getStaleTime() {
|
time_point<steady_clock> PowerHintSession::StaleHandler::getStaleTime() {
|
||||||
return mLastUpdatedTime.load() + kStaleTimeout;
|
return mLastUpdatedTime.load() +
|
||||||
|
std::chrono::duration_cast<milliseconds>(mSession->kAdpfRate) * sStaleTimeFactor;
|
||||||
}
|
}
|
||||||
|
|
||||||
void PowerHintSession::StaleHandler::handleMessage(const Message &) {
|
void PowerHintSession::StaleHandler::handleMessage(const Message &) {
|
||||||
|
|
|
@ -68,8 +68,8 @@ struct AppHintDesc {
|
||||||
|
|
||||||
class PowerHintSession : public BnPowerHintSession {
|
class PowerHintSession : public BnPowerHintSession {
|
||||||
public:
|
public:
|
||||||
PowerHintSession(int32_t tgid, int32_t uid, const std::vector<int32_t> &threadIds,
|
explicit PowerHintSession(int32_t tgid, int32_t uid, const std::vector<int32_t> &threadIds,
|
||||||
int64_t durationNanos);
|
int64_t durationNanos, nanoseconds adpfRate);
|
||||||
~PowerHintSession();
|
~PowerHintSession();
|
||||||
ndk::ScopedAStatus close() override;
|
ndk::ScopedAStatus close() override;
|
||||||
ndk::ScopedAStatus pause() override;
|
ndk::ScopedAStatus pause() override;
|
||||||
|
@ -83,17 +83,13 @@ class PowerHintSession : public BnPowerHintSession {
|
||||||
private:
|
private:
|
||||||
class StaleHandler : public MessageHandler {
|
class StaleHandler : public MessageHandler {
|
||||||
public:
|
public:
|
||||||
StaleHandler(PowerHintSession *session, int64_t timeout_ms)
|
StaleHandler(PowerHintSession *session)
|
||||||
: kStaleTimeout(timeout_ms),
|
: mSession(session), mIsMonitoringStale(false), mLastUpdatedTime(steady_clock::now()) {}
|
||||||
mSession(session),
|
|
||||||
mIsMonitoringStale(false),
|
|
||||||
mLastUpdatedTime(steady_clock::now()) {}
|
|
||||||
void handleMessage(const Message &message) override;
|
void handleMessage(const Message &message) override;
|
||||||
void updateStaleTimer();
|
void updateStaleTimer();
|
||||||
time_point<steady_clock> getStaleTime();
|
time_point<steady_clock> getStaleTime();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
const milliseconds kStaleTimeout;
|
|
||||||
PowerHintSession *mSession;
|
PowerHintSession *mSession;
|
||||||
std::atomic<bool> mIsMonitoringStale;
|
std::atomic<bool> mIsMonitoringStale;
|
||||||
std::atomic<time_point<steady_clock>> mLastUpdatedTime;
|
std::atomic<time_point<steady_clock>> mLastUpdatedTime;
|
||||||
|
@ -104,10 +100,12 @@ class PowerHintSession : public BnPowerHintSession {
|
||||||
void setStale();
|
void setStale();
|
||||||
void updateUniveralBoostMode();
|
void updateUniveralBoostMode();
|
||||||
int setUclamp(int32_t max, int32_t min);
|
int setUclamp(int32_t max, int32_t min);
|
||||||
|
std::string getIdString() const;
|
||||||
AppHintDesc *mDescriptor = nullptr;
|
AppHintDesc *mDescriptor = nullptr;
|
||||||
sp<StaleHandler> mStaleHandler;
|
sp<StaleHandler> mStaleHandler;
|
||||||
sp<MessageHandler> mPowerManagerHandler;
|
sp<MessageHandler> mPowerManagerHandler;
|
||||||
std::mutex mLock;
|
std::mutex mLock;
|
||||||
|
const nanoseconds kAdpfRate;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace pixel
|
} // namespace pixel
|
||||||
|
|
|
@ -37,7 +37,7 @@ void PowerSessionManager::setHintManager(std::shared_ptr<HintManager> const &hin
|
||||||
}
|
}
|
||||||
|
|
||||||
void PowerSessionManager::updateHintMode(const std::string &mode, bool enabled) {
|
void PowerSessionManager::updateHintMode(const std::string &mode, bool enabled) {
|
||||||
ALOGD("PowerSessionManager::updateHintMode: mode: %s, enabled: %d", mode.c_str(), enabled);
|
ALOGV("PowerSessionManager::updateHintMode: mode: %s, enabled: %d", mode.c_str(), enabled);
|
||||||
if (enabled && mode.compare(0, 8, "REFRESH_") == 0) {
|
if (enabled && mode.compare(0, 8, "REFRESH_") == 0) {
|
||||||
if (mode.compare("REFRESH_120FPS") == 0) {
|
if (mode.compare("REFRESH_120FPS") == 0) {
|
||||||
mDisplayRefreshRate = 120;
|
mDisplayRefreshRate = 120;
|
||||||
|
@ -63,19 +63,31 @@ void PowerSessionManager::removePowerSession(PowerHintSession *session) {
|
||||||
mSessions.erase(session);
|
mSessions.erase(session);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool PowerSessionManager::isAnySessionActive() {
|
std::optional<bool> PowerSessionManager::isAnySessionActive() {
|
||||||
std::lock_guard<std::mutex> guard(mLock);
|
std::lock_guard<std::mutex> guard(mLock);
|
||||||
|
bool active = false;
|
||||||
for (PowerHintSession *s : mSessions) {
|
for (PowerHintSession *s : mSessions) {
|
||||||
// session active and not stale is actually active.
|
// session active and not stale is actually active.
|
||||||
if (s->isActive() && !s->isStale()) {
|
if (s->isActive() && !s->isStale()) {
|
||||||
return true;
|
active = true;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return false;
|
if (active == mActive) {
|
||||||
|
return std::nullopt;
|
||||||
|
} else {
|
||||||
|
mActive = active;
|
||||||
|
}
|
||||||
|
|
||||||
|
return active;
|
||||||
}
|
}
|
||||||
|
|
||||||
void PowerSessionManager::handleMessage(const Message &) {
|
void PowerSessionManager::handleMessage(const Message &) {
|
||||||
if (isAnySessionActive()) {
|
auto active = isAnySessionActive();
|
||||||
|
if (!active.has_value()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (active.value()) {
|
||||||
disableSystemTopAppBoost();
|
disableSystemTopAppBoost();
|
||||||
} else {
|
} else {
|
||||||
enableSystemTopAppBoost();
|
enableSystemTopAppBoost();
|
||||||
|
@ -84,20 +96,14 @@ void PowerSessionManager::handleMessage(const Message &) {
|
||||||
|
|
||||||
void PowerSessionManager::enableSystemTopAppBoost() {
|
void PowerSessionManager::enableSystemTopAppBoost() {
|
||||||
if (mHintManager) {
|
if (mHintManager) {
|
||||||
ALOGD("PowerSessionManager::enableSystemTopAppBoost!!");
|
ALOGV("PowerSessionManager::enableSystemTopAppBoost!!");
|
||||||
if (ATRACE_ENABLED()) {
|
|
||||||
ATRACE_INT(kDisableBoostHintName.c_str(), 0);
|
|
||||||
}
|
|
||||||
mHintManager->EndHint(kDisableBoostHintName);
|
mHintManager->EndHint(kDisableBoostHintName);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void PowerSessionManager::disableSystemTopAppBoost() {
|
void PowerSessionManager::disableSystemTopAppBoost() {
|
||||||
if (mHintManager) {
|
if (mHintManager) {
|
||||||
ALOGD("PowerSessionManager::disableSystemTopAppBoost!!");
|
ALOGV("PowerSessionManager::disableSystemTopAppBoost!!");
|
||||||
if (ATRACE_ENABLED()) {
|
|
||||||
ATRACE_INT(kDisableBoostHintName.c_str(), 1);
|
|
||||||
}
|
|
||||||
mHintManager->DoHint(kDisableBoostHintName);
|
mHintManager->DoHint(kDisableBoostHintName);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,6 +23,7 @@
|
||||||
#include <utils/Looper.h>
|
#include <utils/Looper.h>
|
||||||
|
|
||||||
#include <mutex>
|
#include <mutex>
|
||||||
|
#include <optional>
|
||||||
#include <unordered_set>
|
#include <unordered_set>
|
||||||
|
|
||||||
namespace aidl {
|
namespace aidl {
|
||||||
|
@ -48,7 +49,7 @@ class PowerSessionManager : public MessageHandler {
|
||||||
// monitoring session status
|
// monitoring session status
|
||||||
void addPowerSession(PowerHintSession *session);
|
void addPowerSession(PowerHintSession *session);
|
||||||
void removePowerSession(PowerHintSession *session);
|
void removePowerSession(PowerHintSession *session);
|
||||||
bool isAnySessionActive();
|
|
||||||
void handleMessage(const Message &message) override;
|
void handleMessage(const Message &message) override;
|
||||||
void setHintManager(std::shared_ptr<HintManager> const &hint_manager);
|
void setHintManager(std::shared_ptr<HintManager> const &hint_manager);
|
||||||
|
|
||||||
|
@ -59,19 +60,22 @@ class PowerSessionManager : public MessageHandler {
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
std::optional<bool> isAnySessionActive();
|
||||||
void disableSystemTopAppBoost();
|
void disableSystemTopAppBoost();
|
||||||
void enableSystemTopAppBoost();
|
void enableSystemTopAppBoost();
|
||||||
const std::string kDisableBoostHintName;
|
const std::string kDisableBoostHintName;
|
||||||
std::shared_ptr<HintManager> mHintManager;
|
std::shared_ptr<HintManager> mHintManager;
|
||||||
std::unordered_set<PowerHintSession *> mSessions;
|
std::unordered_set<PowerHintSession *> mSessions; // protected by mLock
|
||||||
std::mutex mLock;
|
std::mutex mLock;
|
||||||
int mDisplayRefreshRate;
|
int mDisplayRefreshRate;
|
||||||
|
bool mActive; // protected by mLock
|
||||||
// Singleton
|
// Singleton
|
||||||
PowerSessionManager()
|
PowerSessionManager()
|
||||||
: kDisableBoostHintName(::android::base::GetProperty(kPowerHalAdpfDisableTopAppBoost,
|
: kDisableBoostHintName(::android::base::GetProperty(kPowerHalAdpfDisableTopAppBoost,
|
||||||
"ADPF_DISABLE_TA_BOOST")),
|
"ADPF_DISABLE_TA_BOOST")),
|
||||||
mHintManager(nullptr),
|
mHintManager(nullptr),
|
||||||
mDisplayRefreshRate(60) {}
|
mDisplayRefreshRate(60),
|
||||||
|
mActive(false) {}
|
||||||
PowerSessionManager(PowerSessionManager const &) = delete;
|
PowerSessionManager(PowerSessionManager const &) = delete;
|
||||||
void operator=(PowerSessionManager const &) = delete;
|
void operator=(PowerSessionManager const &) = delete;
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in a new issue