Anurag Singh | 9cec85b | 2012-09-04 21:46:24 -0700 | [diff] [blame] | 1 | /* |
Ananth Raghavan Subramanian | e432dbf | 2017-03-24 16:30:12 -0700 | [diff] [blame] | 2 | * Copyright (c) 2012-2017, The Linux Foundation. All rights reserved. |
Rashed Abdel-Tawab | e52ce10 | 2017-12-30 00:41:49 +0200 | [diff] [blame] | 3 | * Copyright (C) 2017 The Android Open Source Project |
dianlujitao | 8df56d6 | 2018-01-18 21:24:30 +0800 | [diff] [blame] | 4 | * Copyright (C) 2017-2018 The LineageOS Project |
Anurag Singh | 9cec85b | 2012-09-04 21:46:24 -0700 | [diff] [blame] | 5 | * |
| 6 | * Redistribution and use in source and binary forms, with or without |
| 7 | * modification, are permitted provided that the following conditions are |
| 8 | * met: |
| 9 | * * * Redistributions of source code must retain the above copyright |
| 10 | * notice, this list of conditions and the following disclaimer. |
| 11 | * * Redistributions in binary form must reproduce the above |
| 12 | * copyright notice, this list of conditions and the following |
| 13 | * disclaimer in the documentation and/or other materials provided |
| 14 | * with the distribution. |
Duy Truong | 7022245 | 2013-02-10 06:35:11 -0800 | [diff] [blame] | 15 | * * Neither the name of The Linux Foundation nor the names of its |
Anurag Singh | 9cec85b | 2012-09-04 21:46:24 -0700 | [diff] [blame] | 16 | * contributors may be used to endorse or promote products derived |
| 17 | * from this software without specific prior written permission. |
| 18 | * |
| 19 | * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED |
| 20 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF |
| 21 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT |
| 22 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS |
| 23 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
| 24 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
| 25 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR |
| 26 | * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, |
| 27 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE |
| 28 | * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN |
| 29 | * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 30 | */ |
| 31 | |
Anurag Singh | 6ec1206 | 2012-10-02 09:59:01 -0700 | [diff] [blame] | 32 | #define LOG_NIDEBUG 0 |
| 33 | |
Anurag Singh | 9cec85b | 2012-09-04 21:46:24 -0700 | [diff] [blame] | 34 | #include <errno.h> |
| 35 | #include <string.h> |
| 36 | #include <sys/types.h> |
| 37 | #include <sys/stat.h> |
| 38 | #include <fcntl.h> |
| 39 | #include <dlfcn.h> |
Rashed Abdel-Tawab | e52ce10 | 2017-12-30 00:41:49 +0200 | [diff] [blame] | 40 | #include <inttypes.h> |
Anurag Singh | 9cec85b | 2012-09-04 21:46:24 -0700 | [diff] [blame] | 41 | #include <stdlib.h> |
Rashed Abdel-Tawab | 42eb1ee | 2017-12-26 23:11:03 +0200 | [diff] [blame] | 42 | #include <unistd.h> |
Anurag Singh | 9cec85b | 2012-09-04 21:46:24 -0700 | [diff] [blame] | 43 | |
| 44 | #define LOG_TAG "QCOM PowerHAL" |
Rashed Abdel-Tawab | 42eb1ee | 2017-12-26 23:11:03 +0200 | [diff] [blame] | 45 | #include <log/log.h> |
Anurag Singh | 9cec85b | 2012-09-04 21:46:24 -0700 | [diff] [blame] | 46 | #include <hardware/power.h> |
| 47 | |
Anurag Singh | 6ec1206 | 2012-10-02 09:59:01 -0700 | [diff] [blame] | 48 | #include "utils.h" |
Anurag Singh | 9cec85b | 2012-09-04 21:46:24 -0700 | [diff] [blame] | 49 | #include "metadata-defs.h" |
Anurag Singh | 6ec1206 | 2012-10-02 09:59:01 -0700 | [diff] [blame] | 50 | #include "hint-data.h" |
| 51 | #include "performance.h" |
Anurag Singh | 057806b | 2013-04-16 16:53:45 -0700 | [diff] [blame] | 52 | #include "power-common.h" |
Keith Mok | 964d255 | 2015-11-13 09:46:14 -0800 | [diff] [blame] | 53 | #include "power-feature.h" |
Rashed Abdel-Tawab | 711a28d | 2017-11-03 12:44:16 -0700 | [diff] [blame] | 54 | #include "power-helper.h" |
| 55 | |
Rashed Abdel-Tawab | e52ce10 | 2017-12-30 00:41:49 +0200 | [diff] [blame] | 56 | #define USINSEC 1000000L |
| 57 | #define NSINUS 1000L |
| 58 | |
| 59 | #ifndef RPM_STAT |
| 60 | #define RPM_STAT "/d/rpm_stats" |
| 61 | #endif |
| 62 | |
| 63 | #ifndef RPM_MASTER_STAT |
| 64 | #define RPM_MASTER_STAT "/d/rpm_master_stats" |
| 65 | #endif |
| 66 | |
| 67 | #ifndef RPM_SYSTEM_STAT |
| 68 | #define RPM_SYSTEM_STAT "/d/system_stats" |
| 69 | #endif |
| 70 | |
| 71 | /* |
| 72 | Set with TARGET_WLAN_POWER_STAT in BoardConfig.mk |
| 73 | Defaults to QCACLD3 path |
| 74 | Path for QCACLD3: /d/wlan0/power_stats |
| 75 | Path for QCACLD2 and Prima: /d/wlan_wcnss/power_stats |
| 76 | */ |
| 77 | |
| 78 | #ifndef V1_0_HAL |
Rashed Abdel-Tawab | 711a28d | 2017-11-03 12:44:16 -0700 | [diff] [blame] | 79 | #ifndef WLAN_POWER_STAT |
| 80 | #define WLAN_POWER_STAT "/d/wlan0/power_stats" |
| 81 | #endif |
Rashed Abdel-Tawab | e52ce10 | 2017-12-30 00:41:49 +0200 | [diff] [blame] | 82 | #endif |
Rashed Abdel-Tawab | 711a28d | 2017-11-03 12:44:16 -0700 | [diff] [blame] | 83 | |
Rashed Abdel-Tawab | 711a28d | 2017-11-03 12:44:16 -0700 | [diff] [blame] | 84 | #define LINE_SIZE 128 |
| 85 | |
Rashed Abdel-Tawab | e52ce10 | 2017-12-30 00:41:49 +0200 | [diff] [blame] | 86 | #ifdef LEGACY_STATS |
| 87 | /* Use these stats on pre-nougat qualcomm kernels */ |
| 88 | static const char *rpm_param_names[] = { |
| 89 | "vlow_count", |
| 90 | "accumulated_vlow_time", |
| 91 | "vmin_count", |
| 92 | "accumulated_vmin_time" |
| 93 | }; |
| 94 | |
| 95 | static const char *rpm_master_param_names[] = { |
| 96 | "xo_accumulated_duration", |
| 97 | "xo_count", |
| 98 | "xo_accumulated_duration", |
| 99 | "xo_count", |
| 100 | "xo_accumulated_duration", |
| 101 | "xo_count", |
| 102 | "xo_accumulated_duration", |
| 103 | "xo_count" |
| 104 | }; |
Rashed Abdel-Tawab | 031a2bc | 2018-01-09 20:31:32 -0500 | [diff] [blame] | 105 | |
| 106 | static const char *wlan_param_names[] = { |
| 107 | "cumulative_sleep_time_ms", |
| 108 | "cumulative_total_on_time_ms", |
| 109 | "deep_sleep_enter_counter", |
| 110 | "last_deep_sleep_enter_tstamp_ms" |
| 111 | }; |
Rashed Abdel-Tawab | e52ce10 | 2017-12-30 00:41:49 +0200 | [diff] [blame] | 112 | #else |
Rashed Abdel-Tawab | 031a2bc | 2018-01-09 20:31:32 -0500 | [diff] [blame] | 113 | /* Use these stats on nougat kernels and forward */ |
Rashed Abdel-Tawab | e52ce10 | 2017-12-30 00:41:49 +0200 | [diff] [blame] | 114 | const char *rpm_stat_params[MAX_RPM_PARAMS] = { |
| 115 | "count", |
| 116 | "actual last sleep(msec)", |
| 117 | }; |
| 118 | |
| 119 | const char *master_stat_params[MAX_RPM_PARAMS] = { |
| 120 | "Accumulated XO duration", |
| 121 | "XO Count", |
| 122 | }; |
| 123 | |
| 124 | struct stat_pair rpm_stat_map[] = { |
| 125 | { RPM_MODE_XO, "RPM Mode:vlow", rpm_stat_params, ARRAY_SIZE(rpm_stat_params) }, |
| 126 | { RPM_MODE_VMIN, "RPM Mode:vmin", rpm_stat_params, ARRAY_SIZE(rpm_stat_params) }, |
| 127 | { VOTER_APSS, "APSS", master_stat_params, ARRAY_SIZE(master_stat_params) }, |
| 128 | { VOTER_MPSS, "MPSS", master_stat_params, ARRAY_SIZE(master_stat_params) }, |
| 129 | { VOTER_ADSP, "ADSP", master_stat_params, ARRAY_SIZE(master_stat_params) }, |
| 130 | { VOTER_SLPI, "SLPI", master_stat_params, ARRAY_SIZE(master_stat_params) }, |
| 131 | }; |
| 132 | #endif |
| 133 | |
| 134 | #ifndef V1_0_HAL |
Rashed Abdel-Tawab | 711a28d | 2017-11-03 12:44:16 -0700 | [diff] [blame] | 135 | const char *wlan_power_stat_params[] = { |
| 136 | "cumulative_sleep_time_ms", |
| 137 | "cumulative_total_on_time_ms", |
| 138 | "deep_sleep_enter_counter", |
| 139 | "last_deep_sleep_enter_tstamp_ms" |
| 140 | }; |
| 141 | |
| 142 | struct stat_pair wlan_stat_map[] = { |
| 143 | { WLAN_POWER_DEBUG_STATS, "POWER DEBUG STATS", wlan_power_stat_params, ARRAY_SIZE(wlan_power_stat_params) }, |
| 144 | }; |
Rashed Abdel-Tawab | e52ce10 | 2017-12-30 00:41:49 +0200 | [diff] [blame] | 145 | #endif |
Anurag Singh | 9cec85b | 2012-09-04 21:46:24 -0700 | [diff] [blame] | 146 | |
Anurag Singh | 6f64e9f | 2012-10-09 16:08:38 -0700 | [diff] [blame] | 147 | static int saved_dcvs_cpu0_slack_max = -1; |
| 148 | static int saved_dcvs_cpu0_slack_min = -1; |
| 149 | static int saved_mpdecision_slack_max = -1; |
| 150 | static int saved_mpdecision_slack_min = -1; |
Anurag Singh | 6f64e9f | 2012-10-09 16:08:38 -0700 | [diff] [blame] | 151 | static int slack_node_rw_failed = 0; |
Anurag Singh | b15323a | 2013-06-08 16:55:44 -0700 | [diff] [blame] | 152 | static int display_hint_sent; |
Anurag Singh | 9cec85b | 2012-09-04 21:46:24 -0700 | [diff] [blame] | 153 | |
Rashed Abdel-Tawab | 711a28d | 2017-11-03 12:44:16 -0700 | [diff] [blame] | 154 | void power_init(void) |
Anurag Singh | 9cec85b | 2012-09-04 21:46:24 -0700 | [diff] [blame] | 155 | { |
| 156 | ALOGI("QCOM power HAL initing."); |
| 157 | } |
| 158 | |
Anurag Singh | 6ec1206 | 2012-10-02 09:59:01 -0700 | [diff] [blame] | 159 | static void process_video_decode_hint(void *metadata) |
| 160 | { |
| 161 | char governor[80]; |
| 162 | struct video_decode_metadata_t video_decode_metadata; |
Anurag Singh | 9cec85b | 2012-09-04 21:46:24 -0700 | [diff] [blame] | 163 | |
Anurag Singh | 6ec1206 | 2012-10-02 09:59:01 -0700 | [diff] [blame] | 164 | if (get_scaling_governor(governor, sizeof(governor)) == -1) { |
| 165 | ALOGE("Can't obtain scaling governor."); |
Anurag Singh | 9cec85b | 2012-09-04 21:46:24 -0700 | [diff] [blame] | 166 | |
Anurag Singh | 6ec1206 | 2012-10-02 09:59:01 -0700 | [diff] [blame] | 167 | return; |
Anurag Singh | 9cec85b | 2012-09-04 21:46:24 -0700 | [diff] [blame] | 168 | } |
| 169 | |
Anurag Singh | 6ec1206 | 2012-10-02 09:59:01 -0700 | [diff] [blame] | 170 | if (metadata) { |
| 171 | ALOGI("Processing video decode hint. Metadata: %s", (char *)metadata); |
| 172 | } |
| 173 | |
| 174 | /* Initialize encode metadata struct fields. */ |
| 175 | memset(&video_decode_metadata, 0, sizeof(struct video_decode_metadata_t)); |
| 176 | video_decode_metadata.state = -1; |
| 177 | video_decode_metadata.hint_id = DEFAULT_VIDEO_DECODE_HINT_ID; |
| 178 | |
| 179 | if (metadata) { |
| 180 | if (parse_video_decode_metadata((char *)metadata, &video_decode_metadata) == |
| 181 | -1) { |
| 182 | ALOGE("Error occurred while parsing metadata."); |
| 183 | return; |
| 184 | } |
| 185 | } else { |
| 186 | return; |
| 187 | } |
| 188 | |
| 189 | if (video_decode_metadata.state == 1) { |
Michael Bestas | e701b2d | 2018-03-25 23:14:21 +0300 | [diff] [blame^] | 190 | if (is_ondemand_governor(governor)) { |
Vince Leung | f72adfb | 2013-05-03 15:13:29 -0700 | [diff] [blame] | 191 | int resource_values[] = {THREAD_MIGRATION_SYNC_OFF}; |
| 192 | |
| 193 | perform_hint_action(video_decode_metadata.hint_id, |
Zhao Wei Liew | a72f777 | 2016-06-26 11:37:59 +0800 | [diff] [blame] | 194 | resource_values, ARRAY_SIZE(resource_values)); |
Ethan Chen | ed4628c | 2018-03-01 21:41:04 -0800 | [diff] [blame] | 195 | } else if (is_interactive_governor(governor)) { |
Vince Leung | f72adfb | 2013-05-03 15:13:29 -0700 | [diff] [blame] | 196 | int resource_values[] = {TR_MS_30, HISPEED_LOAD_90, HS_FREQ_1026, THREAD_MIGRATION_SYNC_OFF}; |
Anurag Singh | 6ec1206 | 2012-10-02 09:59:01 -0700 | [diff] [blame] | 197 | |
| 198 | perform_hint_action(video_decode_metadata.hint_id, |
Zhao Wei Liew | a72f777 | 2016-06-26 11:37:59 +0800 | [diff] [blame] | 199 | resource_values, ARRAY_SIZE(resource_values)); |
Anurag Singh | 6ec1206 | 2012-10-02 09:59:01 -0700 | [diff] [blame] | 200 | } |
| 201 | } else if (video_decode_metadata.state == 0) { |
Michael Bestas | e701b2d | 2018-03-25 23:14:21 +0300 | [diff] [blame^] | 202 | if (is_ondemand_governor(governor)) { |
Paul Keith | 2d3df8b | 2016-07-31 19:22:50 -0700 | [diff] [blame] | 203 | undo_hint_action(video_decode_metadata.hint_id); |
Ethan Chen | ed4628c | 2018-03-01 21:41:04 -0800 | [diff] [blame] | 204 | } else if (is_interactive_governor(governor)) { |
Anurag Singh | 6ec1206 | 2012-10-02 09:59:01 -0700 | [diff] [blame] | 205 | undo_hint_action(video_decode_metadata.hint_id); |
| 206 | } |
| 207 | } |
Anurag Singh | 9cec85b | 2012-09-04 21:46:24 -0700 | [diff] [blame] | 208 | } |
| 209 | |
| 210 | static void process_video_encode_hint(void *metadata) |
| 211 | { |
Anurag Singh | 9cec85b | 2012-09-04 21:46:24 -0700 | [diff] [blame] | 212 | char governor[80]; |
| 213 | struct video_encode_metadata_t video_encode_metadata; |
| 214 | |
| 215 | if (get_scaling_governor(governor, sizeof(governor)) == -1) { |
| 216 | ALOGE("Can't obtain scaling governor."); |
| 217 | |
| 218 | return; |
| 219 | } |
| 220 | |
| 221 | /* Initialize encode metadata struct fields. */ |
Anurag Singh | 6ec1206 | 2012-10-02 09:59:01 -0700 | [diff] [blame] | 222 | memset(&video_encode_metadata, 0, sizeof(struct video_encode_metadata_t)); |
Anurag Singh | 9cec85b | 2012-09-04 21:46:24 -0700 | [diff] [blame] | 223 | video_encode_metadata.state = -1; |
Anurag Singh | 6ec1206 | 2012-10-02 09:59:01 -0700 | [diff] [blame] | 224 | video_encode_metadata.hint_id = DEFAULT_VIDEO_ENCODE_HINT_ID; |
Anurag Singh | 9cec85b | 2012-09-04 21:46:24 -0700 | [diff] [blame] | 225 | |
| 226 | if (metadata) { |
Anurag Singh | 6ec1206 | 2012-10-02 09:59:01 -0700 | [diff] [blame] | 227 | if (parse_video_encode_metadata((char *)metadata, &video_encode_metadata) == |
Anurag Singh | 9cec85b | 2012-09-04 21:46:24 -0700 | [diff] [blame] | 228 | -1) { |
| 229 | ALOGE("Error occurred while parsing metadata."); |
| 230 | return; |
| 231 | } |
| 232 | } else { |
| 233 | return; |
| 234 | } |
| 235 | |
Anurag Singh | 6ec1206 | 2012-10-02 09:59:01 -0700 | [diff] [blame] | 236 | if (video_encode_metadata.state == 1) { |
Michael Bestas | e701b2d | 2018-03-25 23:14:21 +0300 | [diff] [blame^] | 237 | if (is_ondemand_governor(governor)) { |
Vince Leung | f72adfb | 2013-05-03 15:13:29 -0700 | [diff] [blame] | 238 | int resource_values[] = {IO_BUSY_OFF, SAMPLING_DOWN_FACTOR_1, THREAD_MIGRATION_SYNC_OFF}; |
Anurag Singh | 9cec85b | 2012-09-04 21:46:24 -0700 | [diff] [blame] | 239 | |
Anurag Singh | 6ec1206 | 2012-10-02 09:59:01 -0700 | [diff] [blame] | 240 | perform_hint_action(video_encode_metadata.hint_id, |
Zhao Wei Liew | a72f777 | 2016-06-26 11:37:59 +0800 | [diff] [blame] | 241 | resource_values, ARRAY_SIZE(resource_values)); |
Ethan Chen | ed4628c | 2018-03-01 21:41:04 -0800 | [diff] [blame] | 242 | } else if (is_interactive_governor(governor)) { |
Anurag Singh | 6cda91c | 2013-12-18 18:24:14 -0800 | [diff] [blame] | 243 | int resource_values[] = {TR_MS_30, HISPEED_LOAD_90, HS_FREQ_1026, THREAD_MIGRATION_SYNC_OFF, |
| 244 | INTERACTIVE_IO_BUSY_OFF}; |
Anurag Singh | 9cec85b | 2012-09-04 21:46:24 -0700 | [diff] [blame] | 245 | |
Anurag Singh | 6ec1206 | 2012-10-02 09:59:01 -0700 | [diff] [blame] | 246 | perform_hint_action(video_encode_metadata.hint_id, |
Zhao Wei Liew | a72f777 | 2016-06-26 11:37:59 +0800 | [diff] [blame] | 247 | resource_values, ARRAY_SIZE(resource_values)); |
Anurag Singh | 6ec1206 | 2012-10-02 09:59:01 -0700 | [diff] [blame] | 248 | } |
| 249 | } else if (video_encode_metadata.state == 0) { |
Michael Bestas | e701b2d | 2018-03-25 23:14:21 +0300 | [diff] [blame^] | 250 | if (is_ondemand_governor(governor)) { |
Anurag Singh | 6ec1206 | 2012-10-02 09:59:01 -0700 | [diff] [blame] | 251 | undo_hint_action(video_encode_metadata.hint_id); |
Ethan Chen | ed4628c | 2018-03-01 21:41:04 -0800 | [diff] [blame] | 252 | } else if (is_interactive_governor(governor)) { |
Anurag Singh | 6ec1206 | 2012-10-02 09:59:01 -0700 | [diff] [blame] | 253 | undo_hint_action(video_encode_metadata.hint_id); |
Anurag Singh | 9cec85b | 2012-09-04 21:46:24 -0700 | [diff] [blame] | 254 | } |
| 255 | } |
| 256 | } |
| 257 | |
Rashed Abdel-Tawab | 711a28d | 2017-11-03 12:44:16 -0700 | [diff] [blame] | 258 | int __attribute__ ((weak)) power_hint_override(power_hint_t UNUSED(hint), |
Adrian Salido | a60e94b | 2017-03-29 15:58:38 -0700 | [diff] [blame] | 259 | void *UNUSED(data)) |
Anurag Singh | 9cec85b | 2012-09-04 21:46:24 -0700 | [diff] [blame] | 260 | { |
Anurag Singh | 057806b | 2013-04-16 16:53:45 -0700 | [diff] [blame] | 261 | return HINT_NONE; |
Anurag Singh | 9cec85b | 2012-09-04 21:46:24 -0700 | [diff] [blame] | 262 | } |
| 263 | |
Ajay Dudani | 5e67680 | 2015-04-07 23:56:52 -0700 | [diff] [blame] | 264 | /* Declare function before use */ |
| 265 | void interaction(int duration, int num_args, int opt_list[]); |
| 266 | |
Rashed Abdel-Tawab | 711a28d | 2017-11-03 12:44:16 -0700 | [diff] [blame] | 267 | void power_hint(power_hint_t hint, void *data) |
Anurag Singh | 9cec85b | 2012-09-04 21:46:24 -0700 | [diff] [blame] | 268 | { |
| 269 | /* Check if this hint has been overridden. */ |
Rashed Abdel-Tawab | 711a28d | 2017-11-03 12:44:16 -0700 | [diff] [blame] | 270 | if (power_hint_override(hint, data) == HINT_HANDLED) { |
Anurag Singh | 9cec85b | 2012-09-04 21:46:24 -0700 | [diff] [blame] | 271 | /* The power_hint has been handled. We can skip the rest. */ |
| 272 | return; |
| 273 | } |
| 274 | |
| 275 | switch(hint) { |
Ananth Raghavan Subramanian | e432dbf | 2017-03-24 16:30:12 -0700 | [diff] [blame] | 276 | case POWER_HINT_SUSTAINED_PERFORMANCE: |
| 277 | ALOGI("Sustained perf power hint not handled in power_hint_override"); |
Paul Keith | 4f2dadb | 2017-12-31 02:17:32 +0100 | [diff] [blame] | 278 | break; |
Ananth Raghavan Subramanian | e432dbf | 2017-03-24 16:30:12 -0700 | [diff] [blame] | 279 | case POWER_HINT_VR_MODE: |
| 280 | ALOGI("VR mode power hint not handled in power_hint_override"); |
Paul Keith | 4f2dadb | 2017-12-31 02:17:32 +0100 | [diff] [blame] | 281 | break; |
Anurag Singh | 9cec85b | 2012-09-04 21:46:24 -0700 | [diff] [blame] | 282 | case POWER_HINT_INTERACTION: |
Vince Leung | 699c1bc | 2013-08-14 17:40:36 -0700 | [diff] [blame] | 283 | { |
| 284 | int resources[] = {0x702, 0x20F, 0x30F}; |
| 285 | int duration = 3000; |
| 286 | |
| 287 | interaction(duration, sizeof(resources)/sizeof(resources[0]), resources); |
| 288 | } |
Anurag Singh | 9cec85b | 2012-09-04 21:46:24 -0700 | [diff] [blame] | 289 | break; |
| 290 | case POWER_HINT_VIDEO_ENCODE: |
| 291 | process_video_encode_hint(data); |
| 292 | break; |
Anurag Singh | 6ec1206 | 2012-10-02 09:59:01 -0700 | [diff] [blame] | 293 | case POWER_HINT_VIDEO_DECODE: |
| 294 | process_video_decode_hint(data); |
| 295 | break; |
dianlujitao | 8df56d6 | 2018-01-18 21:24:30 +0800 | [diff] [blame] | 296 | case POWER_HINT_SET_PROFILE: |
| 297 | ALOGI("set profile power hint not handled in power_hint_override"); |
| 298 | break; |
Paul Keith | 4f2dadb | 2017-12-31 02:17:32 +0100 | [diff] [blame] | 299 | default: |
| 300 | break; |
Anurag Singh | 9cec85b | 2012-09-04 21:46:24 -0700 | [diff] [blame] | 301 | } |
| 302 | } |
| 303 | |
dianlujitao | 8df56d6 | 2018-01-18 21:24:30 +0800 | [diff] [blame] | 304 | int get_number_of_profiles() |
| 305 | { |
| 306 | return 0; |
| 307 | } |
| 308 | |
Rashed Abdel-Tawab | 711a28d | 2017-11-03 12:44:16 -0700 | [diff] [blame] | 309 | int __attribute__ ((weak)) set_interactive_override(int UNUSED(on)) |
Anurag Singh | 6ec1206 | 2012-10-02 09:59:01 -0700 | [diff] [blame] | 310 | { |
Anurag Singh | 057806b | 2013-04-16 16:53:45 -0700 | [diff] [blame] | 311 | return HINT_NONE; |
Anurag Singh | 6ec1206 | 2012-10-02 09:59:01 -0700 | [diff] [blame] | 312 | } |
| 313 | |
Steve Kondik | 11a8464 | 2014-03-27 22:00:00 -0700 | [diff] [blame] | 314 | #ifdef SET_INTERACTIVE_EXT |
| 315 | extern void power_set_interactive_ext(int on); |
| 316 | #endif |
| 317 | |
Rashed Abdel-Tawab | 711a28d | 2017-11-03 12:44:16 -0700 | [diff] [blame] | 318 | void power_set_interactive(int on) |
Anurag Singh | 9cec85b | 2012-09-04 21:46:24 -0700 | [diff] [blame] | 319 | { |
Anurag Singh | 6f64e9f | 2012-10-09 16:08:38 -0700 | [diff] [blame] | 320 | char governor[80]; |
| 321 | char tmp_str[NODE_MAX]; |
Anurag Singh | 6ec1206 | 2012-10-02 09:59:01 -0700 | [diff] [blame] | 322 | struct video_encode_metadata_t video_encode_metadata; |
Krishna Vanka | 42c06e1 | 2016-08-29 16:38:54 +0530 | [diff] [blame] | 323 | int rc = 0; |
Anurag Singh | 6ec1206 | 2012-10-02 09:59:01 -0700 | [diff] [blame] | 324 | |
Balamurugan Thanikachalam | 930f9ae | 2017-07-11 14:42:21 +0530 | [diff] [blame] | 325 | if (!on) { |
| 326 | /* Send Display OFF hint to perf HAL */ |
| 327 | perf_hint_enable(VENDOR_HINT_DISPLAY_OFF, 0); |
| 328 | } else { |
| 329 | /* Send Display ON hint to perf HAL */ |
| 330 | perf_hint_enable(VENDOR_HINT_DISPLAY_ON, 0); |
| 331 | } |
| 332 | |
Zhao Wei Liew | 1e86352 | 2016-06-26 21:29:34 +0800 | [diff] [blame] | 333 | /** |
| 334 | * Ignore consecutive display-off hints |
| 335 | * Consecutive display-on hints are already handled |
| 336 | */ |
| 337 | if (display_hint_sent && !on) |
| 338 | return; |
| 339 | |
| 340 | display_hint_sent = !on; |
| 341 | |
Steve Kondik | 11a8464 | 2014-03-27 22:00:00 -0700 | [diff] [blame] | 342 | #ifdef SET_INTERACTIVE_EXT |
| 343 | power_set_interactive_ext(on); |
| 344 | #endif |
| 345 | |
Rashed Abdel-Tawab | 711a28d | 2017-11-03 12:44:16 -0700 | [diff] [blame] | 346 | if (set_interactive_override(on) == HINT_HANDLED) { |
Anurag Singh | 6ec1206 | 2012-10-02 09:59:01 -0700 | [diff] [blame] | 347 | return; |
| 348 | } |
Anurag Singh | 6f64e9f | 2012-10-09 16:08:38 -0700 | [diff] [blame] | 349 | |
Anurag Singh | b15323a | 2013-06-08 16:55:44 -0700 | [diff] [blame] | 350 | ALOGI("Got set_interactive hint"); |
Anurag Singh | fe93c1d | 2012-11-21 15:15:56 -0800 | [diff] [blame] | 351 | |
Anurag Singh | 6f64e9f | 2012-10-09 16:08:38 -0700 | [diff] [blame] | 352 | if (get_scaling_governor(governor, sizeof(governor)) == -1) { |
Anurag Singh | 6ec1206 | 2012-10-02 09:59:01 -0700 | [diff] [blame] | 353 | ALOGE("Can't obtain scaling governor."); |
Anurag Singh | 6f64e9f | 2012-10-09 16:08:38 -0700 | [diff] [blame] | 354 | |
| 355 | return; |
| 356 | } |
| 357 | |
Anurag Singh | 6ec1206 | 2012-10-02 09:59:01 -0700 | [diff] [blame] | 358 | if (!on) { |
| 359 | /* Display off. */ |
Michael Bestas | e701b2d | 2018-03-25 23:14:21 +0300 | [diff] [blame^] | 360 | if (is_ondemand_governor(governor)) { |
Zhao Wei Liew | 40ec34d | 2016-06-26 11:45:11 +0800 | [diff] [blame] | 361 | int resource_values[] = { MS_500, THREAD_MIGRATION_SYNC_OFF }; |
Anurag Singh | 10918c1 | 2012-11-09 17:35:20 -0800 | [diff] [blame] | 362 | |
Zhao Wei Liew | 1e86352 | 2016-06-26 21:29:34 +0800 | [diff] [blame] | 363 | perform_hint_action(DISPLAY_STATE_HINT_ID, |
| 364 | resource_values, ARRAY_SIZE(resource_values)); |
Ethan Chen | ed4628c | 2018-03-01 21:41:04 -0800 | [diff] [blame] | 365 | } else if (is_interactive_governor(governor)) { |
Dilip Gudlur | 2eae266 | 2014-02-25 12:32:37 -0800 | [diff] [blame] | 366 | int resource_values[] = {TR_MS_50, THREAD_MIGRATION_SYNC_OFF}; |
Anurag Singh | 6f64e9f | 2012-10-09 16:08:38 -0700 | [diff] [blame] | 367 | |
Zhao Wei Liew | 1e86352 | 2016-06-26 21:29:34 +0800 | [diff] [blame] | 368 | perform_hint_action(DISPLAY_STATE_HINT_ID, |
| 369 | resource_values, ARRAY_SIZE(resource_values)); |
Michael Bestas | e701b2d | 2018-03-25 23:14:21 +0300 | [diff] [blame^] | 370 | } else if (is_msmdcvs_governor(governor)) { |
Zhao Wei Liew | 1e86352 | 2016-06-26 21:29:34 +0800 | [diff] [blame] | 371 | /* Display turned off. */ |
| 372 | if (sysfs_read(DCVS_CPU0_SLACK_MAX_NODE, tmp_str, NODE_MAX - 1)) { |
| 373 | if (!slack_node_rw_failed) { |
| 374 | ALOGE("Failed to read from %s", DCVS_CPU0_SLACK_MAX_NODE); |
| 375 | } |
| 376 | |
| 377 | rc = 1; |
| 378 | } else { |
| 379 | saved_dcvs_cpu0_slack_max = atoi(tmp_str); |
| 380 | } |
| 381 | |
| 382 | if (sysfs_read(DCVS_CPU0_SLACK_MIN_NODE, tmp_str, NODE_MAX - 1)) { |
| 383 | if (!slack_node_rw_failed) { |
| 384 | ALOGE("Failed to read from %s", DCVS_CPU0_SLACK_MIN_NODE); |
| 385 | } |
| 386 | |
| 387 | rc = 1; |
| 388 | } else { |
| 389 | saved_dcvs_cpu0_slack_min = atoi(tmp_str); |
| 390 | } |
| 391 | |
| 392 | if (sysfs_read(MPDECISION_SLACK_MAX_NODE, tmp_str, NODE_MAX - 1)) { |
| 393 | if (!slack_node_rw_failed) { |
| 394 | ALOGE("Failed to read from %s", MPDECISION_SLACK_MAX_NODE); |
| 395 | } |
| 396 | |
| 397 | rc = 1; |
| 398 | } else { |
| 399 | saved_mpdecision_slack_max = atoi(tmp_str); |
| 400 | } |
| 401 | |
| 402 | if (sysfs_read(MPDECISION_SLACK_MIN_NODE, tmp_str, NODE_MAX - 1)) { |
| 403 | if(!slack_node_rw_failed) { |
| 404 | ALOGE("Failed to read from %s", MPDECISION_SLACK_MIN_NODE); |
| 405 | } |
| 406 | |
| 407 | rc = 1; |
| 408 | } else { |
| 409 | saved_mpdecision_slack_min = atoi(tmp_str); |
| 410 | } |
| 411 | |
| 412 | /* Write new values. */ |
| 413 | if (saved_dcvs_cpu0_slack_max != -1) { |
| 414 | snprintf(tmp_str, NODE_MAX, "%d", 10 * saved_dcvs_cpu0_slack_max); |
| 415 | |
| 416 | if (sysfs_write(DCVS_CPU0_SLACK_MAX_NODE, tmp_str) != 0) { |
Anurag Singh | 6f64e9f | 2012-10-09 16:08:38 -0700 | [diff] [blame] | 417 | if (!slack_node_rw_failed) { |
Zhao Wei Liew | 1e86352 | 2016-06-26 21:29:34 +0800 | [diff] [blame] | 418 | ALOGE("Failed to write to %s", DCVS_CPU0_SLACK_MAX_NODE); |
Anurag Singh | 6f64e9f | 2012-10-09 16:08:38 -0700 | [diff] [blame] | 419 | } |
| 420 | |
| 421 | rc = 1; |
| 422 | } |
Zhao Wei Liew | 1e86352 | 2016-06-26 21:29:34 +0800 | [diff] [blame] | 423 | } |
Anurag Singh | 6f64e9f | 2012-10-09 16:08:38 -0700 | [diff] [blame] | 424 | |
Zhao Wei Liew | 1e86352 | 2016-06-26 21:29:34 +0800 | [diff] [blame] | 425 | if (saved_dcvs_cpu0_slack_min != -1) { |
| 426 | snprintf(tmp_str, NODE_MAX, "%d", 10 * saved_dcvs_cpu0_slack_min); |
Anurag Singh | 6f64e9f | 2012-10-09 16:08:38 -0700 | [diff] [blame] | 427 | |
Zhao Wei Liew | 1e86352 | 2016-06-26 21:29:34 +0800 | [diff] [blame] | 428 | if (sysfs_write(DCVS_CPU0_SLACK_MIN_NODE, tmp_str) != 0) { |
Anurag Singh | 6f64e9f | 2012-10-09 16:08:38 -0700 | [diff] [blame] | 429 | if(!slack_node_rw_failed) { |
Zhao Wei Liew | 1e86352 | 2016-06-26 21:29:34 +0800 | [diff] [blame] | 430 | ALOGE("Failed to write to %s", DCVS_CPU0_SLACK_MIN_NODE); |
Anurag Singh | 6f64e9f | 2012-10-09 16:08:38 -0700 | [diff] [blame] | 431 | } |
| 432 | |
| 433 | rc = 1; |
| 434 | } |
Zhao Wei Liew | 1e86352 | 2016-06-26 21:29:34 +0800 | [diff] [blame] | 435 | } |
Anurag Singh | 6f64e9f | 2012-10-09 16:08:38 -0700 | [diff] [blame] | 436 | |
Zhao Wei Liew | 1e86352 | 2016-06-26 21:29:34 +0800 | [diff] [blame] | 437 | if (saved_mpdecision_slack_max != -1) { |
| 438 | snprintf(tmp_str, NODE_MAX, "%d", 10 * saved_mpdecision_slack_max); |
Anurag Singh | 6f64e9f | 2012-10-09 16:08:38 -0700 | [diff] [blame] | 439 | |
Zhao Wei Liew | 1e86352 | 2016-06-26 21:29:34 +0800 | [diff] [blame] | 440 | if (sysfs_write(MPDECISION_SLACK_MAX_NODE, tmp_str) != 0) { |
| 441 | if(!slack_node_rw_failed) { |
| 442 | ALOGE("Failed to write to %s", MPDECISION_SLACK_MAX_NODE); |
Anurag Singh | 6f64e9f | 2012-10-09 16:08:38 -0700 | [diff] [blame] | 443 | } |
Zhao Wei Liew | 1e86352 | 2016-06-26 21:29:34 +0800 | [diff] [blame] | 444 | |
| 445 | rc = 1; |
Anurag Singh | 6f64e9f | 2012-10-09 16:08:38 -0700 | [diff] [blame] | 446 | } |
Zhao Wei Liew | 1e86352 | 2016-06-26 21:29:34 +0800 | [diff] [blame] | 447 | } |
Anurag Singh | 6f64e9f | 2012-10-09 16:08:38 -0700 | [diff] [blame] | 448 | |
Zhao Wei Liew | 1e86352 | 2016-06-26 21:29:34 +0800 | [diff] [blame] | 449 | if (saved_mpdecision_slack_min != -1) { |
| 450 | snprintf(tmp_str, NODE_MAX, "%d", 10 * saved_mpdecision_slack_min); |
Anurag Singh | 6f64e9f | 2012-10-09 16:08:38 -0700 | [diff] [blame] | 451 | |
Zhao Wei Liew | 1e86352 | 2016-06-26 21:29:34 +0800 | [diff] [blame] | 452 | if (sysfs_write(MPDECISION_SLACK_MIN_NODE, tmp_str) != 0) { |
| 453 | if(!slack_node_rw_failed) { |
| 454 | ALOGE("Failed to write to %s", MPDECISION_SLACK_MIN_NODE); |
Anurag Singh | 6f64e9f | 2012-10-09 16:08:38 -0700 | [diff] [blame] | 455 | } |
| 456 | |
Zhao Wei Liew | 1e86352 | 2016-06-26 21:29:34 +0800 | [diff] [blame] | 457 | rc = 1; |
Anurag Singh | 6f64e9f | 2012-10-09 16:08:38 -0700 | [diff] [blame] | 458 | } |
| 459 | } |
Anurag Singh | 6ec1206 | 2012-10-02 09:59:01 -0700 | [diff] [blame] | 460 | |
| 461 | slack_node_rw_failed = rc; |
Anurag Singh | 6f64e9f | 2012-10-09 16:08:38 -0700 | [diff] [blame] | 462 | } |
Anurag Singh | 6ec1206 | 2012-10-02 09:59:01 -0700 | [diff] [blame] | 463 | } else { |
| 464 | /* Display on. */ |
Michael Bestas | e701b2d | 2018-03-25 23:14:21 +0300 | [diff] [blame^] | 465 | if (is_ondemand_governor(governor)) { |
Anurag Singh | 10918c1 | 2012-11-09 17:35:20 -0800 | [diff] [blame] | 466 | undo_hint_action(DISPLAY_STATE_HINT_ID); |
Ethan Chen | ed4628c | 2018-03-01 21:41:04 -0800 | [diff] [blame] | 467 | } else if (is_interactive_governor(governor)) { |
Anurag Singh | 6ec1206 | 2012-10-02 09:59:01 -0700 | [diff] [blame] | 468 | undo_hint_action(DISPLAY_STATE_HINT_ID); |
Michael Bestas | e701b2d | 2018-03-25 23:14:21 +0300 | [diff] [blame^] | 469 | } else if (is_msmdcvs_governor(governor)) { |
Zhao Wei Liew | 1e86352 | 2016-06-26 21:29:34 +0800 | [diff] [blame] | 470 | /* Display turned on. Restore if possible. */ |
| 471 | if (saved_dcvs_cpu0_slack_max != -1) { |
| 472 | snprintf(tmp_str, NODE_MAX, "%d", saved_dcvs_cpu0_slack_max); |
Anurag Singh | 6f64e9f | 2012-10-09 16:08:38 -0700 | [diff] [blame] | 473 | |
Zhao Wei Liew | 1e86352 | 2016-06-26 21:29:34 +0800 | [diff] [blame] | 474 | if (sysfs_write(DCVS_CPU0_SLACK_MAX_NODE, tmp_str) != 0) { |
| 475 | if (!slack_node_rw_failed) { |
| 476 | ALOGE("Failed to write to %s", DCVS_CPU0_SLACK_MAX_NODE); |
Anurag Singh | 6ec1206 | 2012-10-02 09:59:01 -0700 | [diff] [blame] | 477 | } |
Zhao Wei Liew | 1e86352 | 2016-06-26 21:29:34 +0800 | [diff] [blame] | 478 | |
| 479 | rc = 1; |
Anurag Singh | 6ec1206 | 2012-10-02 09:59:01 -0700 | [diff] [blame] | 480 | } |
Zhao Wei Liew | 1e86352 | 2016-06-26 21:29:34 +0800 | [diff] [blame] | 481 | } |
Anurag Singh | 6ec1206 | 2012-10-02 09:59:01 -0700 | [diff] [blame] | 482 | |
Zhao Wei Liew | 1e86352 | 2016-06-26 21:29:34 +0800 | [diff] [blame] | 483 | if (saved_dcvs_cpu0_slack_min != -1) { |
| 484 | snprintf(tmp_str, NODE_MAX, "%d", saved_dcvs_cpu0_slack_min); |
Anurag Singh | 6ec1206 | 2012-10-02 09:59:01 -0700 | [diff] [blame] | 485 | |
Zhao Wei Liew | 1e86352 | 2016-06-26 21:29:34 +0800 | [diff] [blame] | 486 | if (sysfs_write(DCVS_CPU0_SLACK_MIN_NODE, tmp_str) != 0) { |
| 487 | if (!slack_node_rw_failed) { |
| 488 | ALOGE("Failed to write to %s", DCVS_CPU0_SLACK_MIN_NODE); |
Anurag Singh | 6ec1206 | 2012-10-02 09:59:01 -0700 | [diff] [blame] | 489 | } |
Zhao Wei Liew | 1e86352 | 2016-06-26 21:29:34 +0800 | [diff] [blame] | 490 | |
| 491 | rc = 1; |
Anurag Singh | 6ec1206 | 2012-10-02 09:59:01 -0700 | [diff] [blame] | 492 | } |
Zhao Wei Liew | 1e86352 | 2016-06-26 21:29:34 +0800 | [diff] [blame] | 493 | } |
Anurag Singh | 6ec1206 | 2012-10-02 09:59:01 -0700 | [diff] [blame] | 494 | |
Zhao Wei Liew | 1e86352 | 2016-06-26 21:29:34 +0800 | [diff] [blame] | 495 | if (saved_mpdecision_slack_max != -1) { |
| 496 | snprintf(tmp_str, NODE_MAX, "%d", saved_mpdecision_slack_max); |
Anurag Singh | 6ec1206 | 2012-10-02 09:59:01 -0700 | [diff] [blame] | 497 | |
Zhao Wei Liew | 1e86352 | 2016-06-26 21:29:34 +0800 | [diff] [blame] | 498 | if (sysfs_write(MPDECISION_SLACK_MAX_NODE, tmp_str) != 0) { |
| 499 | if (!slack_node_rw_failed) { |
| 500 | ALOGE("Failed to write to %s", MPDECISION_SLACK_MAX_NODE); |
Anurag Singh | 6ec1206 | 2012-10-02 09:59:01 -0700 | [diff] [blame] | 501 | } |
Zhao Wei Liew | 1e86352 | 2016-06-26 21:29:34 +0800 | [diff] [blame] | 502 | |
| 503 | rc = 1; |
Anurag Singh | 6ec1206 | 2012-10-02 09:59:01 -0700 | [diff] [blame] | 504 | } |
Zhao Wei Liew | 1e86352 | 2016-06-26 21:29:34 +0800 | [diff] [blame] | 505 | } |
Anurag Singh | 6ec1206 | 2012-10-02 09:59:01 -0700 | [diff] [blame] | 506 | |
Zhao Wei Liew | 1e86352 | 2016-06-26 21:29:34 +0800 | [diff] [blame] | 507 | if (saved_mpdecision_slack_min != -1) { |
| 508 | snprintf(tmp_str, NODE_MAX, "%d", saved_mpdecision_slack_min); |
Anurag Singh | 6ec1206 | 2012-10-02 09:59:01 -0700 | [diff] [blame] | 509 | |
Zhao Wei Liew | 1e86352 | 2016-06-26 21:29:34 +0800 | [diff] [blame] | 510 | if (sysfs_write(MPDECISION_SLACK_MIN_NODE, tmp_str) != 0) { |
| 511 | if (!slack_node_rw_failed) { |
| 512 | ALOGE("Failed to write to %s", MPDECISION_SLACK_MIN_NODE); |
Anurag Singh | 6ec1206 | 2012-10-02 09:59:01 -0700 | [diff] [blame] | 513 | } |
Zhao Wei Liew | 1e86352 | 2016-06-26 21:29:34 +0800 | [diff] [blame] | 514 | |
| 515 | rc = 1; |
Anurag Singh | 6ec1206 | 2012-10-02 09:59:01 -0700 | [diff] [blame] | 516 | } |
| 517 | } |
| 518 | |
| 519 | slack_node_rw_failed = rc; |
| 520 | } |
Anurag Singh | 6f64e9f | 2012-10-09 16:08:38 -0700 | [diff] [blame] | 521 | } |
Anurag Singh | 9cec85b | 2012-09-04 21:46:24 -0700 | [diff] [blame] | 522 | } |
| 523 | |
Rashed Abdel-Tawab | 711a28d | 2017-11-03 12:44:16 -0700 | [diff] [blame] | 524 | void __attribute__((weak)) set_device_specific_feature(feature_t UNUSED(feature), int UNUSED(state)) |
Keith Mok | 964d255 | 2015-11-13 09:46:14 -0800 | [diff] [blame] | 525 | { |
| 526 | } |
| 527 | |
Rashed Abdel-Tawab | 711a28d | 2017-11-03 12:44:16 -0700 | [diff] [blame] | 528 | void set_feature(feature_t feature, int state) |
Steve Kondik | e4f15bd | 2015-10-19 14:43:39 -0700 | [diff] [blame] | 529 | { |
| 530 | switch (feature) { |
| 531 | #ifdef TAP_TO_WAKE_NODE |
| 532 | case POWER_FEATURE_DOUBLE_TAP_TO_WAKE: |
| 533 | sysfs_write(TAP_TO_WAKE_NODE, state ? "1" : "0"); |
| 534 | break; |
| 535 | #endif |
| 536 | default: |
| 537 | break; |
| 538 | } |
Rashed Abdel-Tawab | 711a28d | 2017-11-03 12:44:16 -0700 | [diff] [blame] | 539 | set_device_specific_feature(feature, state); |
Steve Kondik | e4f15bd | 2015-10-19 14:43:39 -0700 | [diff] [blame] | 540 | } |
| 541 | |
Rashed Abdel-Tawab | 711a28d | 2017-11-03 12:44:16 -0700 | [diff] [blame] | 542 | static int parse_stats(const char **params, size_t params_size, |
| 543 | uint64_t *list, FILE *fp) { |
| 544 | ssize_t nread; |
| 545 | size_t len = LINE_SIZE; |
| 546 | char *line; |
| 547 | size_t params_read = 0; |
| 548 | size_t i; |
| 549 | line = malloc(len); |
| 550 | if (!line) { |
| 551 | ALOGE("%s: no memory to hold line", __func__); |
| 552 | return -ENOMEM; |
| 553 | } |
| 554 | while ((params_read < params_size) && |
| 555 | (nread = getline(&line, &len, fp) > 0)) { |
| 556 | char *key = line + strspn(line, " \t"); |
| 557 | char *value = strchr(key, ':'); |
| 558 | if (!value || (value > (line + len))) |
| 559 | continue; |
| 560 | *value++ = '\0'; |
| 561 | for (i = 0; i < params_size; i++) { |
| 562 | if (!strcmp(key, params[i])) { |
| 563 | list[i] = strtoull(value, NULL, 0); |
| 564 | params_read++; |
| 565 | break; |
Ananth Raghavan Subramanian | 65a6a06 | 2017-03-21 16:26:20 -0700 | [diff] [blame] | 566 | } |
| 567 | } |
| 568 | } |
Rashed Abdel-Tawab | 711a28d | 2017-11-03 12:44:16 -0700 | [diff] [blame] | 569 | free(line); |
| 570 | return 0; |
Ananth Raghavan Subramanian | 65a6a06 | 2017-03-21 16:26:20 -0700 | [diff] [blame] | 571 | } |
| 572 | |
Rashed Abdel-Tawab | e52ce10 | 2017-12-30 00:41:49 +0200 | [diff] [blame] | 573 | #ifdef LEGACY_STATS |
| 574 | static int extract_stats(uint64_t *list, char *file, const char**param_names, |
| 575 | unsigned int num_parameters, int isHex) { |
| 576 | FILE *fp; |
| 577 | ssize_t read; |
| 578 | size_t len; |
| 579 | size_t index = 0; |
| 580 | char *line; |
| 581 | int ret; |
| 582 | |
| 583 | fp = fopen(file, "r"); |
| 584 | if (fp == NULL) { |
| 585 | ret = -errno; |
| 586 | ALOGE("%s: failed to open: %s Error = %s", __func__, file, strerror(errno)); |
| 587 | return ret; |
| 588 | } |
| 589 | |
| 590 | for (line = NULL, len = 0; |
| 591 | ((read = getline(&line, &len, fp) != -1) && (index < num_parameters)); |
| 592 | free(line), line = NULL, len = 0) { |
| 593 | uint64_t value; |
| 594 | char* offset; |
| 595 | |
| 596 | size_t begin = strspn(line, " \t"); |
| 597 | if (strncmp(line + begin, param_names[index], strlen(param_names[index]))) { |
| 598 | continue; |
| 599 | } |
| 600 | |
| 601 | offset = memchr(line, ':', len); |
| 602 | if (!offset) { |
| 603 | continue; |
| 604 | } |
| 605 | |
| 606 | if (isHex) { |
| 607 | sscanf(offset, ":%" SCNx64, &value); |
| 608 | } else { |
| 609 | sscanf(offset, ":%" SCNu64, &value); |
| 610 | } |
| 611 | list[index] = value; |
| 612 | index++; |
| 613 | } |
| 614 | |
| 615 | free(line); |
| 616 | fclose(fp); |
| 617 | |
| 618 | return 0; |
| 619 | } |
| 620 | |
| 621 | int extract_platform_stats(uint64_t *list) { |
| 622 | int ret; |
| 623 | //Data is located in two files |
| 624 | ret = extract_stats(list, RPM_STAT, rpm_param_names, RPM_PARAM_COUNT, false); |
| 625 | if (ret) { |
| 626 | for (size_t i=0; i < RPM_PARAM_COUNT; i++) |
| 627 | list[i] = 0; |
| 628 | } |
| 629 | ret = extract_stats(list + RPM_PARAM_COUNT, RPM_MASTER_STAT, |
| 630 | rpm_master_param_names, PLATFORM_PARAM_COUNT - RPM_PARAM_COUNT, true); |
| 631 | if (ret) { |
| 632 | for (size_t i=RPM_PARAM_COUNT; i < PLATFORM_PARAM_COUNT; i++) |
| 633 | list[i] = 0; |
| 634 | } |
| 635 | return 0; |
| 636 | } |
| 637 | |
| 638 | #ifndef V1_0_HAL |
| 639 | int extract_wlan_stats(uint64_t *list) { |
| 640 | int ret; |
Rashed Abdel-Tawab | 031a2bc | 2018-01-09 20:31:32 -0500 | [diff] [blame] | 641 | ret = extract_stats(list, WLAN_POWER_STAT, wlan_param_names, WLAN_POWER_PARAMS_COUNT, false); |
Rashed Abdel-Tawab | e52ce10 | 2017-12-30 00:41:49 +0200 | [diff] [blame] | 642 | if (ret) { |
Rashed Abdel-Tawab | 031a2bc | 2018-01-09 20:31:32 -0500 | [diff] [blame] | 643 | for (size_t i=0; i < WLAN_POWER_PARAMS_COUNT; i++) |
Rashed Abdel-Tawab | e52ce10 | 2017-12-30 00:41:49 +0200 | [diff] [blame] | 644 | list[i] = 0; |
| 645 | } |
| 646 | return 0; |
| 647 | } |
| 648 | #endif |
| 649 | #else |
| 650 | |
Rashed Abdel-Tawab | 711a28d | 2017-11-03 12:44:16 -0700 | [diff] [blame] | 651 | static int extract_stats(uint64_t *list, char *file, |
| 652 | struct stat_pair *map, size_t map_size) { |
| 653 | FILE *fp; |
| 654 | ssize_t read; |
| 655 | size_t len = LINE_SIZE; |
| 656 | char *line; |
| 657 | size_t i, stats_read = 0; |
| 658 | int ret = 0; |
Rashed Abdel-Tawab | e52ce10 | 2017-12-30 00:41:49 +0200 | [diff] [blame] | 659 | |
Rashed Abdel-Tawab | 711a28d | 2017-11-03 12:44:16 -0700 | [diff] [blame] | 660 | fp = fopen(file, "re"); |
| 661 | if (fp == NULL) { |
| 662 | ALOGE("%s: failed to open: %s Error = %s", __func__, file, strerror(errno)); |
| 663 | return -errno; |
| 664 | } |
Rashed Abdel-Tawab | e52ce10 | 2017-12-30 00:41:49 +0200 | [diff] [blame] | 665 | |
Rashed Abdel-Tawab | 711a28d | 2017-11-03 12:44:16 -0700 | [diff] [blame] | 666 | line = malloc(len); |
| 667 | if (!line) { |
| 668 | ALOGE("%s: no memory to hold line", __func__); |
| 669 | fclose(fp); |
| 670 | return -ENOMEM; |
| 671 | } |
Rashed Abdel-Tawab | e52ce10 | 2017-12-30 00:41:49 +0200 | [diff] [blame] | 672 | |
Rashed Abdel-Tawab | 711a28d | 2017-11-03 12:44:16 -0700 | [diff] [blame] | 673 | while ((stats_read < map_size) && (read = getline(&line, &len, fp) != -1)) { |
| 674 | size_t begin = strspn(line, " \t"); |
Rashed Abdel-Tawab | e52ce10 | 2017-12-30 00:41:49 +0200 | [diff] [blame] | 675 | |
Rashed Abdel-Tawab | 711a28d | 2017-11-03 12:44:16 -0700 | [diff] [blame] | 676 | for (i = 0; i < map_size; i++) { |
| 677 | if (!strncmp(line + begin, map[i].label, strlen(map[i].label))) { |
| 678 | stats_read++; |
| 679 | break; |
| 680 | } |
| 681 | } |
Rashed Abdel-Tawab | e52ce10 | 2017-12-30 00:41:49 +0200 | [diff] [blame] | 682 | |
Rashed Abdel-Tawab | 711a28d | 2017-11-03 12:44:16 -0700 | [diff] [blame] | 683 | if (i == map_size) |
| 684 | continue; |
Rashed Abdel-Tawab | e52ce10 | 2017-12-30 00:41:49 +0200 | [diff] [blame] | 685 | |
Rashed Abdel-Tawab | 711a28d | 2017-11-03 12:44:16 -0700 | [diff] [blame] | 686 | ret = parse_stats(map[i].parameters, map[i].num_parameters, |
| 687 | &list[map[i].stat * MAX_RPM_PARAMS], fp); |
| 688 | if (ret < 0) |
| 689 | break; |
| 690 | } |
| 691 | free(line); |
| 692 | fclose(fp); |
Rashed Abdel-Tawab | e52ce10 | 2017-12-30 00:41:49 +0200 | [diff] [blame] | 693 | |
Rashed Abdel-Tawab | 711a28d | 2017-11-03 12:44:16 -0700 | [diff] [blame] | 694 | return ret; |
| 695 | } |
Anurag Singh | 9cec85b | 2012-09-04 21:46:24 -0700 | [diff] [blame] | 696 | |
Rashed Abdel-Tawab | e52ce10 | 2017-12-30 00:41:49 +0200 | [diff] [blame] | 697 | int extract_platform_stats(uint64_t *list) { |
| 698 | return extract_stats(list, RPM_SYSTEM_STAT, rpm_stat_map, ARRAY_SIZE(rpm_stat_map)); |
| 699 | } |
| 700 | |
| 701 | #ifndef V1_0_HAL |
Rashed Abdel-Tawab | 711a28d | 2017-11-03 12:44:16 -0700 | [diff] [blame] | 702 | int extract_wlan_stats(uint64_t *list) { |
| 703 | return extract_stats(list, WLAN_POWER_STAT, wlan_stat_map, ARRAY_SIZE(wlan_stat_map)); |
| 704 | } |
Rashed Abdel-Tawab | e52ce10 | 2017-12-30 00:41:49 +0200 | [diff] [blame] | 705 | #endif |
| 706 | #endif |