raphael: Import cleaned up coral powerstats

*Removed pixel specifc bits
* Updated wlan node
This commit is contained in:
kondors1995
2024-08-29 09:14:49 +03:00
committed by Joey Huab
parent 11a244b6d0
commit ece3633986
17 changed files with 797 additions and 4 deletions

View File

@@ -466,6 +466,10 @@ PRODUCT_USE_DYNAMIC_PARTITIONS := true
PRODUCT_PACKAGES += \
XiaomiParts
# Powerstats
PRODUCT_PACKAGES += \
android.hardware.power.stats@1.0-service.raphael
# Perf
PRODUCT_PACKAGES += \
libqti-perfd-client

44
powerstats/Android.bp Normal file
View File

@@ -0,0 +1,44 @@
//
// Copyright (C) 2018 The Android Open Source Project
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
cc_binary {
name: "android.hardware.power.stats@1.0-service.raphael",
relative_install_path: "hw",
vintf_fragments: ["android.hardware.power.stats@1.0-service.raphael.xml"],
init_rc: ["android.hardware.power.stats@1.0-service.raphael.rc"],
srcs: [
"service.cpp",
"RailDataProvider.cpp",
"GpuStateResidencyDataProvider.cpp",
],
cflags: [
"-Wall",
"-Werror",
],
static_libs: [
"libpixelpowerstats",
],
shared_libs: [
"libbase",
"libcutils",
"libfmq",
"libhidlbase",
"liblog",
"libutils",
"android.hardware.power.stats@1.0",
"pixelpowerstats_provider_aidl_interface-cpp",
"libbinder",
],
vendor: true,
}

View File

@@ -0,0 +1,96 @@
/*
* Copyright (C) 2019 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#define LOG_TAG "libpixelpowerstats"
#include "GpuStateResidencyDataProvider.h"
#include <android-base/logging.h>
#include <fstream>
#include <sstream>
namespace android {
namespace hardware {
namespace google {
namespace pixel {
namespace powerstats {
GpuStateResidencyDataProvider::GpuStateResidencyDataProvider(uint32_t id)
: mPowerEntityId(id), mActiveId(0) /* (TODO (b/117228832): enable this) , mSuspendId(1) */ {}
bool GpuStateResidencyDataProvider::getTotalTime(const std::string &path, uint64_t &totalTimeMs) {
std::ifstream inFile(path, std::ifstream::in);
if (!inFile.is_open()) {
PLOG(ERROR) << __func__ << ":Failed to open file " << path;
return false;
}
std::string line;
std::getline(inFile, line);
std::istringstream lineStream(line, std::istringstream::in);
totalTimeMs = 0;
uint64_t curTimeMs = 0;
while (lineStream >> curTimeMs) {
totalTimeMs += curTimeMs;
}
return true;
}
bool GpuStateResidencyDataProvider::getResults(
std::unordered_map<uint32_t, PowerEntityStateResidencyResult> &results) {
uint64_t totalActiveTimeUs = 0;
if (!getTotalTime("/sys/class/kgsl/kgsl-3d0/gpu_clock_stats", totalActiveTimeUs)) {
LOG(ERROR) << __func__ << "Failed to get results for GPU:Active";
return false;
}
/* (TODO (b/117228832): enable this)
uint64_t totalSuspendTimeMs = 0;
if (!getTotalTime("/sys/class/kgsl/kgsl-3d0/devfreq/suspend_time", totalSuspendTimeMs)) {
LOG(ERROR) << __func__ << "Failed to get results for GPU:Suspend";
return false;
}
*/
PowerEntityStateResidencyResult result = {
.powerEntityId = mPowerEntityId,
.stateResidencyData = {
{.powerEntityStateId = mActiveId, .totalTimeInStateMs = totalActiveTimeUs / 1000},
/* (TODO (b/117228832): enable this)
{.powerEntityStateId = mSuspendId, .totalTimeInStateMs = totalSuspendTimeMs},
*/
}};
results.emplace(std::make_pair(mPowerEntityId, result));
return true;
}
std::vector<PowerEntityStateSpace> GpuStateResidencyDataProvider::getStateSpaces() {
return {{.powerEntityId = mPowerEntityId,
.states = {
{.powerEntityStateId = mActiveId, .powerEntityStateName = "Active"},
/* (TODO (b/117228832): enable this)
{.powerEntityStateId = mSuspendId, .powerEntityStateName = "Suspend"}
*/
}}};
}
} // namespace powerstats
} // namespace pixel
} // namespace google
} // namespace hardware
} // namespace android

