Sravan Kumar Ambapuram | eea8e56 | 2016-02-28 15:09:37 +0530 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2016, The Linux Foundation. All rights reserved. |
Michael Bestas | 47636f6 | 2018-05-25 21:30:28 +0300 | [diff] [blame] | 3 | * Copyright (C) 2018 The LineageOS Project |
Sravan Kumar Ambapuram | eea8e56 | 2016-02-28 15:09:37 +0530 | [diff] [blame] | 4 | * |
| 5 | * Redistribution and use in source and binary forms, with or without |
| 6 | * modification, are permitted provided that the following conditions are |
| 7 | * met: |
| 8 | * * * Redistributions of source code must retain the above copyright |
| 9 | * notice, this list of conditions and the following disclaimer. |
| 10 | * * Redistributions in binary form must reproduce the above |
| 11 | * copyright notice, this list of conditions and the following |
| 12 | * disclaimer in the documentation and/or other materials provided |
| 13 | * with the distribution. |
| 14 | * * Neither the name of The Linux Foundation nor the names of its |
| 15 | * contributors may be used to endorse or promote products derived |
| 16 | * from this software without specific prior written permission. |
| 17 | * |
| 18 | * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED |
| 19 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF |
| 20 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT |
| 21 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS |
| 22 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
| 23 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
| 24 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR |
| 25 | * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, |
| 26 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE |
| 27 | * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN |
| 28 | * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 29 | */ |
| 30 | |
| 31 | #define LOG_NIDEBUG 0 |
| 32 | |
| 33 | #include <errno.h> |
BeYkeRYkt | bd52e81 | 2018-12-13 06:42:35 +0900 | [diff] [blame] | 34 | #include <time.h> |
Sravan Kumar Ambapuram | eea8e56 | 2016-02-28 15:09:37 +0530 | [diff] [blame] | 35 | #include <string.h> |
| 36 | #include <sys/types.h> |
| 37 | #include <sys/stat.h> |
| 38 | #include <fcntl.h> |
| 39 | #include <dlfcn.h> |
| 40 | #include <stdlib.h> |
| 41 | |
Michael Bestas | 1add9ac | 2018-03-25 22:56:44 +0300 | [diff] [blame] | 42 | #define LOG_TAG "QCOM PowerHAL" |
Ethan Chen | a42f4a8 | 2018-03-01 21:31:15 -0800 | [diff] [blame] | 43 | #include <log/log.h> |
Sravan Kumar Ambapuram | eea8e56 | 2016-02-28 15:09:37 +0530 | [diff] [blame] | 44 | #include <hardware/hardware.h> |
| 45 | #include <hardware/power.h> |
| 46 | |
| 47 | #include "utils.h" |
| 48 | #include "metadata-defs.h" |
| 49 | #include "hint-data.h" |
| 50 | #include "performance.h" |
| 51 | #include "power-common.h" |
| 52 | |
dianlujitao | 5288c4a | 2018-01-20 19:00:05 +0800 | [diff] [blame] | 53 | #define NUM_PERF_MODES 3 |
| 54 | |
tomascus | 8b038b1 | 2019-02-19 17:15:58 +1100 | [diff] [blame] | 55 | const int kMaxLaunchDuration = 5000; /* ms */ |
BeYkeRYkt | bd52e81 | 2018-12-13 06:42:35 +0900 | [diff] [blame] | 56 | const int kMaxInteractiveDuration = 5000; /* ms */ |
| 57 | const int kMinInteractiveDuration = 500; /* ms */ |
BeYkeRYkt | bd52e81 | 2018-12-13 06:42:35 +0900 | [diff] [blame] | 58 | |
Michael Bestas | f6ea7ab | 2018-05-25 22:57:04 +0300 | [diff] [blame] | 59 | static int current_power_profile = PROFILE_BALANCED; |
| 60 | |
| 61 | static int profile_high_performance[] = { |
| 62 | SCHED_BOOST_ON_V3, 0x1, |
| 63 | ALL_CPUS_PWR_CLPS_DIS_V3, 0x1, |
| 64 | CPUS_ONLINE_MIN_BIG, 0x4, |
| 65 | MIN_FREQ_BIG_CORE_0, 0xFFF, |
| 66 | MIN_FREQ_LITTLE_CORE_0, 0xFFF, |
dianlujitao | 5eb472d | 2018-09-06 21:43:14 +0800 | [diff] [blame] | 67 | GPU_MIN_POWER_LEVEL, 0x1, |
Michael Bestas | f6ea7ab | 2018-05-25 22:57:04 +0300 | [diff] [blame] | 68 | SCHED_PREFER_IDLE_DIS_V3, 0x1, |
dianlujitao | 5eb472d | 2018-09-06 21:43:14 +0800 | [diff] [blame] | 69 | SCHED_SMALL_TASK, 0x1, |
| 70 | SCHED_MOSTLY_IDLE_NR_RUN, 0x1, |
| 71 | SCHED_MOSTLY_IDLE_LOAD, 0x1, |
Michael Bestas | f6ea7ab | 2018-05-25 22:57:04 +0300 | [diff] [blame] | 72 | }; |
| 73 | |
| 74 | static int profile_power_save[] = { |
dianlujitao | 5eb472d | 2018-09-06 21:43:14 +0800 | [diff] [blame] | 75 | CPUS_ONLINE_MAX_BIG, 0x1, |
Michael Bestas | f6ea7ab | 2018-05-25 22:57:04 +0300 | [diff] [blame] | 76 | MAX_FREQ_BIG_CORE_0, 0x3bf, |
| 77 | MAX_FREQ_LITTLE_CORE_0, 0x300, |
| 78 | }; |
| 79 | |
| 80 | static int profile_bias_power[] = { |
| 81 | MAX_FREQ_BIG_CORE_0, 0x4B0, |
| 82 | MAX_FREQ_LITTLE_CORE_0, 0x300, |
| 83 | }; |
| 84 | |
| 85 | static int profile_bias_performance[] = { |
dianlujitao | 5eb472d | 2018-09-06 21:43:14 +0800 | [diff] [blame] | 86 | CPUS_ONLINE_MAX_BIG, 0x4, |
Michael Bestas | f6ea7ab | 2018-05-25 22:57:04 +0300 | [diff] [blame] | 87 | MIN_FREQ_BIG_CORE_0, 0x540, |
| 88 | }; |
| 89 | |
| 90 | #ifdef INTERACTION_BOOST |
| 91 | int get_number_of_profiles() |
| 92 | { |
| 93 | return 5; |
| 94 | } |
| 95 | #endif |
| 96 | |
dianlujitao | 8780cb7 | 2019-02-23 20:24:57 +0800 | [diff] [blame] | 97 | static int set_power_profile(void *data) |
Michael Bestas | f6ea7ab | 2018-05-25 22:57:04 +0300 | [diff] [blame] | 98 | { |
dianlujitao | 8780cb7 | 2019-02-23 20:24:57 +0800 | [diff] [blame] | 99 | int profile = data ? *((int*)data) : 0; |
Corinna Vinschen | 8599e3c | 2018-08-26 22:11:49 +0200 | [diff] [blame] | 100 | int ret = -EINVAL; |
| 101 | const char *profile_name = NULL; |
| 102 | |
Michael Bestas | f6ea7ab | 2018-05-25 22:57:04 +0300 | [diff] [blame] | 103 | if (profile == current_power_profile) |
Corinna Vinschen | 8599e3c | 2018-08-26 22:11:49 +0200 | [diff] [blame] | 104 | return 0; |
Michael Bestas | f6ea7ab | 2018-05-25 22:57:04 +0300 | [diff] [blame] | 105 | |
| 106 | ALOGV("%s: Profile=%d", __func__, profile); |
| 107 | |
| 108 | if (current_power_profile != PROFILE_BALANCED) { |
| 109 | undo_hint_action(DEFAULT_PROFILE_HINT_ID); |
| 110 | ALOGV("%s: Hint undone", __func__); |
Corinna Vinschen | 8599e3c | 2018-08-26 22:11:49 +0200 | [diff] [blame] | 111 | current_power_profile = PROFILE_BALANCED; |
Michael Bestas | f6ea7ab | 2018-05-25 22:57:04 +0300 | [diff] [blame] | 112 | } |
| 113 | |
| 114 | if (profile == PROFILE_POWER_SAVE) { |
Corinna Vinschen | 8599e3c | 2018-08-26 22:11:49 +0200 | [diff] [blame] | 115 | ret = perform_hint_action(DEFAULT_PROFILE_HINT_ID, profile_power_save, |
Michael Bestas | f6ea7ab | 2018-05-25 22:57:04 +0300 | [diff] [blame] | 116 | ARRAY_SIZE(profile_power_save)); |
Corinna Vinschen | 8599e3c | 2018-08-26 22:11:49 +0200 | [diff] [blame] | 117 | profile_name = "powersave"; |
Michael Bestas | f6ea7ab | 2018-05-25 22:57:04 +0300 | [diff] [blame] | 118 | |
| 119 | } else if (profile == PROFILE_HIGH_PERFORMANCE) { |
Corinna Vinschen | 8599e3c | 2018-08-26 22:11:49 +0200 | [diff] [blame] | 120 | ret = perform_hint_action(DEFAULT_PROFILE_HINT_ID, |
| 121 | profile_high_performance, ARRAY_SIZE(profile_high_performance)); |
| 122 | profile_name = "performance"; |
Michael Bestas | f6ea7ab | 2018-05-25 22:57:04 +0300 | [diff] [blame] | 123 | |
| 124 | } else if (profile == PROFILE_BIAS_POWER) { |
Corinna Vinschen | 8599e3c | 2018-08-26 22:11:49 +0200 | [diff] [blame] | 125 | ret = perform_hint_action(DEFAULT_PROFILE_HINT_ID, profile_bias_power, |
Michael Bestas | f6ea7ab | 2018-05-25 22:57:04 +0300 | [diff] [blame] | 126 | ARRAY_SIZE(profile_bias_power)); |
Corinna Vinschen | 8599e3c | 2018-08-26 22:11:49 +0200 | [diff] [blame] | 127 | profile_name = "bias power"; |
Michael Bestas | f6ea7ab | 2018-05-25 22:57:04 +0300 | [diff] [blame] | 128 | |
| 129 | } else if (profile == PROFILE_BIAS_PERFORMANCE) { |
Corinna Vinschen | 8599e3c | 2018-08-26 22:11:49 +0200 | [diff] [blame] | 130 | ret = perform_hint_action(DEFAULT_PROFILE_HINT_ID, |
| 131 | profile_bias_performance, ARRAY_SIZE(profile_bias_performance)); |
| 132 | profile_name = "bias perf"; |
| 133 | } else if (profile == PROFILE_BALANCED) { |
| 134 | ret = 0; |
| 135 | profile_name = "balanced"; |
Michael Bestas | f6ea7ab | 2018-05-25 22:57:04 +0300 | [diff] [blame] | 136 | } |
| 137 | |
Corinna Vinschen | 8599e3c | 2018-08-26 22:11:49 +0200 | [diff] [blame] | 138 | if (ret == 0) { |
| 139 | current_power_profile = profile; |
| 140 | ALOGD("%s: Set %s mode", __func__, profile_name); |
| 141 | } |
| 142 | return ret; |
Michael Bestas | f6ea7ab | 2018-05-25 22:57:04 +0300 | [diff] [blame] | 143 | } |
| 144 | |
dianlujitao | 5288c4a | 2018-01-20 19:00:05 +0800 | [diff] [blame] | 145 | typedef enum { |
| 146 | NORMAL_MODE = 0, |
| 147 | SUSTAINED_MODE = 1, |
| 148 | VR_MODE = 2, |
| 149 | VR_SUSTAINED_MODE = (SUSTAINED_MODE|VR_MODE), |
| 150 | INVALID_MODE = 0xFF |
| 151 | } perf_mode_type_t; |
| 152 | |
| 153 | typedef struct perf_mode { |
| 154 | perf_mode_type_t type; |
| 155 | int perf_hint_id; |
| 156 | } perf_mode_t; |
| 157 | |
| 158 | perf_mode_t perf_modes[NUM_PERF_MODES] = { |
| 159 | { SUSTAINED_MODE, SUSTAINED_PERF_HINT }, |
| 160 | { VR_MODE, VR_MODE_HINT }, |
| 161 | { VR_SUSTAINED_MODE, VR_MODE_SUSTAINED_PERF_HINT } |
| 162 | }; |
| 163 | |
| 164 | static int current_mode = NORMAL_MODE; |
| 165 | |
| 166 | static inline int get_perfd_hint_id(perf_mode_type_t type) { |
| 167 | int i; |
| 168 | for (i = 0; i < NUM_PERF_MODES; i++) { |
| 169 | if (perf_modes[i].type == type) { |
| 170 | ALOGD("Hint id is 0x%x for mode 0x%x", perf_modes[i].perf_hint_id, type); |
| 171 | return perf_modes[i].perf_hint_id; |
| 172 | } |
| 173 | } |
| 174 | ALOGD("Couldn't find the hint for mode 0x%x", type); |
| 175 | return 0; |
| 176 | } |
| 177 | |
| 178 | static int switch_mode(perf_mode_type_t mode) { |
| 179 | int hint_id = 0; |
| 180 | static int perfd_mode_handle = -1; |
| 181 | |
| 182 | // release existing mode if any |
| 183 | if (CHECK_HANDLE(perfd_mode_handle)) { |
| 184 | ALOGD("Releasing handle 0x%x", perfd_mode_handle); |
| 185 | release_request(perfd_mode_handle); |
| 186 | perfd_mode_handle = -1; |
| 187 | } |
| 188 | // switch to a perf mode |
| 189 | hint_id = get_perfd_hint_id(mode); |
| 190 | if (hint_id != 0) { |
| 191 | perfd_mode_handle = perf_hint_enable(hint_id, 0); |
| 192 | if (!CHECK_HANDLE(perfd_mode_handle)) { |
| 193 | ALOGE("Failed perf_hint_interaction for mode: 0x%x", mode); |
| 194 | return -1; |
| 195 | } |
| 196 | ALOGD("Acquired handle 0x%x", perfd_mode_handle); |
| 197 | } |
| 198 | return 0; |
| 199 | } |
| 200 | |
| 201 | static int process_perf_hint(void *data, perf_mode_type_t mode) { |
| 202 | // enable |
dianlujitao | 8780cb7 | 2019-02-23 20:24:57 +0800 | [diff] [blame] | 203 | if (data) { |
dianlujitao | 5288c4a | 2018-01-20 19:00:05 +0800 | [diff] [blame] | 204 | ALOGI("Enable request for mode: 0x%x", mode); |
| 205 | // check if mode is current mode |
| 206 | if (current_mode & mode) { |
| 207 | ALOGD("Mode 0x%x already enabled", mode); |
| 208 | return HINT_HANDLED; |
| 209 | } |
| 210 | // enable requested mode |
| 211 | if (0 != switch_mode(current_mode | mode)) { |
| 212 | ALOGE("Couldn't enable mode 0x%x", mode); |
| 213 | return HINT_NONE; |
| 214 | } |
| 215 | current_mode |= mode; |
| 216 | ALOGI("Current mode is 0x%x", current_mode); |
| 217 | // disable |
| 218 | } else { |
| 219 | ALOGI("Disable request for mode: 0x%x", mode); |
| 220 | // check if mode is enabled |
| 221 | if (!(current_mode & mode)) { |
| 222 | ALOGD("Mode 0x%x already disabled", mode); |
| 223 | return HINT_HANDLED; |
| 224 | } |
| 225 | // disable requested mode |
| 226 | if (0 != switch_mode(current_mode & ~mode)) { |
| 227 | ALOGE("Couldn't disable mode 0x%x", mode); |
| 228 | return HINT_NONE; |
| 229 | } |
| 230 | current_mode &= ~mode; |
| 231 | ALOGI("Current mode is 0x%x", current_mode); |
| 232 | } |
| 233 | |
| 234 | return HINT_HANDLED; |
| 235 | } |
| 236 | |
dianlujitao | 2f57031 | 2018-01-20 18:54:04 +0800 | [diff] [blame] | 237 | static int process_video_encode_hint(void *metadata) |
Sravan Kumar Ambapuram | eea8e56 | 2016-02-28 15:09:37 +0530 | [diff] [blame] | 238 | { |
| 239 | char governor[80]; |
| 240 | struct video_encode_metadata_t video_encode_metadata; |
dianlujitao | 2f57031 | 2018-01-20 18:54:04 +0800 | [diff] [blame] | 241 | static int video_encode_handle = 0; |
| 242 | |
| 243 | if (!metadata) { |
| 244 | return HINT_NONE; |
| 245 | } |
Sravan Kumar Ambapuram | eea8e56 | 2016-02-28 15:09:37 +0530 | [diff] [blame] | 246 | |
Michael Bestas | 47636f6 | 2018-05-25 21:30:28 +0300 | [diff] [blame] | 247 | if (get_scaling_governor_check_cores(governor, sizeof(governor), CPU0) == -1) { |
| 248 | if (get_scaling_governor_check_cores(governor, sizeof(governor), CPU1) == -1) { |
| 249 | if (get_scaling_governor_check_cores(governor, sizeof(governor), CPU2) == -1) { |
| 250 | if (get_scaling_governor_check_cores(governor, sizeof(governor), CPU3) == -1) { |
| 251 | ALOGE("Can't obtain scaling governor."); |
dianlujitao | 2f57031 | 2018-01-20 18:54:04 +0800 | [diff] [blame] | 252 | return HINT_NONE; |
Michael Bestas | 47636f6 | 2018-05-25 21:30:28 +0300 | [diff] [blame] | 253 | } |
Sravan Kumar Ambapuram | eea8e56 | 2016-02-28 15:09:37 +0530 | [diff] [blame] | 254 | } |
Michael Bestas | 47636f6 | 2018-05-25 21:30:28 +0300 | [diff] [blame] | 255 | } |
| 256 | } |
| 257 | |
dianlujitao | 2f57031 | 2018-01-20 18:54:04 +0800 | [diff] [blame] | 258 | /* Initialize encode metadata struct fields */ |
Sravan Kumar Ambapuram | eea8e56 | 2016-02-28 15:09:37 +0530 | [diff] [blame] | 259 | memset(&video_encode_metadata, 0, sizeof(struct video_encode_metadata_t)); |
| 260 | video_encode_metadata.state = -1; |
Sravan Kumar Ambapuram | eea8e56 | 2016-02-28 15:09:37 +0530 | [diff] [blame] | 261 | |
dianlujitao | 2f57031 | 2018-01-20 18:54:04 +0800 | [diff] [blame] | 262 | if (parse_video_encode_metadata((char *)metadata, &video_encode_metadata) == -1) { |
Michael Bestas | 47636f6 | 2018-05-25 21:30:28 +0300 | [diff] [blame] | 263 | ALOGE("Error occurred while parsing metadata."); |
dianlujitao | 2f57031 | 2018-01-20 18:54:04 +0800 | [diff] [blame] | 264 | return HINT_NONE; |
Sravan Kumar Ambapuram | eea8e56 | 2016-02-28 15:09:37 +0530 | [diff] [blame] | 265 | } |
| 266 | |
| 267 | if (video_encode_metadata.state == 1) { |
Ethan Chen | 4b4acdf | 2018-03-01 21:41:04 -0800 | [diff] [blame] | 268 | if (is_interactive_governor(governor)) { |
dianlujitao | 2f57031 | 2018-01-20 18:54:04 +0800 | [diff] [blame] | 269 | video_encode_handle = perf_hint_enable( |
| 270 | VIDEO_ENCODE_HINT, 0); |
| 271 | return HINT_HANDLED; |
Sravan Kumar Ambapuram | eea8e56 | 2016-02-28 15:09:37 +0530 | [diff] [blame] | 272 | } |
| 273 | } else if (video_encode_metadata.state == 0) { |
Ethan Chen | 4b4acdf | 2018-03-01 21:41:04 -0800 | [diff] [blame] | 274 | if (is_interactive_governor(governor)) { |
dianlujitao | 2f57031 | 2018-01-20 18:54:04 +0800 | [diff] [blame] | 275 | release_request(video_encode_handle); |
| 276 | return HINT_HANDLED; |
Sravan Kumar Ambapuram | eea8e56 | 2016-02-28 15:09:37 +0530 | [diff] [blame] | 277 | } |
| 278 | } |
dianlujitao | 2f57031 | 2018-01-20 18:54:04 +0800 | [diff] [blame] | 279 | return HINT_NONE; |
Michael Bestas | 47636f6 | 2018-05-25 21:30:28 +0300 | [diff] [blame] | 280 | } |
| 281 | |
tomascus | 8b038b1 | 2019-02-19 17:15:58 +1100 | [diff] [blame] | 282 | static int process_activity_launch_hint(void *data) |
BeYkeRYkt | bd52e81 | 2018-12-13 06:42:35 +0900 | [diff] [blame] | 283 | { |
tomascus | 8b038b1 | 2019-02-19 17:15:58 +1100 | [diff] [blame] | 284 | static int launch_handle = -1; |
| 285 | static int launch_mode = 0; |
| 286 | |
| 287 | // release lock early if launch has finished |
| 288 | if (!data) { |
| 289 | if (CHECK_HANDLE(launch_handle)) { |
| 290 | release_request(launch_handle); |
| 291 | launch_handle = -1; |
| 292 | } |
| 293 | launch_mode = 0; |
| 294 | return HINT_HANDLED; |
| 295 | } |
| 296 | |
BeYkeRYkt | bd52e81 | 2018-12-13 06:42:35 +0900 | [diff] [blame] | 297 | if (current_mode != NORMAL_MODE) { |
| 298 | ALOGV("%s: ignoring due to other active perf hints", __func__); |
tomascus | 8b038b1 | 2019-02-19 17:15:58 +1100 | [diff] [blame] | 299 | } else if (!launch_mode) { |
| 300 | launch_handle = perf_hint_enable_with_type(VENDOR_HINT_FIRST_LAUNCH_BOOST, |
| 301 | kMaxLaunchDuration, LAUNCH_BOOST_V1); |
| 302 | if (!CHECK_HANDLE(launch_handle)) { |
| 303 | ALOGE("Failed to perform launch boost"); |
| 304 | return HINT_NONE; |
| 305 | } |
| 306 | launch_mode = 1; |
BeYkeRYkt | bd52e81 | 2018-12-13 06:42:35 +0900 | [diff] [blame] | 307 | } |
| 308 | return HINT_HANDLED; |
| 309 | } |
| 310 | |
| 311 | static int process_interaction_hint(void *data) |
| 312 | { |
| 313 | static struct timespec s_previous_boost_timespec; |
| 314 | static int s_previous_duration = 0; |
| 315 | |
| 316 | struct timespec cur_boost_timespec; |
| 317 | long long elapsed_time; |
| 318 | int duration = kMinInteractiveDuration; |
| 319 | |
| 320 | if (current_mode != NORMAL_MODE) { |
| 321 | ALOGV("%s: ignoring due to other active perf hints", __func__); |
| 322 | return HINT_HANDLED; |
| 323 | } |
| 324 | |
| 325 | if (data) { |
| 326 | int input_duration = *((int*)data); |
| 327 | if (input_duration > duration) { |
| 328 | duration = (input_duration > kMaxInteractiveDuration) ? |
| 329 | kMaxInteractiveDuration : input_duration; |
| 330 | } |
| 331 | } |
| 332 | |
| 333 | clock_gettime(CLOCK_MONOTONIC, &cur_boost_timespec); |
| 334 | |
| 335 | elapsed_time = calc_timespan_us(s_previous_boost_timespec, cur_boost_timespec); |
| 336 | // don't hint if previous hint's duration covers this hint's duration |
| 337 | if ((s_previous_duration * 1000) > (elapsed_time + duration * 1000)) { |
| 338 | return HINT_HANDLED; |
| 339 | } |
| 340 | s_previous_boost_timespec = cur_boost_timespec; |
| 341 | s_previous_duration = duration; |
| 342 | |
tomascus | 1c38bac | 2019-02-13 14:42:27 +1100 | [diff] [blame] | 343 | perf_hint_enable_with_type(VENDOR_HINT_SCROLL_BOOST, duration, SCROLL_VERTICAL); |
BeYkeRYkt | bd52e81 | 2018-12-13 06:42:35 +0900 | [diff] [blame] | 344 | |
| 345 | return HINT_HANDLED; |
| 346 | } |
| 347 | |
Michael Bestas | 47636f6 | 2018-05-25 21:30:28 +0300 | [diff] [blame] | 348 | int power_hint_override(power_hint_t hint, void *data) |
| 349 | { |
dianlujitao | 2f57031 | 2018-01-20 18:54:04 +0800 | [diff] [blame] | 350 | int ret_val = HINT_NONE; |
| 351 | |
Michael Bestas | f6ea7ab | 2018-05-25 22:57:04 +0300 | [diff] [blame] | 352 | if (hint == POWER_HINT_SET_PROFILE) { |
dianlujitao | 8780cb7 | 2019-02-23 20:24:57 +0800 | [diff] [blame] | 353 | if (set_power_profile(data) < 0) |
Corinna Vinschen | 8599e3c | 2018-08-26 22:11:49 +0200 | [diff] [blame] | 354 | ALOGE("Setting power profile failed. perf HAL not started?"); |
Michael Bestas | f6ea7ab | 2018-05-25 22:57:04 +0300 | [diff] [blame] | 355 | return HINT_HANDLED; |
| 356 | } |
| 357 | |
| 358 | // Skip other hints in high/low power modes |
| 359 | if (current_power_profile == PROFILE_POWER_SAVE || |
| 360 | current_power_profile == PROFILE_HIGH_PERFORMANCE) { |
| 361 | return HINT_HANDLED; |
| 362 | } |
| 363 | |
Michael Bestas | 47636f6 | 2018-05-25 21:30:28 +0300 | [diff] [blame] | 364 | switch (hint) { |
| 365 | case POWER_HINT_VSYNC: |
| 366 | break; |
| 367 | case POWER_HINT_VIDEO_ENCODE: |
dianlujitao | 2f57031 | 2018-01-20 18:54:04 +0800 | [diff] [blame] | 368 | ret_val = process_video_encode_hint(data); |
| 369 | break; |
dianlujitao | 5288c4a | 2018-01-20 19:00:05 +0800 | [diff] [blame] | 370 | case POWER_HINT_SUSTAINED_PERFORMANCE: |
| 371 | ret_val = process_perf_hint(data, SUSTAINED_MODE); |
| 372 | break; |
| 373 | case POWER_HINT_VR_MODE: |
| 374 | ret_val = process_perf_hint(data, VR_MODE); |
| 375 | break; |
BeYkeRYkt | bd52e81 | 2018-12-13 06:42:35 +0900 | [diff] [blame] | 376 | case POWER_HINT_INTERACTION: |
| 377 | ret_val = process_interaction_hint(data); |
| 378 | break; |
| 379 | case POWER_HINT_LAUNCH: |
| 380 | ret_val = process_activity_launch_hint(data); |
| 381 | break; |
Michael Bestas | 47636f6 | 2018-05-25 21:30:28 +0300 | [diff] [blame] | 382 | default: |
| 383 | break; |
| 384 | } |
dianlujitao | 2f57031 | 2018-01-20 18:54:04 +0800 | [diff] [blame] | 385 | return ret_val; |
Michael Bestas | 47636f6 | 2018-05-25 21:30:28 +0300 | [diff] [blame] | 386 | } |
| 387 | |
| 388 | int set_interactive_override(int on) |
| 389 | { |
| 390 | char governor[80]; |
| 391 | |
| 392 | if (get_scaling_governor_check_cores(governor, sizeof(governor), CPU0) == -1) { |
| 393 | if (get_scaling_governor_check_cores(governor, sizeof(governor), CPU1) == -1) { |
| 394 | if (get_scaling_governor_check_cores(governor, sizeof(governor), CPU2) == -1) { |
| 395 | if (get_scaling_governor_check_cores(governor, sizeof(governor), CPU3) == -1) { |
| 396 | ALOGE("Can't obtain scaling governor."); |
| 397 | return HINT_NONE; |
| 398 | } |
| 399 | } |
| 400 | } |
| 401 | } |
| 402 | |
| 403 | if (!on) { |
| 404 | /* Display off. */ |
| 405 | if (is_interactive_governor(governor)) { |
| 406 | int resource_values[] = { |
| 407 | INT_OP_CLUSTER0_TIMER_RATE, BIG_LITTLE_TR_MS_40 |
| 408 | }; |
| 409 | perform_hint_action(DISPLAY_STATE_HINT_ID, |
| 410 | resource_values, ARRAY_SIZE(resource_values)); |
| 411 | } |
| 412 | } else { |
| 413 | /* Display on. */ |
| 414 | if (is_interactive_governor(governor)) { |
| 415 | undo_hint_action(DISPLAY_STATE_HINT_ID); |
| 416 | } |
| 417 | } |
| 418 | return HINT_HANDLED; |
Sravan Kumar Ambapuram | eea8e56 | 2016-02-28 15:09:37 +0530 | [diff] [blame] | 419 | } |