blob: d67fb3508fe613d8753ee1e7db0af9cc2c41d600 [file] [log] [blame]
Vinay Kalia7b3d7a02018-11-01 11:57:40 -07001/*
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 Schwartza51d9b92019-01-15 14:07:56 -080024#include <unordered_map>
Vinay Kalia7b3d7a02018-11-01 11:57:40 -070025
26namespace android {
27namespace hardware {
28namespace power {
29namespace stats {
30namespace V1_0 {
31namespace implementation {
32
33using ::android::hardware::hidl_vec;
34using ::android::hardware::kSynchronizedReadWrite;
35using ::android::hardware::Return;
36using ::android::hardware::Void;
37using ::android::hardware::power::stats::V1_0::EnergyData;
38using ::android::hardware::power::stats::V1_0::PowerEntityInfo;
39using ::android::hardware::power::stats::V1_0::PowerEntityStateInfo;
40using ::android::hardware::power::stats::V1_0::PowerEntityStateResidencyData;
41using ::android::hardware::power::stats::V1_0::PowerEntityStateResidencyResult;
42using ::android::hardware::power::stats::V1_0::PowerEntityStateSpace;
43using ::android::hardware::power::stats::V1_0::PowerEntityType;
44using ::android::hardware::power::stats::V1_0::RailInfo;
45using ::android::hardware::power::stats::V1_0::Status;
46
47typedef MessageQueue<EnergyData, kSynchronizedReadWrite> MessageQueueSync;
48struct RailData {
49 std::string devicePath;
50 uint32_t index;
51 std::string subsysName;
52 uint32_t samplingRate;
53};
54
55struct 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 Schwartza51d9b92019-01-15 14:07:56 -080064class 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 Kalia7b3d7a02018-11-01 11:57:40 -070072struct PowerStats : public IPowerStats {
Benjamin Schwartza51d9b92019-01-15 14:07:56 -080073 public:
Vinay Kalia7b3d7a02018-11-01 11:57:40 -070074 PowerStats();
Benjamin Schwartza51d9b92019-01-15 14:07:56 -080075 uint32_t addPowerEntity(const std::string& name, PowerEntityType type);
76 void addStateResidencyDataProvider(std::shared_ptr<IStateResidencyDataProvider> p);
Vinay Kalia7b3d7a02018-11-01 11:57:40 -070077 // 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 Schwartza51d9b92019-01-15 14:07:56 -080090 // 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 Kalia7b3d7a02018-11-01 11:57:40 -070093 private:
94 OnDeviceMmt mPm;
95 void findIioPowerMonitorNodes();
96 size_t parsePowerRails();
97 int parseIioEnergyNode(std::string devName);
98 Status parseIioEnergyNodes();
Benjamin Schwartza51d9b92019-01-15 14:07:56 -080099 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 Kalia7b3d7a02018-11-01 11:57:40 -0700103};
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