View File

@@ -0,0 +1,51 @@
/*
* Copyright (C) 2019 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef HARDWARE_GOOGLE_PIXEL_POWERSTATS_GPUSTATERESIDENCYDATAPROVIDER_H
#define HARDWARE_GOOGLE_PIXEL_POWERSTATS_GPUSTATERESIDENCYDATAPROVIDER_H
#include <pixelpowerstats/PowerStats.h>
using android::hardware::power::stats::V1_0::PowerEntityStateResidencyResult;
using android::hardware::power::stats::V1_0::PowerEntityStateSpace;
namespace android {
namespace hardware {
namespace google {
namespace pixel {
namespace powerstats {
class GpuStateResidencyDataProvider : public IStateResidencyDataProvider {
public:
GpuStateResidencyDataProvider(uint32_t id);
~GpuStateResidencyDataProvider() = default;
bool getResults(
std::unordered_map<uint32_t, PowerEntityStateResidencyResult> &results) override;
std::vector<PowerEntityStateSpace> getStateSpaces() override;
private:
bool getTotalTime(const std::string &path, uint64_t &totalTimeMs);
const uint32_t mPowerEntityId;
const uint32_t mActiveId;
/* (TODO (b/117228832): enable this) const uint32_t mSuspendId; */
};
} // namespace powerstats
} // namespace pixel
} // namespace google
} // namespace hardware
} // namespace android
#endif // HARDWARE_GOOGLE_PIXEL_POWERSTATS_GPUSTATERESIDENCYDATAPROVIDER_H

View File

