Vinay Kalia | 7b3d7a0 | 2018-11-01 11:57:40 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2018 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | #ifndef ANDROID_HARDWARE_POWERSTATS_V1_0_POWERSTATS_H |
| 18 | #define ANDROID_HARDWARE_POWERSTATS_V1_0_POWERSTATS_H |
| 19 | |
| 20 | #include <android/hardware/power/stats/1.0/IPowerStats.h> |
| 21 | #include <fmq/MessageQueue.h> |
| 22 | #include <hidl/MQDescriptor.h> |
| 23 | #include <hidl/Status.h> |
Benjamin Schwartz | a51d9b9 | 2019-01-15 14:07:56 -0800 | [diff] [blame] | 24 | #include <unordered_map> |
Vinay Kalia | 7b3d7a0 | 2018-11-01 11:57:40 -0700 | [diff] [blame] | 25 | |
| 26 | namespace android { |
| 27 | namespace hardware { |
| 28 | namespace power { |
| 29 | namespace stats { |
| 30 | namespace V1_0 { |
| 31 | namespace implementation { |
| 32 | |
| 33 | using ::android::hardware::hidl_vec; |
| 34 | using ::android::hardware::kSynchronizedReadWrite; |
| 35 | using ::android::hardware::Return; |
| 36 | using ::android::hardware::Void; |
| 37 | using ::android::hardware::power::stats::V1_0::EnergyData; |
| 38 | using ::android::hardware::power::stats::V1_0::PowerEntityInfo; |
| 39 | using ::android::hardware::power::stats::V1_0::PowerEntityStateInfo; |
| 40 | using ::android::hardware::power::stats::V1_0::PowerEntityStateResidencyData; |
| 41 | using ::android::hardware::power::stats::V1_0::PowerEntityStateResidencyResult; |
| 42 | using ::android::hardware::power::stats::V1_0::PowerEntityStateSpace; |
| 43 | using ::android::hardware::power::stats::V1_0::PowerEntityType; |
| 44 | using ::android::hardware::power::stats::V1_0::RailInfo; |
| 45 | using ::android::hardware::power::stats::V1_0::Status; |
| 46 | |
| 47 | typedef MessageQueue<EnergyData, kSynchronizedReadWrite> MessageQueueSync; |
| 48 | struct RailData { |
| 49 | std::string devicePath; |
| 50 | uint32_t index; |
| 51 | std::string subsysName; |
| 52 | uint32_t samplingRate; |
| 53 | }; |
| 54 | |
| 55 | struct OnDeviceMmt { |
| 56 | std::mutex mLock; |
| 57 | bool hwEnabled; |
| 58 | std::vector<std::string> devicePaths; |
| 59 | std::map<std::string, RailData> railsInfo; |
| 60 | std::vector<EnergyData> reading; |
| 61 | std::unique_ptr<MessageQueueSync> fmqSynchronized; |
| 62 | }; |
| 63 | |
Benjamin Schwartz | a51d9b9 | 2019-01-15 14:07:56 -0800 | [diff] [blame] | 64 | class IStateResidencyDataProvider { |
| 65 | public: |
| 66 | virtual ~IStateResidencyDataProvider() = default; |
| 67 | virtual bool getResults( |
| 68 | std::unordered_map<uint32_t, PowerEntityStateResidencyResult>& results) = 0; |
| 69 | virtual std::vector<PowerEntityStateSpace> getStateSpaces() = 0; |
| 70 | }; |
| 71 | |
Vinay Kalia | 7b3d7a0 | 2018-11-01 11:57:40 -0700 | [diff] [blame] | 72 | struct PowerStats : public IPowerStats { |
Benjamin Schwartz | a51d9b9 | 2019-01-15 14:07:56 -0800 | [diff] [blame] | 73 | public: |
Vinay Kalia | 7b3d7a0 | 2018-11-01 11:57:40 -0700 | [diff] [blame] | 74 | PowerStats(); |
Benjamin Schwartz | a51d9b9 | 2019-01-15 14:07:56 -0800 | [diff] [blame] | 75 | uint32_t addPowerEntity(const std::string& name, PowerEntityType type); |
| 76 | void addStateResidencyDataProvider(std::shared_ptr<IStateResidencyDataProvider> p); |
Vinay Kalia | 7b3d7a0 | 2018-11-01 11:57:40 -0700 | [diff] [blame] | 77 | // Methods from ::android::hardware::power::stats::V1_0::IPowerStats follow. |
| 78 | Return<void> getRailInfo(getRailInfo_cb _hidl_cb) override; |
| 79 | Return<void> getEnergyData(const hidl_vec<uint32_t>& railIndices, |
| 80 | getEnergyData_cb _hidl_cb) override; |
| 81 | Return<void> streamEnergyData(uint32_t timeMs, uint32_t samplingRate, |
| 82 | streamEnergyData_cb _hidl_cb) override; |
| 83 | Return<void> getPowerEntityInfo(getPowerEntityInfo_cb _hidl_cb) override; |
| 84 | Return<void> getPowerEntityStateInfo(const hidl_vec<uint32_t>& powerEntityIds, |
| 85 | getPowerEntityStateInfo_cb _hidl_cb) override; |
| 86 | Return<void> getPowerEntityStateResidencyData( |
| 87 | const hidl_vec<uint32_t>& powerEntityIds, |
| 88 | getPowerEntityStateResidencyData_cb _hidl_cb) override; |
| 89 | |
Benjamin Schwartz | a51d9b9 | 2019-01-15 14:07:56 -0800 | [diff] [blame] | 90 | // Methods from ::android::hidl::base::V1_0::IBase follow. |
| 91 | Return<void> debug(const hidl_handle& fd, const hidl_vec<hidl_string>& args) override; |
| 92 | |
Vinay Kalia | 7b3d7a0 | 2018-11-01 11:57:40 -0700 | [diff] [blame] | 93 | private: |
| 94 | OnDeviceMmt mPm; |
| 95 | void findIioPowerMonitorNodes(); |
| 96 | size_t parsePowerRails(); |
| 97 | int parseIioEnergyNode(std::string devName); |
| 98 | Status parseIioEnergyNodes(); |
Benjamin Schwartz | a51d9b9 | 2019-01-15 14:07:56 -0800 | [diff] [blame] | 99 | std::vector<PowerEntityInfo> mPowerEntityInfos; |
| 100 | std::unordered_map<uint32_t, PowerEntityStateSpace> mPowerEntityStateSpaces; |
| 101 | std::unordered_map<uint32_t, std::shared_ptr<IStateResidencyDataProvider>> |
| 102 | mStateResidencyDataProviders; |
Vinay Kalia | 7b3d7a0 | 2018-11-01 11:57:40 -0700 | [diff] [blame] | 103 | }; |
| 104 | |
| 105 | } // namespace implementation |
| 106 | } // namespace V1_0 |
| 107 | } // namespace stats |
| 108 | } // namespace power |
| 109 | } // namespace hardware |
| 110 | } // namespace android |
| 111 | |
| 112 | #endif // ANDROID_HARDWARE_POWERSTATS_V1_0_POWERSTATS_H |