sdm710-common: Import libperfmgr from hardware/xiaomi again
This commit is contained in:
parent
894299a3b4
commit
16255e2c1e
15 changed files with 9 additions and 258 deletions
|
@ -13,16 +13,11 @@
|
||||||
# See the License for the specific language governing permissions and
|
# See the License for the specific language governing permissions and
|
||||||
# limitations under the License.
|
# limitations under the License.
|
||||||
#
|
#
|
||||||
|
|
||||||
ifneq (,$(findstring hardware/google/interfaces, $(PRODUCT_SOONG_NAMESPACES)))
|
ifneq (,$(findstring hardware/google/interfaces, $(PRODUCT_SOONG_NAMESPACES)))
|
||||||
ifneq (,$(findstring hardware/google/pixel, $(PRODUCT_SOONG_NAMESPACES)))
|
ifneq (,$(findstring hardware/google/pixel, $(PRODUCT_SOONG_NAMESPACES)))
|
||||||
|
|
||||||
LOCAL_PATH := $(call my-dir)
|
LOCAL_PATH := $(call my-dir)
|
||||||
|
|
||||||
include $(CLEAR_VARS)
|
include $(CLEAR_VARS)
|
||||||
|
|
||||||
LOCAL_MODULE_RELATIVE_PATH := hw
|
LOCAL_MODULE_RELATIVE_PATH := hw
|
||||||
|
|
||||||
LOCAL_SHARED_LIBRARIES := \
|
LOCAL_SHARED_LIBRARIES := \
|
||||||
android.hardware.power-V2-ndk \
|
android.hardware.power-V2-ndk \
|
||||||
libbase \
|
libbase \
|
||||||
|
@ -34,7 +29,6 @@ LOCAL_SHARED_LIBRARIES := \
|
||||||
libprocessgroup \
|
libprocessgroup \
|
||||||
libutils \
|
libutils \
|
||||||
pixel-power-ext-V1-ndk
|
pixel-power-ext-V1-ndk
|
||||||
|
|
||||||
LOCAL_SRC_FILES := \
|
LOCAL_SRC_FILES := \
|
||||||
service.cpp \
|
service.cpp \
|
||||||
InteractionHandler.cpp \
|
InteractionHandler.cpp \
|
||||||
|
@ -42,25 +36,19 @@ LOCAL_SRC_FILES := \
|
||||||
PowerExt.cpp \
|
PowerExt.cpp \
|
||||||
PowerHintSession.cpp \
|
PowerHintSession.cpp \
|
||||||
PowerSessionManager.cpp
|
PowerSessionManager.cpp
|
||||||
|
|
||||||
LOCAL_CFLAGS := -Wno-unused-parameter -Wno-unused-variable
|
LOCAL_CFLAGS := -Wno-unused-parameter -Wno-unused-variable
|
||||||
|
|
||||||
ifneq ($(TARGET_POWERHAL_MODE_EXT),)
|
ifneq ($(TARGET_POWERHAL_MODE_EXT),)
|
||||||
LOCAL_CFLAGS += -DMODE_EXT
|
LOCAL_CFLAGS += -DMODE_EXT
|
||||||
LOCAL_SRC_FILES += ../../../../$(TARGET_POWERHAL_MODE_EXT)
|
LOCAL_SRC_FILES += ../../../../$(TARGET_POWERHAL_MODE_EXT)
|
||||||
endif
|
endif
|
||||||
|
|
||||||
ifneq ($(TARGET_TAP_TO_WAKE_NODE),)
|
ifneq ($(TARGET_TAP_TO_WAKE_NODE),)
|
||||||
LOCAL_CFLAGS += -DTAP_TO_WAKE_NODE=\"$(TARGET_TAP_TO_WAKE_NODE)\"
|
LOCAL_CFLAGS += -DTAP_TO_WAKE_NODE=\"$(TARGET_TAP_TO_WAKE_NODE)\"
|
||||||
endif
|
endif
|
||||||
|
LOCAL_MODULE := android.hardware.power-service.xiaomi-libperfmgr
|
||||||
LOCAL_MODULE := android.hardware.power-service.lenovo-sdm710-libperfmgr
|
LOCAL_INIT_RC := android.hardware.power-service.xiaomi-libperfmgr.rc
|
||||||
LOCAL_INIT_RC := android.hardware.power-service.lenovo-sdm710-libperfmgr.rc
|
|
||||||
LOCAL_MODULE_TAGS := optional
|
LOCAL_MODULE_TAGS := optional
|
||||||
LOCAL_VENDOR_MODULE := true
|
LOCAL_VENDOR_MODULE := true
|
||||||
LOCAL_VINTF_FRAGMENTS := android.hardware.power-service.lenovo-sdm710.xml
|
LOCAL_VINTF_FRAGMENTS := android.hardware.power-service.xiaomi.xml
|
||||||
|
|
||||||
include $(BUILD_EXECUTABLE)
|
include $(BUILD_EXECUTABLE)
|
||||||
|
|
||||||
endif
|
endif
|
||||||
endif
|
endif
|
||||||
|
|
|
@ -13,12 +13,9 @@
|
||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#define ATRACE_TAG (ATRACE_TAG_POWER | ATRACE_TAG_HAL)
|
#define ATRACE_TAG (ATRACE_TAG_POWER | ATRACE_TAG_HAL)
|
||||||
#define LOG_TAG "powerhal-libperfmgr"
|
#define LOG_TAG "powerhal-libperfmgr"
|
||||||
|
|
||||||
#include "InteractionHandler.h"
|
#include "InteractionHandler.h"
|
||||||
|
|
||||||
#include <android-base/properties.h>
|
#include <android-base/properties.h>
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
#include <perfmgr/HintManager.h>
|
#include <perfmgr/HintManager.h>
|
||||||
|
@ -28,24 +25,18 @@
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <utils/Log.h>
|
#include <utils/Log.h>
|
||||||
#include <utils/Trace.h>
|
#include <utils/Trace.h>
|
||||||
|
|
||||||
#include <array>
|
#include <array>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
|
||||||
#define MAX_LENGTH 64
|
#define MAX_LENGTH 64
|
||||||
|
|
||||||
#define MSINSEC 1000L
|
#define MSINSEC 1000L
|
||||||
#define NSINMS 1000000L
|
#define NSINMS 1000000L
|
||||||
|
|
||||||
namespace aidl {
|
namespace aidl {
|
||||||
namespace google {
|
namespace google {
|
||||||
namespace hardware {
|
namespace hardware {
|
||||||
namespace power {
|
namespace power {
|
||||||
namespace impl {
|
namespace impl {
|
||||||
namespace pixel {
|
namespace pixel {
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
static const bool kDisplayIdleSupport =
|
static const bool kDisplayIdleSupport =
|
||||||
::android::base::GetBoolProperty("vendor.powerhal.disp.idle_support", true);
|
::android::base::GetBoolProperty("vendor.powerhal.disp.idle_support", true);
|
||||||
static const std::array<const char *, 2> kDispIdlePath = {"/sys/class/drm/card0/device/idle_state",
|
static const std::array<const char *, 2> kDispIdlePath = {"/sys/class/drm/card0/device/idle_state",
|
||||||
|
@ -58,14 +49,12 @@ static const uint32_t kMaxDurationMs =
|
||||||
::android::base::GetUintProperty("vendor.powerhal.interaction.max", /*default*/ 5650U);
|
::android::base::GetUintProperty("vendor.powerhal.interaction.max", /*default*/ 5650U);
|
||||||
static const uint32_t kDurationOffsetMs =
|
static const uint32_t kDurationOffsetMs =
|
||||||
::android::base::GetUintProperty("vendor.powerhal.interaction.offset", /*default*/ 650U);
|
::android::base::GetUintProperty("vendor.powerhal.interaction.offset", /*default*/ 650U);
|
||||||
|
|
||||||
static size_t CalcTimespecDiffMs(struct timespec start, struct timespec end) {
|
static size_t CalcTimespecDiffMs(struct timespec start, struct timespec end) {
|
||||||
size_t diff_in_ms = 0;
|
size_t diff_in_ms = 0;
|
||||||
diff_in_ms += (end.tv_sec - start.tv_sec) * MSINSEC;
|
diff_in_ms += (end.tv_sec - start.tv_sec) * MSINSEC;
|
||||||
diff_in_ms += (end.tv_nsec - start.tv_nsec) / NSINMS;
|
diff_in_ms += (end.tv_nsec - start.tv_nsec) / NSINMS;
|
||||||
return diff_in_ms;
|
return diff_in_ms;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int FbIdleOpen(void) {
|
static int FbIdleOpen(void) {
|
||||||
int fd;
|
int fd;
|
||||||
for (const auto &path : kDispIdlePath) {
|
for (const auto &path : kDispIdlePath) {
|
||||||
|
@ -76,77 +65,58 @@ static int FbIdleOpen(void) {
|
||||||
ALOGE("Unable to open fb idle state path (%d)", errno);
|
ALOGE("Unable to open fb idle state path (%d)", errno);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
using ::android::perfmgr::HintManager;
|
using ::android::perfmgr::HintManager;
|
||||||
|
|
||||||
InteractionHandler::InteractionHandler()
|
InteractionHandler::InteractionHandler()
|
||||||
: mState(INTERACTION_STATE_UNINITIALIZED), mDurationMs(0) {}
|
: mState(INTERACTION_STATE_UNINITIALIZED), mDurationMs(0) {}
|
||||||
|
|
||||||
InteractionHandler::~InteractionHandler() {
|
InteractionHandler::~InteractionHandler() {
|
||||||
Exit();
|
Exit();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool InteractionHandler::Init() {
|
bool InteractionHandler::Init() {
|
||||||
std::lock_guard<std::mutex> lk(mLock);
|
std::lock_guard<std::mutex> lk(mLock);
|
||||||
|
|
||||||
if (mState != INTERACTION_STATE_UNINITIALIZED)
|
if (mState != INTERACTION_STATE_UNINITIALIZED)
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
int fd = FbIdleOpen();
|
int fd = FbIdleOpen();
|
||||||
if (fd < 0)
|
if (fd < 0)
|
||||||
return false;
|
return false;
|
||||||
mIdleFd = fd;
|
mIdleFd = fd;
|
||||||
|
|
||||||
mEventFd = eventfd(0, EFD_NONBLOCK);
|
mEventFd = eventfd(0, EFD_NONBLOCK);
|
||||||
if (mEventFd < 0) {
|
if (mEventFd < 0) {
|
||||||
ALOGE("Unable to create event fd (%d)", errno);
|
ALOGE("Unable to create event fd (%d)", errno);
|
||||||
close(mIdleFd);
|
close(mIdleFd);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
mState = INTERACTION_STATE_IDLE;
|
mState = INTERACTION_STATE_IDLE;
|
||||||
mThread = std::unique_ptr<std::thread>(new std::thread(&InteractionHandler::Routine, this));
|
mThread = std::unique_ptr<std::thread>(new std::thread(&InteractionHandler::Routine, this));
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void InteractionHandler::Exit() {
|
void InteractionHandler::Exit() {
|
||||||
std::unique_lock<std::mutex> lk(mLock);
|
std::unique_lock<std::mutex> lk(mLock);
|
||||||
if (mState == INTERACTION_STATE_UNINITIALIZED)
|
if (mState == INTERACTION_STATE_UNINITIALIZED)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
AbortWaitLocked();
|
AbortWaitLocked();
|
||||||
mState = INTERACTION_STATE_UNINITIALIZED;
|
mState = INTERACTION_STATE_UNINITIALIZED;
|
||||||
lk.unlock();
|
lk.unlock();
|
||||||
|
|
||||||
mCond.notify_all();
|
mCond.notify_all();
|
||||||
mThread->join();
|
mThread->join();
|
||||||
|
|
||||||
close(mEventFd);
|
close(mEventFd);
|
||||||
close(mIdleFd);
|
close(mIdleFd);
|
||||||
}
|
}
|
||||||
|
|
||||||
void InteractionHandler::PerfLock() {
|
void InteractionHandler::PerfLock() {
|
||||||
ALOGV("%s: acquiring perf lock", __func__);
|
ALOGV("%s: acquiring perf lock", __func__);
|
||||||
if (!HintManager::GetInstance()->DoHint("INTERACTION")) {
|
if (!HintManager::GetInstance()->DoHint("INTERACTION")) {
|
||||||
ALOGE("%s: do hint INTERACTION failed", __func__);
|
ALOGE("%s: do hint INTERACTION failed", __func__);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void InteractionHandler::PerfRel() {
|
void InteractionHandler::PerfRel() {
|
||||||
ALOGV("%s: releasing perf lock", __func__);
|
ALOGV("%s: releasing perf lock", __func__);
|
||||||
if (!HintManager::GetInstance()->EndHint("INTERACTION")) {
|
if (!HintManager::GetInstance()->EndHint("INTERACTION")) {
|
||||||
ALOGE("%s: end hint INTERACTION failed", __func__);
|
ALOGE("%s: end hint INTERACTION failed", __func__);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void InteractionHandler::Acquire(int32_t duration) {
|
void InteractionHandler::Acquire(int32_t duration) {
|
||||||
ATRACE_CALL();
|
ATRACE_CALL();
|
||||||
|
|
||||||
std::lock_guard<std::mutex> lk(mLock);
|
std::lock_guard<std::mutex> lk(mLock);
|
||||||
|
|
||||||
int inputDuration = duration + kDurationOffsetMs;
|
int inputDuration = duration + kDurationOffsetMs;
|
||||||
int finalDuration;
|
int finalDuration;
|
||||||
if (inputDuration > kMaxDurationMs)
|
if (inputDuration > kMaxDurationMs)
|
||||||
|
@ -155,7 +125,6 @@ void InteractionHandler::Acquire(int32_t duration) {
|
||||||
finalDuration = inputDuration;
|
finalDuration = inputDuration;
|
||||||
else
|
else
|
||||||
finalDuration = kMinDurationMs;
|
finalDuration = kMinDurationMs;
|
||||||
|
|
||||||
// Fallback to do boost directly
|
// Fallback to do boost directly
|
||||||
// 1) override property is set OR
|
// 1) override property is set OR
|
||||||
// 2) InteractionHandler not initialized
|
// 2) InteractionHandler not initialized
|
||||||
|
@ -163,7 +132,6 @@ void InteractionHandler::Acquire(int32_t duration) {
|
||||||
HintManager::GetInstance()->DoHint("INTERACTION", std::chrono::milliseconds(finalDuration));
|
HintManager::GetInstance()->DoHint("INTERACTION", std::chrono::milliseconds(finalDuration));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
struct timespec cur_timespec;
|
struct timespec cur_timespec;
|
||||||
clock_gettime(CLOCK_MONOTONIC, &cur_timespec);
|
clock_gettime(CLOCK_MONOTONIC, &cur_timespec);
|
||||||
if (mState != INTERACTION_STATE_IDLE && finalDuration <= mDurationMs) {
|
if (mState != INTERACTION_STATE_IDLE && finalDuration <= mDurationMs) {
|
||||||
|
@ -178,18 +146,14 @@ void InteractionHandler::Acquire(int32_t duration) {
|
||||||
}
|
}
|
||||||
mLastTimespec = cur_timespec;
|
mLastTimespec = cur_timespec;
|
||||||
mDurationMs = finalDuration;
|
mDurationMs = finalDuration;
|
||||||
|
|
||||||
ALOGV("%s: input: %d final duration: %d", __func__, duration, finalDuration);
|
ALOGV("%s: input: %d final duration: %d", __func__, duration, finalDuration);
|
||||||
|
|
||||||
if (mState == INTERACTION_STATE_WAITING)
|
if (mState == INTERACTION_STATE_WAITING)
|
||||||
AbortWaitLocked();
|
AbortWaitLocked();
|
||||||
else if (mState == INTERACTION_STATE_IDLE)
|
else if (mState == INTERACTION_STATE_IDLE)
|
||||||
PerfLock();
|
PerfLock();
|
||||||
|
|
||||||
mState = INTERACTION_STATE_INTERACTION;
|
mState = INTERACTION_STATE_INTERACTION;
|
||||||
mCond.notify_one();
|
mCond.notify_one();
|
||||||
}
|
}
|
||||||
|
|
||||||
void InteractionHandler::Release() {
|
void InteractionHandler::Release() {
|
||||||
std::lock_guard<std::mutex> lk(mLock);
|
std::lock_guard<std::mutex> lk(mLock);
|
||||||
if (mState == INTERACTION_STATE_WAITING) {
|
if (mState == INTERACTION_STATE_WAITING) {
|
||||||
|
@ -200,11 +164,9 @@ void InteractionHandler::Release() {
|
||||||
// clear any wait aborts pending in event fd
|
// clear any wait aborts pending in event fd
|
||||||
uint64_t val;
|
uint64_t val;
|
||||||
ssize_t ret = read(mEventFd, &val, sizeof(val));
|
ssize_t ret = read(mEventFd, &val, sizeof(val));
|
||||||
|
|
||||||
ALOGW_IF(ret < 0, "%s: failed to clear eventfd (%zd, %d)", __func__, ret, errno);
|
ALOGW_IF(ret < 0, "%s: failed to clear eventfd (%zd, %d)", __func__, ret, errno);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// should be called while locked
|
// should be called while locked
|
||||||
void InteractionHandler::AbortWaitLocked() {
|
void InteractionHandler::AbortWaitLocked() {
|
||||||
uint64_t val = 1;
|
uint64_t val = 1;
|
||||||
|
@ -212,21 +174,16 @@ void InteractionHandler::AbortWaitLocked() {
|
||||||
if (ret != sizeof(val))
|
if (ret != sizeof(val))
|
||||||
ALOGW("Unable to write to event fd (%zd)", ret);
|
ALOGW("Unable to write to event fd (%zd)", ret);
|
||||||
}
|
}
|
||||||
|
|
||||||
void InteractionHandler::WaitForIdle(int32_t wait_ms, int32_t timeout_ms) {
|
void InteractionHandler::WaitForIdle(int32_t wait_ms, int32_t timeout_ms) {
|
||||||
char data[MAX_LENGTH];
|
char data[MAX_LENGTH];
|
||||||
ssize_t ret;
|
ssize_t ret;
|
||||||
struct pollfd pfd[2];
|
struct pollfd pfd[2];
|
||||||
|
|
||||||
ATRACE_CALL();
|
ATRACE_CALL();
|
||||||
|
|
||||||
ALOGV("%s: wait:%d timeout:%d", __func__, wait_ms, timeout_ms);
|
ALOGV("%s: wait:%d timeout:%d", __func__, wait_ms, timeout_ms);
|
||||||
|
|
||||||
pfd[0].fd = mEventFd;
|
pfd[0].fd = mEventFd;
|
||||||
pfd[0].events = POLLIN;
|
pfd[0].events = POLLIN;
|
||||||
pfd[1].fd = mIdleFd;
|
pfd[1].fd = mIdleFd;
|
||||||
pfd[1].events = POLLPRI | POLLERR;
|
pfd[1].events = POLLPRI | POLLERR;
|
||||||
|
|
||||||
ret = poll(pfd, 1, wait_ms);
|
ret = poll(pfd, 1, wait_ms);
|
||||||
if (ret > 0) {
|
if (ret > 0) {
|
||||||
ALOGV("%s: wait aborted", __func__);
|
ALOGV("%s: wait aborted", __func__);
|
||||||
|
@ -235,18 +192,15 @@ void InteractionHandler::WaitForIdle(int32_t wait_ms, int32_t timeout_ms) {
|
||||||
ALOGE("%s: error in poll while waiting", __func__);
|
ALOGE("%s: error in poll while waiting", __func__);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = pread(mIdleFd, data, sizeof(data), 0);
|
ret = pread(mIdleFd, data, sizeof(data), 0);
|
||||||
if (!ret) {
|
if (!ret) {
|
||||||
ALOGE("%s: Unexpected EOF!", __func__);
|
ALOGE("%s: Unexpected EOF!", __func__);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!strncmp(data, "idle", 4)) {
|
if (!strncmp(data, "idle", 4)) {
|
||||||
ALOGV("%s: already idle", __func__);
|
ALOGV("%s: already idle", __func__);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = poll(pfd, 2, timeout_ms);
|
ret = poll(pfd, 2, timeout_ms);
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
ALOGE("%s: Error on waiting for idle (%zd)", __func__, ret);
|
ALOGE("%s: Error on waiting for idle (%zd)", __func__, ret);
|
||||||
|
@ -257,11 +211,9 @@ void InteractionHandler::WaitForIdle(int32_t wait_ms, int32_t timeout_ms) {
|
||||||
else if (pfd[1].revents)
|
else if (pfd[1].revents)
|
||||||
ALOGV("%s: idle detected", __func__);
|
ALOGV("%s: idle detected", __func__);
|
||||||
}
|
}
|
||||||
|
|
||||||
void InteractionHandler::Routine() {
|
void InteractionHandler::Routine() {
|
||||||
pthread_setname_np(pthread_self(), "DispIdle");
|
pthread_setname_np(pthread_self(), "DispIdle");
|
||||||
std::unique_lock<std::mutex> lk(mLock, std::defer_lock);
|
std::unique_lock<std::mutex> lk(mLock, std::defer_lock);
|
||||||
|
|
||||||
while (true) {
|
while (true) {
|
||||||
lk.lock();
|
lk.lock();
|
||||||
mCond.wait(lk, [&] { return mState != INTERACTION_STATE_IDLE; });
|
mCond.wait(lk, [&] { return mState != INTERACTION_STATE_IDLE; });
|
||||||
|
@ -269,12 +221,10 @@ void InteractionHandler::Routine() {
|
||||||
return;
|
return;
|
||||||
mState = INTERACTION_STATE_WAITING;
|
mState = INTERACTION_STATE_WAITING;
|
||||||
lk.unlock();
|
lk.unlock();
|
||||||
|
|
||||||
WaitForIdle(kWaitMs, mDurationMs);
|
WaitForIdle(kWaitMs, mDurationMs);
|
||||||
Release();
|
Release();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace pixel
|
} // namespace pixel
|
||||||
} // namespace impl
|
} // namespace impl
|
||||||
} // namespace power
|
} // namespace power
|
||||||
|
|
|
@ -13,29 +13,24 @@
|
||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <condition_variable>
|
#include <condition_variable>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <mutex>
|
#include <mutex>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <thread>
|
#include <thread>
|
||||||
|
|
||||||
namespace aidl {
|
namespace aidl {
|
||||||
namespace google {
|
namespace google {
|
||||||
namespace hardware {
|
namespace hardware {
|
||||||
namespace power {
|
namespace power {
|
||||||
namespace impl {
|
namespace impl {
|
||||||
namespace pixel {
|
namespace pixel {
|
||||||
|
|
||||||
enum InteractionState {
|
enum InteractionState {
|
||||||
INTERACTION_STATE_UNINITIALIZED,
|
INTERACTION_STATE_UNINITIALIZED,
|
||||||
INTERACTION_STATE_IDLE,
|
INTERACTION_STATE_IDLE,
|
||||||
INTERACTION_STATE_INTERACTION,
|
INTERACTION_STATE_INTERACTION,
|
||||||
INTERACTION_STATE_WAITING,
|
INTERACTION_STATE_WAITING,
|
||||||
};
|
};
|
||||||
|
|
||||||
class InteractionHandler {
|
class InteractionHandler {
|
||||||
public:
|
public:
|
||||||
InteractionHandler();
|
InteractionHandler();
|
||||||
|
@ -43,16 +38,13 @@ class InteractionHandler {
|
||||||
bool Init();
|
bool Init();
|
||||||
void Exit();
|
void Exit();
|
||||||
void Acquire(int32_t duration);
|
void Acquire(int32_t duration);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void Release();
|
void Release();
|
||||||
void WaitForIdle(int32_t wait_ms, int32_t timeout_ms);
|
void WaitForIdle(int32_t wait_ms, int32_t timeout_ms);
|
||||||
void AbortWaitLocked();
|
void AbortWaitLocked();
|
||||||
void Routine();
|
void Routine();
|
||||||
|
|
||||||
void PerfLock();
|
void PerfLock();
|
||||||
void PerfRel();
|
void PerfRel();
|
||||||
|
|
||||||
enum InteractionState mState;
|
enum InteractionState mState;
|
||||||
int mIdleFd;
|
int mIdleFd;
|
||||||
int mEventFd;
|
int mEventFd;
|
||||||
|
@ -62,7 +54,6 @@ class InteractionHandler {
|
||||||
std::mutex mLock;
|
std::mutex mLock;
|
||||||
std::condition_variable mCond;
|
std::condition_variable mCond;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace pixel
|
} // namespace pixel
|
||||||
} // namespace impl
|
} // namespace impl
|
||||||
} // namespace power
|
} // namespace power
|
||||||
|
|
|
@ -13,11 +13,8 @@
|
||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#define LOG_TAG "powerhal-libperfmgr"
|
#define LOG_TAG "powerhal-libperfmgr"
|
||||||
|
|
||||||
#include "Power.h"
|
#include "Power.h"
|
||||||
|
|
||||||
#include <android-base/file.h>
|
#include <android-base/file.h>
|
||||||
#include <android-base/logging.h>
|
#include <android-base/logging.h>
|
||||||
#include <android-base/properties.h>
|
#include <android-base/properties.h>
|
||||||
|
@ -25,37 +22,29 @@
|
||||||
#include <android-base/strings.h>
|
#include <android-base/strings.h>
|
||||||
#include <perfmgr/HintManager.h>
|
#include <perfmgr/HintManager.h>
|
||||||
#include <utils/Log.h>
|
#include <utils/Log.h>
|
||||||
|
|
||||||
#include <mutex>
|
#include <mutex>
|
||||||
|
|
||||||
#include "PowerHintSession.h"
|
#include "PowerHintSession.h"
|
||||||
#include "PowerSessionManager.h"
|
#include "PowerSessionManager.h"
|
||||||
|
|
||||||
namespace aidl {
|
namespace aidl {
|
||||||
namespace google {
|
namespace google {
|
||||||
namespace hardware {
|
namespace hardware {
|
||||||
namespace power {
|
namespace power {
|
||||||
namespace impl {
|
namespace impl {
|
||||||
namespace pixel {
|
namespace pixel {
|
||||||
|
|
||||||
using ::aidl::google::hardware::power::impl::pixel::PowerHintSession;
|
using ::aidl::google::hardware::power::impl::pixel::PowerHintSession;
|
||||||
using ::android::perfmgr::HintManager;
|
using ::android::perfmgr::HintManager;
|
||||||
|
|
||||||
#ifdef MODE_EXT
|
#ifdef MODE_EXT
|
||||||
extern bool isDeviceSpecificModeSupported(Mode type, bool* _aidl_return);
|
extern bool isDeviceSpecificModeSupported(Mode type, bool* _aidl_return);
|
||||||
extern bool setDeviceSpecificMode(Mode type, bool enabled);
|
extern bool setDeviceSpecificMode(Mode type, bool enabled);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
constexpr char kPowerHalStateProp[] = "vendor.powerhal.state";
|
constexpr char kPowerHalStateProp[] = "vendor.powerhal.state";
|
||||||
constexpr char kPowerHalAudioProp[] = "vendor.powerhal.audio";
|
constexpr char kPowerHalAudioProp[] = "vendor.powerhal.audio";
|
||||||
constexpr char kPowerHalRenderingProp[] = "vendor.powerhal.rendering";
|
constexpr char kPowerHalRenderingProp[] = "vendor.powerhal.rendering";
|
||||||
|
|
||||||
Power::Power()
|
Power::Power()
|
||||||
: mInteractionHandler(nullptr),
|
: mInteractionHandler(nullptr),
|
||||||
mSustainedPerfModeOn(false) {
|
mSustainedPerfModeOn(false) {
|
||||||
mInteractionHandler = std::make_unique<InteractionHandler>();
|
mInteractionHandler = std::make_unique<InteractionHandler>();
|
||||||
mInteractionHandler->Init();
|
mInteractionHandler->Init();
|
||||||
|
|
||||||
std::string state = ::android::base::GetProperty(kPowerHalStateProp, "");
|
std::string state = ::android::base::GetProperty(kPowerHalStateProp, "");
|
||||||
if (state == "SUSTAINED_PERFORMANCE") {
|
if (state == "SUSTAINED_PERFORMANCE") {
|
||||||
LOG(INFO) << "Initialize with SUSTAINED_PERFORMANCE on";
|
LOG(INFO) << "Initialize with SUSTAINED_PERFORMANCE on";
|
||||||
|
@ -64,20 +53,17 @@ Power::Power()
|
||||||
} else {
|
} else {
|
||||||
LOG(INFO) << "Initialize PowerHAL";
|
LOG(INFO) << "Initialize PowerHAL";
|
||||||
}
|
}
|
||||||
|
|
||||||
state = ::android::base::GetProperty(kPowerHalAudioProp, "");
|
state = ::android::base::GetProperty(kPowerHalAudioProp, "");
|
||||||
if (state == "AUDIO_STREAMING_LOW_LATENCY") {
|
if (state == "AUDIO_STREAMING_LOW_LATENCY") {
|
||||||
LOG(INFO) << "Initialize with AUDIO_LOW_LATENCY on";
|
LOG(INFO) << "Initialize with AUDIO_LOW_LATENCY on";
|
||||||
HintManager::GetInstance()->DoHint(state);
|
HintManager::GetInstance()->DoHint(state);
|
||||||
}
|
}
|
||||||
|
|
||||||
state = ::android::base::GetProperty(kPowerHalRenderingProp, "");
|
state = ::android::base::GetProperty(kPowerHalRenderingProp, "");
|
||||||
if (state == "EXPENSIVE_RENDERING") {
|
if (state == "EXPENSIVE_RENDERING") {
|
||||||
LOG(INFO) << "Initialize with EXPENSIVE_RENDERING on";
|
LOG(INFO) << "Initialize with EXPENSIVE_RENDERING on";
|
||||||
HintManager::GetInstance()->DoHint("EXPENSIVE_RENDERING");
|
HintManager::GetInstance()->DoHint("EXPENSIVE_RENDERING");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ndk::ScopedAStatus Power::setMode(Mode type, bool enabled) {
|
ndk::ScopedAStatus Power::setMode(Mode type, bool enabled) {
|
||||||
LOG(DEBUG) << "Power setMode: " << toString(type) << " to: " << enabled;
|
LOG(DEBUG) << "Power setMode: " << toString(type) << " to: " << enabled;
|
||||||
if (HintManager::GetInstance()->GetAdpfProfile() &&
|
if (HintManager::GetInstance()->GetAdpfProfile() &&
|
||||||
|
@ -130,17 +116,14 @@ ndk::ScopedAStatus Power::setMode(Mode type, bool enabled) {
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
return ndk::ScopedAStatus::ok();
|
return ndk::ScopedAStatus::ok();
|
||||||
}
|
}
|
||||||
|
|
||||||
ndk::ScopedAStatus Power::isModeSupported(Mode type, bool *_aidl_return) {
|
ndk::ScopedAStatus Power::isModeSupported(Mode type, bool *_aidl_return) {
|
||||||
#ifdef MODE_EXT
|
#ifdef MODE_EXT
|
||||||
if (isDeviceSpecificModeSupported(type, _aidl_return)) {
|
if (isDeviceSpecificModeSupported(type, _aidl_return)) {
|
||||||
return ndk::ScopedAStatus::ok();
|
return ndk::ScopedAStatus::ok();
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
bool supported = HintManager::GetInstance()->IsHintSupported(toString(type));
|
bool supported = HintManager::GetInstance()->IsHintSupported(toString(type));
|
||||||
#ifdef TAP_TO_WAKE_NODE
|
#ifdef TAP_TO_WAKE_NODE
|
||||||
if (type == Mode::DOUBLE_TAP_TO_WAKE) {
|
if (type == Mode::DOUBLE_TAP_TO_WAKE) {
|
||||||
|
@ -151,7 +134,6 @@ ndk::ScopedAStatus Power::isModeSupported(Mode type, bool *_aidl_return) {
|
||||||
*_aidl_return = supported;
|
*_aidl_return = supported;
|
||||||
return ndk::ScopedAStatus::ok();
|
return ndk::ScopedAStatus::ok();
|
||||||
}
|
}
|
||||||
|
|
||||||
ndk::ScopedAStatus Power::setBoost(Boost type, int32_t durationMs) {
|
ndk::ScopedAStatus Power::setBoost(Boost type, int32_t durationMs) {
|
||||||
LOG(DEBUG) << "Power setBoost: " << toString(type) << " duration: " << durationMs;
|
LOG(DEBUG) << "Power setBoost: " << toString(type) << " duration: " << durationMs;
|
||||||
if (HintManager::GetInstance()->GetAdpfProfile() &&
|
if (HintManager::GetInstance()->GetAdpfProfile() &&
|
||||||
|
@ -185,21 +167,17 @@ ndk::ScopedAStatus Power::setBoost(Boost type, int32_t durationMs) {
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
return ndk::ScopedAStatus::ok();
|
return ndk::ScopedAStatus::ok();
|
||||||
}
|
}
|
||||||
|
|
||||||
ndk::ScopedAStatus Power::isBoostSupported(Boost type, bool *_aidl_return) {
|
ndk::ScopedAStatus Power::isBoostSupported(Boost type, bool *_aidl_return) {
|
||||||
bool supported = HintManager::GetInstance()->IsHintSupported(toString(type));
|
bool supported = HintManager::GetInstance()->IsHintSupported(toString(type));
|
||||||
LOG(INFO) << "Power boost " << toString(type) << " isBoostSupported: " << supported;
|
LOG(INFO) << "Power boost " << toString(type) << " isBoostSupported: " << supported;
|
||||||
*_aidl_return = supported;
|
*_aidl_return = supported;
|
||||||
return ndk::ScopedAStatus::ok();
|
return ndk::ScopedAStatus::ok();
|
||||||
}
|
}
|
||||||
|
|
||||||
constexpr const char *boolToString(bool b) {
|
constexpr const char *boolToString(bool b) {
|
||||||
return b ? "true" : "false";
|
return b ? "true" : "false";
|
||||||
}
|
}
|
||||||
|
|
||||||
binder_status_t Power::dump(int fd, const char **, uint32_t) {
|
binder_status_t Power::dump(int fd, const char **, uint32_t) {
|
||||||
std::string buf(::android::base::StringPrintf(
|
std::string buf(::android::base::StringPrintf(
|
||||||
"HintManager Running: %s\n"
|
"HintManager Running: %s\n"
|
||||||
|
@ -215,7 +193,6 @@ binder_status_t Power::dump(int fd, const char **, uint32_t) {
|
||||||
fsync(fd);
|
fsync(fd);
|
||||||
return STATUS_OK;
|
return STATUS_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
ndk::ScopedAStatus Power::createHintSession(int32_t tgid, int32_t uid,
|
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,
|
||||||
|
@ -235,7 +212,6 @@ ndk::ScopedAStatus Power::createHintSession(int32_t tgid, int32_t uid,
|
||||||
*_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 = HintManager::GetInstance()->GetAdpfProfile()
|
*outNanoseconds = HintManager::GetInstance()->GetAdpfProfile()
|
||||||
? HintManager::GetInstance()->GetAdpfProfile()->mReportingRateLimitNs
|
? HintManager::GetInstance()->GetAdpfProfile()->mReportingRateLimitNs
|
||||||
|
@ -243,10 +219,8 @@ ndk::ScopedAStatus Power::getHintSessionPreferredRate(int64_t *outNanoseconds) {
|
||||||
if (*outNanoseconds <= 0) {
|
if (*outNanoseconds <= 0) {
|
||||||
return ndk::ScopedAStatus::fromExceptionCode(EX_UNSUPPORTED_OPERATION);
|
return ndk::ScopedAStatus::fromExceptionCode(EX_UNSUPPORTED_OPERATION);
|
||||||
}
|
}
|
||||||
|
|
||||||
return ndk::ScopedAStatus::ok();
|
return ndk::ScopedAStatus::ok();
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace pixel
|
} // namespace pixel
|
||||||
} // namespace impl
|
} // namespace impl
|
||||||
} // namespace power
|
} // namespace power
|
||||||
|
|
|
@ -13,28 +13,21 @@
|
||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <aidl/android/hardware/power/BnPower.h>
|
#include <aidl/android/hardware/power/BnPower.h>
|
||||||
|
|
||||||
#include <atomic>
|
#include <atomic>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <thread>
|
#include <thread>
|
||||||
|
|
||||||
#include "InteractionHandler.h"
|
#include "InteractionHandler.h"
|
||||||
|
|
||||||
namespace aidl {
|
namespace aidl {
|
||||||
namespace google {
|
namespace google {
|
||||||
namespace hardware {
|
namespace hardware {
|
||||||
namespace power {
|
namespace power {
|
||||||
namespace impl {
|
namespace impl {
|
||||||
namespace pixel {
|
namespace pixel {
|
||||||
|
|
||||||
using ::aidl::android::hardware::power::Boost;
|
using ::aidl::android::hardware::power::Boost;
|
||||||
using ::aidl::android::hardware::power::IPowerHintSession;
|
using ::aidl::android::hardware::power::IPowerHintSession;
|
||||||
using ::aidl::android::hardware::power::Mode;
|
using ::aidl::android::hardware::power::Mode;
|
||||||
|
|
||||||
class Power : public ::aidl::android::hardware::power::BnPower {
|
class Power : public ::aidl::android::hardware::power::BnPower {
|
||||||
public:
|
public:
|
||||||
Power();
|
Power();
|
||||||
|
@ -48,12 +41,10 @@ class Power : public ::aidl::android::hardware::power::BnPower {
|
||||||
std::shared_ptr<IPowerHintSession> *_aidl_return) override;
|
std::shared_ptr<IPowerHintSession> *_aidl_return) override;
|
||||||
ndk::ScopedAStatus getHintSessionPreferredRate(int64_t *outNanoseconds) override;
|
ndk::ScopedAStatus getHintSessionPreferredRate(int64_t *outNanoseconds) override;
|
||||||
binder_status_t dump(int fd, const char **args, uint32_t numArgs) override;
|
binder_status_t dump(int fd, const char **args, uint32_t numArgs) override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::unique_ptr<InteractionHandler> mInteractionHandler;
|
std::unique_ptr<InteractionHandler> mInteractionHandler;
|
||||||
std::atomic<bool> mSustainedPerfModeOn;
|
std::atomic<bool> mSustainedPerfModeOn;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace pixel
|
} // namespace pixel
|
||||||
} // namespace impl
|
} // namespace impl
|
||||||
} // namespace power
|
} // namespace power
|
||||||
|
|
|
@ -13,11 +13,8 @@
|
||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
#define LOG_TAG "android.hardware.power-service.xiaomi.ext-libperfmgr"
|
||||||
#define LOG_TAG "android.hardware.power-service.lenovo-sdm710-libperfmgr"
|
|
||||||
|
|
||||||
#include "PowerExt.h"
|
#include "PowerExt.h"
|
||||||
|
|
||||||
#include <android-base/file.h>
|
#include <android-base/file.h>
|
||||||
#include <android-base/logging.h>
|
#include <android-base/logging.h>
|
||||||
#include <android-base/properties.h>
|
#include <android-base/properties.h>
|
||||||
|
@ -25,23 +22,17 @@
|
||||||
#include <android-base/strings.h>
|
#include <android-base/strings.h>
|
||||||
#include <perfmgr/HintManager.h>
|
#include <perfmgr/HintManager.h>
|
||||||
#include <utils/Log.h>
|
#include <utils/Log.h>
|
||||||
|
|
||||||
#include <mutex>
|
#include <mutex>
|
||||||
|
|
||||||
#include "PowerSessionManager.h"
|
#include "PowerSessionManager.h"
|
||||||
|
|
||||||
namespace aidl {
|
namespace aidl {
|
||||||
namespace google {
|
namespace google {
|
||||||
namespace hardware {
|
namespace hardware {
|
||||||
namespace power {
|
namespace power {
|
||||||
namespace impl {
|
namespace impl {
|
||||||
namespace pixel {
|
namespace pixel {
|
||||||
|
|
||||||
using ::android::perfmgr::HintManager;
|
using ::android::perfmgr::HintManager;
|
||||||
|
|
||||||
ndk::ScopedAStatus PowerExt::setMode(const std::string &mode, bool enabled) {
|
ndk::ScopedAStatus PowerExt::setMode(const std::string &mode, bool enabled) {
|
||||||
LOG(DEBUG) << "PowerExt setMode: " << mode << " to: " << enabled;
|
LOG(DEBUG) << "PowerExt setMode: " << mode << " to: " << enabled;
|
||||||
|
|
||||||
if (enabled) {
|
if (enabled) {
|
||||||
HintManager::GetInstance()->DoHint(mode);
|
HintManager::GetInstance()->DoHint(mode);
|
||||||
} else {
|
} else {
|
||||||
|
@ -51,24 +42,20 @@ ndk::ScopedAStatus PowerExt::setMode(const std::string &mode, bool enabled) {
|
||||||
HintManager::GetInstance()->GetAdpfProfile()->mReportingRateLimitNs > 0) {
|
HintManager::GetInstance()->GetAdpfProfile()->mReportingRateLimitNs > 0) {
|
||||||
PowerSessionManager::getInstance()->updateHintMode(mode, enabled);
|
PowerSessionManager::getInstance()->updateHintMode(mode, enabled);
|
||||||
}
|
}
|
||||||
|
|
||||||
return ndk::ScopedAStatus::ok();
|
return ndk::ScopedAStatus::ok();
|
||||||
}
|
}
|
||||||
|
|
||||||
ndk::ScopedAStatus PowerExt::isModeSupported(const std::string &mode, bool *_aidl_return) {
|
ndk::ScopedAStatus PowerExt::isModeSupported(const std::string &mode, bool *_aidl_return) {
|
||||||
bool supported = HintManager::GetInstance()->IsHintSupported(mode);
|
bool supported = HintManager::GetInstance()->IsHintSupported(mode);
|
||||||
LOG(INFO) << "PowerExt mode " << mode << " isModeSupported: " << supported;
|
LOG(INFO) << "PowerExt mode " << mode << " isModeSupported: " << supported;
|
||||||
*_aidl_return = supported;
|
*_aidl_return = supported;
|
||||||
return ndk::ScopedAStatus::ok();
|
return ndk::ScopedAStatus::ok();
|
||||||
}
|
}
|
||||||
|
|
||||||
ndk::ScopedAStatus PowerExt::setBoost(const std::string &boost, int32_t durationMs) {
|
ndk::ScopedAStatus PowerExt::setBoost(const std::string &boost, int32_t durationMs) {
|
||||||
LOG(DEBUG) << "PowerExt setBoost: " << boost << " duration: " << durationMs;
|
LOG(DEBUG) << "PowerExt setBoost: " << boost << " duration: " << durationMs;
|
||||||
if (HintManager::GetInstance()->GetAdpfProfile() &&
|
if (HintManager::GetInstance()->GetAdpfProfile() &&
|
||||||
HintManager::GetInstance()->GetAdpfProfile()->mReportingRateLimitNs > 0) {
|
HintManager::GetInstance()->GetAdpfProfile()->mReportingRateLimitNs > 0) {
|
||||||
PowerSessionManager::getInstance()->updateHintBoost(boost, durationMs);
|
PowerSessionManager::getInstance()->updateHintBoost(boost, durationMs);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (durationMs > 0) {
|
if (durationMs > 0) {
|
||||||
HintManager::GetInstance()->DoHint(boost, std::chrono::milliseconds(durationMs));
|
HintManager::GetInstance()->DoHint(boost, std::chrono::milliseconds(durationMs));
|
||||||
} else if (durationMs == 0) {
|
} else if (durationMs == 0) {
|
||||||
|
@ -76,17 +63,14 @@ ndk::ScopedAStatus PowerExt::setBoost(const std::string &boost, int32_t duration
|
||||||
} else {
|
} else {
|
||||||
HintManager::GetInstance()->EndHint(boost);
|
HintManager::GetInstance()->EndHint(boost);
|
||||||
}
|
}
|
||||||
|
|
||||||
return ndk::ScopedAStatus::ok();
|
return ndk::ScopedAStatus::ok();
|
||||||
}
|
}
|
||||||
|
|
||||||
ndk::ScopedAStatus PowerExt::isBoostSupported(const std::string &boost, bool *_aidl_return) {
|
ndk::ScopedAStatus PowerExt::isBoostSupported(const std::string &boost, bool *_aidl_return) {
|
||||||
bool supported = HintManager::GetInstance()->IsHintSupported(boost);
|
bool supported = HintManager::GetInstance()->IsHintSupported(boost);
|
||||||
LOG(INFO) << "PowerExt boost " << boost << " isBoostSupported: " << supported;
|
LOG(INFO) << "PowerExt boost " << boost << " isBoostSupported: " << supported;
|
||||||
*_aidl_return = supported;
|
*_aidl_return = supported;
|
||||||
return ndk::ScopedAStatus::ok();
|
return ndk::ScopedAStatus::ok();
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace pixel
|
} // namespace pixel
|
||||||
} // namespace impl
|
} // namespace impl
|
||||||
} // namespace power
|
} // namespace power
|
||||||
|
|
|
@ -13,23 +13,18 @@
|
||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <atomic>
|
#include <atomic>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <thread>
|
#include <thread>
|
||||||
|
|
||||||
#include <aidl/google/hardware/power/extension/pixel/BnPowerExt.h>
|
#include <aidl/google/hardware/power/extension/pixel/BnPowerExt.h>
|
||||||
#include <perfmgr/HintManager.h>
|
#include <perfmgr/HintManager.h>
|
||||||
|
|
||||||
namespace aidl {
|
namespace aidl {
|
||||||
namespace google {
|
namespace google {
|
||||||
namespace hardware {
|
namespace hardware {
|
||||||
namespace power {
|
namespace power {
|
||||||
namespace impl {
|
namespace impl {
|
||||||
namespace pixel {
|
namespace pixel {
|
||||||
|
|
||||||
class PowerExt : public ::aidl::google::hardware::power::extension::pixel::BnPowerExt {
|
class PowerExt : public ::aidl::google::hardware::power::extension::pixel::BnPowerExt {
|
||||||
public:
|
public:
|
||||||
PowerExt() {}
|
PowerExt() {}
|
||||||
|
@ -37,10 +32,8 @@ class PowerExt : public ::aidl::google::hardware::power::extension::pixel::BnPow
|
||||||
ndk::ScopedAStatus isModeSupported(const std::string &mode, bool *_aidl_return) override;
|
ndk::ScopedAStatus isModeSupported(const std::string &mode, bool *_aidl_return) override;
|
||||||
ndk::ScopedAStatus setBoost(const std::string &boost, int32_t durationMs) override;
|
ndk::ScopedAStatus setBoost(const std::string &boost, int32_t durationMs) override;
|
||||||
ndk::ScopedAStatus isBoostSupported(const std::string &boost, bool *_aidl_return) override;
|
ndk::ScopedAStatus isBoostSupported(const std::string &boost, bool *_aidl_return) override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace pixel
|
} // namespace pixel
|
||||||
} // namespace impl
|
} // namespace impl
|
||||||
} // namespace power
|
} // namespace power
|
||||||
|
|
|
@ -13,12 +13,9 @@
|
||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#define LOG_TAG "powerhal-libperfmgr"
|
#define LOG_TAG "powerhal-libperfmgr"
|
||||||
#define ATRACE_TAG (ATRACE_TAG_POWER | ATRACE_TAG_HAL)
|
#define ATRACE_TAG (ATRACE_TAG_POWER | ATRACE_TAG_HAL)
|
||||||
|
|
||||||
#include "PowerHintSession.h"
|
#include "PowerHintSession.h"
|
||||||
|
|
||||||
#include <android-base/logging.h>
|
#include <android-base/logging.h>
|
||||||
#include <android-base/parsedouble.h>
|
#include <android-base/parsedouble.h>
|
||||||
#include <android-base/properties.h>
|
#include <android-base/properties.h>
|
||||||
|
@ -28,32 +25,24 @@
|
||||||
#include <sys/syscall.h>
|
#include <sys/syscall.h>
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
#include <utils/Trace.h>
|
#include <utils/Trace.h>
|
||||||
|
|
||||||
#include <atomic>
|
#include <atomic>
|
||||||
|
|
||||||
#include "PowerSessionManager.h"
|
#include "PowerSessionManager.h"
|
||||||
|
|
||||||
namespace aidl {
|
namespace aidl {
|
||||||
namespace google {
|
namespace google {
|
||||||
namespace hardware {
|
namespace hardware {
|
||||||
namespace power {
|
namespace power {
|
||||||
namespace impl {
|
namespace impl {
|
||||||
namespace pixel {
|
namespace pixel {
|
||||||
|
|
||||||
using ::android::base::StringPrintf;
|
using ::android::base::StringPrintf;
|
||||||
using ::android::perfmgr::AdpfConfig;
|
using ::android::perfmgr::AdpfConfig;
|
||||||
using ::android::perfmgr::HintManager;
|
using ::android::perfmgr::HintManager;
|
||||||
using std::chrono::duration_cast;
|
using std::chrono::duration_cast;
|
||||||
using std::chrono::nanoseconds;
|
using std::chrono::nanoseconds;
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
static inline int64_t ns_to_100us(int64_t ns) {
|
static inline int64_t ns_to_100us(int64_t ns) {
|
||||||
return ns / 100000;
|
return ns / 100000;
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
int64_t PowerHintSession::convertWorkDurationToBoostByPid(
|
int64_t PowerHintSession::convertWorkDurationToBoostByPid(
|
||||||
const std::vector<WorkDuration> &actualDurations) {
|
const std::vector<WorkDuration> &actualDurations) {
|
||||||
std::shared_ptr<AdpfConfig> adpfConfig = HintManager::GetInstance()->GetAdpfProfile();
|
std::shared_ptr<AdpfConfig> adpfConfig = HintManager::GetInstance()->GetAdpfProfile();
|
||||||
|
@ -101,7 +90,6 @@ int64_t PowerHintSession::convertWorkDurationToBoostByPid(
|
||||||
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()) {
|
||||||
traceSessionVal("pid.err", err_sum / (length - p_start));
|
traceSessionVal("pid.err", err_sum / (length - p_start));
|
||||||
|
@ -114,7 +102,6 @@ int64_t PowerHintSession::convertWorkDurationToBoostByPid(
|
||||||
}
|
}
|
||||||
return output;
|
return output;
|
||||||
}
|
}
|
||||||
|
|
||||||
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) {
|
||||||
mDescriptor = new AppHintDesc(tgid, uid, threadIds);
|
mDescriptor = new AppHintDesc(tgid, uid, threadIds);
|
||||||
|
@ -133,7 +120,6 @@ PowerHintSession::PowerHintSession(int32_t tgid, int32_t uid, const std::vector<
|
||||||
setSessionUclampMin(HintManager::GetInstance()->GetAdpfProfile()->mUclampMinInit);
|
setSessionUclampMin(HintManager::GetInstance()->GetAdpfProfile()->mUclampMinInit);
|
||||||
ALOGV("PowerHintSession created: %s", mDescriptor->toString().c_str());
|
ALOGV("PowerHintSession created: %s", mDescriptor->toString().c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
PowerHintSession::~PowerHintSession() {
|
PowerHintSession::~PowerHintSession() {
|
||||||
close();
|
close();
|
||||||
ALOGV("PowerHintSession deleted: %s", mDescriptor->toString().c_str());
|
ALOGV("PowerHintSession deleted: %s", mDescriptor->toString().c_str());
|
||||||
|
@ -144,16 +130,13 @@ PowerHintSession::~PowerHintSession() {
|
||||||
}
|
}
|
||||||
delete mDescriptor;
|
delete mDescriptor;
|
||||||
}
|
}
|
||||||
|
|
||||||
void PowerHintSession::traceSessionVal(char const *identifier, int64_t val) const {
|
void PowerHintSession::traceSessionVal(char const *identifier, int64_t val) const {
|
||||||
ATRACE_INT(StringPrintf("adpf.%s-%s", mIdString.c_str(), identifier).c_str(), val);
|
ATRACE_INT(StringPrintf("adpf.%s-%s", mIdString.c_str(), identifier).c_str(), val);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool PowerHintSession::isAppSession() {
|
bool PowerHintSession::isAppSession() {
|
||||||
// Check if uid is in range reserved for applications
|
// Check if uid is in range reserved for applications
|
||||||
return mDescriptor->uid >= AID_APP_START;
|
return mDescriptor->uid >= AID_APP_START;
|
||||||
}
|
}
|
||||||
|
|
||||||
void PowerHintSession::updateUniveralBoostMode() {
|
void PowerHintSession::updateUniveralBoostMode() {
|
||||||
if (!isAppSession()) {
|
if (!isAppSession()) {
|
||||||
return;
|
return;
|
||||||
|
@ -167,7 +150,6 @@ void PowerHintSession::updateUniveralBoostMode() {
|
||||||
ATRACE_END();
|
ATRACE_END();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void PowerHintSession::tryToSendPowerHint(std::string hint) {
|
void PowerHintSession::tryToSendPowerHint(std::string hint) {
|
||||||
if (!mSupportedHints[hint].has_value()) {
|
if (!mSupportedHints[hint].has_value()) {
|
||||||
mSupportedHints[hint] = HintManager::GetInstance()->IsHintSupported(hint);
|
mSupportedHints[hint] = HintManager::GetInstance()->IsHintSupported(hint);
|
||||||
|
@ -176,7 +158,6 @@ void PowerHintSession::tryToSendPowerHint(std::string hint) {
|
||||||
HintManager::GetInstance()->DoHint(hint);
|
HintManager::GetInstance()->DoHint(hint);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int PowerHintSession::setSessionUclampMin(int32_t min) {
|
int PowerHintSession::setSessionUclampMin(int32_t min) {
|
||||||
{
|
{
|
||||||
std::lock_guard<std::mutex> guard(mSessionLock);
|
std::lock_guard<std::mutex> guard(mSessionLock);
|
||||||
|
@ -186,24 +167,20 @@ int PowerHintSession::setSessionUclampMin(int32_t min) {
|
||||||
mStaleTimerHandler->updateTimer();
|
mStaleTimerHandler->updateTimer();
|
||||||
}
|
}
|
||||||
PowerSessionManager::getInstance()->setUclampMin(this, min);
|
PowerSessionManager::getInstance()->setUclampMin(this, min);
|
||||||
|
|
||||||
if (ATRACE_ENABLED()) {
|
if (ATRACE_ENABLED()) {
|
||||||
traceSessionVal("min", min);
|
traceSessionVal("min", min);
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int PowerHintSession::getUclampMin() {
|
int PowerHintSession::getUclampMin() {
|
||||||
return mDescriptor->current_min;
|
return mDescriptor->current_min;
|
||||||
}
|
}
|
||||||
|
|
||||||
void PowerHintSession::dumpToStream(std::ostream &stream) {
|
void PowerHintSession::dumpToStream(std::ostream &stream) {
|
||||||
stream << "ID.Min.Act.Timeout(" << mIdString;
|
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() << ")";
|
||||||
}
|
}
|
||||||
|
|
||||||
ndk::ScopedAStatus PowerHintSession::pause() {
|
ndk::ScopedAStatus PowerHintSession::pause() {
|
||||||
if (mSessionClosed) {
|
if (mSessionClosed) {
|
||||||
ALOGE("Error: session is dead");
|
ALOGE("Error: session is dead");
|
||||||
|
@ -220,7 +197,6 @@ ndk::ScopedAStatus PowerHintSession::pause() {
|
||||||
updateUniveralBoostMode();
|
updateUniveralBoostMode();
|
||||||
return ndk::ScopedAStatus::ok();
|
return ndk::ScopedAStatus::ok();
|
||||||
}
|
}
|
||||||
|
|
||||||
ndk::ScopedAStatus PowerHintSession::resume() {
|
ndk::ScopedAStatus PowerHintSession::resume() {
|
||||||
if (mSessionClosed) {
|
if (mSessionClosed) {
|
||||||
ALOGE("Error: session is dead");
|
ALOGE("Error: session is dead");
|
||||||
|
@ -237,7 +213,6 @@ ndk::ScopedAStatus PowerHintSession::resume() {
|
||||||
updateUniveralBoostMode();
|
updateUniveralBoostMode();
|
||||||
return ndk::ScopedAStatus::ok();
|
return ndk::ScopedAStatus::ok();
|
||||||
}
|
}
|
||||||
|
|
||||||
ndk::ScopedAStatus PowerHintSession::close() {
|
ndk::ScopedAStatus PowerHintSession::close() {
|
||||||
bool sessionClosedExpectedToBe = false;
|
bool sessionClosedExpectedToBe = false;
|
||||||
if (!mSessionClosed.compare_exchange_strong(sessionClosedExpectedToBe, true)) {
|
if (!mSessionClosed.compare_exchange_strong(sessionClosedExpectedToBe, true)) {
|
||||||
|
@ -251,7 +226,6 @@ ndk::ScopedAStatus PowerHintSession::close() {
|
||||||
updateUniveralBoostMode();
|
updateUniveralBoostMode();
|
||||||
return ndk::ScopedAStatus::ok();
|
return ndk::ScopedAStatus::ok();
|
||||||
}
|
}
|
||||||
|
|
||||||
ndk::ScopedAStatus PowerHintSession::updateTargetWorkDuration(int64_t targetDurationNanos) {
|
ndk::ScopedAStatus PowerHintSession::updateTargetWorkDuration(int64_t targetDurationNanos) {
|
||||||
if (mSessionClosed) {
|
if (mSessionClosed) {
|
||||||
ALOGE("Error: session is dead");
|
ALOGE("Error: session is dead");
|
||||||
|
@ -264,15 +238,12 @@ ndk::ScopedAStatus PowerHintSession::updateTargetWorkDuration(int64_t targetDura
|
||||||
targetDurationNanos =
|
targetDurationNanos =
|
||||||
targetDurationNanos * HintManager::GetInstance()->GetAdpfProfile()->mTargetTimeFactor;
|
targetDurationNanos * HintManager::GetInstance()->GetAdpfProfile()->mTargetTimeFactor;
|
||||||
ALOGV("update target duration: %" PRId64 " ns", targetDurationNanos);
|
ALOGV("update target duration: %" PRId64 " ns", targetDurationNanos);
|
||||||
|
|
||||||
mDescriptor->duration = std::chrono::nanoseconds(targetDurationNanos);
|
mDescriptor->duration = std::chrono::nanoseconds(targetDurationNanos);
|
||||||
if (ATRACE_ENABLED()) {
|
if (ATRACE_ENABLED()) {
|
||||||
traceSessionVal("target", mDescriptor->duration.count());
|
traceSessionVal("target", mDescriptor->duration.count());
|
||||||
}
|
}
|
||||||
|
|
||||||
return ndk::ScopedAStatus::ok();
|
return ndk::ScopedAStatus::ok();
|
||||||
}
|
}
|
||||||
|
|
||||||
ndk::ScopedAStatus PowerHintSession::reportActualWorkDuration(
|
ndk::ScopedAStatus PowerHintSession::reportActualWorkDuration(
|
||||||
const std::vector<WorkDuration> &actualDurations) {
|
const std::vector<WorkDuration> &actualDurations) {
|
||||||
if (mSessionClosed) {
|
if (mSessionClosed) {
|
||||||
|
@ -303,7 +274,6 @@ ndk::ScopedAStatus PowerHintSession::reportActualWorkDuration(
|
||||||
actualDurations.back().durationNanos - mDescriptor->duration.count() > 0);
|
actualDurations.back().durationNanos - mDescriptor->duration.count() > 0);
|
||||||
traceSessionVal("session_hint", -1);
|
traceSessionVal("session_hint", -1);
|
||||||
}
|
}
|
||||||
|
|
||||||
mLastUpdatedTime.store(std::chrono::steady_clock::now());
|
mLastUpdatedTime.store(std::chrono::steady_clock::now());
|
||||||
if (isFirstFrame) {
|
if (isFirstFrame) {
|
||||||
if (isAppSession()) {
|
if (isAppSession()) {
|
||||||
|
@ -311,22 +281,18 @@ ndk::ScopedAStatus PowerHintSession::reportActualWorkDuration(
|
||||||
}
|
}
|
||||||
updateUniveralBoostMode();
|
updateUniveralBoostMode();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!adpfConfig->mPidOn) {
|
if (!adpfConfig->mPidOn) {
|
||||||
setSessionUclampMin(adpfConfig->mUclampMinHigh);
|
setSessionUclampMin(adpfConfig->mUclampMinHigh);
|
||||||
return ndk::ScopedAStatus::ok();
|
return ndk::ScopedAStatus::ok();
|
||||||
}
|
}
|
||||||
int64_t output = convertWorkDurationToBoostByPid(actualDurations);
|
int64_t output = convertWorkDurationToBoostByPid(actualDurations);
|
||||||
|
|
||||||
/* 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),
|
||||||
mDescriptor->current_min + static_cast<int>(output));
|
mDescriptor->current_min + static_cast<int>(output));
|
||||||
next_min = std::max(static_cast<int>(adpfConfig->mUclampMinLow), next_min);
|
next_min = std::max(static_cast<int>(adpfConfig->mUclampMinLow), next_min);
|
||||||
setSessionUclampMin(next_min);
|
setSessionUclampMin(next_min);
|
||||||
|
|
||||||
return ndk::ScopedAStatus::ok();
|
return ndk::ScopedAStatus::ok();
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string AppHintDesc::toString() const {
|
std::string AppHintDesc::toString() const {
|
||||||
std::string out =
|
std::string out =
|
||||||
StringPrintf("session %" PRIxPTR "\n", reinterpret_cast<uintptr_t>(this) & 0xffff);
|
StringPrintf("session %" PRIxPTR "\n", reinterpret_cast<uintptr_t>(this) & 0xffff);
|
||||||
|
@ -334,7 +300,6 @@ std::string AppHintDesc::toString() const {
|
||||||
out.append(StringPrintf(" duration: %" PRId64 " ns\n", durationNanos));
|
out.append(StringPrintf(" duration: %" PRId64 " ns\n", durationNanos));
|
||||||
out.append(StringPrintf(" uclamp.min: %d \n", current_min));
|
out.append(StringPrintf(" uclamp.min: %d \n", current_min));
|
||||||
out.append(StringPrintf(" uid: %d, tgid: %d\n", uid, tgid));
|
out.append(StringPrintf(" uid: %d, tgid: %d\n", uid, tgid));
|
||||||
|
|
||||||
out.append(" threadIds: [");
|
out.append(" threadIds: [");
|
||||||
bool first = true;
|
bool first = true;
|
||||||
for (int tid : threadIds) {
|
for (int tid : threadIds) {
|
||||||
|
@ -347,11 +312,9 @@ std::string AppHintDesc::toString() const {
|
||||||
out.append("]\n");
|
out.append("]\n");
|
||||||
return out;
|
return out;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool PowerHintSession::isActive() {
|
bool PowerHintSession::isActive() {
|
||||||
return mDescriptor->is_active.load();
|
return mDescriptor->is_active.load();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool PowerHintSession::isTimeout() {
|
bool PowerHintSession::isTimeout() {
|
||||||
auto now = std::chrono::steady_clock::now();
|
auto now = std::chrono::steady_clock::now();
|
||||||
time_point<steady_clock> staleTime =
|
time_point<steady_clock> staleTime =
|
||||||
|
@ -361,11 +324,9 @@ bool PowerHintSession::isTimeout() {
|
||||||
HintManager::GetInstance()->GetAdpfProfile()->mStaleTimeFactor));
|
HintManager::GetInstance()->GetAdpfProfile()->mStaleTimeFactor));
|
||||||
return now >= staleTime;
|
return now >= staleTime;
|
||||||
}
|
}
|
||||||
|
|
||||||
const std::vector<int> &PowerHintSession::getTidList() const {
|
const std::vector<int> &PowerHintSession::getTidList() const {
|
||||||
return mDescriptor->threadIds;
|
return mDescriptor->threadIds;
|
||||||
}
|
}
|
||||||
|
|
||||||
void PowerHintSession::setStale() {
|
void PowerHintSession::setStale() {
|
||||||
// Reset to default uclamp value.
|
// Reset to default uclamp value.
|
||||||
PowerSessionManager::getInstance()->setUclampMin(this, 0);
|
PowerSessionManager::getInstance()->setUclampMin(this, 0);
|
||||||
|
@ -375,7 +336,6 @@ void PowerHintSession::setStale() {
|
||||||
traceSessionVal("min", 0);
|
traceSessionVal("min", 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void PowerHintSession::StaleTimerHandler::updateTimer() {
|
void PowerHintSession::StaleTimerHandler::updateTimer() {
|
||||||
auto now = std::chrono::steady_clock::now();
|
auto now = std::chrono::steady_clock::now();
|
||||||
nanoseconds staleDuration = std::chrono::nanoseconds(
|
nanoseconds staleDuration = std::chrono::nanoseconds(
|
||||||
|
@ -393,7 +353,6 @@ void PowerHintSession::StaleTimerHandler::updateTimer() {
|
||||||
mSession->traceSessionVal("timer.stale", 0);
|
mSession->traceSessionVal("timer.stale", 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void PowerHintSession::StaleTimerHandler::handleMessage(const Message &) {
|
void PowerHintSession::StaleTimerHandler::handleMessage(const Message &) {
|
||||||
std::lock_guard<std::mutex> guard(mClosedLock);
|
std::lock_guard<std::mutex> guard(mClosedLock);
|
||||||
if (mIsSessionDead) {
|
if (mIsSessionDead) {
|
||||||
|
@ -418,13 +377,11 @@ void PowerHintSession::StaleTimerHandler::handleMessage(const Message &) {
|
||||||
mSession->traceSessionVal("timer.stale", next > 0 ? 0 : 1);
|
mSession->traceSessionVal("timer.stale", next > 0 ? 0 : 1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void PowerHintSession::StaleTimerHandler::setSessionDead() {
|
void PowerHintSession::StaleTimerHandler::setSessionDead() {
|
||||||
std::lock_guard<std::mutex> guard(mClosedLock);
|
std::lock_guard<std::mutex> guard(mClosedLock);
|
||||||
mIsSessionDead = true;
|
mIsSessionDead = true;
|
||||||
PowerHintMonitor::getInstance()->getLooper()->removeMessages(mSession->mStaleTimerHandler);
|
PowerHintMonitor::getInstance()->getLooper()->removeMessages(mSession->mStaleTimerHandler);
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace pixel
|
} // namespace pixel
|
||||||
} // namespace impl
|
} // namespace impl
|
||||||
} // namespace power
|
} // namespace power
|
||||||
|
|
|
@ -13,24 +13,19 @@
|
||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <aidl/android/hardware/power/BnPowerHintSession.h>
|
#include <aidl/android/hardware/power/BnPowerHintSession.h>
|
||||||
#include <aidl/android/hardware/power/WorkDuration.h>
|
#include <aidl/android/hardware/power/WorkDuration.h>
|
||||||
#include <utils/Looper.h>
|
#include <utils/Looper.h>
|
||||||
#include <utils/Thread.h>
|
#include <utils/Thread.h>
|
||||||
|
|
||||||
#include <mutex>
|
#include <mutex>
|
||||||
#include <unordered_map>
|
#include <unordered_map>
|
||||||
|
|
||||||
namespace aidl {
|
namespace aidl {
|
||||||
namespace google {
|
namespace google {
|
||||||
namespace hardware {
|
namespace hardware {
|
||||||
namespace power {
|
namespace power {
|
||||||
namespace impl {
|
namespace impl {
|
||||||
namespace pixel {
|
namespace pixel {
|
||||||
|
|
||||||
using aidl::android::hardware::power::BnPowerHintSession;
|
using aidl::android::hardware::power::BnPowerHintSession;
|
||||||
using aidl::android::hardware::power::WorkDuration;
|
using aidl::android::hardware::power::WorkDuration;
|
||||||
using ::android::Message;
|
using ::android::Message;
|
||||||
|
@ -40,7 +35,6 @@ using std::chrono::milliseconds;
|
||||||
using std::chrono::nanoseconds;
|
using std::chrono::nanoseconds;
|
||||||
using std::chrono::steady_clock;
|
using std::chrono::steady_clock;
|
||||||
using std::chrono::time_point;
|
using std::chrono::time_point;
|
||||||
|
|
||||||
struct AppHintDesc {
|
struct AppHintDesc {
|
||||||
AppHintDesc(int32_t tgid, int32_t uid, std::vector<int> threadIds)
|
AppHintDesc(int32_t tgid, int32_t uid, std::vector<int> threadIds)
|
||||||
: tgid(tgid),
|
: tgid(tgid),
|
||||||
|
@ -65,7 +59,6 @@ struct AppHintDesc {
|
||||||
int64_t integral_error;
|
int64_t integral_error;
|
||||||
int64_t previous_error;
|
int64_t previous_error;
|
||||||
};
|
};
|
||||||
|
|
||||||
class PowerHintSession : public BnPowerHintSession {
|
class PowerHintSession : public BnPowerHintSession {
|
||||||
public:
|
public:
|
||||||
explicit 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,
|
||||||
|
@ -85,9 +78,7 @@ class PowerHintSession : public BnPowerHintSession {
|
||||||
const std::vector<int> &getTidList() const;
|
const std::vector<int> &getTidList() const;
|
||||||
int getUclampMin();
|
int getUclampMin();
|
||||||
void dumpToStream(std::ostream &stream);
|
void dumpToStream(std::ostream &stream);
|
||||||
|
|
||||||
time_point<steady_clock> getStaleTime();
|
time_point<steady_clock> getStaleTime();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
class StaleTimerHandler : public MessageHandler {
|
class StaleTimerHandler : public MessageHandler {
|
||||||
public:
|
public:
|
||||||
|
@ -95,7 +86,6 @@ class PowerHintSession : public BnPowerHintSession {
|
||||||
void updateTimer();
|
void updateTimer();
|
||||||
void handleMessage(const Message &message) override;
|
void handleMessage(const Message &message) override;
|
||||||
void setSessionDead();
|
void setSessionDead();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
PowerHintSession *mSession;
|
PowerHintSession *mSession;
|
||||||
std::mutex mClosedLock;
|
std::mutex mClosedLock;
|
||||||
|
@ -103,7 +93,6 @@ class PowerHintSession : public BnPowerHintSession {
|
||||||
std::atomic<time_point<steady_clock>> mStaleTime;
|
std::atomic<time_point<steady_clock>> mStaleTime;
|
||||||
bool mIsSessionDead;
|
bool mIsSessionDead;
|
||||||
};
|
};
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void updateUniveralBoostMode();
|
void updateUniveralBoostMode();
|
||||||
int setSessionUclampMin(int32_t min);
|
int setSessionUclampMin(int32_t min);
|
||||||
|
@ -120,7 +109,6 @@ class PowerHintSession : public BnPowerHintSession {
|
||||||
// To cache the status of whether ADPF hints are supported.
|
// To cache the status of whether ADPF hints are supported.
|
||||||
std::unordered_map<std::string, std::optional<bool>> mSupportedHints;
|
std::unordered_map<std::string, std::optional<bool>> mSupportedHints;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace pixel
|
} // namespace pixel
|
||||||
} // namespace impl
|
} // namespace impl
|
||||||
} // namespace power
|
} // namespace power
|
||||||
|
|
|
@ -13,29 +13,23 @@
|
||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#define LOG_TAG "powerhal-libperfmgr"
|
#define LOG_TAG "powerhal-libperfmgr"
|
||||||
#define ATRACE_TAG (ATRACE_TAG_POWER | ATRACE_TAG_HAL)
|
#define ATRACE_TAG (ATRACE_TAG_POWER | ATRACE_TAG_HAL)
|
||||||
|
|
||||||
#include "PowerSessionManager.h"
|
#include "PowerSessionManager.h"
|
||||||
|
|
||||||
#include <android-base/file.h>
|
#include <android-base/file.h>
|
||||||
#include <log/log.h>
|
#include <log/log.h>
|
||||||
#include <perfmgr/HintManager.h>
|
#include <perfmgr/HintManager.h>
|
||||||
#include <processgroup/processgroup.h>
|
#include <processgroup/processgroup.h>
|
||||||
#include <sys/syscall.h>
|
#include <sys/syscall.h>
|
||||||
#include <utils/Trace.h>
|
#include <utils/Trace.h>
|
||||||
|
|
||||||
namespace aidl {
|
namespace aidl {
|
||||||
namespace google {
|
namespace google {
|
||||||
namespace hardware {
|
namespace hardware {
|
||||||
namespace power {
|
namespace power {
|
||||||
namespace impl {
|
namespace impl {
|
||||||
namespace pixel {
|
namespace pixel {
|
||||||
|
|
||||||
using ::android::perfmgr::AdpfConfig;
|
using ::android::perfmgr::AdpfConfig;
|
||||||
using ::android::perfmgr::HintManager;
|
using ::android::perfmgr::HintManager;
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
/* there is no glibc or bionic wrapper */
|
/* there is no glibc or bionic wrapper */
|
||||||
struct sched_attr {
|
struct sched_attr {
|
||||||
|
@ -50,7 +44,6 @@ struct sched_attr {
|
||||||
__u32 sched_util_min;
|
__u32 sched_util_min;
|
||||||
__u32 sched_util_max;
|
__u32 sched_util_max;
|
||||||
};
|
};
|
||||||
|
|
||||||
static int sched_setattr(int pid, struct sched_attr *attr, unsigned int flags) {
|
static int sched_setattr(int pid, struct sched_attr *attr, unsigned int flags) {
|
||||||
if (!HintManager::GetInstance()->GetAdpfProfile()->mUclampMinOn) {
|
if (!HintManager::GetInstance()->GetAdpfProfile()->mUclampMinOn) {
|
||||||
ALOGV("PowerSessionManager:%s: skip", __func__);
|
ALOGV("PowerSessionManager:%s: skip", __func__);
|
||||||
|
@ -58,25 +51,20 @@ static int sched_setattr(int pid, struct sched_attr *attr, unsigned int flags) {
|
||||||
}
|
}
|
||||||
return syscall(__NR_sched_setattr, pid, attr, flags);
|
return syscall(__NR_sched_setattr, pid, attr, flags);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void set_uclamp_min(int tid, int min) {
|
static void set_uclamp_min(int tid, int min) {
|
||||||
static constexpr int32_t kMaxUclampValue = 1024;
|
static constexpr int32_t kMaxUclampValue = 1024;
|
||||||
min = std::max(0, min);
|
min = std::max(0, min);
|
||||||
min = std::min(min, kMaxUclampValue);
|
min = std::min(min, kMaxUclampValue);
|
||||||
|
|
||||||
sched_attr attr = {};
|
sched_attr attr = {};
|
||||||
attr.size = sizeof(attr);
|
attr.size = sizeof(attr);
|
||||||
|
|
||||||
attr.sched_flags = (SCHED_FLAG_KEEP_ALL | SCHED_FLAG_UTIL_CLAMP_MIN);
|
attr.sched_flags = (SCHED_FLAG_KEEP_ALL | SCHED_FLAG_UTIL_CLAMP_MIN);
|
||||||
attr.sched_util_min = min;
|
attr.sched_util_min = min;
|
||||||
|
|
||||||
int ret = sched_setattr(tid, &attr, 0);
|
int ret = sched_setattr(tid, &attr, 0);
|
||||||
if (ret) {
|
if (ret) {
|
||||||
ALOGW("sched_setattr failed for thread %d, err=%d", tid, errno);
|
ALOGW("sched_setattr failed for thread %d, err=%d", tid, errno);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
void PowerSessionManager::updateHintMode(const std::string &mode, bool enabled) {
|
void PowerSessionManager::updateHintMode(const std::string &mode, bool enabled) {
|
||||||
ALOGV("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) {
|
||||||
|
@ -92,17 +80,14 @@ void PowerSessionManager::updateHintMode(const std::string &mode, bool enabled)
|
||||||
HintManager::GetInstance()->SetAdpfProfile(mode);
|
HintManager::GetInstance()->SetAdpfProfile(mode);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void PowerSessionManager::updateHintBoost(const std::string &boost, int32_t durationMs) {
|
void PowerSessionManager::updateHintBoost(const std::string &boost, int32_t durationMs) {
|
||||||
ATRACE_CALL();
|
ATRACE_CALL();
|
||||||
ALOGV("PowerSessionManager::updateHintBoost: boost: %s, durationMs: %d", boost.c_str(),
|
ALOGV("PowerSessionManager::updateHintBoost: boost: %s, durationMs: %d", boost.c_str(),
|
||||||
durationMs);
|
durationMs);
|
||||||
}
|
}
|
||||||
|
|
||||||
int PowerSessionManager::getDisplayRefreshRate() {
|
int PowerSessionManager::getDisplayRefreshRate() {
|
||||||
return mDisplayRefreshRate;
|
return mDisplayRefreshRate;
|
||||||
}
|
}
|
||||||
|
|
||||||
void PowerSessionManager::addPowerSession(PowerHintSession *session) {
|
void PowerSessionManager::addPowerSession(PowerHintSession *session) {
|
||||||
std::lock_guard<std::mutex> guard(mLock);
|
std::lock_guard<std::mutex> guard(mLock);
|
||||||
for (auto t : session->getTidList()) {
|
for (auto t : session->getTidList()) {
|
||||||
|
@ -123,7 +108,6 @@ void PowerSessionManager::addPowerSession(PowerHintSession *session) {
|
||||||
}
|
}
|
||||||
mSessions.insert(session);
|
mSessions.insert(session);
|
||||||
}
|
}
|
||||||
|
|
||||||
void PowerSessionManager::removePowerSession(PowerHintSession *session) {
|
void PowerSessionManager::removePowerSession(PowerHintSession *session) {
|
||||||
std::lock_guard<std::mutex> guard(mLock);
|
std::lock_guard<std::mutex> guard(mLock);
|
||||||
for (auto t : session->getTidList()) {
|
for (auto t : session->getTidList()) {
|
||||||
|
@ -142,12 +126,10 @@ void PowerSessionManager::removePowerSession(PowerHintSession *session) {
|
||||||
}
|
}
|
||||||
mSessions.erase(session);
|
mSessions.erase(session);
|
||||||
}
|
}
|
||||||
|
|
||||||
void PowerSessionManager::setUclampMin(PowerHintSession *session, int val) {
|
void PowerSessionManager::setUclampMin(PowerHintSession *session, int val) {
|
||||||
std::lock_guard<std::mutex> guard(mLock);
|
std::lock_guard<std::mutex> guard(mLock);
|
||||||
setUclampMinLocked(session, val);
|
setUclampMinLocked(session, val);
|
||||||
}
|
}
|
||||||
|
|
||||||
void PowerSessionManager::setUclampMinLocked(PowerHintSession *session, int val) {
|
void PowerSessionManager::setUclampMinLocked(PowerHintSession *session, int val) {
|
||||||
for (auto t : session->getTidList()) {
|
for (auto t : session->getTidList()) {
|
||||||
// Get thex max uclamp.min across sessions which include the tid.
|
// Get thex max uclamp.min across sessions which include the tid.
|
||||||
|
@ -160,7 +142,6 @@ void PowerSessionManager::setUclampMinLocked(PowerHintSession *session, int val)
|
||||||
set_uclamp_min(t, std::max(val, tidMax));
|
set_uclamp_min(t, std::max(val, tidMax));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
std::optional<bool> PowerSessionManager::isAnyAppSessionActive() {
|
std::optional<bool> PowerSessionManager::isAnyAppSessionActive() {
|
||||||
std::lock_guard<std::mutex> guard(mLock);
|
std::lock_guard<std::mutex> guard(mLock);
|
||||||
bool active = false;
|
bool active = false;
|
||||||
|
@ -176,10 +157,8 @@ std::optional<bool> PowerSessionManager::isAnyAppSessionActive() {
|
||||||
} else {
|
} else {
|
||||||
mActive = active;
|
mActive = active;
|
||||||
}
|
}
|
||||||
|
|
||||||
return active;
|
return active;
|
||||||
}
|
}
|
||||||
|
|
||||||
void PowerSessionManager::handleMessage(const Message &) {
|
void PowerSessionManager::handleMessage(const Message &) {
|
||||||
auto active = isAnyAppSessionActive();
|
auto active = isAnyAppSessionActive();
|
||||||
if (!active.has_value()) {
|
if (!active.has_value()) {
|
||||||
|
@ -191,7 +170,6 @@ void PowerSessionManager::handleMessage(const Message &) {
|
||||||
enableSystemTopAppBoost();
|
enableSystemTopAppBoost();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void PowerSessionManager::dumpToFd(int fd) {
|
void PowerSessionManager::dumpToFd(int fd) {
|
||||||
std::ostringstream dump_buf;
|
std::ostringstream dump_buf;
|
||||||
std::lock_guard<std::mutex> guard(mLock);
|
std::lock_guard<std::mutex> guard(mLock);
|
||||||
|
@ -213,39 +191,33 @@ void PowerSessionManager::dumpToFd(int fd) {
|
||||||
ALOGE("Failed to dump one of session list to fd:%d", fd);
|
ALOGE("Failed to dump one of session list to fd:%d", fd);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void PowerSessionManager::enableSystemTopAppBoost() {
|
void PowerSessionManager::enableSystemTopAppBoost() {
|
||||||
if (HintManager::GetInstance()->IsHintSupported(kDisableBoostHintName)) {
|
if (HintManager::GetInstance()->IsHintSupported(kDisableBoostHintName)) {
|
||||||
ALOGV("PowerSessionManager::enableSystemTopAppBoost!!");
|
ALOGV("PowerSessionManager::enableSystemTopAppBoost!!");
|
||||||
HintManager::GetInstance()->EndHint(kDisableBoostHintName);
|
HintManager::GetInstance()->EndHint(kDisableBoostHintName);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void PowerSessionManager::disableSystemTopAppBoost() {
|
void PowerSessionManager::disableSystemTopAppBoost() {
|
||||||
if (HintManager::GetInstance()->IsHintSupported(kDisableBoostHintName)) {
|
if (HintManager::GetInstance()->IsHintSupported(kDisableBoostHintName)) {
|
||||||
ALOGV("PowerSessionManager::disableSystemTopAppBoost!!");
|
ALOGV("PowerSessionManager::disableSystemTopAppBoost!!");
|
||||||
HintManager::GetInstance()->DoHint(kDisableBoostHintName);
|
HintManager::GetInstance()->DoHint(kDisableBoostHintName);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// =========== PowerHintMonitor implementation start from here ===========
|
// =========== PowerHintMonitor implementation start from here ===========
|
||||||
void PowerHintMonitor::start() {
|
void PowerHintMonitor::start() {
|
||||||
if (!isRunning()) {
|
if (!isRunning()) {
|
||||||
run("PowerHintMonitor", ::android::PRIORITY_HIGHEST);
|
run("PowerHintMonitor", ::android::PRIORITY_HIGHEST);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool PowerHintMonitor::threadLoop() {
|
bool PowerHintMonitor::threadLoop() {
|
||||||
while (true) {
|
while (true) {
|
||||||
mLooper->pollOnce(-1);
|
mLooper->pollOnce(-1);
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
sp<Looper> PowerHintMonitor::getLooper() {
|
sp<Looper> PowerHintMonitor::getLooper() {
|
||||||
return mLooper;
|
return mLooper;
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace pixel
|
} // namespace pixel
|
||||||
} // namespace impl
|
} // namespace impl
|
||||||
} // namespace power
|
} // namespace power
|
||||||
|
|
|
@ -13,34 +13,26 @@
|
||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <android-base/properties.h>
|
#include <android-base/properties.h>
|
||||||
#include <perfmgr/HintManager.h>
|
#include <perfmgr/HintManager.h>
|
||||||
#include <utils/Looper.h>
|
#include <utils/Looper.h>
|
||||||
|
|
||||||
#include <mutex>
|
#include <mutex>
|
||||||
#include <optional>
|
#include <optional>
|
||||||
#include <unordered_set>
|
#include <unordered_set>
|
||||||
|
|
||||||
#include "PowerHintSession.h"
|
#include "PowerHintSession.h"
|
||||||
|
|
||||||
namespace aidl {
|
namespace aidl {
|
||||||
namespace google {
|
namespace google {
|
||||||
namespace hardware {
|
namespace hardware {
|
||||||
namespace power {
|
namespace power {
|
||||||
namespace impl {
|
namespace impl {
|
||||||
namespace pixel {
|
namespace pixel {
|
||||||
|
|
||||||
using ::android::Looper;
|
using ::android::Looper;
|
||||||
using ::android::Message;
|
using ::android::Message;
|
||||||
using ::android::MessageHandler;
|
using ::android::MessageHandler;
|
||||||
using ::android::Thread;
|
using ::android::Thread;
|
||||||
using ::android::perfmgr::HintManager;
|
using ::android::perfmgr::HintManager;
|
||||||
|
|
||||||
constexpr char kPowerHalAdpfDisableTopAppBoost[] = "vendor.powerhal.adpf.disable.hint";
|
constexpr char kPowerHalAdpfDisableTopAppBoost[] = "vendor.powerhal.adpf.disable.hint";
|
||||||
|
|
||||||
class PowerSessionManager : public MessageHandler {
|
class PowerSessionManager : public MessageHandler {
|
||||||
public:
|
public:
|
||||||
// current hint info
|
// current hint info
|
||||||
|
@ -54,19 +46,16 @@ class PowerSessionManager : public MessageHandler {
|
||||||
void setUclampMinLocked(PowerHintSession *session, int min);
|
void setUclampMinLocked(PowerHintSession *session, int min);
|
||||||
void handleMessage(const Message &message) override;
|
void handleMessage(const Message &message) override;
|
||||||
void dumpToFd(int fd);
|
void dumpToFd(int fd);
|
||||||
|
|
||||||
// Singleton
|
// Singleton
|
||||||
static sp<PowerSessionManager> getInstance() {
|
static sp<PowerSessionManager> getInstance() {
|
||||||
static sp<PowerSessionManager> instance = new PowerSessionManager();
|
static sp<PowerSessionManager> instance = new PowerSessionManager();
|
||||||
return instance;
|
return instance;
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::optional<bool> isAnyAppSessionActive();
|
std::optional<bool> isAnyAppSessionActive();
|
||||||
void disableSystemTopAppBoost();
|
void disableSystemTopAppBoost();
|
||||||
void enableSystemTopAppBoost();
|
void enableSystemTopAppBoost();
|
||||||
const std::string kDisableBoostHintName;
|
const std::string kDisableBoostHintName;
|
||||||
|
|
||||||
std::unordered_set<PowerHintSession *> mSessions; // protected by mLock
|
std::unordered_set<PowerHintSession *> mSessions; // protected by mLock
|
||||||
std::unordered_map<int, int> mTidRefCountMap; // protected by mLock
|
std::unordered_map<int, int> mTidRefCountMap; // protected by mLock
|
||||||
std::unordered_map<int, std::unordered_set<PowerHintSession *>> mTidSessionListMap;
|
std::unordered_map<int, std::unordered_set<PowerHintSession *>> mTidSessionListMap;
|
||||||
|
@ -85,7 +74,6 @@ class PowerSessionManager : public MessageHandler {
|
||||||
PowerSessionManager(PowerSessionManager const &) = delete;
|
PowerSessionManager(PowerSessionManager const &) = delete;
|
||||||
void operator=(PowerSessionManager const &) = delete;
|
void operator=(PowerSessionManager const &) = delete;
|
||||||
};
|
};
|
||||||
|
|
||||||
class PowerHintMonitor : public Thread {
|
class PowerHintMonitor : public Thread {
|
||||||
public:
|
public:
|
||||||
void start();
|
void start();
|
||||||
|
@ -98,13 +86,11 @@ class PowerHintMonitor : public Thread {
|
||||||
}
|
}
|
||||||
PowerHintMonitor(PowerHintMonitor const &) = delete;
|
PowerHintMonitor(PowerHintMonitor const &) = delete;
|
||||||
void operator=(PowerHintMonitor const &) = delete;
|
void operator=(PowerHintMonitor const &) = delete;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
sp<Looper> mLooper;
|
sp<Looper> mLooper;
|
||||||
// Singleton
|
// Singleton
|
||||||
PowerHintMonitor() : Thread(false), mLooper(new Looper(true)) {}
|
PowerHintMonitor() : Thread(false), mLooper(new Looper(true)) {}
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace pixel
|
} // namespace pixel
|
||||||
} // namespace impl
|
} // namespace impl
|
||||||
} // namespace power
|
} // namespace power
|
||||||
|
|
|
@ -1,32 +1,25 @@
|
||||||
service vendor.power-hal-aidl /vendor/bin/hw/android.hardware.power-service.lenovo-sdm710-libperfmgr
|
service vendor.power-hal-aidl /vendor/bin/hw/android.hardware.power-service.xiaomi-libperfmgr
|
||||||
class hal
|
class hal
|
||||||
user root
|
user root
|
||||||
group system
|
group system
|
||||||
priority -20
|
priority -20
|
||||||
|
|
||||||
on late-fs
|
on late-fs
|
||||||
start vendor.power-hal-aidl
|
start vendor.power-hal-aidl
|
||||||
|
|
||||||
# Restart powerHAL when framework died
|
# Restart powerHAL when framework died
|
||||||
on property:init.svc.zygote=restarting && property:vendor.powerhal.state=*
|
on property:init.svc.zygote=restarting && property:vendor.powerhal.state=*
|
||||||
setprop vendor.powerhal.state ""
|
setprop vendor.powerhal.state ""
|
||||||
setprop vendor.powerhal.audio ""
|
setprop vendor.powerhal.audio ""
|
||||||
setprop vendor.powerhal.rendering ""
|
setprop vendor.powerhal.rendering ""
|
||||||
restart vendor.power-hal-aidl
|
restart vendor.power-hal-aidl
|
||||||
|
|
||||||
# Clean up after b/163539793 resolved
|
# Clean up after b/163539793 resolved
|
||||||
on property:vendor.powerhal.dalvik.vm.dex2oat-threads=*
|
on property:vendor.powerhal.dalvik.vm.dex2oat-threads=*
|
||||||
setprop dalvik.vm.dex2oat-threads ${vendor.powerhal.dalvik.vm.dex2oat-threads}
|
setprop dalvik.vm.dex2oat-threads ${vendor.powerhal.dalvik.vm.dex2oat-threads}
|
||||||
setprop dalvik.vm.restore-dex2oat-threads ${vendor.powerhal.dalvik.vm.dex2oat-threads}
|
setprop dalvik.vm.restore-dex2oat-threads ${vendor.powerhal.dalvik.vm.dex2oat-threads}
|
||||||
|
|
||||||
on property:vendor.powerhal.dalvik.vm.dex2oat-cpu-set=*
|
on property:vendor.powerhal.dalvik.vm.dex2oat-cpu-set=*
|
||||||
setprop dalvik.vm.dex2oat-cpu-set ${vendor.powerhal.dalvik.vm.dex2oat-cpu-set}
|
setprop dalvik.vm.dex2oat-cpu-set ${vendor.powerhal.dalvik.vm.dex2oat-cpu-set}
|
||||||
setprop dalvik.vm.restore-dex2oat-cpu-set ${vendor.powerhal.dalvik.vm.dex2oat-cpu-set}
|
setprop dalvik.vm.restore-dex2oat-cpu-set ${vendor.powerhal.dalvik.vm.dex2oat-cpu-set}
|
||||||
|
|
||||||
# Restart powerHAL when debug property set
|
# Restart powerHAL when debug property set
|
||||||
on property:ro.debuggable=1 && property:vendor.powerhal.config.debug=*
|
on property:ro.debuggable=1 && property:vendor.powerhal.config.debug=*
|
||||||
restart vendor.power-hal-aidl
|
restart vendor.power-hal-aidl
|
||||||
|
|
||||||
on property:persist.vendor.powerhal.config.debug=*
|
on property:persist.vendor.powerhal.config.debug=*
|
||||||
setprop vendor.powerhal.config.debug ${persist.vendor.powerhal.config.debug}
|
setprop vendor.powerhal.config.debug ${persist.vendor.powerhal.config.debug}
|
||||||
|
|
|
@ -13,71 +13,55 @@
|
||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#define LOG_TAG "powerhal-libperfmgr"
|
#define LOG_TAG "powerhal-libperfmgr"
|
||||||
|
|
||||||
#include <android-base/logging.h>
|
#include <android-base/logging.h>
|
||||||
#include <android-base/properties.h>
|
#include <android-base/properties.h>
|
||||||
#include <android/binder_ibinder_platform.h>
|
#include <android/binder_ibinder_platform.h>
|
||||||
#include <android/binder_manager.h>
|
#include <android/binder_manager.h>
|
||||||
#include <android/binder_process.h>
|
#include <android/binder_process.h>
|
||||||
#include <perfmgr/HintManager.h>
|
#include <perfmgr/HintManager.h>
|
||||||
|
|
||||||
#include <thread>
|
#include <thread>
|
||||||
|
|
||||||
#include "Power.h"
|
#include "Power.h"
|
||||||
#include "PowerExt.h"
|
#include "PowerExt.h"
|
||||||
#include "PowerSessionManager.h"
|
#include "PowerSessionManager.h"
|
||||||
|
|
||||||
using aidl::google::hardware::power::impl::pixel::Power;
|
using aidl::google::hardware::power::impl::pixel::Power;
|
||||||
using aidl::google::hardware::power::impl::pixel::PowerExt;
|
using aidl::google::hardware::power::impl::pixel::PowerExt;
|
||||||
using aidl::google::hardware::power::impl::pixel::PowerHintMonitor;
|
using aidl::google::hardware::power::impl::pixel::PowerHintMonitor;
|
||||||
using aidl::google::hardware::power::impl::pixel::PowerSessionManager;
|
using aidl::google::hardware::power::impl::pixel::PowerSessionManager;
|
||||||
using ::android::perfmgr::HintManager;
|
using ::android::perfmgr::HintManager;
|
||||||
|
|
||||||
constexpr std::string_view kPowerHalInitProp("vendor.powerhal.init");
|
constexpr std::string_view kPowerHalInitProp("vendor.powerhal.init");
|
||||||
|
|
||||||
int main() {
|
int main() {
|
||||||
// Parse config but do not start the looper
|
// Parse config but do not start the looper
|
||||||
HintManager *hm = HintManager::GetInstance();
|
std::shared_ptr<HintManager> hm = std::shared_ptr<HintManager>(HintManager::GetInstance());
|
||||||
if (!hm) {
|
if (!hm) {
|
||||||
LOG(FATAL) << "HintManager Init failed";
|
LOG(FATAL) << "HintManager Init failed";
|
||||||
}
|
}
|
||||||
|
|
||||||
// single thread
|
// single thread
|
||||||
ABinderProcess_setThreadPoolMaxThreadCount(0);
|
ABinderProcess_setThreadPoolMaxThreadCount(0);
|
||||||
|
|
||||||
// core service
|
// core service
|
||||||
std::shared_ptr<Power> pw = ndk::SharedRefBase::make<Power>();
|
std::shared_ptr<Power> pw = ndk::SharedRefBase::make<Power>();
|
||||||
ndk::SpAIBinder pwBinder = pw->asBinder();
|
ndk::SpAIBinder pwBinder = pw->asBinder();
|
||||||
AIBinder_setMinSchedulerPolicy(pwBinder.get(), SCHED_NORMAL, -20);
|
AIBinder_setMinSchedulerPolicy(pwBinder.get(), SCHED_NORMAL, -20);
|
||||||
|
|
||||||
// extension service
|
// extension service
|
||||||
std::shared_ptr<PowerExt> pwExt = ndk::SharedRefBase::make<PowerExt>();
|
std::shared_ptr<PowerExt> pwExt = ndk::SharedRefBase::make<PowerExt>();
|
||||||
auto pwExtBinder = pwExt->asBinder();
|
auto pwExtBinder = pwExt->asBinder();
|
||||||
AIBinder_setMinSchedulerPolicy(pwExtBinder.get(), SCHED_NORMAL, -20);
|
AIBinder_setMinSchedulerPolicy(pwExtBinder.get(), SCHED_NORMAL, -20);
|
||||||
|
|
||||||
// attach the extension to the same binder we will be registering
|
// attach the extension to the same binder we will be registering
|
||||||
CHECK(STATUS_OK == AIBinder_setExtension(pwBinder.get(), pwExt->asBinder().get()));
|
CHECK(STATUS_OK == AIBinder_setExtension(pwBinder.get(), pwExt->asBinder().get()));
|
||||||
|
|
||||||
const std::string instance = std::string() + Power::descriptor + "/default";
|
const std::string instance = std::string() + Power::descriptor + "/default";
|
||||||
binder_status_t status = AServiceManager_addService(pw->asBinder().get(), instance.c_str());
|
binder_status_t status = AServiceManager_addService(pw->asBinder().get(), instance.c_str());
|
||||||
CHECK(status == STATUS_OK);
|
CHECK(status == STATUS_OK);
|
||||||
LOG(INFO) << "Lenovo Power HAL AIDL Service with Extension is started.";
|
LOG(INFO) << "Xiaomi Power HAL AIDL Service with Extension is started.";
|
||||||
|
|
||||||
if (HintManager::GetInstance()->GetAdpfProfile()) {
|
if (HintManager::GetInstance()->GetAdpfProfile()) {
|
||||||
PowerHintMonitor::getInstance()->start();
|
PowerHintMonitor::getInstance()->start();
|
||||||
}
|
}
|
||||||
|
|
||||||
std::thread initThread([&]() {
|
std::thread initThread([&]() {
|
||||||
::android::base::WaitForProperty(kPowerHalInitProp.data(), "1");
|
::android::base::WaitForProperty(kPowerHalInitProp.data(), "1");
|
||||||
HintManager::GetInstance()->Start();
|
HintManager::GetInstance()->Start();
|
||||||
});
|
});
|
||||||
initThread.detach();
|
initThread.detach();
|
||||||
|
|
||||||
ABinderProcess_joinThreadPool();
|
ABinderProcess_joinThreadPool();
|
||||||
|
|
||||||
// should not reach
|
// should not reach
|
||||||
LOG(ERROR) << "Lenovo Power HAL AIDL Service with Extension just died.";
|
LOG(ERROR) << "Xiaomi Power HAL AIDL Service with Extension just died.";
|
||||||
return EXIT_FAILURE;
|
return EXIT_FAILURE;
|
||||||
}
|
}
|
||||||
|
|
|
@ -371,7 +371,7 @@ PRODUCT_PACKAGES += \
|
||||||
android.hardware.power@1.2 \
|
android.hardware.power@1.2 \
|
||||||
android.hardware.power@1.2.vendor \
|
android.hardware.power@1.2.vendor \
|
||||||
android.hardware.power.stats@1.0-service.mock \
|
android.hardware.power.stats@1.0-service.mock \
|
||||||
android.hardware.power-service.lenovo-sdm710-libperfmgr
|
android.hardware.power-service.xiaomi-libperfmgr
|
||||||
|
|
||||||
PRODUCT_COPY_FILES += \
|
PRODUCT_COPY_FILES += \
|
||||||
$(LOCAL_PATH)/configs/powerhint.json:$(TARGET_COPY_OUT_VENDOR)/etc/powerhint.json
|
$(LOCAL_PATH)/configs/powerhint.json:$(TARGET_COPY_OUT_VENDOR)/etc/powerhint.json
|
||||||
|
|
Loading…
Reference in a new issue