@@ -0,0 +1,305 @@
/*
* Copyright (C) 2018 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#define LOG_TAG "libpixelpowerstats"
#include <algorithm>
#include <thread>
#include <exception>
#include <inttypes.h>
#include <stdlib.h>
#include <android-base/file.h>
#include <android-base/logging.h>
#include <android-base/properties.h>
#include <android-base/strings.h>
#include <android-base/stringprintf.h>
#include "RailDataProvider.h"
namespace android {
namespace hardware {
namespace google {
namespace pixel {
namespace powerstats {
#define MAX_FILE_PATH_LEN 128
#define MAX_DEVICE_NAME_LEN 64
#define MAX_QUEUE_SIZE 8192
constexpr char kIioDirRoot[] = "/sys/bus/iio/devices/";
constexpr char kDeviceName[] = "microchip,pac1934";
constexpr char kDeviceType[] = "iio:device";
constexpr uint32_t MAX_SAMPLING_RATE = 10;
constexpr uint64_t WRITE_TIMEOUT_NS = 1000000000;
void RailDataProvider::findIioPowerMonitorNodes() {
struct dirent *ent;
int fd;
char devName[MAX_DEVICE_NAME_LEN];
char filePath[MAX_FILE_PATH_LEN];
DIR *iioDir = opendir(kIioDirRoot);
if (!iioDir) {
ALOGE("Error opening directory: %s, error: %d", kIioDirRoot, errno);
return;
}
while (ent = readdir(iioDir), ent) {
if (strcmp(ent->d_name, ".") != 0 &&
strcmp(ent->d_name, "..") != 0 &&
strlen(ent->d_name) > strlen(kDeviceType) &&
strncmp(ent->d_name, kDeviceType, strlen(kDeviceType)) == 0) {
snprintf(filePath, MAX_FILE_PATH_LEN, "%s/%s", ent->d_name, "name");
fd = openat(dirfd(iioDir), filePath, O_RDONLY);
if (fd < 0) {
ALOGW("Failed to open directory: %s, error: %d", filePath, errno);
continue;
}
if (read(fd, devName, MAX_DEVICE_NAME_LEN) < 0) {
ALOGW("Failed to read device name from file: %s(%d)",
filePath, fd);
close(fd);
continue;
}
if (strncmp(devName, kDeviceName, strlen(kDeviceName)) == 0) {
snprintf(filePath, MAX_FILE_PATH_LEN, "%s/%s", kIioDirRoot, ent->d_name);
mOdpm.devicePaths.push_back(filePath);
}
close(fd);
}
}
closedir(iioDir);
return;
}
size_t RailDataProvider::parsePowerRails() {
std::string data;
std::string railFileName;
std::string spsFileName;
uint32_t index = 0;
uint32_t samplingRate;
for (const auto &path : mOdpm.devicePaths) {
railFileName = path + "/enabled_rails";
spsFileName = path + "/sampling_rate";
if (!android::base::ReadFileToString(spsFileName, &data)) {
ALOGW("Error reading file: %s", spsFileName.c_str());
continue;
}
samplingRate = strtoul(data.c_str(), NULL, 10);
if (!samplingRate || samplingRate == ULONG_MAX) {
ALOGE("Error parsing: %s", spsFileName.c_str());
break;
}
if (!android::base::ReadFileToString(railFileName, &data)) {
ALOGW("Error reading file: %s", railFileName.c_str());
continue;
}
std::istringstream railNames(data);
std::string line;
while (std::getline(railNames, line)) {
std::vector<std::string> words = android::base::Split(line, ":");
if (words.size() == 2) {
mOdpm.railsInfo.emplace(words[0],
RailData {
.devicePath = path,
.index = index,
.subsysName = words[1],
.samplingRate = samplingRate
});
index++;
} else {
ALOGW("Unexpected format in file: %s", railFileName.c_str());
}
}
}
return index;
}
int RailDataProvider::parseIioEnergyNode(std::string devName) {
int ret = 0;
std::string data;
std::string fileName = devName + "/energy_value";
if (!android::base::ReadFileToString(fileName, &data)) {
ALOGE("Error reading file: %s", fileName.c_str());
return -1;
}
std::istringstream energyData(data);
std::string line;
uint64_t timestamp = 0;
bool timestampRead = false;
while (std::getline(energyData, line)) {
std::vector<std::string> words = android::base::Split(line, ",");
if (timestampRead == false) {
if (words.size() == 1) {
timestamp = strtoull(words[0].c_str(), NULL, 10);
if (timestamp == 0 || timestamp == ULLONG_MAX) {
ALOGW("Potentially wrong timestamp: %" PRIu64, timestamp);
}
timestampRead = true;
}
} else if (words.size() == 2) {
std::string railName = words[0];
if (mOdpm.railsInfo.count(railName) != 0) {
size_t index = mOdpm.railsInfo[railName].index;
mOdpm.reading[index].index = index;
mOdpm.reading[index].timestamp = timestamp;
mOdpm.reading[index].energy = strtoull(words[1].c_str(), NULL, 10);
if (mOdpm.reading[index].energy == ULLONG_MAX) {
ALOGW("Potentially wrong energy value: %" PRIu64,
mOdpm.reading[index].energy);
}
}
} else {
ALOGW("Unexpected format in file: %s", fileName.c_str());
ret = -1;
break;
}
}
return ret;
}
Status RailDataProvider::parseIioEnergyNodes() {
Status ret = Status::SUCCESS;
if (mOdpm.hwEnabled == false) {
return Status::NOT_SUPPORTED;
}
for (const auto &devicePath : mOdpm.devicePaths) {
if(parseIioEnergyNode(devicePath) < 0) {
ALOGE("Error in parsing power stats");
ret = Status::FILESYSTEM_ERROR;
break;
}
}
return ret;
}
RailDataProvider::RailDataProvider() {
findIioPowerMonitorNodes();
size_t numRails = parsePowerRails();
if (mOdpm.devicePaths.empty() || numRails == 0) {
mOdpm.hwEnabled = false;
} else {
mOdpm.hwEnabled = true;
mOdpm.reading.resize(numRails);
}
}
Return<void> RailDataProvider::getRailInfo(IPowerStats::getRailInfo_cb _hidl_cb) {
hidl_vec<RailInfo> rInfo;
Status ret = Status::SUCCESS;
size_t index;
std::lock_guard<std::mutex> _lock(mOdpm.mLock);
if (mOdpm.hwEnabled == false) {
ALOGI("getRailInfo not supported");
_hidl_cb(rInfo, Status::NOT_SUPPORTED);
return Void();
}
rInfo.resize(mOdpm.railsInfo.size());
for (const auto& railData : mOdpm.railsInfo) {
index = railData.second.index;
rInfo[index].railName = railData.first;
rInfo[index].subsysName = railData.second.subsysName;
rInfo[index].index = index;
rInfo[index].samplingRate = railData.second.samplingRate;
}
_hidl_cb(rInfo, ret);
return Void();
}
Return<void> RailDataProvider::getEnergyData(const hidl_vec<uint32_t>& railIndices, IPowerStats::getEnergyData_cb _hidl_cb) {
hidl_vec<EnergyData> eVal;
std::lock_guard<std::mutex> _lock(mOdpm.mLock);
Status ret = parseIioEnergyNodes();
if (ret != Status::SUCCESS) {
ALOGE("Failed to getEnergyData");
_hidl_cb(eVal, ret);
return Void();
}
if (railIndices.size() == 0) {
eVal.resize(mOdpm.railsInfo.size());
memcpy(&eVal[0], &mOdpm.reading[0], mOdpm.reading.size() * sizeof(EnergyData));
} else {
eVal.resize(railIndices.size());
int i = 0;
for (const auto &railIndex : railIndices) {
if (railIndex >= mOdpm.reading.size()) {
ret = Status::INVALID_INPUT;
eVal.resize(0);
break;
}
memcpy(&eVal[i], &mOdpm.reading[railIndex], sizeof(EnergyData));
i++;
}
}
_hidl_cb(eVal, ret);
return Void();
}
Return<void> RailDataProvider::streamEnergyData(uint32_t timeMs, uint32_t samplingRate,
IPowerStats::streamEnergyData_cb _hidl_cb) {
std::lock_guard<std::mutex> _lock(mOdpm.mLock);
if (mOdpm.fmqSynchronized != nullptr) {
_hidl_cb(MessageQueueSync::Descriptor(),
0, 0, Status::INSUFFICIENT_RESOURCES);
return Void();
}
uint32_t sps = std::min(samplingRate, MAX_SAMPLING_RATE);
uint32_t numSamples = timeMs * sps / 1000;
mOdpm.fmqSynchronized.reset(new (std::nothrow) MessageQueueSync(MAX_QUEUE_SIZE, true));
if (mOdpm.fmqSynchronized == nullptr || mOdpm.fmqSynchronized->isValid() == false) {
mOdpm.fmqSynchronized = nullptr;
_hidl_cb(MessageQueueSync::Descriptor(),
0, 0, Status::INSUFFICIENT_RESOURCES);
return Void();
}
std::thread pollThread = std::thread([this, sps, numSamples]() {
uint64_t sleepTimeUs = 1000000/sps;
uint32_t currSamples = 0;
while (currSamples < numSamples) {
mOdpm.mLock.lock();
if (parseIioEnergyNodes() == Status::SUCCESS) {
mOdpm.fmqSynchronized->writeBlocking(&mOdpm.reading[0],
mOdpm.reading.size(), WRITE_TIMEOUT_NS);
mOdpm.mLock.unlock();
currSamples++;
if (usleep(sleepTimeUs) < 0) {
ALOGW("Sleep interrupted");
break;
}
} else {
mOdpm.mLock.unlock();
break;
}
}
mOdpm.mLock.lock();
mOdpm.fmqSynchronized = nullptr;
mOdpm.mLock.unlock();
return;
});
pollThread.detach();
_hidl_cb(*(mOdpm.fmqSynchronized)->getDesc(), numSamples,
mOdpm.reading.size(), Status::SUCCESS);
return Void();
}
} // namespace powerstats
} // namespace pixel
} // namespace google
} // namespace hardware
} // namespace android

View File

@@ -0,0 +1,53 @@
#ifndef ANDROID_HARDWARE_POWERSTATS_RAILDATAPROVIDER_H
#define ANDROID_HARDWARE_POWERSTATS_RAILDATAPROVIDER_H
#include <fmq/MessageQueue.h>
#include <pixelpowerstats/PowerStats.h>
namespace android {
namespace hardware {
namespace google {
namespace pixel {
namespace powerstats {
typedef MessageQueue<EnergyData, kSynchronizedReadWrite> MessageQueueSync;
struct RailData {
std::string devicePath;
uint32_t index;
std::string subsysName;
uint32_t samplingRate;
};
struct OnDeviceMmt {
std::mutex mLock;
bool hwEnabled;
std::vector<std::string> devicePaths;
std::map<std::string, RailData> railsInfo;
std::vector<EnergyData> reading;
std::unique_ptr<MessageQueueSync> fmqSynchronized;
};
class RailDataProvider : public IRailDataProvider {
public:
RailDataProvider();
// Methods from ::android::hardware::power::stats::V1_0::IPowerStats follow.
Return<void> getRailInfo(IPowerStats::getRailInfo_cb _hidl_cb) override;
Return<void> getEnergyData(const hidl_vec<uint32_t>& railIndices,
IPowerStats::getEnergyData_cb _hidl_cb) override;
Return<void> streamEnergyData(uint32_t timeMs, uint32_t samplingRate,
IPowerStats::streamEnergyData_cb _hidl_cb) override;
private:
OnDeviceMmt mOdpm;
void findIioPowerMonitorNodes();
size_t parsePowerRails();
int parseIioEnergyNode(std::string devName);
Status parseIioEnergyNodes();
};
} // namespace powerstats
} // namespace pixel
} // namespace google
} // namespace hardware
} // namespace android
#endif // ANDROID_HARDWARE_POWERSTATS_RAILDATAPROVIDER_H

View File

@@ -0,0 +1,4 @@
service vendor.power.stats-hal-1-0 /vendor/bin/hw/android.hardware.power.stats@1.0-service.raphael
class hal
user system
group system

View File

@@ -0,0 +1,11 @@
<manifest version="1.0" type="device">
<hal format="hidl">
<name>android.hardware.power.stats</name>
<transport>hwbinder</transport>
<version>1.0</version>
<interface>
<name>IPowerStats</name>
<instance>default</instance>
</interface>
</hal>
</manifest>

175
powerstats/service.cpp Normal file
View File

@@ -0,0 +1,175 @@
/*
* Copyright (C) 2018 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#define LOG_TAG "android.hardware.power.stats@1.0-service.raphael"
#include <android/log.h>
#include <binder/IPCThreadState.h>
#include <binder/IServiceManager.h>
#include <binder/ProcessState.h>
#include <hidl/HidlTransportSupport.h>
#include <pixelpowerstats/AidlStateResidencyDataProvider.h>
#include <pixelpowerstats/GenericStateResidencyDataProvider.h>
#include <pixelpowerstats/PowerStats.h>
#include <pixelpowerstats/WlanStateResidencyDataProvider.h>
#include "GpuStateResidencyDataProvider.h"
#include "RailDataProvider.h"
using android::OK;
using android::sp;
using android::status_t;
// libhwbinder:
using android::hardware::configureRpcThreadpool;
using android::hardware::joinRpcThreadpool;
// Generated HIDL files
using android::hardware::power::stats::V1_0::IPowerStats;
using android::hardware::power::stats::V1_0::PowerEntityType;
using android::hardware::power::stats::V1_0::implementation::PowerStats;
// Pixel specific
using android::hardware::google::pixel::powerstats::AidlStateResidencyDataProvider;
using android::hardware::google::pixel::powerstats::generateGenericStateResidencyConfigs;
using android::hardware::google::pixel::powerstats::GenericStateResidencyDataProvider;
using android::hardware::google::pixel::powerstats::GpuStateResidencyDataProvider;
using android::hardware::google::pixel::powerstats::PowerEntityConfig;
using android::hardware::google::pixel::powerstats::RailDataProvider;
using android::hardware::google::pixel::powerstats::StateResidencyConfig;
using android::hardware::google::pixel::powerstats::WlanStateResidencyDataProvider;
int main(int /* argc */, char** /* argv */) {
ALOGI("power.stats service 1.0 is starting.");
PowerStats* service = new PowerStats();
// Add rail data provider
service->setRailDataProvider(std::make_unique<RailDataProvider>());
// Add power entities related to rpmh
const uint64_t RPM_CLK = 19200; // RPM runs at 19.2Mhz. Divide by 19200 for msec
std::function<uint64_t(uint64_t)> rpmConvertToMs = [](uint64_t a) { return a / RPM_CLK; };
std::vector<StateResidencyConfig> rpmStateResidencyConfigs = {
{.name = "Sleep",
.entryCountSupported = true,
.entryCountPrefix = "Sleep Count:",
.totalTimeSupported = true,
.totalTimePrefix = "Sleep Accumulated Duration:",
.totalTimeTransform = rpmConvertToMs,
.lastEntrySupported = true,
.lastEntryPrefix = "Sleep Last Entered At:",
.lastEntryTransform = rpmConvertToMs}};
sp<GenericStateResidencyDataProvider> rpmSdp =
new GenericStateResidencyDataProvider("/sys/power/rpmh_stats/master_stats");
uint32_t apssId = service->addPowerEntity("APSS", PowerEntityType::SUBSYSTEM);
rpmSdp->addEntity(apssId, PowerEntityConfig("APSS", rpmStateResidencyConfigs));
uint32_t mpssId = service->addPowerEntity("MPSS", PowerEntityType::SUBSYSTEM);
rpmSdp->addEntity(mpssId, PowerEntityConfig("MPSS", rpmStateResidencyConfigs));
uint32_t adspId = service->addPowerEntity("ADSP", PowerEntityType::SUBSYSTEM);
rpmSdp->addEntity(adspId, PowerEntityConfig("ADSP", rpmStateResidencyConfigs));
uint32_t cdspId = service->addPowerEntity("CDSP", PowerEntityType::SUBSYSTEM);
rpmSdp->addEntity(cdspId, PowerEntityConfig("CDSP", rpmStateResidencyConfigs));
uint32_t slpiId = service->addPowerEntity("SLPI", PowerEntityType::SUBSYSTEM);
rpmSdp->addEntity(slpiId, PowerEntityConfig("SLPI", rpmStateResidencyConfigs));
uint32_t slpiIslandId = service->addPowerEntity("SLPI_ISLAND", PowerEntityType::SUBSYSTEM);
rpmSdp->addEntity(slpiIslandId, PowerEntityConfig("SLPI_ISLAND", {
{.name = "uImage",
.entryCountSupported = true,
.entryCountPrefix = "Sleep Count:",
.totalTimeSupported = true,
.totalTimePrefix = "Sleep Accumulated Duration:",
.totalTimeTransform = rpmConvertToMs,
.lastEntrySupported = true,
.lastEntryPrefix = "Sleep Last Entered At:",
.lastEntryTransform = rpmConvertToMs}}));
service->addStateResidencyDataProvider(rpmSdp);
// Add SoC power entity
StateResidencyConfig socStateConfig = {
.entryCountSupported = true,
.entryCountPrefix = "count:",
.totalTimeSupported = true,
.totalTimePrefix = "actual last sleep(msec):",
.lastEntrySupported = false
};
std::vector<std::pair<std::string, std::string>> socStateHeaders = {
std::make_pair("AOSD", "RPM Mode:aosd"),
std::make_pair("CXSD", "RPM Mode:cxsd"),
std::make_pair("DDR", "RPM Mode:ddr"),
};
sp<GenericStateResidencyDataProvider> socSdp =
new GenericStateResidencyDataProvider("/sys/power/system_sleep/stats");
uint32_t socId = service->addPowerEntity("SoC", PowerEntityType::POWER_DOMAIN);
socSdp->addEntity(socId,
PowerEntityConfig(generateGenericStateResidencyConfigs(socStateConfig, socStateHeaders)));
service->addStateResidencyDataProvider(socSdp);
// Add WLAN power entity
uint32_t wlanId = service->addPowerEntity("WLAN", PowerEntityType::SUBSYSTEM);
sp<WlanStateResidencyDataProvider> wlanSdp =
new WlanStateResidencyDataProvider(wlanId, "/sys/kernel/wifi/power_stats");
service->addStateResidencyDataProvider(wlanSdp);
// Add GPU power entity
uint32_t gpuId = service->addPowerEntity("GPU", PowerEntityType::SUBSYSTEM);
sp<GpuStateResidencyDataProvider> gpuSdp = new GpuStateResidencyDataProvider(gpuId);
service->addStateResidencyDataProvider(gpuSdp);
// Add Power Entities that require the Aidl data provider
sp<AidlStateResidencyDataProvider> aidlSdp = new AidlStateResidencyDataProvider();
uint32_t citadelId = service->addPowerEntity("Citadel", PowerEntityType::SUBSYSTEM);
aidlSdp->addEntity(citadelId, "Citadel", {"Last-Reset", "Active", "Deep-Sleep"});
auto serviceStatus = android::defaultServiceManager()->addService(
android::String16("power.stats-vendor"), aidlSdp);
if (serviceStatus != android::OK) {
ALOGE("Unable to register power.stats-vendor service %d", serviceStatus);
return 1;
}
sp<android::ProcessState> ps{android::ProcessState::self()}; // Create non-HW binder threadpool
ps->startThreadPool();
service->addStateResidencyDataProvider(aidlSdp);
// Configure the threadpool
configureRpcThreadpool(1, true /*callerWillJoin*/);
status_t status = service->registerAsService();
if (status != OK) {
ALOGE("Could not register service for power.stats HAL Iface (%d), exiting.", status);
return 1;
}
ALOGI("power.stats service is ready");
joinRpcThreadpool();
// In normal operation, we don't expect the thread pool to exit
ALOGE("power.stats service is shutting down");
return 1;
}

