sm6375-common: power-libperfmgr: ADPF: add Early Hint feature

Add Early Hint feature and integrate with Stale Timer

Bug: 198379880
Test: build and manual test

Change-Id: I17009ee5b9ff922a79ccf5cb68be5b959038267d
This commit is contained in:
Jimmy Shiu 2024-07-18 20:16:00 +05:30 committed by Anand S
commit 938e2b96f7
No known key found for this signature in database
GPG key ID: 3B2983FA448B3D61
2 changed files with 145 additions and 51 deletions

View file

@ -52,7 +52,9 @@ struct AppHintDesc {
is_active(true),
update_count(0),
integral_error(0),
previous_error(0) {}
previous_error(0),
work_period(0),
last_start(0) {}
std::string toString() const;
const int32_t tgid;
const int32_t uid;
@ -66,6 +68,9 @@ struct AppHintDesc {
uint64_t update_count;
int64_t integral_error;
int64_t previous_error;
// earlyhint pace
int64_t work_period;
int64_t last_start;
};
class PowerHintSession : public BnPowerHintSession {
@ -85,22 +90,34 @@ class PowerHintSession : public BnPowerHintSession {
int restoreUclamp();
private:
class StaleHandler : public MessageHandler {
class HintTimerHandler : public MessageHandler {
public:
StaleHandler(PowerHintSession *session)
enum HintTimerState {
STALE,
MONITORING,
EARLY_BOOST,
};
HintTimerHandler(PowerHintSession *session)
: mSession(session),
mIsMonitoringStale(false),
mState(STALE),
mLastUpdatedTime(steady_clock::now()),
mIsSessionDead(false) {}
~HintTimerHandler();
void handleMessage(const Message &message) override;
void updateStaleTimer();
// Update HintTimer by actual work duration.
void updateHintTimer(int64_t actualDurationNs);
// Update HintTimer by a list of work durations which could be used for
// calculating the work period.
void updateHintTimer(const std::vector<WorkDuration> &actualDurations);
time_point<steady_clock> getEarlyBoostTime();
time_point<steady_clock> getStaleTime();
void setSessionDead();
private:
PowerHintSession *mSession;
std::atomic<bool> mIsMonitoringStale;
HintTimerState mState;
std::atomic<time_point<steady_clock>> mLastUpdatedTime;
std::atomic<time_point<steady_clock>> mNextStartTime;
std::mutex mStaleLock;
bool mIsSessionDead;
};
@ -111,7 +128,7 @@ class PowerHintSession : public BnPowerHintSession {
int setUclamp(int32_t min, bool update = true);
std::string getIdString() const;
AppHintDesc *mDescriptor = nullptr;
sp<StaleHandler> mStaleHandler;
sp<HintTimerHandler> mHintTimerHandler;
sp<MessageHandler> mPowerManagerHandler;
std::mutex mLock;
std::atomic<bool> mSessionClosed = false;