Skip to content

Commit 8760555

Browse files
lpymikeNG
authored andcommitted
power-libperfmgr: Implement IPowerHintSession.setThreads
Implement IPowerHintSession.setThreads, when threads are updated, remove all previous threads and readd new threads, set the boost to initial state. Minor: Update IPower version to 4. Bug: b/244216750 Bug: b/257217984 Test: manual Change-Id: I29e2574d3a107a3e75bf27a4528635e3eedc2d14
1 parent 108fdb7 commit 8760555

File tree

5 files changed

+43
-7
lines changed

5 files changed

+43
-7
lines changed

power-libperfmgr/aidl/PowerHintSession.cpp

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -363,6 +363,25 @@ ndk::ScopedAStatus PowerHintSession::sendHint(SessionHint hint) {
363363
return ndk::ScopedAStatus::ok();
364364
}
365365

366+
ndk::ScopedAStatus PowerHintSession::setThreads(const std::vector<int32_t> &threadIds) {
367+
if (mSessionClosed) {
368+
ALOGE("Error: session is dead");
369+
return ndk::ScopedAStatus::fromExceptionCode(EX_ILLEGAL_STATE);
370+
}
371+
if (threadIds.size() == 0) {
372+
LOG(ERROR) << "Error: threadIds.size() shouldn't be " << threadIds.size();
373+
return ndk::ScopedAStatus::fromExceptionCode(EX_ILLEGAL_ARGUMENT);
374+
}
375+
376+
PowerSessionManager::getInstance()->removeThreadsFromPowerSession(this);
377+
mDescriptor->threadIds.resize(threadIds.size());
378+
std::copy(threadIds.begin(), threadIds.end(), back_inserter(mDescriptor->threadIds));
379+
PowerSessionManager::getInstance()->addThreadsFromPowerSession(this);
380+
// init boost
381+
setSessionUclampMin(HintManager::GetInstance()->GetAdpfProfile()->mUclampMinInit);
382+
return ndk::ScopedAStatus::ok();
383+
}
384+
366385
std::string AppHintDesc::toString() const {
367386
std::string out =
368387
StringPrintf("session %" PRIxPTR "\n", reinterpret_cast<uintptr_t>(this) & 0xffff);
@@ -398,7 +417,7 @@ bool PowerHintSession::isTimeout() {
398417
return now >= staleTime;
399418
}
400419

401-
const std::vector<int> &PowerHintSession::getTidList() const {
420+
const std::vector<int32_t> &PowerHintSession::getTidList() const {
402421
return mDescriptor->threadIds;
403422
}
404423

power-libperfmgr/aidl/PowerHintSession.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ using std::chrono::steady_clock;
4444
using std::chrono::time_point;
4545

4646
struct AppHintDesc {
47-
AppHintDesc(int32_t tgid, int32_t uid, std::vector<int> threadIds)
47+
AppHintDesc(int32_t tgid, int32_t uid, std::vector<int32_t> threadIds)
4848
: tgid(tgid),
4949
uid(uid),
5050
threadIds(std::move(threadIds)),
@@ -57,7 +57,7 @@ struct AppHintDesc {
5757
std::string toString() const;
5858
const int32_t tgid;
5959
const int32_t uid;
60-
const std::vector<int> threadIds;
60+
std::vector<int32_t> threadIds;
6161
nanoseconds duration;
6262
int current_min;
6363
// status
@@ -80,6 +80,7 @@ class PowerHintSession : public BnPowerHintSession {
8080
ndk::ScopedAStatus reportActualWorkDuration(
8181
const std::vector<WorkDuration> &actualDurations) override;
8282
ndk::ScopedAStatus sendHint(SessionHint hint) override;
83+
ndk::ScopedAStatus setThreads(const std::vector<int32_t> &threadIds) override;
8384
bool isActive();
8485
bool isTimeout();
8586
void setStale();

power-libperfmgr/aidl/PowerSessionManager.cpp

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,22 @@ int PowerSessionManager::getDisplayRefreshRate() {
104104
}
105105

106106
void PowerSessionManager::addPowerSession(PowerHintSession *session) {
107+
addThreadsFromPowerSession(session);
108+
{
109+
std::lock_guard<std::mutex> guard(mLock);
110+
mSessions.insert(session);
111+
}
112+
}
113+
114+
void PowerSessionManager::removePowerSession(PowerHintSession *session) {
115+
removeThreadsFromPowerSession(session);
116+
{
117+
std::lock_guard<std::mutex> guard(mLock);
118+
mSessions.erase(session);
119+
}
120+
}
121+
122+
void PowerSessionManager::addThreadsFromPowerSession(PowerHintSession *session) {
107123
std::lock_guard<std::mutex> guard(mLock);
108124
for (auto t : session->getTidList()) {
109125
mTidSessionListMap[t].insert(session);
@@ -121,10 +137,9 @@ void PowerSessionManager::addPowerSession(PowerHintSession *session) {
121137
}
122138
mTidRefCountMap[t]++;
123139
}
124-
mSessions.insert(session);
125140
}
126141

127-
void PowerSessionManager::removePowerSession(PowerHintSession *session) {
142+
void PowerSessionManager::removeThreadsFromPowerSession(PowerHintSession *session) {
128143
std::lock_guard<std::mutex> guard(mLock);
129144
for (auto t : session->getTidList()) {
130145
if (mTidRefCountMap.find(t) == mTidRefCountMap.end()) {
@@ -140,7 +155,6 @@ void PowerSessionManager::removePowerSession(PowerHintSession *session) {
140155
mTidRefCountMap.erase(t);
141156
}
142157
}
143-
mSessions.erase(session);
144158
}
145159

146160
void PowerSessionManager::setUclampMin(PowerHintSession *session, int val) {

power-libperfmgr/aidl/PowerSessionManager.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@ class PowerSessionManager : public MessageHandler {
5050
// monitoring session status
5151
void addPowerSession(PowerHintSession *session);
5252
void removePowerSession(PowerHintSession *session);
53+
void addThreadsFromPowerSession(PowerHintSession *session);
54+
void removeThreadsFromPowerSession(PowerHintSession *session);
5355
void setUclampMin(PowerHintSession *session, int min);
5456
void setUclampMinLocked(PowerHintSession *session, int min);
5557
void handleMessage(const Message &message) override;
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<manifest version="1.0" type="device">
22
<hal format="aidl">
33
<name>android.hardware.power</name>
4-
<version>3</version>
4+
<version>4</version>
55
<fqname>IPower/default</fqname>
66
</hal>
77
</manifest>

0 commit comments

Comments
 (0)