power.stats: Add power.stats HIDL interface
Initial commit defines APIS to collect on-device
power-related data.
BUG: 117424656
BUG: 111185513
Test: Compilation and device boot
Change-Id: I6e3153c9fcd2d67e4a566a4621d7aa4c01da7636
(cherry picked from commit f91dcb5bfdfdd69e7c9023e0650ab21b4710586f)
Merged-In: I6e3153c9fcd2d67e4a566a4621d7aa4c01da7636
diff --git a/power/stats/1.0/Android.bp b/power/stats/1.0/Android.bp
new file mode 100644
index 0000000..2f16a21
--- /dev/null
+++ b/power/stats/1.0/Android.bp
@@ -0,0 +1,23 @@
+// This file is autogenerated by hidl-gen -Landroidbp.
+
+hidl_interface {
+ name: "android.hardware.power.stats@1.0",
+ root: "android.hardware",
+ vndk: {
+ enabled: true,
+ },
+ srcs: [
+ "types.hal",
+ "IPowerStats.hal",
+ ],
+ interfaces: [
+ "android.hidl.base@1.0",
+ ],
+ types: [
+ "Status",
+ "RailInfo",
+ "EnergyData",
+ ],
+ gen_java: false,
+}
+
diff --git a/power/stats/1.0/IPowerStats.hal b/power/stats/1.0/IPowerStats.hal
new file mode 100644
index 0000000..d75e170
--- /dev/null
+++ b/power/stats/1.0/IPowerStats.hal
@@ -0,0 +1,95 @@
+/*
+ * 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.
+ */
+package android.hardware.power.stats@1.0;
+
+interface IPowerStats {
+
+ /**
+ * Rail information:
+ * Reports information related to the rails being monitored.
+ *
+ * @return rails Information about monitored rails.
+ * @return status SUCCESS on success or NOT_SUPPORTED if
+ * feature is not enabled or FILESYSTEM_ERROR on filesystem nodes
+ * access error.
+ */
+ getRailInfo()
+ generates(vec<RailInfo> rails, Status status);
+
+ /**
+ * Rail level energy measurements for low frequency clients:
+ * Reports accumulated energy since boot on each rail.
+ *
+ * @param railIndices Indices of rails for which data is required.
+ * To get data for all rails pass an empty vector. Rail name to
+ * index mapping can be queried from getRailInfo() API.
+ * @return data Energy values since boot for all requested rails.
+ * @return status SUCCESS on success or NOT_SUPPORTED if
+ * feature is not enabled or FILESYSTEM_ERROR on filesystem nodes
+ * access error.
+ */
+ getEnergyData(vec<uint32_t> railIndices)
+ generates(vec<EnergyData> data, Status status);
+
+ /**
+ * Stream rail level power measurements for high frequency clients:
+ * Streams accumulated energy since boot on each rail. This API is
+ * asynchronous.
+ *
+ * @param timeMs Time(in ms) for which energyData should be streamed
+ * @return mqDesc Unsynchronous Fast Message Queue descriptor - One
+ * writer(power.stats HAL) multiple readers are supported. Reader
+ * should read faster than writer otherwise data might be
+ * overwritten. Data is present in following format in the queue:
+ * +-----------------------+ <--
+ * | EnergyData for rail 1 | |
+ * +-----------------------+ |
+ * | EnergyData for rail 2 | |
+ * +-----------------------+ |
+ * | . | |-- 1st Sample
+ * | . | |
+ * | . | |
+ * +-----------------------+ |
+ * | EnergyData for rail n | |
+ * +-----------------------+ <--
+ * | . |
+ * | . |
+ * | . |
+ * +-----------------------+ <--
+ * | EnergyData for rail 1 | |
+ * +-----------------------+ |
+ * | EnergyData for rail 2 | |
+ * +-----------------------+ |
+ * | . | |-- kth Sample
+ * | . | |
+ * | . | |
+ * +-----------------------+ |
+ * | EnergyData for rail n | |
+ * +-----------------------+ <--
+ *
+ * where,
+ * n = railsPerSample
+ * k = numSamples
+ *
+ * @return numSamples Number of samples which will be generated in timeMs.
+ * @return railsPerSample Number of rails measured per sample.
+ * @return status SUCCESS on success or FILESYSTEM_ERROR on filesystem
+ * nodes access or NOT_SUPPORTED if feature is not enabled.
+ */
+ streamEnergyData(uint32_t timeMs)
+ generates(fmq_unsync<EnergyData> mqDesc, uint32_t numSamples,
+ uint32_t railsPerSample, Status status);
+};
diff --git a/power/stats/1.0/types.hal b/power/stats/1.0/types.hal
new file mode 100644
index 0000000..826c29b
--- /dev/null
+++ b/power/stats/1.0/types.hal
@@ -0,0 +1,46 @@
+/*
+ * 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.
+ */
+package android.hardware.power.stats@1.0;
+
+enum Status : uint32_t {
+ SUCCESS = 0,
+ NOT_SUPPORTED = 1,
+ INVALID_INPUT = 2,
+ FILESYSTEM_ERROR = 3,
+};
+
+struct RailInfo {
+ /** Index corresponding to the rail */
+ uint32_t index;
+ /** Name of the rail */
+ string railName;
+ /** Name of the subsystem to which this rail belongs */
+ string subsysName;
+ /** Hardware sampling rate */
+ uint32_t samplingRate;
+};
+
+struct EnergyData {
+ /**
+ * Index corrensponding to the rail. This index matches
+ * the index returned in RailInfo
+ */
+ uint32_t index;
+ /** Time since device boot(CLOCK_BOOTTIME) in milli-seconds */
+ uint64_t timestamp;
+ /** Accumulated energy since device boot in microwatt-seconds (uWs) */
+ uint64_t energy;
+};