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 | |
Sravan Kumar Ambapuram | 5838747 | 2015-05-20 22:22:54 +0530 | [diff] [blame] | 53 | char scaling_gov_path[4][80] ={ |
| 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" |
| 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 | { |
Anurag Singh | fe93c1d | 2012-11-21 15:15:56 -0800 | [diff] [blame] | 70 | void *handle = NULL; |
Anurag Singh | 6ec1206 | 2012-10-02 09:59:01 -0700 | [diff] [blame] | 71 | |
Anurag Singh | fe93c1d | 2012-11-21 15:15:56 -0800 | [diff] [blame] | 72 | dlerror(); |
Anurag Singh | 6ec1206 | 2012-10-02 09:59:01 -0700 | [diff] [blame] | 73 | |
Ananth Raghavan Subramanian | 0c226b7 | 2017-06-27 21:28:43 -0700 | [diff] [blame] | 74 | handle = dlopen(PERF_HAL_PATH, RTLD_NOW); |
| 75 | if (!handle) { |
| 76 | ALOGE("Unable to open %s: %s\n", PERF_HAL_PATH, |
| 77 | dlerror()); |
Anurag Singh | 6ec1206 | 2012-10-02 09:59:01 -0700 | [diff] [blame] | 78 | } |
| 79 | |
Anurag Singh | fe93c1d | 2012-11-21 15:15:56 -0800 | [diff] [blame] | 80 | return handle; |
| 81 | } |
| 82 | |
| 83 | static void __attribute__ ((constructor)) initialize(void) |
| 84 | { |
| 85 | qcopt_handle = get_qcopt_handle(); |
| 86 | |
| 87 | if (!qcopt_handle) { |
| 88 | ALOGE("Failed to get qcopt handle.\n"); |
| 89 | } else { |
| 90 | /* |
| 91 | * qc-opt handle obtained. Get the perflock acquire/release |
| 92 | * function pointers. |
| 93 | */ |
| 94 | perf_lock_acq = dlsym(qcopt_handle, "perf_lock_acq"); |
| 95 | |
| 96 | if (!perf_lock_acq) { |
| 97 | ALOGE("Unable to get perf_lock_acq function handle.\n"); |
| 98 | } |
| 99 | |
| 100 | perf_lock_rel = dlsym(qcopt_handle, "perf_lock_rel"); |
| 101 | |
| 102 | if (!perf_lock_rel) { |
| 103 | ALOGE("Unable to get perf_lock_rel function handle.\n"); |
| 104 | } |
Ananth Raghavan Subramanian | 0c226b7 | 2017-06-27 21:28:43 -0700 | [diff] [blame] | 105 | |
| 106 | perf_hint = dlsym(qcopt_handle, "perf_hint"); |
| 107 | |
| 108 | if (!perf_hint) { |
| 109 | ALOGE("Unable to get perf_hint function handle.\n"); |
| 110 | } |
Anurag Singh | fe93c1d | 2012-11-21 15:15:56 -0800 | [diff] [blame] | 111 | } |
| 112 | } |
| 113 | |
| 114 | static void __attribute__ ((destructor)) cleanup(void) |
| 115 | { |
| 116 | if (qcopt_handle) { |
| 117 | if (dlclose(qcopt_handle)) |
| 118 | ALOGE("Error occurred while closing qc-opt library."); |
| 119 | } |
Anurag Singh | 6ec1206 | 2012-10-02 09:59:01 -0700 | [diff] [blame] | 120 | } |
| 121 | |
| 122 | int sysfs_read(char *path, char *s, int num_bytes) |
| 123 | { |
| 124 | char buf[80]; |
| 125 | int count; |
| 126 | int ret = 0; |
| 127 | int fd = open(path, O_RDONLY); |
| 128 | |
| 129 | if (fd < 0) { |
| 130 | strerror_r(errno, buf, sizeof(buf)); |
| 131 | ALOGE("Error opening %s: %s\n", path, buf); |
| 132 | |
| 133 | return -1; |
| 134 | } |
| 135 | |
| 136 | if ((count = read(fd, s, num_bytes - 1)) < 0) { |
| 137 | strerror_r(errno, buf, sizeof(buf)); |
| 138 | ALOGE("Error writing to %s: %s\n", path, buf); |
| 139 | |
| 140 | ret = -1; |
| 141 | } else { |
| 142 | s[count] = '\0'; |
| 143 | } |
| 144 | |
| 145 | close(fd); |
| 146 | |
| 147 | return ret; |
| 148 | } |
| 149 | |
| 150 | int sysfs_write(char *path, char *s) |
| 151 | { |
| 152 | char buf[80]; |
| 153 | int len; |
| 154 | int ret = 0; |
| 155 | int fd = open(path, O_WRONLY); |
| 156 | |
| 157 | if (fd < 0) { |
| 158 | strerror_r(errno, buf, sizeof(buf)); |
| 159 | ALOGE("Error opening %s: %s\n", path, buf); |
| 160 | return -1 ; |
| 161 | } |
| 162 | |
| 163 | len = write(fd, s, strlen(s)); |
| 164 | if (len < 0) { |
| 165 | strerror_r(errno, buf, sizeof(buf)); |
| 166 | ALOGE("Error writing to %s: %s\n", path, buf); |
| 167 | |
| 168 | ret = -1; |
| 169 | } |
| 170 | |
| 171 | close(fd); |
| 172 | |
| 173 | return ret; |
| 174 | } |
| 175 | |
| 176 | int get_scaling_governor(char governor[], int size) |
| 177 | { |
| 178 | if (sysfs_read(SCALING_GOVERNOR_PATH, governor, |
| 179 | size) == -1) { |
| 180 | // Can't obtain the scaling governor. Return. |
| 181 | return -1; |
| 182 | } else { |
| 183 | // Strip newline at the end. |
| 184 | int len = strlen(governor); |
| 185 | |
| 186 | len--; |
| 187 | |
| 188 | while (len >= 0 && (governor[len] == '\n' || governor[len] == '\r')) |
| 189 | governor[len--] = '\0'; |
| 190 | } |
| 191 | |
| 192 | return 0; |
| 193 | } |
| 194 | |
Sravan Kumar Ambapuram | 5838747 | 2015-05-20 22:22:54 +0530 | [diff] [blame] | 195 | int get_scaling_governor_check_cores(char governor[], int size,int core_num) |
| 196 | { |
| 197 | |
| 198 | if (sysfs_read(scaling_gov_path[core_num], governor, |
| 199 | size) == -1) { |
| 200 | // Can't obtain the scaling governor. Return. |
| 201 | return -1; |
| 202 | } |
| 203 | |
| 204 | // Strip newline at the end. |
| 205 | int len = strlen(governor); |
| 206 | len--; |
| 207 | while (len >= 0 && (governor[len] == '\n' || governor[len] == '\r')) |
| 208 | governor[len--] = '\0'; |
| 209 | |
| 210 | return 0; |
| 211 | } |
| 212 | |
Ananth Raghavan Subramanian | e432dbf | 2017-03-24 16:30:12 -0700 | [diff] [blame] | 213 | int is_interactive_governor(char* governor) { |
| 214 | if (strncmp(governor, INTERACTIVE_GOVERNOR, (strlen(INTERACTIVE_GOVERNOR)+1)) == 0) |
| 215 | return 1; |
| 216 | return 0; |
| 217 | } |
| 218 | |
Michael Bestas | fc62e7c | 2018-03-25 23:14:21 +0300 | [diff] [blame] | 219 | int is_ondemand_governor(char* governor) { |
| 220 | if (strncmp(governor, ONDEMAND_GOVERNOR, (strlen(ONDEMAND_GOVERNOR)+1)) == 0) |
| 221 | return 1; |
| 222 | return 0; |
| 223 | } |
| 224 | |
| 225 | int is_msmdcvs_governor(char* governor) { |
| 226 | if (strncmp(governor, MSMDCVS_GOVERNOR, (strlen(MSMDCVS_GOVERNOR)+1)) == 0) |
| 227 | return 1; |
| 228 | return 0; |
| 229 | } |
| 230 | |
Paul Keith | d524aea | 2017-12-31 02:17:32 +0100 | [diff] [blame] | 231 | #ifndef INTERACTION_BOOST |
| 232 | void interaction(int UNUSED(duration), int UNUSED(num_args), int UNUSED(opt_list[])) |
| 233 | { |
| 234 | #else |
Vince Leung | 699c1bc | 2013-08-14 17:40:36 -0700 | [diff] [blame] | 235 | void interaction(int duration, int num_args, int opt_list[]) |
Vince Leung | 6857466 | 2013-07-16 16:47:00 -0700 | [diff] [blame] | 236 | { |
Vince Leung | 6857466 | 2013-07-16 16:47:00 -0700 | [diff] [blame] | 237 | static int lock_handle = 0; |
Vince Leung | 699c1bc | 2013-08-14 17:40:36 -0700 | [diff] [blame] | 238 | |
Paul Keith | d524aea | 2017-12-31 02:17:32 +0100 | [diff] [blame] | 239 | if (duration < 0 || num_args < 1 || opt_list[0] == 0) |
Vince Leung | 699c1bc | 2013-08-14 17:40:36 -0700 | [diff] [blame] | 240 | return; |
| 241 | |
Vince Leung | 6857466 | 2013-07-16 16:47:00 -0700 | [diff] [blame] | 242 | if (qcopt_handle) { |
| 243 | if (perf_lock_acq) { |
Vince Leung | 699c1bc | 2013-08-14 17:40:36 -0700 | [diff] [blame] | 244 | lock_handle = perf_lock_acq(lock_handle, duration, opt_list, num_args); |
Vince Leung | 6857466 | 2013-07-16 16:47:00 -0700 | [diff] [blame] | 245 | if (lock_handle == -1) |
| 246 | ALOGE("Failed to acquire lock."); |
| 247 | } |
| 248 | } |
| 249 | #endif |
| 250 | } |
| 251 | |
Ananth Raghavan Subramanian | e432dbf | 2017-03-24 16:30:12 -0700 | [diff] [blame] | 252 | int interaction_with_handle(int lock_handle, int duration, int num_args, int opt_list[]) |
| 253 | { |
Paul Keith | d524aea | 2017-12-31 02:17:32 +0100 | [diff] [blame] | 254 | if (duration < 0 || num_args < 1 || opt_list[0] == 0) |
Ananth Raghavan Subramanian | e432dbf | 2017-03-24 16:30:12 -0700 | [diff] [blame] | 255 | return 0; |
| 256 | |
| 257 | if (qcopt_handle) { |
| 258 | if (perf_lock_acq) { |
| 259 | lock_handle = perf_lock_acq(lock_handle, duration, opt_list, num_args); |
| 260 | if (lock_handle == -1) |
| 261 | ALOGE("Failed to acquire lock."); |
| 262 | } |
| 263 | } |
| 264 | return lock_handle; |
| 265 | } |
| 266 | |
Ananth Raghavan Subramanian | 0c226b7 | 2017-06-27 21:28:43 -0700 | [diff] [blame] | 267 | //this is interaction_with_handle using perf_hint instead of |
| 268 | //perf_lock_acq |
| 269 | int perf_hint_enable(int hint_id , int duration) |
| 270 | { |
| 271 | int lock_handle = 0; |
| 272 | |
| 273 | if (duration < 0) |
| 274 | return 0; |
| 275 | |
| 276 | if (qcopt_handle) { |
| 277 | if (perf_hint) { |
| 278 | lock_handle = perf_hint(hint_id, NULL, duration, -1); |
| 279 | if (lock_handle == -1) |
| 280 | ALOGE("Failed to acquire lock."); |
| 281 | } |
| 282 | } |
| 283 | return lock_handle; |
| 284 | } |
| 285 | |
| 286 | |
Ananth Raghavan Subramanian | e432dbf | 2017-03-24 16:30:12 -0700 | [diff] [blame] | 287 | void release_request(int lock_handle) { |
| 288 | if (qcopt_handle && perf_lock_rel) |
| 289 | perf_lock_rel(lock_handle); |
| 290 | } |
| 291 | |
Anurag Singh | 6ec1206 | 2012-10-02 09:59:01 -0700 | [diff] [blame] | 292 | void perform_hint_action(int hint_id, int resource_values[], int num_resources) |
| 293 | { |
Anurag Singh | fe93c1d | 2012-11-21 15:15:56 -0800 | [diff] [blame] | 294 | if (qcopt_handle) { |
| 295 | if (perf_lock_acq) { |
| 296 | /* Acquire an indefinite lock for the requested resources. */ |
| 297 | int lock_handle = perf_lock_acq(0, 0, resource_values, |
Anurag Singh | 6ec1206 | 2012-10-02 09:59:01 -0700 | [diff] [blame] | 298 | num_resources); |
| 299 | |
Anurag Singh | fe93c1d | 2012-11-21 15:15:56 -0800 | [diff] [blame] | 300 | if (lock_handle == -1) { |
| 301 | ALOGE("Failed to acquire lock."); |
| 302 | } else { |
| 303 | /* Add this handle to our internal hint-list. */ |
| 304 | struct hint_data *new_hint = |
| 305 | (struct hint_data *)malloc(sizeof(struct hint_data)); |
Anurag Singh | 6ec1206 | 2012-10-02 09:59:01 -0700 | [diff] [blame] | 306 | |
Anurag Singh | fe93c1d | 2012-11-21 15:15:56 -0800 | [diff] [blame] | 307 | if (new_hint) { |
| 308 | if (!active_hint_list_head.compare) { |
| 309 | active_hint_list_head.compare = |
| 310 | (int (*)(void *, void *))hint_compare; |
| 311 | active_hint_list_head.dump = (void (*)(void *))hint_dump; |
| 312 | } |
Anurag Singh | 6ec1206 | 2012-10-02 09:59:01 -0700 | [diff] [blame] | 313 | |
Anurag Singh | fe93c1d | 2012-11-21 15:15:56 -0800 | [diff] [blame] | 314 | new_hint->hint_id = hint_id; |
| 315 | new_hint->perflock_handle = lock_handle; |
Anurag Singh | 6ec1206 | 2012-10-02 09:59:01 -0700 | [diff] [blame] | 316 | |
Anurag Singh | fe93c1d | 2012-11-21 15:15:56 -0800 | [diff] [blame] | 317 | if (add_list_node(&active_hint_list_head, new_hint) == NULL) { |
| 318 | free(new_hint); |
Anurag Singh | 6ec1206 | 2012-10-02 09:59:01 -0700 | [diff] [blame] | 319 | /* Can't keep track of this lock. Release it. */ |
Anurag Singh | fe93c1d | 2012-11-21 15:15:56 -0800 | [diff] [blame] | 320 | if (perf_lock_rel) |
| 321 | perf_lock_rel(lock_handle); |
| 322 | |
Anurag Singh | 6ec1206 | 2012-10-02 09:59:01 -0700 | [diff] [blame] | 323 | ALOGE("Failed to process hint."); |
| 324 | } |
Anurag Singh | fe93c1d | 2012-11-21 15:15:56 -0800 | [diff] [blame] | 325 | } else { |
| 326 | /* Can't keep track of this lock. Release it. */ |
| 327 | if (perf_lock_rel) |
| 328 | perf_lock_rel(lock_handle); |
| 329 | |
| 330 | ALOGE("Failed to process hint."); |
Anurag Singh | 6ec1206 | 2012-10-02 09:59:01 -0700 | [diff] [blame] | 331 | } |
Anurag Singh | 6ec1206 | 2012-10-02 09:59:01 -0700 | [diff] [blame] | 332 | } |
| 333 | } |
| 334 | } |
| 335 | } |
| 336 | |
| 337 | void undo_hint_action(int hint_id) |
| 338 | { |
Anurag Singh | fe93c1d | 2012-11-21 15:15:56 -0800 | [diff] [blame] | 339 | if (qcopt_handle) { |
| 340 | if (perf_lock_rel) { |
| 341 | /* Get hint-data associated with this hint-id */ |
| 342 | struct list_node *found_node; |
| 343 | struct hint_data temp_hint_data = { |
| 344 | .hint_id = hint_id |
| 345 | }; |
Anurag Singh | 6ec1206 | 2012-10-02 09:59:01 -0700 | [diff] [blame] | 346 | |
Anurag Singh | fe93c1d | 2012-11-21 15:15:56 -0800 | [diff] [blame] | 347 | found_node = find_node(&active_hint_list_head, |
| 348 | &temp_hint_data); |
Anurag Singh | 6ec1206 | 2012-10-02 09:59:01 -0700 | [diff] [blame] | 349 | |
Anurag Singh | fe93c1d | 2012-11-21 15:15:56 -0800 | [diff] [blame] | 350 | if (found_node) { |
| 351 | /* Release this lock. */ |
| 352 | struct hint_data *found_hint_data = |
| 353 | (struct hint_data *)(found_node->data); |
Anurag Singh | 6ec1206 | 2012-10-02 09:59:01 -0700 | [diff] [blame] | 354 | |
Anurag Singh | fe93c1d | 2012-11-21 15:15:56 -0800 | [diff] [blame] | 355 | if (found_hint_data) { |
| 356 | if (perf_lock_rel(found_hint_data->perflock_handle) == -1) |
Anurag Singh | 6ec1206 | 2012-10-02 09:59:01 -0700 | [diff] [blame] | 357 | ALOGE("Perflock release failed."); |
Anurag Singh | 6ec1206 | 2012-10-02 09:59:01 -0700 | [diff] [blame] | 358 | } |
Anurag Singh | fe93c1d | 2012-11-21 15:15:56 -0800 | [diff] [blame] | 359 | |
| 360 | if (found_node->data) { |
| 361 | /* We can free the hint-data for this node. */ |
| 362 | free(found_node->data); |
| 363 | } |
| 364 | |
| 365 | remove_list_node(&active_hint_list_head, found_node); |
Anurag Singh | 6ec1206 | 2012-10-02 09:59:01 -0700 | [diff] [blame] | 366 | } else { |
Anurag Singh | fe93c1d | 2012-11-21 15:15:56 -0800 | [diff] [blame] | 367 | ALOGE("Invalid hint ID."); |
Anurag Singh | 6ec1206 | 2012-10-02 09:59:01 -0700 | [diff] [blame] | 368 | } |
| 369 | } |
| 370 | } |
| 371 | } |
Zhoulu Luo | 3b1fbdb | 2013-12-06 16:32:10 -0800 | [diff] [blame] | 372 | |
| 373 | /* |
| 374 | * Used to release initial lock holding |
| 375 | * two cores online when the display is on |
| 376 | */ |
| 377 | void undo_initial_hint_action() |
| 378 | { |
| 379 | if (qcopt_handle) { |
| 380 | if (perf_lock_rel) { |
| 381 | perf_lock_rel(1); |
| 382 | } |
| 383 | } |
| 384 | } |
Wei Wang | 5584ebb | 2016-06-07 18:44:31 -0700 | [diff] [blame] | 385 | |
| 386 | long long calc_timespan_us(struct timespec start, struct timespec end) |
| 387 | { |
| 388 | long long diff_in_us = 0; |
| 389 | diff_in_us += (end.tv_sec - start.tv_sec) * USINSEC; |
| 390 | diff_in_us += (end.tv_nsec - start.tv_nsec) / NSINUS; |
| 391 | return diff_in_us; |
| 392 | } |
Zhao Wei Liew | 6fe5252 | 2016-07-19 19:57:06 +0800 | [diff] [blame] | 393 | |
| 394 | int get_soc_id(void) |
| 395 | { |
| 396 | int fd; |
| 397 | int soc_id = -1; |
| 398 | char buf[10] = { 0 }; |
| 399 | |
| 400 | if (!access(SOC_ID_0, F_OK)) |
| 401 | fd = open(SOC_ID_0, O_RDONLY); |
| 402 | else |
| 403 | fd = open(SOC_ID_1, O_RDONLY); |
| 404 | |
| 405 | if (fd >= 0) { |
| 406 | if (read(fd, buf, sizeof(buf) - 1) == -1) |
| 407 | ALOGW("Unable to read soc_id"); |
| 408 | else |
| 409 | soc_id = atoi(buf); |
| 410 | } |
| 411 | |
| 412 | close(fd); |
| 413 | return soc_id; |
| 414 | } |