View File

@@ -4,4 +4,5 @@ type motor_device, dev_type;
type thermal_link_device, dev_type;
type ultrasound_device, dev_type;
typeattribute system_block_device super_block_device_type;
type latency_device, dev_type;
type latency_device, dev_type;
type power_stats_device, dev_type;

View File

@@ -17,3 +17,9 @@ type sysfs_fod, sysfs_type, fs_type;
type sysfs_msm_boot, fs_type, sysfs_type;
type sysfs_touchpanel, fs_type, sysfs_type;
type pps_socket, file_type;
# Powerstats
type sysfs_power_stats, fs_type, sysfs_type;
type sysfs_power_stats_ignore, sysfs_type, fs_type;
type sysfs_iio_devices, fs_type, sysfs_type;
type sysfs_msm_wlan, sysfs_type, fs_type;

View File

@@ -26,6 +26,7 @@
/vendor/bin/hw/android\.hardware\.biometrics\.fingerprint@2\.3-service\.xiaomi_raphael u:object_r:hal_fingerprint_default_exec:s0
/vendor/bin/hw/android\.hardware\.light@2\.0-service\.xiaomi_raphael u:object_r:hal_light_default_exec:s0
/vendor/bin/hw/android\.hardware\.power-service\.pixel-libperfmgr u:object_r:hal_power_default_exec:s0
/vendor/bin/hw/android\.hardware\.power\.stats@1\.0-service\.raphael u:object_r:hal_power_stats_default_exec:s0
/vendor/bin/hw/android\.hardware\.thermal-service\.pixel u:object_r:hal_thermal_default_exec:s0
/vendor/bin/hw/vendor\.xiaomi\.hardware\.motor@1\.0-service u:object_r:hal_motor_default_exec:s0
/vendor/bin/mlipayd@1\.1 u:object_r:hal_mlipay_default_exec:s0

