summaryrefslogtreecommitdiffstats
path: root/utils.c
diff options
context:
space:
mode:
Diffstat (limited to 'utils.c')
-rw-r--r--utils.c150
1 files changed, 54 insertions, 96 deletions
diff --git a/utils.c b/utils.c
index 209efc8..7f6229b 100644
--- a/utils.c
+++ b/utils.c
@@ -29,53 +29,47 @@
#define LOG_NIDEBUG 0
#include <dlfcn.h>
-#include <fcntl.h>
#include <errno.h>
+#include <fcntl.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
-#include "utils.h"
-#include "list.h"
#include "hint-data.h"
+#include "list.h"
#include "power-common.h"
+#include "utils.h"
#define LOG_TAG "QTI PowerHAL"
#include <log/log.h>
-char scaling_gov_path[4][80] ={
- "sys/devices/system/cpu/cpu0/cpufreq/scaling_governor",
- "sys/devices/system/cpu/cpu1/cpufreq/scaling_governor",
- "sys/devices/system/cpu/cpu2/cpufreq/scaling_governor",
- "sys/devices/system/cpu/cpu3/cpufreq/scaling_governor"
-};
+char scaling_gov_path[4][80] = {"sys/devices/system/cpu/cpu0/cpufreq/scaling_governor",
+ "sys/devices/system/cpu/cpu1/cpufreq/scaling_governor",
+ "sys/devices/system/cpu/cpu2/cpufreq/scaling_governor",
+ "sys/devices/system/cpu/cpu3/cpufreq/scaling_governor"};
#define PERF_HAL_PATH "libqti-perfd-client.so"
-static void *qcopt_handle;
-static int (*perf_lock_acq)(int handle, int duration,
- int list[], int numArgs);
+static void* qcopt_handle;
+static int (*perf_lock_acq)(int handle, int duration, int list[], int numArgs);
static int (*perf_lock_rel)(int handle);
-static int (*perf_hint)(int, const char *, int, int);
+static int (*perf_hint)(int, const char*, int, int);
static struct list_node active_hint_list_head;
-const char *pkg = "QTI PowerHAL";
+const char* pkg = "QTI PowerHAL";
-static void *get_qcopt_handle()
-{
- void *handle = NULL;
+static void* get_qcopt_handle() {
+ void* handle = NULL;
dlerror();
handle = dlopen(PERF_HAL_PATH, RTLD_NOW);
if (!handle) {
- ALOGE("Unable to open %s: %s\n", PERF_HAL_PATH,
- dlerror());
+ ALOGE("Unable to open %s: %s\n", PERF_HAL_PATH, dlerror());
}
return handle;
}
-static void __attribute__ ((constructor)) initialize(void)
-{
+static void __attribute__((constructor)) initialize(void) {
qcopt_handle = get_qcopt_handle();
if (!qcopt_handle) {
@@ -105,16 +99,13 @@ static void __attribute__ ((constructor)) initialize(void)
}
}
-static void __attribute__ ((destructor)) cleanup(void)
-{
+static void __attribute__((destructor)) cleanup(void) {
if (qcopt_handle) {
- if (dlclose(qcopt_handle))
- ALOGE("Error occurred while closing qc-opt library.");
+ if (dlclose(qcopt_handle)) ALOGE("Error occurred while closing qc-opt library.");
}
}
-int sysfs_read(char *path, char *s, int num_bytes)
-{
+int sysfs_read(char* path, char* s, int num_bytes) {
char buf[80];
int count;
int ret = 0;
@@ -141,8 +132,7 @@ int sysfs_read(char *path, char *s, int num_bytes)
return ret;
}
-int sysfs_write(char *path, char *s)
-{
+int sysfs_write(char* path, char* s) {
char buf[80];
int len;
int ret = 0;
@@ -151,7 +141,7 @@ int sysfs_write(char *path, char *s)
if (fd < 0) {
strerror_r(errno, buf, sizeof(buf));
ALOGE("Error opening %s: %s\n", path, buf);
- return -1 ;
+ return -1;
}
len = write(fd, s, strlen(s));
@@ -167,10 +157,8 @@ int sysfs_write(char *path, char *s)
return ret;
}
-int get_scaling_governor(char governor[], int size)
-{
- if (sysfs_read(SCALING_GOVERNOR_PATH, governor,
- size) == -1) {
+int get_scaling_governor(char governor[], int size) {
+ if (sysfs_read(SCALING_GOVERNOR_PATH, governor, size) == -1) {
// Can't obtain the scaling governor. Return.
return -1;
} else {
@@ -179,18 +167,14 @@ int get_scaling_governor(char governor[], int size)
len--;
- while (len >= 0 && (governor[len] == '\n' || governor[len] == '\r'))
- governor[len--] = '\0';
+ while (len >= 0 && (governor[len] == '\n' || governor[len] == '\r')) governor[len--] = '\0';
}
return 0;
}
-int get_scaling_governor_check_cores(char governor[], int size,int core_num)
-{
-
- if (sysfs_read(scaling_gov_path[core_num], governor,
- size) == -1) {
+int get_scaling_governor_check_cores(char governor[], int size, int core_num) {
+ if (sysfs_read(scaling_gov_path[core_num], governor, size) == -1) {
// Can't obtain the scaling governor. Return.
return -1;
}
@@ -198,99 +182,81 @@ int get_scaling_governor_check_cores(char governor[], int size,int core_num)
// Strip newline at the end.
int len = strlen(governor);
len--;
- while (len >= 0 && (governor[len] == '\n' || governor[len] == '\r'))
- governor[len--] = '\0';
+ while (len >= 0 && (governor[len] == '\n' || governor[len] == '\r')) governor[len--] = '\0';
return 0;
}
int is_interactive_governor(char* governor) {
- if (strncmp(governor, INTERACTIVE_GOVERNOR, (strlen(INTERACTIVE_GOVERNOR)+1)) == 0)
- return 1;
- return 0;
+ if (strncmp(governor, INTERACTIVE_GOVERNOR, (strlen(INTERACTIVE_GOVERNOR) + 1)) == 0) return 1;
+ return 0;
}
#ifndef INTERACTION_BOOST
-void interaction(int UNUSED(duration), int UNUSED(num_args), int UNUSED(opt_list[]))
-{
+void interaction(int UNUSED(duration), int UNUSED(num_args), int UNUSED(opt_list[])) {
#else
-void interaction(int duration, int num_args, int opt_list[])
-{
+void interaction(int duration, int num_args, int opt_list[]) {
static int lock_handle = 0;
- if (duration < 0 || num_args < 1 || opt_list[0] == 0)
- return;
+ if (duration < 0 || num_args < 1 || opt_list[0] == 0) return;
if (qcopt_handle) {
if (perf_lock_acq) {
lock_handle = perf_lock_acq(lock_handle, duration, opt_list, num_args);
- if (lock_handle == -1)
- ALOGE("Failed to acquire lock.");
+ if (lock_handle == -1) ALOGE("Failed to acquire lock.");
}
}
#endif
}
-int interaction_with_handle(int lock_handle, int duration, int num_args, int opt_list[])
-{
- if (duration < 0 || num_args < 1 || opt_list[0] == 0)
- return 0;
+int interaction_with_handle(int lock_handle, int duration, int num_args, int opt_list[]) {
+ if (duration < 0 || num_args < 1 || opt_list[0] == 0) return 0;
if (qcopt_handle) {
if (perf_lock_acq) {
lock_handle = perf_lock_acq(lock_handle, duration, opt_list, num_args);
- if (lock_handle == -1)
- ALOGE("Failed to acquire lock.");
+ if (lock_handle == -1) ALOGE("Failed to acquire lock.");
}
}
return lock_handle;
}
-//this is interaction_with_handle using perf_hint instead of
-//perf_lock_acq
-int perf_hint_enable(int hint_id , int duration)
-{
+// this is interaction_with_handle using perf_hint instead of
+// perf_lock_acq
+int perf_hint_enable(int hint_id, int duration) {
int lock_handle = 0;
- if (duration < 0)
- return 0;
+ if (duration < 0) return 0;
if (qcopt_handle) {
if (perf_hint) {
lock_handle = perf_hint(hint_id, pkg, duration, -1);
- if (lock_handle == -1)
- ALOGE("Failed to acquire lock for hint_id: %X.", hint_id);
+ if (lock_handle == -1) ALOGE("Failed to acquire lock for hint_id: %X.", hint_id);
}
}
return lock_handle;
}
-
void release_request(int lock_handle) {
- if (qcopt_handle && perf_lock_rel)
- perf_lock_rel(lock_handle);
+ if (qcopt_handle && perf_lock_rel) perf_lock_rel(lock_handle);
}
-void perform_hint_action(int hint_id, int resource_values[], int num_resources)
-{
+void perform_hint_action(int hint_id, int resource_values[], int num_resources) {
if (qcopt_handle) {
if (perf_lock_acq) {
/* Acquire an indefinite lock for the requested resources. */
- int lock_handle = perf_lock_acq(0, 0, resource_values,
- num_resources);
+ int lock_handle = perf_lock_acq(0, 0, resource_values, num_resources);
if (lock_handle == -1) {
ALOGE("Failed to acquire lock.");
} else {
/* Add this handle to our internal hint-list. */
- struct hint_data *new_hint =
- (struct hint_data *)malloc(sizeof(struct hint_data));
+ struct hint_data* new_hint = (struct hint_data*)malloc(sizeof(struct hint_data));
if (new_hint) {
if (!active_hint_list_head.compare) {
- active_hint_list_head.compare =
- (int (*)(void *, void *))hint_compare;
- active_hint_list_head.dump = (void (*)(void *))hint_dump;
+ active_hint_list_head.compare = (int (*)(void*, void*))hint_compare;
+ active_hint_list_head.dump = (void (*)(void*))hint_dump;
}
new_hint->hint_id = hint_id;
@@ -299,15 +265,13 @@ void perform_hint_action(int hint_id, int resource_values[], int num_resources)
if (add_list_node(&active_hint_list_head, new_hint) == NULL) {
free(new_hint);
/* Can't keep track of this lock. Release it. */
- if (perf_lock_rel)
- perf_lock_rel(lock_handle);
+ if (perf_lock_rel) perf_lock_rel(lock_handle);
ALOGE("Failed to process hint.");
}
} else {
/* Can't keep track of this lock. Release it. */
- if (perf_lock_rel)
- perf_lock_rel(lock_handle);
+ if (perf_lock_rel) perf_lock_rel(lock_handle);
ALOGE("Failed to process hint.");
}
@@ -316,23 +280,18 @@ void perform_hint_action(int hint_id, int resource_values[], int num_resources)
}
}
-void undo_hint_action(int hint_id)
-{
+void undo_hint_action(int hint_id) {
if (qcopt_handle) {
if (perf_lock_rel) {
/* Get hint-data associated with this hint-id */
- struct list_node *found_node;
- struct hint_data temp_hint_data = {
- .hint_id = hint_id
- };
+ struct list_node* found_node;
+ struct hint_data temp_hint_data = {.hint_id = hint_id};
- found_node = find_node(&active_hint_list_head,
- &temp_hint_data);
+ found_node = find_node(&active_hint_list_head, &temp_hint_data);
if (found_node) {
/* Release this lock. */
- struct hint_data *found_hint_data =
- (struct hint_data *)(found_node->data);
+ struct hint_data* found_hint_data = (struct hint_data*)(found_node->data);
if (found_hint_data) {
if (perf_lock_rel(found_hint_data->perflock_handle) == -1)
@@ -356,8 +315,7 @@ void undo_hint_action(int hint_id)
* Used to release initial lock holding
* two cores online when the display is on
*/
-void undo_initial_hint_action()
-{
+void undo_initial_hint_action() {
if (qcopt_handle) {
if (perf_lock_rel) {
perf_lock_rel(1);