power: clang-format

* Using AOSP interface .clang-format
* Clean Android.mk while we are at it

Change-Id: I630f72e3dffb676ca1930e72945e897f62103ada
Signed-off-by: Arian <arian.kulmer@web.de>
This commit is contained in:
Michael Bestas
2019-09-29 23:59:05 +03:00
parent 39e18570bf
commit 0b6459f08e
27 changed files with 634 additions and 809 deletions

151
utils.c
View File

@@ -29,54 +29,48 @@
#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 <utils/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 PropVal (*perf_get_prop)(const char *prop , const char *def_val);
static int (*perf_hint)(int, const char*, int, int);
static PropVal (*perf_get_prop)(const char* prop, const char* def_val);
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) {
@@ -111,16 +105,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;
@@ -147,8 +138,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;
@@ -157,7 +147,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));
@@ -173,10 +163,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 {
@@ -185,18 +173,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;
}
@@ -204,19 +188,17 @@ 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;
}
PropVal perf_get_property(const char *prop , const char *def_val) {
PropVal perf_get_property(const char* prop, const char* def_val) {
PropVal retVal;
if (qcopt_handle && perf_get_prop) {
retVal = perf_get_prop(prop, def_val);
@@ -226,84 +208,69 @@ PropVal perf_get_property(const char *prop , const char *def_val) {
return retVal;
}
void interaction(int duration, int num_args, int opt_list[])
{
void interaction(int duration, int num_args, int opt_list[]) {
#ifdef INTERACTION_BOOST
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;
@@ -312,15 +279,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.");
}
@@ -329,23 +294,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)
@@ -369,8 +329,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);