View File

@@ -3,11 +3,13 @@ genfscon sysfs /kernel/boot_cdsp/boot
# Display
genfscon sysfs /devices/platform/soc/2c00000.qcom,kgsl-3d0 u:object_r:sysfs_msm_subsys:s0
genfscon sysfs /devices/platform/soc/ae00000.qcom,mdss_mdp u:object_r:sysfs_msm_subsys:s0
genfscon sysfs /devices/platform/soc/ae00000.qcom,mdss_mdp/idle_state u:object_r:vendor_sysfs_graphics:s0
genfscon sysfs /devices/platform/soc/ae00000.qcom,mdss_mdp/drm/card0/sde-crtc-0/early_wakeup u:object_r:vendor_sysfs_graphics:s0
genfscon sysfs /devices/platform/soc/soc:qcom,cpu-cpu-llcc-bw u:object_r:sysfs_msm_subsys:s0
genfscon sysfs /devices/platform/soc/soc:qcom,cpu-llcc-ddr-bw u:object_r:sysfs_msm_subsys:s0
genfscon sysfs /devices/platform/soc/soc:qcom,cpu0-cpu-l3-lat u:object_r:sysfs_msm_subsys:s0
genfscon sysfs /devices/platform/soc/soc:qcom,cpu4-cpu-l3-lat u:object_r:sysfs_msm_subsys:s0
genfscon sysfs /devices/platform/soc/soc:qcom,cpu6-cpu-l3-lat u:object_r:sysfs_msm_subsys:s0
genfscon sysfs /devices/platform/soc/soc:qcom,dsi-display u:object_r:vendor_sysfs_graphics:s0
genfscon sysfs /devices/platform/soc/soc:qcom,gpubw u:object_r:sysfs_msm_subsys:s0
@@ -19,6 +21,15 @@ genfscon sysfs /devices/platform/soc/soc:qcom,dsi-display-primary/dc_dim
# Graphics
genfscon sysfs /devices/platform/soc/soc:qcom,dsi-display-primary u:object_r:vendor_sysfs_graphics:s0
# Pixel Powerstats
genfscon sysfs /power/system_sleep/stats u:object_r:sysfs_power_stats:s0
genfscon sysfs /power/rpmh_stats/master_stats u:object_r:sysfs_power_stats:s0
genfscon sysfs /kernel/wifi/power_stats u:object_r:sysfs_power_stats:s0
genfscon sysfs /kernel/wlan u:object_r:sysfs_msm_wlan:s0
genfscon sysfs /bus/iio/devices u:object_r:sysfs_iio_devices:s0
genfscon sysfs /devices/platform/soc/c440000.qcom,spmi/spmi-0/spmi0-02/c440000.qcom,spmi:qcom,pm8150b@2:vadc@3100/iio:device1/name u:object_r:sysfs_power_stats_ignore:s0
genfscon sysfs /devices/platform/soc/c440000.qcom,spmi/spmi-0/spmi0-04/c440000.qcom,spmi:qcom,pm8150l@4:vadc@3100/iio:device2/name u:object_r:sysfs_power_stats_ignore:s0
# Health
genfscon sysfs /class/power_supply/battery/capacity u:object_r:sysfs_battery_supply:s0
genfscon sysfs /devices/platform/soc/884000.i2c/i2c-3/3-0066/power_supply/bq2597x-standalone u:object_r:sysfs_battery_supply:s0

