Anurag Singh | 6ec1206 | 2012-10-02 09:59:01 -0700 | [diff] [blame] | 1 | /* |
Ananth Raghavan Subramanian | e432dbf | 2017-03-24 16:30:12 -0700 | [diff] [blame] | 2 | * Copyright (c) 2012-2013,2015-2017, The Linux Foundation. All rights reserved. |
Anurag Singh | 6ec1206 | 2012-10-02 09:59:01 -0700 | [diff] [blame] | 3 | * |
| 4 | * Redistribution and use in source and binary forms, with or without |
| 5 | * modification, are permitted provided that the following conditions are |
| 6 | * met: |
| 7 | * * * Redistributions of source code must retain the above copyright |
| 8 | * notice, this list of conditions and the following disclaimer. |
| 9 | * * Redistributions in binary form must reproduce the above |
| 10 | * copyright notice, this list of conditions and the following |
| 11 | * disclaimer in the documentation and/or other materials provided |
| 12 | * with the distribution. |
Duy Truong | 7022245 | 2013-02-10 06:35:11 -0800 | [diff] [blame] | 13 | * * Neither the name of The Linux Foundation nor the names of its |
Anurag Singh | 6ec1206 | 2012-10-02 09:59:01 -0700 | [diff] [blame] | 14 | * contributors may be used to endorse or promote products derived |
| 15 | * from this software without specific prior written permission. |
| 16 | * |
| 17 | * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED |
| 18 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF |
| 19 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT |
| 20 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS |
| 21 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
| 22 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
| 23 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR |
| 24 | * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, |
| 25 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE |
| 26 | * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN |
| 27 | * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 28 | */ |
Anurag Singh | 6ec1206 | 2012-10-02 09:59:01 -0700 | [diff] [blame] | 29 | #define LOG_NIDEBUG 0 |
| 30 | |
| 31 | #include <dlfcn.h> |
| 32 | #include <fcntl.h> |
| 33 | #include <errno.h> |
Ajay Dudani | 5e67680 | 2015-04-07 23:56:52 -0700 | [diff] [blame] | 34 | #include <stdlib.h> |
| 35 | #include <string.h> |
Rashed Abdel-Tawab | 9c14c9f | 2017-12-26 23:11:03 +0200 | [diff] [blame] | 36 | #include <unistd.h> |
Anurag Singh | 6ec1206 | 2012-10-02 09:59:01 -0700 | [diff] [blame] | 37 | |
| 38 | #include "utils.h" |
| 39 | #include "list.h" |
| 40 | #include "hint-data.h" |
Anurag Singh | 057806b | 2013-04-16 16:53:45 -0700 | [diff] [blame] | 41 | #include "power-common.h" |
Rashed Abdel-Tawab | 00b2185 | 2017-11-03 12:44:16 -0700 | [diff] [blame] | 42 | #include "power-helper.h" |
Anurag Singh | 6ec1206 | 2012-10-02 09:59:01 -0700 | [diff] [blame] | 43 | |
| 44 | #define LOG_TAG "QCOM PowerHAL" |
Rashed Abdel-Tawab | 9c14c9f | 2017-12-26 23:11:03 +0200 | [diff] [blame] | 45 | #include <log/log.h> |
Anurag Singh | 6ec1206 | 2012-10-02 09:59:01 -0700 | [diff] [blame] | 46 | |
Wei Wang | 5584ebb | 2016-06-07 18:44:31 -0700 | [diff] [blame] | 47 | #define USINSEC 1000000L |
| 48 | #define NSINUS 1000L |
| 49 | |
Zhao Wei Liew | 6fe5252 | 2016-07-19 19:57:06 +0800 | [diff] [blame] | 50 | #define SOC_ID_0 "/sys/devices/soc0/soc_id" |
| 51 | #define SOC_ID_1 "/sys/devices/system/soc/soc0/id" |
| 52 | |
Corinna Vinschen | ed3426d | 2018-04-10 11:57:37 +0200 | [diff] [blame] | 53 | const char *scaling_gov_path[4] = { |
| 54 | "/sys/devices/system/cpu/cpu0/cpufreq/scaling_governor", |
| 55 | "/sys/devices/system/cpu/cpu1/cpufreq/scaling_governor", |
| 56 | "/sys/devices/system/cpu/cpu2/cpufreq/scaling_governor", |
| 57 | "/sys/devices/system/cpu/cpu3/cpufreq/scaling_governor" |
Sravan Kumar Ambapuram | 5838747 | 2015-05-20 22:22:54 +0530 | [diff] [blame] | 58 | }; |
| 59 | |
Ananth Raghavan Subramanian | 0c226b7 | 2017-06-27 21:28:43 -0700 | [diff] [blame] | 60 | #define PERF_HAL_PATH "libqti-perfd-client.so" |
Anurag Singh | 6ec1206 | 2012-10-02 09:59:01 -0700 | [diff] [blame] | 61 | static void *qcopt_handle; |
Anurag Singh | 6ec1206 | 2012-10-02 09:59:01 -0700 | [diff] [blame] | 62 | static int (*perf_lock_acq)(unsigned long handle, int duration, |
| 63 | int list[], int numArgs); |
Anurag Singh | 6ec1206 | 2012-10-02 09:59:01 -0700 | [diff] [blame] | 64 | static int (*perf_lock_rel)(unsigned long handle); |
Ananth Raghavan Subramanian | 0c226b7 | 2017-06-27 21:28:43 -0700 | [diff] [blame] | 65 | static int (*perf_hint)(int, char *, int, int); |
Anurag Singh | 6ec1206 | 2012-10-02 09:59:01 -0700 | [diff] [blame] | 66 | static struct list_node active_hint_list_head; |
| 67 | |
| 68 | static void *get_qcopt_handle() |
| 69 | { |
Corinna Vinschen | 158576f | 2018-04-09 22:55:59 +0200 | [diff] [blame] | 70 | char qcopt_lib_path[PATH_MAX] = {0}; |
Anurag Singh | fe93c1d | 2012-11-21 15:15:56 -0800 | [diff] [blame] | 71 | void *handle = NULL; |
Anurag Singh | 6ec1206 | 2012-10-02 09:59:01 -0700 | [diff] [blame] | 72 | |
Anurag Singh | fe93c1d | 2012-11-21 15:15:56 -0800 | [diff] [blame] | 73 | dlerror(); |
Anurag Singh | 6ec1206 | 2012-10-02 09:59:01 -0700 | [diff] [blame] | 74 | |
Corinna Vinschen | 158576f | 2018-04-09 22:55:59 +0200 | [diff] [blame] | 75 | if (property_get("ro.vendor.extension_library", qcopt_lib_path, |
| 76 | NULL)) { |
| 77 | handle = dlopen(qcopt_lib_path, RTLD_NOW); |
| 78 | if (!handle) { |
| 79 | ALOGE("Unable to open %s: %s\n", qcopt_lib_path, |
| 80 | dlerror()); |
| 81 | } |
| 82 | } |
Ananth Raghavan Subramanian | 0c226b7 | 2017-06-27 21:28:43 -0700 | [diff] [blame] | 83 | if (!handle) { |
Corinna Vinschen | 158576f | 2018-04-09 22:55:59 +0200 | [diff] [blame] | 84 | handle = dlopen(PERF_HAL_PATH, RTLD_NOW); |
| 85 | if (!handle) { |
| 86 | ALOGE("Unable to open %s: %s\n", PERF_HAL_PATH, |
| 87 | dlerror()); |
| 88 | } |
Anurag Singh | 6ec1206 | 2012-10-02 09:59:01 -0700 | [diff] [blame] | 89 | } |
| 90 | |
Anurag Singh | fe93c1d | 2012-11-21 15:15:56 -0800 | [diff] [blame] | 91 | return handle; |
| 92 | } |
| 93 | |
| 94 | static void __attribute__ ((constructor)) initialize(void) |
| 95 | { |
| 96 | qcopt_handle = get_qcopt_handle(); |
| 97 | |
| 98 | if (!qcopt_handle) { |
| 99 | ALOGE("Failed to get qcopt handle.\n"); |
| 100 | } else { |
| 101 | /* |
| 102 | * qc-opt handle obtained. Get the perflock acquire/release |
| 103 | * function pointers. |
| 104 | */ |
| 105 | perf_lock_acq = dlsym(qcopt_handle, "perf_lock_acq"); |
| 106 | |
| 107 | if (!perf_lock_acq) { |
| 108 | ALOGE("Unable to get perf_lock_acq function handle.\n"); |
| 109 | } |
| 110 | |
| 111 | perf_lock_rel = dlsym(qcopt_handle, "perf_lock_rel"); |
| 112 | |
| 113 | if (!perf_lock_rel) { |
| 114 | ALOGE("Unable to get perf_lock_rel function handle.\n"); |
| 115 | } |
Ananth Raghavan Subramanian | 0c226b7 | 2017-06-27 21:28:43 -0700 | [diff] [blame] | 116 | |
| 117 | perf_hint = dlsym(qcopt_handle, "perf_hint"); |
| 118 | |
| 119 | if (!perf_hint) { |
| 120 | ALOGE("Unable to get perf_hint function handle.\n"); |
| 121 | } |
Anurag Singh | fe93c1d | 2012-11-21 15:15:56 -0800 | [diff] [blame] | 122 | } |
| 123 | } |
| 124 | |
| 125 | static void __attribute__ ((destructor)) cleanup(void) |
| 126 | { |
| 127 | if (qcopt_handle) { |
| 128 | if (dlclose(qcopt_handle)) |
| 129 | ALOGE("Error occurred while closing qc-opt library."); |
| 130 | } |
Anurag Singh | 6ec1206 | 2012-10-02 09:59:01 -0700 | [diff] [blame] | 131 | } |
| 132 | |
Corinna Vinschen | ed3426d | 2018-04-10 11:57:37 +0200 | [diff] [blame] | 133 | int sysfs_read(const char *path, char *s, int num_bytes) |
Anurag Singh | 6ec1206 | 2012-10-02 09:59:01 -0700 | [diff] [blame] | 134 | { |
| 135 | char buf[80]; |
| 136 | int count; |
| 137 | int ret = 0; |
| 138 | int fd = open(path, O_RDONLY); |
| 139 | |
| 140 | if (fd < 0) { |
| 141 | strerror_r(errno, buf, sizeof(buf)); |
| 142 | ALOGE("Error opening %s: %s\n", path, buf); |
| 143 | |
| 144 | return -1; |
| 145 | } |
| 146 | |
| 147 | if ((count = read(fd, s, num_bytes - 1)) < 0) { |
| 148 | strerror_r(errno, buf, sizeof(buf)); |
| 149 | ALOGE("Error writing to %s: %s\n", path, buf); |
| 150 | |
| 151 | ret = -1; |
| 152 | } else { |
| 153 | s[count] = '\0'; |
| 154 | } |
| 155 | |
| 156 | close(fd); |
| 157 | |
| 158 | return ret; |
| 159 | } |
| 160 | |
Corinna Vinschen | ed3426d | 2018-04-10 11:57:37 +0200 | [diff] [blame] | 161 | int sysfs_write(const char *path, char *s) |
Anurag Singh | 6ec1206 | 2012-10-02 09:59:01 -0700 | [diff] [blame] | 162 | { |
| 163 | char buf[80]; |
| 164 | int len; |
| 165 | int ret = 0; |
| 166 | int fd = open(path, O_WRONLY); |
| 167 | |
| 168 | if (fd < 0) { |
| 169 | strerror_r(errno, buf, sizeof(buf)); |
| 170 | ALOGE("Error opening %s: %s\n", path, buf); |
| 171 | return -1 ; |
| 172 | } |
| 173 | |
| 174 | len = write(fd, s, strlen(s)); |
| 175 | if (len < 0) { |
| 176 | strerror_r(errno, buf, sizeof(buf)); |
| 177 | ALOGE("Error writing to %s: %s\n", path, buf); |
| 178 | |
| 179 | ret = -1; |
| 180 | } |
| 181 | |
| 182 | close(fd); |
| 183 | |
| 184 | return ret; |
| 185 | } |
| 186 | |
| 187 | int get_scaling_governor(char governor[], int size) |
| 188 | { |
| 189 | if (sysfs_read(SCALING_GOVERNOR_PATH, governor, |
| 190 | size) == -1) { |
| 191 | // Can't obtain the scaling governor. Return. |
| 192 | return -1; |
| 193 | } else { |
| 194 | // Strip newline at the end. |
| 195 | int len = strlen(governor); |
| 196 | |
| 197 | len--; |
| 198 | |
| 199 | while (len >= 0 && (governor[len] == '\n' || governor[len] == '\r')) |
| 200 | governor[len--] = '\0'; |
| 201 | } |
| 202 | |
| 203 | return 0; |
| 204 | } |
| 205 | |
Sravan Kumar Ambapuram | 5838747 | 2015-05-20 22:22:54 +0530 | [diff] [blame] | 206 | int get_scaling_governor_check_cores(char governor[], int size,int core_num) |
| 207 | { |
| 208 | |
| 209 | if (sysfs_read(scaling_gov_path[core_num], governor, |
| 210 | size) == -1) { |
| 211 | // Can't obtain the scaling governor. Return. |
| 212 | return -1; |
| 213 | } |
| 214 | |
| 215 | // Strip newline at the end. |
| 216 | int len = strlen(governor); |
| 217 | len--; |
| 218 | while (len >= 0 && (governor[len] == '\n' || governor[len] == '\r')) |
| 219 | governor[len--] = '\0'; |
| 220 | |
| 221 | return 0; |
| 222 | } |
| 223 | |
Ananth Raghavan Subramanian | e432dbf | 2017-03-24 16:30:12 -0700 | [diff] [blame] | 224 | int is_interactive_governor(char* governor) { |
| 225 | if (strncmp(governor, INTERACTIVE_GOVERNOR, (strlen(INTERACTIVE_GOVERNOR)+1)) == 0) |
| 226 | return 1; |
| 227 | return 0; |
| 228 | } |
| 229 | |
Michael Bestas | fc62e7c | 2018-03-25 23:14:21 +0300 | [diff] [blame] | 230 | int is_ondemand_governor(char* governor) { |
| 231 | if (strncmp(governor, ONDEMAND_GOVERNOR, (strlen(ONDEMAND_GOVERNOR)+1)) == 0) |
| 232 | return 1; |
| 233 | return 0; |
| 234 | } |
| 235 | |
Paul Keith | d524aea | 2017-12-31 02:17:32 +0100 | [diff] [blame] | 236 | #ifndef INTERACTION_BOOST |
| 237 | void interaction(int UNUSED(duration), int UNUSED(num_args), int UNUSED(opt_list[])) |
| 238 | { |
| 239 | #else |
Vince Leung | 699c1bc | 2013-08-14 17:40:36 -0700 | [diff] [blame] | 240 | void interaction(int duration, int num_args, int opt_list[]) |
Vince Leung | 6857466 | 2013-07-16 16:47:00 -0700 | [diff] [blame] | 241 | { |
Vince Leung | 6857466 | 2013-07-16 16:47:00 -0700 | [diff] [blame] | 242 | static int lock_handle = 0; |
Vince Leung | 699c1bc | 2013-08-14 17:40:36 -0700 | [diff] [blame] | 243 | |
Paul Keith | d524aea | 2017-12-31 02:17:32 +0100 | [diff] [blame] | 244 | if (duration < 0 || num_args < 1 || opt_list[0] == 0) |
Vince Leung | 699c1bc | 2013-08-14 17:40:36 -0700 | [diff] [blame] | 245 | return; |
| 246 | |
Vince Leung | 6857466 | 2013-07-16 16:47:00 -0700 | [diff] [blame] | 247 | if (qcopt_handle) { |
| 248 | if (perf_lock_acq) { |
Vince Leung | 699c1bc | 2013-08-14 17:40:36 -0700 | [diff] [blame] | 249 | lock_handle = perf_lock_acq(lock_handle, duration, opt_list, num_args); |
Vince Leung | 6857466 | 2013-07-16 16:47:00 -0700 | [diff] [blame] | 250 | if (lock_handle == -1) |
| 251 | ALOGE("Failed to acquire lock."); |
| 252 | } |
| 253 | } |
| 254 | #endif |
| 255 | } |
| 256 | |
dianlujitao | 1f5b987 | 2019-02-19 18:06:41 +0800 | [diff] [blame] | 257 | #ifndef INTERACTION_BOOST |
| 258 | int interaction_with_handle(int UNUSED(lock_handle), int UNUSED(duration), int UNUSED(num_args), int UNUSED(opt_list[])) |
| 259 | { |
| 260 | return 0; |
| 261 | #else |
| 262 | int interaction_with_handle(int lock_handle, int duration, int num_args, int opt_list[]) |
| 263 | { |
| 264 | if (duration < 0 || num_args < 1 || opt_list[0] == 0) |
| 265 | return 0; |
| 266 | |
| 267 | if (qcopt_handle) { |
| 268 | if (perf_lock_acq) { |
| 269 | lock_handle = perf_lock_acq(lock_handle, duration, opt_list, num_args); |
| 270 | if (lock_handle == -1) |
| 271 | ALOGE("Failed to acquire lock."); |
| 272 | } |
| 273 | } |
| 274 | return lock_handle; |
| 275 | #endif |
| 276 | } |
| 277 | |
| 278 | //this is interaction_with_handle using perf_hint instead of |
Ananth Raghavan Subramanian | 0c226b7 | 2017-06-27 21:28:43 -0700 | [diff] [blame] | 279 | //perf_lock_acq |
| 280 | int perf_hint_enable(int hint_id , int duration) |
| 281 | { |
| 282 | int lock_handle = 0; |
| 283 | |
| 284 | if (duration < 0) |
| 285 | return 0; |
| 286 | |
| 287 | if (qcopt_handle) { |
| 288 | if (perf_hint) { |
| 289 | lock_handle = perf_hint(hint_id, NULL, duration, -1); |
| 290 | if (lock_handle == -1) |
| 291 | ALOGE("Failed to acquire lock."); |
| 292 | } |
| 293 | } |
| 294 | return lock_handle; |
| 295 | } |
| 296 | |
BeYkeRYkt | bd52e81 | 2018-12-13 06:42:35 +0900 | [diff] [blame] | 297 | //Same as perf_hint_enable, but with the ability to |
| 298 | //choose the type |
| 299 | int perf_hint_enable_with_type(int hint_id, int duration, int type) |
| 300 | { |
| 301 | int lock_handle = 0; |
| 302 | |
| 303 | if (qcopt_handle) { |
| 304 | if (perf_hint) { |
| 305 | lock_handle = perf_hint(hint_id, NULL, duration, type); |
| 306 | if (lock_handle == -1) |
| 307 | ALOGE("Failed to acquire lock."); |
| 308 | } |
| 309 | } |
| 310 | return lock_handle; |
| 311 | } |
Ananth Raghavan Subramanian | 0c226b7 | 2017-06-27 21:28:43 -0700 | [diff] [blame] | 312 | |
Ananth Raghavan Subramanian | e432dbf | 2017-03-24 16:30:12 -0700 | [diff] [blame] | 313 | void release_request(int lock_handle) { |
| 314 | if (qcopt_handle && perf_lock_rel) |
| 315 | perf_lock_rel(lock_handle); |
| 316 | } |
| 317 | |
Corinna Vinschen | 282e889 | 2018-08-26 21:16:23 +0200 | [diff] [blame] | 318 | int perform_hint_action(int hint_id, int resource_values[], int num_resources) |
Anurag Singh | 6ec1206 | 2012-10-02 09:59:01 -0700 | [diff] [blame] | 319 | { |
Corinna Vinschen | 282e889 | 2018-08-26 21:16:23 +0200 | [diff] [blame] | 320 | if (qcopt_handle && perf_lock_acq) { |
| 321 | /* Acquire an indefinite lock for the requested resources. */ |
| 322 | int lock_handle = perf_lock_acq(0, 0, resource_values, |
| 323 | num_resources); |
Anurag Singh | 6ec1206 | 2012-10-02 09:59:01 -0700 | [diff] [blame] | 324 | |
Corinna Vinschen | 282e889 | 2018-08-26 21:16:23 +0200 | [diff] [blame] | 325 | if (lock_handle == -1) { |
| 326 | ALOGE("Failed to acquire lock."); |
| 327 | return -EINVAL; |
| 328 | } |
Anurag Singh | 6ec1206 | 2012-10-02 09:59:01 -0700 | [diff] [blame] | 329 | |
Corinna Vinschen | 282e889 | 2018-08-26 21:16:23 +0200 | [diff] [blame] | 330 | /* Add this handle to our internal hint-list. */ |
| 331 | struct hint_data *new_hint = |
| 332 | (struct hint_data *)malloc(sizeof(struct hint_data)); |
Anurag Singh | 6ec1206 | 2012-10-02 09:59:01 -0700 | [diff] [blame] | 333 | |
Corinna Vinschen | 282e889 | 2018-08-26 21:16:23 +0200 | [diff] [blame] | 334 | if (!new_hint) { |
| 335 | /* Can't keep track of this lock. Release it. */ |
| 336 | if (perf_lock_rel) |
| 337 | perf_lock_rel(lock_handle); |
| 338 | ALOGE("Failed to process hint."); |
| 339 | return -ENOMEM; |
| 340 | } |
Anurag Singh | 6ec1206 | 2012-10-02 09:59:01 -0700 | [diff] [blame] | 341 | |
Corinna Vinschen | 282e889 | 2018-08-26 21:16:23 +0200 | [diff] [blame] | 342 | if (!active_hint_list_head.compare) { |
| 343 | active_hint_list_head.compare = |
| 344 | (int (*)(void *, void *))hint_compare; |
| 345 | active_hint_list_head.dump = (void (*)(void *))hint_dump; |
| 346 | } |
Anurag Singh | fe93c1d | 2012-11-21 15:15:56 -0800 | [diff] [blame] | 347 | |
Corinna Vinschen | 282e889 | 2018-08-26 21:16:23 +0200 | [diff] [blame] | 348 | new_hint->hint_id = hint_id; |
| 349 | new_hint->perflock_handle = lock_handle; |
Anurag Singh | fe93c1d | 2012-11-21 15:15:56 -0800 | [diff] [blame] | 350 | |
Corinna Vinschen | 282e889 | 2018-08-26 21:16:23 +0200 | [diff] [blame] | 351 | if (add_list_node(&active_hint_list_head, new_hint) == NULL) { |
| 352 | free(new_hint); |
| 353 | /* Can't keep track of this lock. Release it. */ |
| 354 | if (perf_lock_rel) |
| 355 | perf_lock_rel(lock_handle); |
| 356 | ALOGE("Failed to process hint."); |
| 357 | return -ENOMEM; |
Anurag Singh | 6ec1206 | 2012-10-02 09:59:01 -0700 | [diff] [blame] | 358 | } |
| 359 | } |
Corinna Vinschen | 282e889 | 2018-08-26 21:16:23 +0200 | [diff] [blame] | 360 | return 0; |
Anurag Singh | 6ec1206 | 2012-10-02 09:59:01 -0700 | [diff] [blame] | 361 | } |
| 362 | |
| 363 | void undo_hint_action(int hint_id) |
| 364 | { |
Anurag Singh | fe93c1d | 2012-11-21 15:15:56 -0800 | [diff] [blame] | 365 | if (qcopt_handle) { |
| 366 | if (perf_lock_rel) { |
| 367 | /* Get hint-data associated with this hint-id */ |
| 368 | struct list_node *found_node; |
| 369 | struct hint_data temp_hint_data = { |
| 370 | .hint_id = hint_id |
| 371 | }; |
Anurag Singh | 6ec1206 | 2012-10-02 09:59:01 -0700 | [diff] [blame] | 372 | |
Anurag Singh | fe93c1d | 2012-11-21 15:15:56 -0800 | [diff] [blame] | 373 | found_node = find_node(&active_hint_list_head, |
| 374 | &temp_hint_data); |
Anurag Singh | 6ec1206 | 2012-10-02 09:59:01 -0700 | [diff] [blame] | 375 | |
Anurag Singh | fe93c1d | 2012-11-21 15:15:56 -0800 | [diff] [blame] | 376 | if (found_node) { |
| 377 | /* Release this lock. */ |
| 378 | struct hint_data *found_hint_data = |
| 379 | (struct hint_data *)(found_node->data); |
Anurag Singh | 6ec1206 | 2012-10-02 09:59:01 -0700 | [diff] [blame] | 380 | |
Anurag Singh | fe93c1d | 2012-11-21 15:15:56 -0800 | [diff] [blame] | 381 | if (found_hint_data) { |
| 382 | if (perf_lock_rel(found_hint_data->perflock_handle) == -1) |
Anurag Singh | 6ec1206 | 2012-10-02 09:59:01 -0700 | [diff] [blame] | 383 | ALOGE("Perflock release failed."); |
Anurag Singh | 6ec1206 | 2012-10-02 09:59:01 -0700 | [diff] [blame] | 384 | } |
Anurag Singh | fe93c1d | 2012-11-21 15:15:56 -0800 | [diff] [blame] | 385 | |
| 386 | if (found_node->data) { |
| 387 | /* We can free the hint-data for this node. */ |
| 388 | free(found_node->data); |
| 389 | } |
| 390 | |
| 391 | remove_list_node(&active_hint_list_head, found_node); |
Anurag Singh | 6ec1206 | 2012-10-02 09:59:01 -0700 | [diff] [blame] | 392 | } else { |
Anurag Singh | fe93c1d | 2012-11-21 15:15:56 -0800 | [diff] [blame] | 393 | ALOGE("Invalid hint ID."); |
Anurag Singh | 6ec1206 | 2012-10-02 09:59:01 -0700 | [diff] [blame] | 394 | } |
| 395 | } |
| 396 | } |
| 397 | } |
Zhoulu Luo | 3b1fbdb | 2013-12-06 16:32:10 -0800 | [diff] [blame] | 398 | |
| 399 | /* |
| 400 | * Used to release initial lock holding |
| 401 | * two cores online when the display is on |
| 402 | */ |
| 403 | void undo_initial_hint_action() |
| 404 | { |
| 405 | if (qcopt_handle) { |
| 406 | if (perf_lock_rel) { |
| 407 | perf_lock_rel(1); |
| 408 | } |
| 409 | } |
| 410 | } |
Wei Wang | 5584ebb | 2016-06-07 18:44:31 -0700 | [diff] [blame] | 411 | |
| 412 | long long calc_timespan_us(struct timespec start, struct timespec end) |
| 413 | { |
| 414 | long long diff_in_us = 0; |
| 415 | diff_in_us += (end.tv_sec - start.tv_sec) * USINSEC; |
| 416 | diff_in_us += (end.tv_nsec - start.tv_nsec) / NSINUS; |
| 417 | return diff_in_us; |
| 418 | } |
Zhao Wei Liew | 6fe5252 | 2016-07-19 19:57:06 +0800 | [diff] [blame] | 419 | |
| 420 | int get_soc_id(void) |
| 421 | { |
| 422 | int fd; |
| 423 | int soc_id = -1; |
| 424 | char buf[10] = { 0 }; |
| 425 | |
| 426 | if (!access(SOC_ID_0, F_OK)) |
| 427 | fd = open(SOC_ID_0, O_RDONLY); |
| 428 | else |
| 429 | fd = open(SOC_ID_1, O_RDONLY); |
| 430 | |
| 431 | if (fd >= 0) { |
| 432 | if (read(fd, buf, sizeof(buf) - 1) == -1) |
| 433 | ALOGW("Unable to read soc_id"); |
| 434 | else |
| 435 | soc_id = atoi(buf); |
| 436 | } |
| 437 | |
| 438 | close(fd); |
| 439 | return soc_id; |
| 440 | } |