Loading cmds/statsd/src/external/PowerStatsPuller.cpp +29 −6 Original line number Original line Diff line number Diff line Loading @@ -39,17 +39,40 @@ namespace android { namespace os { namespace os { namespace statsd { namespace statsd { sp<android::hardware::power::stats::V1_0::IPowerStats> gPowerStatsHal = nullptr; static sp<android::hardware::power::stats::V1_0::IPowerStats> gPowerStatsHal = nullptr; std::mutex gPowerStatsHalMutex; static std::mutex gPowerStatsHalMutex; bool gPowerStatsExist = true; // Initialized to ensure making a first attempt. static bool gPowerStatsExist = true; // Initialized to ensure making a first attempt. std::vector<RailInfo> gRailInfo; static std::vector<RailInfo> gRailInfo; struct PowerStatsPullerDeathRecipient : virtual public hardware::hidl_death_recipient { virtual void serviceDied(uint64_t cookie, const wp<android::hidl::base::V1_0::IBase>& who) override { // The HAL just died. Reset all handles to HAL services. std::lock_guard<std::mutex> lock(gPowerStatsHalMutex); gPowerStatsHal = nullptr; } }; static sp<PowerStatsPullerDeathRecipient> gDeathRecipient = new PowerStatsPullerDeathRecipient(); bool getPowerStatsHal() { static bool getPowerStatsHalLocked() { if (gPowerStatsHal == nullptr && gPowerStatsExist) { if (gPowerStatsHal == nullptr && gPowerStatsExist) { gPowerStatsHal = android::hardware::power::stats::V1_0::IPowerStats::getService(); gPowerStatsHal = android::hardware::power::stats::V1_0::IPowerStats::getService(); if (gPowerStatsHal == nullptr) { if (gPowerStatsHal == nullptr) { ALOGW("Couldn't load power.stats HAL service"); ALOGW("Couldn't load power.stats HAL service"); gPowerStatsExist = false; gPowerStatsExist = false; } else { // Link death recipient to power.stats service handle hardware::Return<bool> linked = gPowerStatsHal->linkToDeath(gDeathRecipient, 0); if (!linked.isOk()) { ALOGE("Transaction error in linking to power.stats HAL death: %s", linked.description().c_str()); gPowerStatsHal = nullptr; return false; } else if (!linked) { ALOGW("Unable to link to power.stats HAL death notifications"); // We should still continue even though linking failed } } } } } return gPowerStatsHal != nullptr; return gPowerStatsHal != nullptr; Loading @@ -61,7 +84,7 @@ PowerStatsPuller::PowerStatsPuller() : StatsPuller(android::util::ON_DEVICE_POWE bool PowerStatsPuller::PullInternal(vector<shared_ptr<LogEvent>>* data) { bool PowerStatsPuller::PullInternal(vector<shared_ptr<LogEvent>>* data) { std::lock_guard<std::mutex> lock(gPowerStatsHalMutex); std::lock_guard<std::mutex> lock(gPowerStatsHalMutex); if (!getPowerStatsHal()) { if (!getPowerStatsHalLocked()) { ALOGE("power.stats Hal not loaded"); ALOGE("power.stats Hal not loaded"); return false; return false; } } Loading cmds/statsd/src/external/SubsystemSleepStatePuller.cpp +19 −17 Original line number Original line Diff line number Diff line Loading @@ -60,41 +60,43 @@ namespace android { namespace os { namespace os { namespace statsd { namespace statsd { std::function<bool(vector<shared_ptr<LogEvent>>* data)> gPuller = {}; static std::function<bool(vector<shared_ptr<LogEvent>>* data)> gPuller = {}; sp<android::hardware::power::V1_0::IPower> gPowerHalV1_0 = nullptr; static sp<android::hardware::power::V1_0::IPower> gPowerHalV1_0 = nullptr; sp<android::hardware::power::V1_1::IPower> gPowerHalV1_1 = nullptr; static sp<android::hardware::power::V1_1::IPower> gPowerHalV1_1 = nullptr; sp<android::hardware::power::stats::V1_0::IPowerStats> gPowerStatsHalV1_0 = nullptr; static sp<android::hardware::power::stats::V1_0::IPowerStats> gPowerStatsHalV1_0 = nullptr; std::unordered_map<uint32_t, std::string> gEntityNames = {}; static std::unordered_map<uint32_t, std::string> gEntityNames = {}; std::unordered_map<uint32_t, std::unordered_map<uint32_t, std::string>> gStateNames = {}; static std::unordered_map<uint32_t, std::unordered_map<uint32_t, std::string>> gStateNames = {}; std::mutex gPowerHalMutex; static std::mutex gPowerHalMutex; // The caller must be holding gPowerHalMutex. // The caller must be holding gPowerHalMutex. void deinitPowerStatsLocked() { static void deinitPowerStatsLocked() { gPowerHalV1_0 = nullptr; gPowerHalV1_0 = nullptr; gPowerHalV1_1 = nullptr; gPowerHalV1_1 = nullptr; gPowerStatsHalV1_0 = nullptr; gPowerStatsHalV1_0 = nullptr; } } struct PowerHalDeathRecipient : virtual public hardware::hidl_death_recipient { struct SubsystemSleepStatePullerDeathRecipient : virtual public hardware::hidl_death_recipient { virtual void serviceDied(uint64_t cookie, virtual void serviceDied(uint64_t cookie, const wp<android::hidl::base::V1_0::IBase>& who) override { const wp<android::hidl::base::V1_0::IBase>& who) override { // The HAL just died. Reset all handles to HAL services. // The HAL just died. Reset all handles to HAL services. std::lock_guard<std::mutex> lock(gPowerHalMutex); std::lock_guard<std::mutex> lock(gPowerHalMutex); deinitPowerStatsLocked(); deinitPowerStatsLocked(); } } }; }; sp<PowerHalDeathRecipient> gDeathRecipient = new PowerHalDeathRecipient(); static sp<SubsystemSleepStatePullerDeathRecipient> gDeathRecipient = new SubsystemSleepStatePullerDeathRecipient(); SubsystemSleepStatePuller::SubsystemSleepStatePuller() : SubsystemSleepStatePuller::SubsystemSleepStatePuller() : StatsPuller(android::util::SUBSYSTEM_SLEEP_STATE) { StatsPuller(android::util::SUBSYSTEM_SLEEP_STATE) { } } // The caller must be holding gPowerHalMutex. // The caller must be holding gPowerHalMutex. bool checkResultLocked(const Return<void> &ret, const char* function) { static bool checkResultLocked(const Return<void> &ret, const char* function) { if (!ret.isOk()) { if (!ret.isOk()) { ALOGE("%s failed: requested HAL service not available. Description: %s", ALOGE("%s failed: requested HAL service not available. Description: %s", function, ret.description().c_str()); function, ret.description().c_str()); Loading @@ -108,7 +110,7 @@ bool checkResultLocked(const Return<void> &ret, const char* function) { // The caller must be holding gPowerHalMutex. // The caller must be holding gPowerHalMutex. // gPowerStatsHalV1_0 must not be null // gPowerStatsHalV1_0 must not be null bool initializePowerStats() { static bool initializePowerStats() { using android::hardware::power::stats::V1_0::Status; using android::hardware::power::stats::V1_0::Status; // Clear out previous content if we are re-initializing // Clear out previous content if we are re-initializing Loading Loading @@ -155,7 +157,7 @@ bool initializePowerStats() { } } // The caller must be holding gPowerHalMutex. // The caller must be holding gPowerHalMutex. bool getPowerStatsHalLocked() { static bool getPowerStatsHalLocked() { if(gPowerStatsHalV1_0 == nullptr) { if(gPowerStatsHalV1_0 == nullptr) { gPowerStatsHalV1_0 = android::hardware::power::stats::V1_0::IPowerStats::getService(); gPowerStatsHalV1_0 = android::hardware::power::stats::V1_0::IPowerStats::getService(); if (gPowerStatsHalV1_0 == nullptr) { if (gPowerStatsHalV1_0 == nullptr) { Loading @@ -180,7 +182,7 @@ bool getPowerStatsHalLocked() { } } // The caller must be holding gPowerHalMutex. // The caller must be holding gPowerHalMutex. bool getIPowerStatsDataLocked(vector<shared_ptr<LogEvent>>* data) { static bool getIPowerStatsDataLocked(vector<shared_ptr<LogEvent>>* data) { using android::hardware::power::stats::V1_0::Status; using android::hardware::power::stats::V1_0::Status; if(!getPowerStatsHalLocked()) { if(!getPowerStatsHalLocked()) { Loading Loading @@ -225,7 +227,7 @@ bool getIPowerStatsDataLocked(vector<shared_ptr<LogEvent>>* data) { } } // The caller must be holding gPowerHalMutex. // The caller must be holding gPowerHalMutex. bool getPowerHalLocked() { static bool getPowerHalLocked() { if(gPowerHalV1_0 == nullptr) { if(gPowerHalV1_0 == nullptr) { gPowerHalV1_0 = android::hardware::power::V1_0::IPower::getService(); gPowerHalV1_0 = android::hardware::power::V1_0::IPower::getService(); if(gPowerHalV1_0 == nullptr) { if(gPowerHalV1_0 == nullptr) { Loading @@ -250,7 +252,7 @@ bool getPowerHalLocked() { } } // The caller must be holding gPowerHalMutex. // The caller must be holding gPowerHalMutex. bool getIPowerDataLocked(vector<shared_ptr<LogEvent>>* data) { static bool getIPowerDataLocked(vector<shared_ptr<LogEvent>>* data) { using android::hardware::power::V1_0::Status; using android::hardware::power::V1_0::Status; if(!getPowerHalLocked()) { if(!getPowerHalLocked()) { Loading Loading
cmds/statsd/src/external/PowerStatsPuller.cpp +29 −6 Original line number Original line Diff line number Diff line Loading @@ -39,17 +39,40 @@ namespace android { namespace os { namespace os { namespace statsd { namespace statsd { sp<android::hardware::power::stats::V1_0::IPowerStats> gPowerStatsHal = nullptr; static sp<android::hardware::power::stats::V1_0::IPowerStats> gPowerStatsHal = nullptr; std::mutex gPowerStatsHalMutex; static std::mutex gPowerStatsHalMutex; bool gPowerStatsExist = true; // Initialized to ensure making a first attempt. static bool gPowerStatsExist = true; // Initialized to ensure making a first attempt. std::vector<RailInfo> gRailInfo; static std::vector<RailInfo> gRailInfo; struct PowerStatsPullerDeathRecipient : virtual public hardware::hidl_death_recipient { virtual void serviceDied(uint64_t cookie, const wp<android::hidl::base::V1_0::IBase>& who) override { // The HAL just died. Reset all handles to HAL services. std::lock_guard<std::mutex> lock(gPowerStatsHalMutex); gPowerStatsHal = nullptr; } }; static sp<PowerStatsPullerDeathRecipient> gDeathRecipient = new PowerStatsPullerDeathRecipient(); bool getPowerStatsHal() { static bool getPowerStatsHalLocked() { if (gPowerStatsHal == nullptr && gPowerStatsExist) { if (gPowerStatsHal == nullptr && gPowerStatsExist) { gPowerStatsHal = android::hardware::power::stats::V1_0::IPowerStats::getService(); gPowerStatsHal = android::hardware::power::stats::V1_0::IPowerStats::getService(); if (gPowerStatsHal == nullptr) { if (gPowerStatsHal == nullptr) { ALOGW("Couldn't load power.stats HAL service"); ALOGW("Couldn't load power.stats HAL service"); gPowerStatsExist = false; gPowerStatsExist = false; } else { // Link death recipient to power.stats service handle hardware::Return<bool> linked = gPowerStatsHal->linkToDeath(gDeathRecipient, 0); if (!linked.isOk()) { ALOGE("Transaction error in linking to power.stats HAL death: %s", linked.description().c_str()); gPowerStatsHal = nullptr; return false; } else if (!linked) { ALOGW("Unable to link to power.stats HAL death notifications"); // We should still continue even though linking failed } } } } } return gPowerStatsHal != nullptr; return gPowerStatsHal != nullptr; Loading @@ -61,7 +84,7 @@ PowerStatsPuller::PowerStatsPuller() : StatsPuller(android::util::ON_DEVICE_POWE bool PowerStatsPuller::PullInternal(vector<shared_ptr<LogEvent>>* data) { bool PowerStatsPuller::PullInternal(vector<shared_ptr<LogEvent>>* data) { std::lock_guard<std::mutex> lock(gPowerStatsHalMutex); std::lock_guard<std::mutex> lock(gPowerStatsHalMutex); if (!getPowerStatsHal()) { if (!getPowerStatsHalLocked()) { ALOGE("power.stats Hal not loaded"); ALOGE("power.stats Hal not loaded"); return false; return false; } } Loading
cmds/statsd/src/external/SubsystemSleepStatePuller.cpp +19 −17 Original line number Original line Diff line number Diff line Loading @@ -60,41 +60,43 @@ namespace android { namespace os { namespace os { namespace statsd { namespace statsd { std::function<bool(vector<shared_ptr<LogEvent>>* data)> gPuller = {}; static std::function<bool(vector<shared_ptr<LogEvent>>* data)> gPuller = {}; sp<android::hardware::power::V1_0::IPower> gPowerHalV1_0 = nullptr; static sp<android::hardware::power::V1_0::IPower> gPowerHalV1_0 = nullptr; sp<android::hardware::power::V1_1::IPower> gPowerHalV1_1 = nullptr; static sp<android::hardware::power::V1_1::IPower> gPowerHalV1_1 = nullptr; sp<android::hardware::power::stats::V1_0::IPowerStats> gPowerStatsHalV1_0 = nullptr; static sp<android::hardware::power::stats::V1_0::IPowerStats> gPowerStatsHalV1_0 = nullptr; std::unordered_map<uint32_t, std::string> gEntityNames = {}; static std::unordered_map<uint32_t, std::string> gEntityNames = {}; std::unordered_map<uint32_t, std::unordered_map<uint32_t, std::string>> gStateNames = {}; static std::unordered_map<uint32_t, std::unordered_map<uint32_t, std::string>> gStateNames = {}; std::mutex gPowerHalMutex; static std::mutex gPowerHalMutex; // The caller must be holding gPowerHalMutex. // The caller must be holding gPowerHalMutex. void deinitPowerStatsLocked() { static void deinitPowerStatsLocked() { gPowerHalV1_0 = nullptr; gPowerHalV1_0 = nullptr; gPowerHalV1_1 = nullptr; gPowerHalV1_1 = nullptr; gPowerStatsHalV1_0 = nullptr; gPowerStatsHalV1_0 = nullptr; } } struct PowerHalDeathRecipient : virtual public hardware::hidl_death_recipient { struct SubsystemSleepStatePullerDeathRecipient : virtual public hardware::hidl_death_recipient { virtual void serviceDied(uint64_t cookie, virtual void serviceDied(uint64_t cookie, const wp<android::hidl::base::V1_0::IBase>& who) override { const wp<android::hidl::base::V1_0::IBase>& who) override { // The HAL just died. Reset all handles to HAL services. // The HAL just died. Reset all handles to HAL services. std::lock_guard<std::mutex> lock(gPowerHalMutex); std::lock_guard<std::mutex> lock(gPowerHalMutex); deinitPowerStatsLocked(); deinitPowerStatsLocked(); } } }; }; sp<PowerHalDeathRecipient> gDeathRecipient = new PowerHalDeathRecipient(); static sp<SubsystemSleepStatePullerDeathRecipient> gDeathRecipient = new SubsystemSleepStatePullerDeathRecipient(); SubsystemSleepStatePuller::SubsystemSleepStatePuller() : SubsystemSleepStatePuller::SubsystemSleepStatePuller() : StatsPuller(android::util::SUBSYSTEM_SLEEP_STATE) { StatsPuller(android::util::SUBSYSTEM_SLEEP_STATE) { } } // The caller must be holding gPowerHalMutex. // The caller must be holding gPowerHalMutex. bool checkResultLocked(const Return<void> &ret, const char* function) { static bool checkResultLocked(const Return<void> &ret, const char* function) { if (!ret.isOk()) { if (!ret.isOk()) { ALOGE("%s failed: requested HAL service not available. Description: %s", ALOGE("%s failed: requested HAL service not available. Description: %s", function, ret.description().c_str()); function, ret.description().c_str()); Loading @@ -108,7 +110,7 @@ bool checkResultLocked(const Return<void> &ret, const char* function) { // The caller must be holding gPowerHalMutex. // The caller must be holding gPowerHalMutex. // gPowerStatsHalV1_0 must not be null // gPowerStatsHalV1_0 must not be null bool initializePowerStats() { static bool initializePowerStats() { using android::hardware::power::stats::V1_0::Status; using android::hardware::power::stats::V1_0::Status; // Clear out previous content if we are re-initializing // Clear out previous content if we are re-initializing Loading Loading @@ -155,7 +157,7 @@ bool initializePowerStats() { } } // The caller must be holding gPowerHalMutex. // The caller must be holding gPowerHalMutex. bool getPowerStatsHalLocked() { static bool getPowerStatsHalLocked() { if(gPowerStatsHalV1_0 == nullptr) { if(gPowerStatsHalV1_0 == nullptr) { gPowerStatsHalV1_0 = android::hardware::power::stats::V1_0::IPowerStats::getService(); gPowerStatsHalV1_0 = android::hardware::power::stats::V1_0::IPowerStats::getService(); if (gPowerStatsHalV1_0 == nullptr) { if (gPowerStatsHalV1_0 == nullptr) { Loading @@ -180,7 +182,7 @@ bool getPowerStatsHalLocked() { } } // The caller must be holding gPowerHalMutex. // The caller must be holding gPowerHalMutex. bool getIPowerStatsDataLocked(vector<shared_ptr<LogEvent>>* data) { static bool getIPowerStatsDataLocked(vector<shared_ptr<LogEvent>>* data) { using android::hardware::power::stats::V1_0::Status; using android::hardware::power::stats::V1_0::Status; if(!getPowerStatsHalLocked()) { if(!getPowerStatsHalLocked()) { Loading Loading @@ -225,7 +227,7 @@ bool getIPowerStatsDataLocked(vector<shared_ptr<LogEvent>>* data) { } } // The caller must be holding gPowerHalMutex. // The caller must be holding gPowerHalMutex. bool getPowerHalLocked() { static bool getPowerHalLocked() { if(gPowerHalV1_0 == nullptr) { if(gPowerHalV1_0 == nullptr) { gPowerHalV1_0 = android::hardware::power::V1_0::IPower::getService(); gPowerHalV1_0 = android::hardware::power::V1_0::IPower::getService(); if(gPowerHalV1_0 == nullptr) { if(gPowerHalV1_0 == nullptr) { Loading @@ -250,7 +252,7 @@ bool getPowerHalLocked() { } } // The caller must be holding gPowerHalMutex. // The caller must be holding gPowerHalMutex. bool getIPowerDataLocked(vector<shared_ptr<LogEvent>>* data) { static bool getIPowerDataLocked(vector<shared_ptr<LogEvent>>* data) { using android::hardware::power::V1_0::Status; using android::hardware::power::V1_0::Status; if(!getPowerHalLocked()) { if(!getPowerHalLocked()) { Loading