View File

@@ -1,3 +1,31 @@
allow hal_power_stats_default vendor_sysfs_iio:dir r_dir_perms;
allow hal_power_stats_default vendor_sysfs_iio:file r_file_perms;
allow hal_power_stats_default vendor_sysfs_iio:lnk_file read;
# Needed to traverse to wlan stats file
allow hal_power_stats_default sysfs_msm_wlan:dir search;
allow hal_power_stats_default vendor_sysfs_kgsl:file {
r_file_perms
getattr
};
# Needed to detect wifi on/off
get_prop(hal_power_stats_default, wifi_hal_prop)
# Needed to traverse odpm files
r_dir_file(hal_power_stats_default, sysfs_iio_devices)
# Needed to traverse platform low power stats
r_dir_file(hal_power_stats_default, sysfs_power_stats)
# Needed to traverse subsystem low power stats
r_dir_file(hal_power_stats_default, sysfs_msm_subsys)
# The following folders are incidentally accessed by hal_power_stats_default and are not needed.
dontaudit hal_power_stats_default sysfs_power_stats_ignore:dir r_dir_perms;
dontaudit hal_power_stats_default sysfs_power_stats_ignore:file r_file_perms;
dontaudit hal_power_stats_default sysfs:file read;
vndbinder_use(hal_power_stats)
add_service(hal_power_stats_server, hal_power_stats_service)
add_service(hal_power_stats_default, hal_power_stats_vendor_service)
allow hal_power_stats_default power_stats_device:chr_file rw_file_perms;

1
sepolicy/vendor/service_contexts vendored Normal file
View File

@@ -0,0 +1 @@
power.stats-vendor u:object_r:hal_power_stats_vendor_service:s0

View File

@@ -1 +1,2 @@
type remosaic_daemon_service, vndservice_manager_type;
type hal_power_stats_vendor_service, vndservice_manager_type;

View File

@@ -1 +1,2 @@
android.IRemosaicDaemon u:object_r:remosaic_daemon_service:s0
power.stats-vendor u:object_r:hal_power_stats_vendor_service:s0