sdm660-common: libperfmgr: power: Add better tracing for sendHint and refactor existing tracing

Reset traced hint value to -1 on reportActualWorkDuration or stale
timeout, and rewrite existing tracing for readability.

Bug: b/243973548
Test: manual
Change-Id: I135ec5f8971a9902d880e4089b0df746f5b917e2
This commit is contained in:
Matt Buckley 2022-11-10 20:53:24 +00:00 committed by CakesTwix
parent 9636d797ca
commit cc568c5a3b
2 changed files with 53 additions and 82 deletions

View file

@ -52,11 +52,14 @@ static inline int64_t ns_to_100us(int64_t ns) {
return ns / 100000; return ns / 100000;
} }
static int64_t convertWorkDurationToBoostByPid(std::shared_ptr<AdpfConfig> adpfConfig, } // namespace
nanoseconds targetDuration,
const std::vector<WorkDuration> &actualDurations, int64_t PowerHintSession::convertWorkDurationToBoostByPid(
int64_t *integral_error, int64_t *previous_error, const std::vector<WorkDuration> &actualDurations) {
const std::string &idstr) { std::shared_ptr<AdpfConfig> adpfConfig = HintManager::GetInstance()->GetAdpfProfile();
const nanoseconds &targetDuration = mDescriptor->duration;
int64_t &integral_error = mDescriptor->integral_error;
int64_t &previous_error = mDescriptor->previous_error;
uint64_t samplingWindowP = adpfConfig->mSamplingWindowP; uint64_t samplingWindowP = adpfConfig->mSamplingWindowP;
uint64_t samplingWindowI = adpfConfig->mSamplingWindowI; uint64_t samplingWindowI = adpfConfig->mSamplingWindowI;
uint64_t samplingWindowD = adpfConfig->mSamplingWindowD; uint64_t samplingWindowD = adpfConfig->mSamplingWindowD;
@ -80,46 +83,38 @@ static int64_t convertWorkDurationToBoostByPid(std::shared_ptr<AdpfConfig> adpfC
// PID control algorithm // PID control algorithm
int64_t error = ns_to_100us(actualDurationNanos - targetDurationNanos); int64_t error = ns_to_100us(actualDurationNanos - targetDurationNanos);
if (i >= d_start) { if (i >= d_start) {
derivative_sum += error - (*previous_error); derivative_sum += error - previous_error;
} }
if (i >= p_start) { if (i >= p_start) {
err_sum += error; err_sum += error;
} }
if (i >= i_start) { if (i >= i_start) {
*integral_error = *integral_error + error * dt; integral_error += error * dt;
*integral_error = std::min(adpfConfig->getPidIHighDivI(), *integral_error); integral_error = std::min(adpfConfig->getPidIHighDivI(), integral_error);
*integral_error = std::max(adpfConfig->getPidILowDivI(), *integral_error); integral_error = std::max(adpfConfig->getPidILowDivI(), integral_error);
} }
*previous_error = error; previous_error = error;
} }
int64_t pOut = static_cast<int64_t>((err_sum > 0 ? adpfConfig->mPidPo : adpfConfig->mPidPu) * int64_t pOut = static_cast<int64_t>((err_sum > 0 ? adpfConfig->mPidPo : adpfConfig->mPidPu) *
err_sum / (length - p_start)); err_sum / (length - p_start));
int64_t iOut = static_cast<int64_t>(adpfConfig->mPidI * (*integral_error)); int64_t iOut = static_cast<int64_t>(adpfConfig->mPidI * integral_error);
int64_t dOut = int64_t dOut =
static_cast<int64_t>((derivative_sum > 0 ? adpfConfig->mPidDo : adpfConfig->mPidDu) * static_cast<int64_t>((derivative_sum > 0 ? adpfConfig->mPidDo : adpfConfig->mPidDu) *
derivative_sum / dt / (length - d_start)); derivative_sum / dt / (length - d_start));
int64_t output = pOut + iOut + dOut; int64_t output = pOut + iOut + dOut;
if (ATRACE_ENABLED()) { if (ATRACE_ENABLED()) {
std::string sz = StringPrintf("adpf.%s-pid.err", idstr.c_str()); traceSessionVal("pid.err", err_sum / (length - p_start));
ATRACE_INT(sz.c_str(), err_sum / (length - p_start)); traceSessionVal("pid.integral", integral_error);
sz = StringPrintf("adpf.%s-pid.integral", idstr.c_str()); traceSessionVal("pid.derivative", derivative_sum / dt / (length - d_start));
ATRACE_INT(sz.c_str(), *integral_error); traceSessionVal("pid.pOut", pOut);
sz = StringPrintf("adpf.%s-pid.derivative", idstr.c_str()); traceSessionVal("pid.iOut", iOut);
ATRACE_INT(sz.c_str(), derivative_sum / dt / (length - d_start)); traceSessionVal("pid.dOut", dOut);
sz = StringPrintf("adpf.%s-pid.pOut", idstr.c_str()); traceSessionVal("pid.output", output);
ATRACE_INT(sz.c_str(), pOut);
sz = StringPrintf("adpf.%s-pid.iOut", idstr.c_str());
ATRACE_INT(sz.c_str(), iOut);
sz = StringPrintf("adpf.%s-pid.dOut", idstr.c_str());
ATRACE_INT(sz.c_str(), dOut);
sz = StringPrintf("adpf.%s-pid.output", idstr.c_str());
ATRACE_INT(sz.c_str(), output);
} }
return output; return output;
} }
} // namespace
PowerHintSession::PowerHintSession(std::shared_ptr<AdaptiveCpu> adaptiveCpu, int32_t tgid, PowerHintSession::PowerHintSession(std::shared_ptr<AdaptiveCpu> adaptiveCpu, int32_t tgid,
int32_t uid, const std::vector<int32_t> &threadIds, int32_t uid, const std::vector<int32_t> &threadIds,
@ -127,16 +122,14 @@ PowerHintSession::PowerHintSession(std::shared_ptr<AdaptiveCpu> adaptiveCpu, int
: mAdaptiveCpu(adaptiveCpu) { : mAdaptiveCpu(adaptiveCpu) {
mDescriptor = new AppHintDesc(tgid, uid, threadIds); mDescriptor = new AppHintDesc(tgid, uid, threadIds);
mDescriptor->duration = std::chrono::nanoseconds(durationNanos); mDescriptor->duration = std::chrono::nanoseconds(durationNanos);
mIdString = StringPrintf("%" PRId32 "-%" PRId32 "-%" PRIxPTR, mDescriptor->tgid,
mDescriptor->uid, reinterpret_cast<uintptr_t>(this) & 0xffff);
mStaleTimerHandler = sp<StaleTimerHandler>(new StaleTimerHandler(this)); mStaleTimerHandler = sp<StaleTimerHandler>(new StaleTimerHandler(this));
mPowerManagerHandler = PowerSessionManager::getInstance(); mPowerManagerHandler = PowerSessionManager::getInstance();
mLastUpdatedTime.store(std::chrono::steady_clock::now()); mLastUpdatedTime.store(std::chrono::steady_clock::now());
if (ATRACE_ENABLED()) { if (ATRACE_ENABLED()) {
const std::string idstr = getIdString(); traceSessionVal("target", mDescriptor->duration.count());
std::string sz = StringPrintf("adpf.%s-target", idstr.c_str()); traceSessionVal("active", mDescriptor->is_active.load());
ATRACE_INT(sz.c_str(), (int64_t)mDescriptor->duration.count());
sz = StringPrintf("adpf.%s-active", idstr.c_str());
ATRACE_INT(sz.c_str(), mDescriptor->is_active.load());
} }
PowerSessionManager::getInstance()->addPowerSession(this); PowerSessionManager::getInstance()->addPowerSession(this);
// init boost // init boost
@ -148,21 +141,15 @@ PowerHintSession::~PowerHintSession() {
close(); close();
ALOGV("PowerHintSession deleted: %s", mDescriptor->toString().c_str()); ALOGV("PowerHintSession deleted: %s", mDescriptor->toString().c_str());
if (ATRACE_ENABLED()) { if (ATRACE_ENABLED()) {
const std::string idstr = getIdString(); traceSessionVal("target", 0);
std::string sz = StringPrintf("adpf.%s-target", idstr.c_str()); traceSessionVal("actl_last", 0);
ATRACE_INT(sz.c_str(), 0); traceSessionVal("active", 0);
sz = StringPrintf("adpf.%s-actl_last", idstr.c_str());
ATRACE_INT(sz.c_str(), 0);
sz = sz = StringPrintf("adpf.%s-active", idstr.c_str());
ATRACE_INT(sz.c_str(), 0);
} }
delete mDescriptor; delete mDescriptor;
} }
std::string PowerHintSession::getIdString() const { void PowerHintSession::traceSessionVal(char const *identifier, int64_t val) const {
std::string idstr = StringPrintf("%" PRId32 "-%" PRId32 "-%" PRIxPTR, mDescriptor->tgid, ATRACE_INT(StringPrintf("adpf.%s-%s", mIdString.c_str(), identifier).c_str(), val);
mDescriptor->uid, reinterpret_cast<uintptr_t>(this) & 0xffff);
return idstr;
} }
bool PowerHintSession::isAppSession() { bool PowerHintSession::isAppSession() {
@ -175,7 +162,7 @@ void PowerHintSession::updateUniveralBoostMode() {
return; return;
} }
if (ATRACE_ENABLED()) { if (ATRACE_ENABLED()) {
const std::string tag = StringPrintf("%s:updateUniveralBoostMode()", getIdString().c_str()); const std::string tag = StringPrintf("%s:updateUniveralBoostMode()", mIdString.c_str());
ATRACE_BEGIN(tag.c_str()); ATRACE_BEGIN(tag.c_str());
} }
PowerHintMonitor::getInstance()->getLooper()->sendMessage(mPowerManagerHandler, NULL); PowerHintMonitor::getInstance()->getLooper()->sendMessage(mPowerManagerHandler, NULL);
@ -195,9 +182,7 @@ int PowerHintSession::setSessionUclampMin(int32_t min) {
PowerSessionManager::getInstance()->setUclampMin(this, min); PowerSessionManager::getInstance()->setUclampMin(this, min);
if (ATRACE_ENABLED()) { if (ATRACE_ENABLED()) {
const std::string idstr = getIdString(); traceSessionVal("min", min);
std::string sz = StringPrintf("adpf.%s-min", idstr.c_str());
ATRACE_INT(sz.c_str(), min);
} }
return 0; return 0;
} }
@ -207,7 +192,7 @@ int PowerHintSession::getUclampMin() {
} }
void PowerHintSession::dumpToStream(std::ostream &stream) { void PowerHintSession::dumpToStream(std::ostream &stream) {
stream << "ID.Min.Act.Timeout(" << getIdString(); stream << "ID.Min.Act.Timeout(" << mIdString;
stream << ", " << mDescriptor->current_min; stream << ", " << mDescriptor->current_min;
stream << ", " << mDescriptor->is_active; stream << ", " << mDescriptor->is_active;
stream << ", " << isTimeout() << ")"; stream << ", " << isTimeout() << ")";
@ -224,9 +209,7 @@ ndk::ScopedAStatus PowerHintSession::pause() {
mDescriptor->is_active.store(false); mDescriptor->is_active.store(false);
setStale(); setStale();
if (ATRACE_ENABLED()) { if (ATRACE_ENABLED()) {
const std::string idstr = getIdString(); traceSessionVal("active", mDescriptor->is_active.load());
std::string sz = StringPrintf("adpf.%s-active", idstr.c_str());
ATRACE_INT(sz.c_str(), mDescriptor->is_active.load());
} }
updateUniveralBoostMode(); updateUniveralBoostMode();
return ndk::ScopedAStatus::ok(); return ndk::ScopedAStatus::ok();
@ -243,9 +226,7 @@ ndk::ScopedAStatus PowerHintSession::resume() {
// resume boost // resume boost
setSessionUclampMin(mDescriptor->current_min); setSessionUclampMin(mDescriptor->current_min);
if (ATRACE_ENABLED()) { if (ATRACE_ENABLED()) {
const std::string idstr = getIdString(); traceSessionVal("active", mDescriptor->is_active.load());
std::string sz = StringPrintf("adpf.%s-active", idstr.c_str());
ATRACE_INT(sz.c_str(), mDescriptor->is_active.load());
} }
updateUniveralBoostMode(); updateUniveralBoostMode();
return ndk::ScopedAStatus::ok(); return ndk::ScopedAStatus::ok();
@ -284,9 +265,7 @@ ndk::ScopedAStatus PowerHintSession::updateTargetWorkDuration(int64_t targetDura
mDescriptor->duration = std::chrono::nanoseconds(targetDurationNanos); mDescriptor->duration = std::chrono::nanoseconds(targetDurationNanos);
if (ATRACE_ENABLED()) { if (ATRACE_ENABLED()) {
const std::string idstr = getIdString(); traceSessionVal("target", mDescriptor->duration.count());
std::string sz = StringPrintf("adpf.%s-target", idstr.c_str());
ATRACE_INT(sz.c_str(), (int64_t)mDescriptor->duration.count());
} }
return ndk::ScopedAStatus::ok(); return ndk::ScopedAStatus::ok();
@ -314,18 +293,13 @@ ndk::ScopedAStatus PowerHintSession::reportActualWorkDuration(
mDescriptor->update_count++; mDescriptor->update_count++;
bool isFirstFrame = isTimeout(); bool isFirstFrame = isTimeout();
if (ATRACE_ENABLED()) { if (ATRACE_ENABLED()) {
const std::string idstr = getIdString(); traceSessionVal("batch_size", actualDurations.size());
std::string sz = StringPrintf("adpf.%s-batch_size", idstr.c_str()); traceSessionVal("actl_last", actualDurations.back().durationNanos);
ATRACE_INT(sz.c_str(), actualDurations.size()); traceSessionVal("target", mDescriptor->duration.count());
sz = StringPrintf("adpf.%s-actl_last", idstr.c_str()); traceSessionVal("hint.count", mDescriptor->update_count);
ATRACE_INT(sz.c_str(), actualDurations.back().durationNanos); traceSessionVal("hint.overtime",
sz = StringPrintf("adpf.%s-target", idstr.c_str());
ATRACE_INT(sz.c_str(), (int64_t)mDescriptor->duration.count());
sz = StringPrintf("adpf.%s-hint.count", idstr.c_str());
ATRACE_INT(sz.c_str(), mDescriptor->update_count);
sz = StringPrintf("adpf.%s-hint.overtime", idstr.c_str());
ATRACE_INT(sz.c_str(),
actualDurations.back().durationNanos - mDescriptor->duration.count() > 0); actualDurations.back().durationNanos - mDescriptor->duration.count() > 0);
traceSessionVal("session_hint", -1);
} }
mLastUpdatedTime.store(std::chrono::steady_clock::now()); mLastUpdatedTime.store(std::chrono::steady_clock::now());
@ -337,9 +311,7 @@ ndk::ScopedAStatus PowerHintSession::reportActualWorkDuration(
setSessionUclampMin(adpfConfig->mUclampMinHigh); setSessionUclampMin(adpfConfig->mUclampMinHigh);
return ndk::ScopedAStatus::ok(); return ndk::ScopedAStatus::ok();
} }
int64_t output = convertWorkDurationToBoostByPid( int64_t output = convertWorkDurationToBoostByPid(actualDurations);
adpfConfig, mDescriptor->duration, actualDurations, &(mDescriptor->integral_error),
&(mDescriptor->previous_error), getIdString());
/* apply to all the threads in the group */ /* apply to all the threads in the group */
int next_min = std::min(static_cast<int>(adpfConfig->mUclampMinHigh), int next_min = std::min(static_cast<int>(adpfConfig->mUclampMinHigh),
@ -397,9 +369,7 @@ void PowerHintSession::setStale() {
// Deliver a task to check if all sessions are inactive. // Deliver a task to check if all sessions are inactive.
updateUniveralBoostMode(); updateUniveralBoostMode();
if (ATRACE_ENABLED()) { if (ATRACE_ENABLED()) {
const std::string idstr = getIdString(); traceSessionVal("min", 0);
std::string sz = StringPrintf("adpf.%s-min", idstr.c_str());
ATRACE_INT(sz.c_str(), 0);
} }
} }
@ -417,9 +387,7 @@ void PowerHintSession::StaleTimerHandler::updateTimer() {
next, mSession->mStaleTimerHandler, NULL); next, mSession->mStaleTimerHandler, NULL);
} }
if (ATRACE_ENABLED()) { if (ATRACE_ENABLED()) {
const std::string idstr = mSession->getIdString(); mSession->traceSessionVal("timer.stale", 0);
std::string sz = StringPrintf("adpf.%s-timer.stale", idstr.c_str());
ATRACE_INT(sz.c_str(), 0);
} }
} }
@ -438,11 +406,12 @@ void PowerHintSession::StaleTimerHandler::handleMessage(const Message &) {
next, mSession->mStaleTimerHandler, NULL); next, mSession->mStaleTimerHandler, NULL);
} else { } else {
mSession->setStale(); mSession->setStale();
if (ATRACE_ENABLED()) {
mSession->traceSessionVal("session_hint", -1);
}
} }
if (ATRACE_ENABLED()) { if (ATRACE_ENABLED()) {
const std::string idstr = mSession->getIdString(); mSession->traceSessionVal("timer.stale", next > 0 ? 0 : 1);
std::string sz = StringPrintf("adpf.%s-timer.stale", idstr.c_str());
ATRACE_INT(sz.c_str(), next > 0 ? 0 : 1);
} }
} }

View file

@ -109,7 +109,8 @@ class PowerHintSession : public BnPowerHintSession {
private: private:
void updateUniveralBoostMode(); void updateUniveralBoostMode();
int setSessionUclampMin(int32_t min); int setSessionUclampMin(int32_t min);
std::string getIdString() const; int64_t convertWorkDurationToBoostByPid(const std::vector<WorkDuration> &actualDurations);
void traceSessionVal(char const *identifier, int64_t val) const;
const std::shared_ptr<AdaptiveCpu> mAdaptiveCpu; const std::shared_ptr<AdaptiveCpu> mAdaptiveCpu;
AppHintDesc *mDescriptor = nullptr; AppHintDesc *mDescriptor = nullptr;
sp<StaleTimerHandler> mStaleTimerHandler; sp<StaleTimerHandler> mStaleTimerHandler;
@ -117,6 +118,7 @@ class PowerHintSession : public BnPowerHintSession {
sp<MessageHandler> mPowerManagerHandler; sp<MessageHandler> mPowerManagerHandler;
std::mutex mSessionLock; std::mutex mSessionLock;
std::atomic<bool> mSessionClosed = false; std::atomic<bool> mSessionClosed = false;
std::string mIdString;
}; };
} // namespace pixel } // namespace pixel