Merge "power: import and enable binderized power hal"

This commit is contained in:
Thierry Strudel
2017-03-30 04:49:38 +00:00
committed by Android (Google) Code Review
22 changed files with 2224 additions and 1 deletions

View File

@@ -80,7 +80,7 @@ MASTER_SIDE_CP_TARGET_LIST := msm8998 # ION specific settings
# Vendor Interface Manifest
PRODUCT_COPY_FILES += \
$(LOCAL_PATH)/manifest.xml:vendor/manifest.xml
$(LOCAL_PATH)/manifest.xml:$(TARGET_COPY_OUT_VENDOR)/manifest.xml
# A/B support
PRODUCT_PACKAGES += \
@@ -157,6 +157,15 @@ PRODUCT_COPY_FILES += \
PRODUCT_COPY_FILES += \
$(LOCAL_PATH)/init.power.sh:system/bin/init.power.sh \
# power HAL
PRODUCT_PACKAGES += \
power.$(PRODUCT_HARDWARE) \
android.hardware.power@1.0-impl \
android.hardware.power@1.0-service
PRODUCT_COPY_FILES += \
$(LOCAL_PATH)/powerhint.xml:$(TARGET_COPY_OUT_VENDOR)/etc/powerhint.xml
# graphics
PRODUCT_PROPERTY_OVERRIDES += \
ro.opengles.version=196610

View File

@@ -50,3 +50,6 @@ done
write /sys/class/devfreq/soc:qcom,mincpubw/governor "cpufreq"
# Signal perfd that boot has completed
setprop sys.post_boot.parsed 1

View File

@@ -61,4 +61,10 @@
<impl level="generic"></impl>
<version>1.0</version>
</hal>
<hal format="hidl">
<name>android.hardware.power</name>
<transport>hwbinder</transport>
<impl level="generic"></impl>
<version>1.0</version>
</hal>
</manifest>

27
power/Android.mk Normal file
View File

@@ -0,0 +1,27 @@
LOCAL_PATH := $(call my-dir)
ifeq ($(call is-vendor-board-platform,QCOM),true)
# HAL module implemenation stored in
# hw/<POWERS_HARDWARE_MODULE_ID>.<ro.hardware>.so
include $(CLEAR_VARS)
LOCAL_MODULE_RELATIVE_PATH := hw
LOCAL_SHARED_LIBRARIES := liblog libcutils libdl libxml2
LOCAL_SRC_FILES := power.c metadata-parser.c utils.c list.c hint-data.c powerhintparser.c
LOCAL_C_INCLUDES := external/libxml2/include \
external/icu/icu4c/source/common
ifeq ($(call is-board-platform-in-list,msm8998), true)
LOCAL_SRC_FILES += power-8998.c
endif
# Enable interaction boost all the time
LOCAL_CFLAGS += -DINTERACTION_BOOST
LOCAL_MODULE := power.$(TARGET_DEVICE)
LOCAL_MODULE_TAGS := optional
LOCAL_CFLAGS += -Wno-unused-parameter -Wno-unused-variable
include $(BUILD_SHARED_LIBRARY)
endif

47
power/hint-data.c Normal file
View File

@@ -0,0 +1,47 @@
/*
* Copyright (c) 2012, The Linux Foundation. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
* * * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials provided
* with the distribution.
* * Neither the name of The Linux Foundation nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "hint-data.h"
int hint_compare(struct hint_data *first_hint,
struct hint_data *other_hint) {
if (first_hint == other_hint) {
return 0;
} else if ((first_hint && other_hint) &&
(first_hint->hint_id == other_hint->hint_id)) {
return 0;
} else {
return 1;
}
}
void hint_dump(struct hint_data *hint)
{
/*ALOGI("hint_id: %lu", hint->hint_id);*/
}

48
power/hint-data.h Normal file
View File

@@ -0,0 +1,48 @@
/*
* Copyright (c) 2012, The Linux Foundation. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
* * * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials provided
* with the distribution.
* * Neither the name of The Linux Foundation nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/* Default use-case hint IDs */
#define DEFAULT_VIDEO_ENCODE_HINT_ID (0x0A00)
#define DEFAULT_VIDEO_DECODE_HINT_ID (0x0B00)
#define DISPLAY_STATE_HINT_ID (0x0C00)
#define DISPLAY_STATE_HINT_ID_2 (0x0D00)
#define CAM_PREVIEW_HINT_ID (0x0E00)
#define SUSTAINED_PERF_HINT_ID (0x0F00)
#define VR_MODE_HINT_ID (0x1000)
#define VR_MODE_SUSTAINED_PERF_HINT_ID (0x1001)
#define INTERACTION_HINT_ID (0x1A00)
struct hint_data {
unsigned long hint_id; /* This is our key. */
unsigned long perflock_handle;
};
int hint_compare(struct hint_data *first_hint,
struct hint_data *other_hint);
void hint_dump(struct hint_data *hint);

145
power/list.c Normal file
View File

@@ -0,0 +1,145 @@
/*
* Copyright (c) 2012, The Linux Foundation. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
* * * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials provided
* with the distribution.
* * Neither the name of The Linux Foundation nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "list.h"
#include <utils/Log.h>
int init_list_head(struct list_node *head)
{
if (head == NULL)
return -1;
memset(head, 0, sizeof(*head));
return 0;
}
struct list_node *add_list_node(struct list_node *head, void *data)
{
/* Create a new list_node. And put 'data' into it. */
struct list_node *new_node;
if (head == NULL) {
return NULL;
}
if (!(new_node = malloc(sizeof(struct list_node)))) {
return NULL;
}
new_node->data = data;
new_node->next = head->next;
new_node->compare = head->compare;
new_node->dump = head->dump;
head->next = new_node;
return new_node;
}
int is_list_empty(struct list_node *head)
{
return (head == NULL || head->next == NULL);
}
/*
* Delink and de-allocate 'node'.
*/
int remove_list_node(struct list_node *head, struct list_node *del_node)
{
struct list_node *current_node;
struct list_node *saved_node;
if (head == NULL || head->next == NULL) {
return -1;
}
current_node = head->next;
saved_node = head;
while (current_node && current_node != del_node) {
saved_node = current_node;
current_node = current_node->next;
}
if (saved_node) {
if (current_node) {
saved_node->next = current_node->next;
} else {
/* Node not found. */
return -1;
}
}
if (del_node) {
free(del_node);
}
return 0;
}
void dump_list(struct list_node *head)
{
struct list_node *current_node = head;
if (head == NULL)
return;
printf("List:\n");
while ((current_node = current_node->next)) {
if (current_node->dump) {
current_node->dump(current_node->data);
}
}
}
struct list_node *find_node(struct list_node *head, void *comparison_data)
{
struct list_node *current_node = head;
if (head == NULL)
return NULL;
while ((current_node = current_node->next)) {
if (current_node->compare) {
if (current_node->compare(current_node->data,
comparison_data) == 0) {
/* Match found. Return current_node. */
return current_node;
}
}
}
/* No match found. */
return NULL;
}

41
power/list.h Normal file
View File

@@ -0,0 +1,41 @@
/*
* Copyright (c) 2012, The Linux Foundation. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
* * * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials provided
* with the distribution.
* * Neither the name of The Linux Foundation nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
struct list_node {
struct list_node *next;
void *data;
int (*compare)(void *data1, void *data2);
void (*dump)(void *data);
};
int init_list_head(struct list_node *head);
struct list_node * add_list_node(struct list_node *head, void *data);
int remove_list_node(struct list_node *head, struct list_node *del_node);
void dump_list(struct list_node *head);
struct list_node *find_node(struct list_node *head, void *comparison_data);

54
power/metadata-defs.h Normal file
View File

@@ -0,0 +1,54 @@
/* Copyright (c) 2012, The Linux Foundation. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials provided
* with the distribution.
* * Neither the name of The Linux Foundation nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
#define ATTRIBUTE_VALUE_DELIM ('=')
#define ATTRIBUTE_STRING_DELIM (";")
#define METADATA_PARSING_ERR (-1)
#define METADATA_PARSING_CONTINUE (0)
#define METADATA_PARSING_DONE (1)
#define MIN(x,y) (((x)>(y))?(y):(x))
struct video_encode_metadata_t {
int hint_id;
int state;
};
struct video_decode_metadata_t {
int hint_id;
int state;
};
int parse_metadata(char *metadata, char **metadata_saveptr,
char *attribute, int attribute_size, char *value, int value_size);
int parse_video_encode_metadata(char *metadata,
struct video_encode_metadata_t *video_encode_metadata);
int parse_video_decode_metadata(char *metadata,
struct video_decode_metadata_t *video_decode_metadata);

133
power/metadata-parser.c Normal file
View File

@@ -0,0 +1,133 @@
/* Copyright (c) 2012, The Linux Foundation. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials provided
* with the distribution.
* * Neither the name of The Linux Foundation nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include "metadata-defs.h"
int parse_metadata(char *metadata, char **metadata_saveptr,
char *attribute, int attribute_size, char *value, int value_size)
{
char *attribute_string;
char *attribute_value_delim;
unsigned int bytes_to_copy;
attribute_string = strtok_r(metadata, ATTRIBUTE_STRING_DELIM,
metadata_saveptr);
if (attribute_string == NULL)
return METADATA_PARSING_DONE;
attribute[0] = value[0] = '\0';
if ((attribute_value_delim = strchr(attribute_string,
ATTRIBUTE_VALUE_DELIM)) != NULL) {
bytes_to_copy = MIN((attribute_value_delim - attribute_string),
attribute_size - 1);
/* Replace strncpy with strlcpy
* Add +1 to bytes_to_copy as strlcpy copies size-1 bytes */
strlcpy(attribute, attribute_string,
bytes_to_copy+1);
bytes_to_copy = MIN(strlen(attribute_string) - strlen(attribute) - 1,
value_size - 1);
/* Replace strncpy with strlcpy
* Add +1 to bytes_to_copy as strlcpy copies size-1 bytes */
strlcpy(value, attribute_value_delim + 1,
bytes_to_copy+1);
}
return METADATA_PARSING_CONTINUE;
}
int parse_video_encode_metadata(char *metadata,
struct video_encode_metadata_t *video_encode_metadata)
{
char attribute[1024], value[1024], *saveptr;
char *temp_metadata = metadata;
int parsing_status;
while ((parsing_status = parse_metadata(temp_metadata, &saveptr,
attribute, sizeof(attribute), value, sizeof(value))) == METADATA_PARSING_CONTINUE) {
if (strlen(attribute) == strlen("hint_id") &&
(strncmp(attribute, "hint_id", strlen("hint_id")) == 0)) {
if (strlen(value) > 0) {
video_encode_metadata->hint_id = atoi(value);
}
}
if (strlen(attribute) == strlen("state") &&
(strncmp(attribute, "state", strlen("state")) == 0)) {
if (strlen(value) > 0) {
video_encode_metadata->state = atoi(value);
}
}
temp_metadata = NULL;
}
if (parsing_status == METADATA_PARSING_ERR)
return -1;
return 0;
}
int parse_video_decode_metadata(char *metadata,
struct video_decode_metadata_t *video_decode_metadata)
{
char attribute[1024], value[1024], *saveptr;
char *temp_metadata = metadata;
int parsing_status;
while ((parsing_status = parse_metadata(temp_metadata, &saveptr,
attribute, sizeof(attribute), value, sizeof(value))) == METADATA_PARSING_CONTINUE) {
if (strlen(attribute) == strlen("hint_id") &&
(strncmp(attribute, "hint_id", strlen("hint_id")) == 0)) {
if (strlen(value) > 0) {
video_decode_metadata->hint_id = atoi(value);
}
}
if (strlen(attribute) == strlen("state") &&
(strncmp(attribute, "state", strlen("state")) == 0)) {
if (strlen(value) > 0) {
video_decode_metadata->state = atoi(value);
}
}
temp_metadata = NULL;
}
if (parsing_status == METADATA_PARSING_ERR)
return -1;
return 0;
}

View File

@@ -209,6 +209,11 @@ enum THREAD_MIGRATION_LVL {
THREAD_MIGRATION_SYNC_OFF = 0x1400,
};
enum SCHED_GUIDED_LVL {
INTERACTIVE_USE_SCHED_LOAD_OFF = 0x5201,
INTERACTIVE_USE_MIGRATION_NOTIF_OFF = 0x5301
};
enum INTERACTIVE_IO_BUSY_LVL {
INTERACTIVE_IO_BUSY_OFF = 0x1B00,
INTERACTIVE_IO_BUSY_ON = 0x1B01,

311
power/power-8998.c Normal file
View File

@@ -0,0 +1,311 @@
/*
* Copyright (c) 2016, The Linux Foundation. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
* * * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials provided
* with the distribution.
* * Neither the name of The Linux Foundation nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#define LOG_NIDEBUG 0
#include <errno.h>
#include <string.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <dlfcn.h>
#include <stdlib.h>
#define LOG_TAG "QTI PowerHAL"
#include <utils/Log.h>
#include <hardware/hardware.h>
#include <hardware/power.h>
#include "utils.h"
#include "metadata-defs.h"
#include "hint-data.h"
#include "performance.h"
#include "power-common.h"
#include "powerhintparser.h"
#define USINSEC 1000000L
#define NSINUS 1000L
static int sustained_mode_handle = 0;
static int vr_mode_handle = 0;
int sustained_performance_mode = 0;
int vr_mode = 0;
static pthread_mutex_t s_interaction_lock = PTHREAD_MUTEX_INITIALIZER;
#define CHECK_HANDLE(x) (((x)>0) && ((x)!=-1))
static struct timespec s_previous_boost_timespec;
static int s_previous_duration;
void interaction(int duration, int num_args, int opt_list[]);
static int process_sustained_perf_hint(void *data)
{
int duration = 0;
int *resource_values = NULL;
int resources = 0;
pthread_mutex_lock(&s_interaction_lock);
if (data && sustained_performance_mode == 0) {
if (vr_mode == 0) { // Sustained mode only.
resource_values = getPowerhint(SUSTAINED_PERF_HINT_ID, &resources);
if (!resource_values) {
ALOGE("Can't get sustained perf hints from xml ");
pthread_mutex_unlock(&s_interaction_lock);
return HINT_NONE;
}
sustained_mode_handle = interaction_with_handle(
sustained_mode_handle, duration, resources, resource_values);
if (!CHECK_HANDLE(sustained_mode_handle)) {
ALOGE("Failed interaction_with_handle for sustained_mode_handle");
pthread_mutex_unlock(&s_interaction_lock);
return HINT_NONE;
}
} else if (vr_mode == 1) { // Sustained + VR mode.
release_request(vr_mode_handle);
resource_values = getPowerhint(VR_MODE_SUSTAINED_PERF_HINT_ID, &resources);
if (!resource_values) {
ALOGE("Can't get VR mode sustained perf hints from xml ");
pthread_mutex_unlock(&s_interaction_lock);
return HINT_NONE;
}
sustained_mode_handle = interaction_with_handle(
sustained_mode_handle, duration, resources, resource_values);
if (!CHECK_HANDLE(sustained_mode_handle)) {
ALOGE("Failed interaction_with_handle for sustained_mode_handle");
pthread_mutex_unlock(&s_interaction_lock);
return HINT_NONE;
}
}
sustained_performance_mode = 1;
} else if (sustained_performance_mode == 1) {
release_request(sustained_mode_handle);
if (vr_mode == 1) { // Switch back to VR Mode.
resource_values = getPowerhint(VR_MODE_HINT_ID, &resources);
if (!resource_values) {
ALOGE("Can't get VR mode perf hints from xml ");
pthread_mutex_unlock(&s_interaction_lock);
return HINT_NONE;
}
vr_mode_handle = interaction_with_handle(
vr_mode_handle, duration, resources, resource_values);
if (!CHECK_HANDLE(vr_mode_handle)) {
ALOGE("Failed interaction_with_handle for vr_mode_handle");
pthread_mutex_unlock(&s_interaction_lock);
return HINT_NONE;
}
}
sustained_performance_mode = 0;
}
pthread_mutex_unlock(&s_interaction_lock);
return HINT_HANDLED;
}
static int process_vr_mode_hint(void *data)
{
int duration = 0;
int *resource_values = NULL;
int resources = 0;
pthread_mutex_lock(&s_interaction_lock);
if (data && vr_mode == 0) {
if (sustained_performance_mode == 0) { // VR mode only.
resource_values = getPowerhint(VR_MODE_HINT_ID, &resources);
if (!resource_values) {
ALOGE("Can't get VR mode perf hints from xml ");
pthread_mutex_unlock(&s_interaction_lock);
return HINT_NONE;
}
vr_mode_handle = interaction_with_handle(
vr_mode_handle, duration, resources, resource_values);
if (!CHECK_HANDLE(vr_mode_handle)) {
ALOGE("Failed interaction_with_handle for vr_mode_handle");
pthread_mutex_unlock(&s_interaction_lock);
return HINT_NONE;
}
} else if (sustained_performance_mode == 1) { // Sustained + VR mode.
release_request(sustained_mode_handle);
resource_values = getPowerhint(VR_MODE_SUSTAINED_PERF_HINT_ID, &resources);
if (!resource_values) {
ALOGE("Can't get VR mode sustained perf hints from xml ");
pthread_mutex_unlock(&s_interaction_lock);
return HINT_NONE;
}
vr_mode_handle = interaction_with_handle(
vr_mode_handle, duration, resources, resource_values);
if (!CHECK_HANDLE(vr_mode_handle)) {
ALOGE("Failed interaction_with_handle for vr_mode_handle");
pthread_mutex_unlock(&s_interaction_lock);
return HINT_NONE;
}
}
vr_mode = 1;
} else if (vr_mode == 1) {
release_request(vr_mode_handle);
if (sustained_performance_mode == 1) { // Switch back to sustained Mode.
resource_values = getPowerhint(SUSTAINED_PERF_HINT_ID, &resources);
if (!resource_values) {
ALOGE("Can't get sustained perf hints from xml ");
pthread_mutex_unlock(&s_interaction_lock);
return HINT_NONE;
}
sustained_mode_handle = interaction_with_handle(
sustained_mode_handle, duration, resources, resource_values);
if (!CHECK_HANDLE(sustained_mode_handle)) {
ALOGE("Failed interaction_with_handle for sustained_mode_handle");
pthread_mutex_unlock(&s_interaction_lock);
return HINT_NONE;
}
}
vr_mode = 0;
}
pthread_mutex_unlock(&s_interaction_lock);
return HINT_HANDLED;
}
static int process_video_encode_hint(void *metadata)
{
char governor[80];
struct video_encode_metadata_t video_encode_metadata;
if(!metadata)
return HINT_NONE;
if (get_scaling_governor(governor, sizeof(governor)) == -1) {
ALOGE("Can't obtain scaling governor.");
return HINT_NONE;
}
/* Initialize encode metadata struct fields */
memset(&video_encode_metadata, 0, sizeof(struct video_encode_metadata_t));
video_encode_metadata.state = -1;
video_encode_metadata.hint_id = DEFAULT_VIDEO_ENCODE_HINT_ID;
if (parse_video_encode_metadata((char *)metadata, &video_encode_metadata) ==
-1) {
ALOGE("Error occurred while parsing metadata.");
return HINT_NONE;
}
if (video_encode_metadata.state == 1) {
if (is_interactive_governor(governor)) {
int *resource_values;
int resources;
/* extract perflock resources */
resource_values = getPowerhint(video_encode_metadata.hint_id, &resources);
if (resource_values != NULL)
perform_hint_action(video_encode_metadata.hint_id, resource_values, resources);
ALOGI("Video Encode hint start");
return HINT_HANDLED;
}
} else if (video_encode_metadata.state == 0) {
if (is_interactive_governor(governor)) {
undo_hint_action(video_encode_metadata.hint_id);
ALOGI("Video Encode hint stop");
return HINT_HANDLED;
}
}
return HINT_NONE;
}
static long long calc_timespan_us(struct timespec start, struct timespec end) {
long long diff_in_us = 0;
diff_in_us += (end.tv_sec - start.tv_sec) * USINSEC;
diff_in_us += (end.tv_nsec - start.tv_nsec) / NSINUS;
return diff_in_us;
}
static int interaction_hint(void *data)
{
if (sustained_performance_mode || vr_mode) {
ALOGW("%s: already handled?", __FUNCTION__);
return HINT_HANDLED;
}
int duration = 1500; // 1.5s by default
if (data) {
int input_duration = *((int*)data) + 750;
if (input_duration > duration) {
duration = (input_duration > 5750) ? 5750 : input_duration;
}
}
struct timespec cur_boost_timespec;
clock_gettime(CLOCK_MONOTONIC, &cur_boost_timespec);
long long elapsed_time = calc_timespan_us(s_previous_boost_timespec, cur_boost_timespec);
// don't hint if previous hint's duration covers this hint's duration
if ((s_previous_duration * 1000) > (elapsed_time + duration * 1000)) {
return HINT_HANDLED;
}
s_previous_boost_timespec = cur_boost_timespec;
s_previous_duration = duration;
int *resource_values;
int num_resources;
/* extract perflock resources */
resource_values = getPowerhint(INTERACTION_HINT_ID, &num_resources);
if (resource_values != NULL)
interaction(duration, num_resources, resource_values);
return HINT_HANDLED;
}
int power_hint_override(struct power_module *module, power_hint_t hint, void *data)
{
int ret_val = HINT_NONE;
switch(hint) {
case POWER_HINT_VIDEO_ENCODE:
ret_val = process_video_encode_hint(data);
break;
case POWER_HINT_SUSTAINED_PERFORMANCE:
ret_val = process_sustained_perf_hint(data);
break;
case POWER_HINT_VR_MODE:
ret_val = process_vr_mode_hint(data);
break;
case POWER_HINT_INTERACTION:
pthread_mutex_lock(&s_interaction_lock);
ret_val = interaction_hint(data);
pthread_mutex_unlock(&s_interaction_lock);
break;
default:
break;
}
return ret_val;
}
int set_interactive_override(struct power_module *module, int on)
{
return HINT_HANDLED; /* Don't excecute this code path, not in use */
}

50
power/power-common.h Normal file
View File

@@ -0,0 +1,50 @@
/*
* Copyright (c) 2013, The Linux Foundation. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
* * * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials provided
* with the distribution.
* * Neither the name of The Linux Foundation nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#define NODE_MAX (64)
#define SCALING_GOVERNOR_PATH "/sys/devices/system/cpu/cpu0/cpufreq/scaling_governor"
#define DCVS_CPU0_SLACK_MAX_NODE "/sys/module/msm_dcvs/cores/cpu0/slack_time_max_us"
#define DCVS_CPU0_SLACK_MIN_NODE "/sys/module/msm_dcvs/cores/cpu0/slack_time_min_us"
#define MPDECISION_SLACK_MAX_NODE "/sys/module/msm_mpdecision/slack_time_max_us"
#define MPDECISION_SLACK_MIN_NODE "/sys/module/msm_mpdecision/slack_time_min_us"
#define SCALING_MIN_FREQ "/sys/devices/system/cpu/cpu0/cpufreq/scaling_min_freq"
#define ONDEMAND_GOVERNOR "ondemand"
#define INTERACTIVE_GOVERNOR "interactive"
#define MSMDCVS_GOVERNOR "msm-dcvs"
#define SCHED_GOVERNOR "sched"
#define HINT_HANDLED (0)
#define HINT_NONE (-1)
enum CPU_GOV_CHECK {
CPU0 = 0,
CPU1 = 1,
CPU2 = 2,
CPU3 = 3
};

635
power/power.c Normal file
View File

@@ -0,0 +1,635 @@
/*
* Copyright (c) 2012-2013, The Linux Foundation. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
* * * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials provided
* with the distribution.
* * Neither the name of The Linux Foundation nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#define LOG_NIDEBUG 0
#include <errno.h>
#include <inttypes.h>
#include <string.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <dlfcn.h>
#include <stdlib.h>
#define LOG_TAG "QCOM PowerHAL"
#include <utils/Log.h>
#include <hardware/hardware.h>
#include <hardware/power.h>
#include "utils.h"
#include "metadata-defs.h"
#include "hint-data.h"
#include "performance.h"
#include "power-common.h"
#define PLATFORM_SLEEP_MODES 2
#define XO_VOTERS 4
#define VMIN_VOTERS 0
#define RPM_PARAMETERS 4
#define NUM_PARAMETERS 12
#ifndef RPM_STAT
#define RPM_STAT "/d/rpm_stats"
#endif
#ifndef RPM_MASTER_STAT
#define RPM_MASTER_STAT "/d/rpm_master_stats"
#endif
/* RPM runs at 19.2Mhz. Divide by 19200 for msec */
#define RPM_CLK 19200
const char *parameter_names[] = {
"vlow_count",
"accumulated_vlow_time",
"vmin_count",
"accumulated_vmin_time",
"xo_accumulated_duration",
"xo_count",
"xo_accumulated_duration",
"xo_count",
"xo_accumulated_duration",
"xo_count",
"xo_accumulated_duration",
"xo_count"
};
static int saved_dcvs_cpu0_slack_max = -1;
static int saved_dcvs_cpu0_slack_min = -1;
static int saved_mpdecision_slack_max = -1;
static int saved_mpdecision_slack_min = -1;
static int saved_interactive_mode = -1;
static int slack_node_rw_failed = 0;
static int display_hint_sent;
static void power_init(struct power_module *module)
{
ALOGI("QCOM power HAL initing.");
}
static void process_video_decode_hint(void *metadata)
{
char governor[80];
struct video_decode_metadata_t video_decode_metadata;
if (get_scaling_governor(governor, sizeof(governor)) == -1) {
ALOGE("Can't obtain scaling governor.");
return;
}
if (metadata) {
ALOGI("Processing video decode hint. Metadata: %s", (char *)metadata);
}
/* Initialize encode metadata struct fields. */
memset(&video_decode_metadata, 0, sizeof(struct video_decode_metadata_t));
video_decode_metadata.state = -1;
video_decode_metadata.hint_id = DEFAULT_VIDEO_DECODE_HINT_ID;
if (metadata) {
if (parse_video_decode_metadata((char *)metadata, &video_decode_metadata) ==
-1) {
ALOGE("Error occurred while parsing metadata.");
return;
}
} else {
return;
}
if (video_decode_metadata.state == 1) {
if ((strncmp(governor, ONDEMAND_GOVERNOR, strlen(ONDEMAND_GOVERNOR)) == 0) &&
(strlen(governor) == strlen(ONDEMAND_GOVERNOR))) {
int resource_values[] = {THREAD_MIGRATION_SYNC_OFF};
perform_hint_action(video_decode_metadata.hint_id,
resource_values, sizeof(resource_values)/sizeof(resource_values[0]));
} else if ((strncmp(governor, INTERACTIVE_GOVERNOR, strlen(INTERACTIVE_GOVERNOR)) == 0) &&
(strlen(governor) == strlen(INTERACTIVE_GOVERNOR))) {
int resource_values[] = {TR_MS_30, HISPEED_LOAD_90, HS_FREQ_1026, THREAD_MIGRATION_SYNC_OFF};
perform_hint_action(video_decode_metadata.hint_id,
resource_values, sizeof(resource_values)/sizeof(resource_values[0]));
}
} else if (video_decode_metadata.state == 0) {
if ((strncmp(governor, ONDEMAND_GOVERNOR, strlen(ONDEMAND_GOVERNOR)) == 0) &&
(strlen(governor) == strlen(ONDEMAND_GOVERNOR))) {
} else if ((strncmp(governor, INTERACTIVE_GOVERNOR, strlen(INTERACTIVE_GOVERNOR)) == 0) &&
(strlen(governor) == strlen(INTERACTIVE_GOVERNOR))) {
undo_hint_action(video_decode_metadata.hint_id);
}
}
}
static void process_video_encode_hint(void *metadata)
{
char governor[80];
struct video_encode_metadata_t video_encode_metadata;
if (get_scaling_governor(governor, sizeof(governor)) == -1) {
ALOGE("Can't obtain scaling governor.");
return;
}
/* Initialize encode metadata struct fields. */
memset(&video_encode_metadata, 0, sizeof(struct video_encode_metadata_t));
video_encode_metadata.state = -1;
video_encode_metadata.hint_id = DEFAULT_VIDEO_ENCODE_HINT_ID;
if (metadata) {
if (parse_video_encode_metadata((char *)metadata, &video_encode_metadata) ==
-1) {
ALOGE("Error occurred while parsing metadata.");
return;
}
} else {
return;
}
if (video_encode_metadata.state == 1) {
if ((strncmp(governor, ONDEMAND_GOVERNOR, strlen(ONDEMAND_GOVERNOR)) == 0) &&
(strlen(governor) == strlen(ONDEMAND_GOVERNOR))) {
int resource_values[] = {IO_BUSY_OFF, SAMPLING_DOWN_FACTOR_1, THREAD_MIGRATION_SYNC_OFF};
perform_hint_action(video_encode_metadata.hint_id,
resource_values, sizeof(resource_values)/sizeof(resource_values[0]));
} else if ((strncmp(governor, INTERACTIVE_GOVERNOR, strlen(INTERACTIVE_GOVERNOR)) == 0) &&
(strlen(governor) == strlen(INTERACTIVE_GOVERNOR))) {
int resource_values[] = {TR_MS_30, HISPEED_LOAD_90, HS_FREQ_1026, THREAD_MIGRATION_SYNC_OFF,
INTERACTIVE_IO_BUSY_OFF};
perform_hint_action(video_encode_metadata.hint_id,
resource_values, sizeof(resource_values)/sizeof(resource_values[0]));
}
} else if (video_encode_metadata.state == 0) {
if ((strncmp(governor, ONDEMAND_GOVERNOR, strlen(ONDEMAND_GOVERNOR)) == 0) &&
(strlen(governor) == strlen(ONDEMAND_GOVERNOR))) {
undo_hint_action(video_encode_metadata.hint_id);
} else if ((strncmp(governor, INTERACTIVE_GOVERNOR, strlen(INTERACTIVE_GOVERNOR)) == 0) &&
(strlen(governor) == strlen(INTERACTIVE_GOVERNOR))) {
undo_hint_action(video_encode_metadata.hint_id);
}
}
}
int __attribute__ ((weak)) power_hint_override(struct power_module *module, power_hint_t hint,
void *data)
{
return HINT_NONE;
}
/* Declare function before use */
void interaction(int duration, int num_args, int opt_list[]);
static void power_hint(struct power_module *module, power_hint_t hint,
void *data)
{
/* Check if this hint has been overridden. */
if (power_hint_override(module, hint, data) == HINT_HANDLED) {
/* The power_hint has been handled. We can skip the rest. */
return;
}
switch(hint) {
case POWER_HINT_VSYNC:
break;
case POWER_HINT_SUSTAINED_PERFORMANCE:
ALOGI("Sustained perf power hint not handled in power_hint_override");
break;
case POWER_HINT_VR_MODE:
ALOGI("VR mode power hint not handled in power_hint_override");
break;
case POWER_HINT_INTERACTION:
{
int resources[] = {0x702, 0x20F, 0x30F};
int duration = 3000;
interaction(duration, sizeof(resources)/sizeof(resources[0]), resources);
}
break;
case POWER_HINT_VIDEO_ENCODE:
process_video_encode_hint(data);
break;
case POWER_HINT_VIDEO_DECODE:
process_video_decode_hint(data);
break;
default:
break;
}
}
int __attribute__ ((weak)) set_interactive_override(struct power_module *module, int on)
{
return HINT_NONE;
}
void set_interactive(struct power_module *module, int on)
{
char governor[80];
char tmp_str[NODE_MAX];
struct video_encode_metadata_t video_encode_metadata;
int rc = 0;
if (set_interactive_override(module, on) == HINT_HANDLED) {
return;
}
ALOGI("Got set_interactive hint");
if (get_scaling_governor(governor, sizeof(governor)) == -1) {
ALOGE("Can't obtain scaling governor.");
return;
}
if (!on) {
/* Display off. */
if ((strncmp(governor, ONDEMAND_GOVERNOR, strlen(ONDEMAND_GOVERNOR)) == 0) &&
(strlen(governor) == strlen(ONDEMAND_GOVERNOR))) {
int resource_values[] = {DISPLAY_OFF, MS_500, THREAD_MIGRATION_SYNC_OFF};
if (!display_hint_sent) {
perform_hint_action(DISPLAY_STATE_HINT_ID,
resource_values, sizeof(resource_values)/sizeof(resource_values[0]));
display_hint_sent = 1;
}
} else if ((strncmp(governor, INTERACTIVE_GOVERNOR, strlen(INTERACTIVE_GOVERNOR)) == 0) &&
(strlen(governor) == strlen(INTERACTIVE_GOVERNOR))) {
int resource_values[] = {TR_MS_50, THREAD_MIGRATION_SYNC_OFF};
if (!display_hint_sent) {
perform_hint_action(DISPLAY_STATE_HINT_ID,
resource_values, sizeof(resource_values)/sizeof(resource_values[0]));
display_hint_sent = 1;
}
} else if ((strncmp(governor, MSMDCVS_GOVERNOR, strlen(MSMDCVS_GOVERNOR)) == 0) &&
(strlen(governor) == strlen(MSMDCVS_GOVERNOR))) {
if (saved_interactive_mode == 1){
/* Display turned off. */
if (sysfs_read(DCVS_CPU0_SLACK_MAX_NODE, tmp_str, NODE_MAX - 1)) {
if (!slack_node_rw_failed) {
ALOGE("Failed to read from %s", DCVS_CPU0_SLACK_MAX_NODE);
}
rc = 1;
} else {
saved_dcvs_cpu0_slack_max = atoi(tmp_str);
}
if (sysfs_read(DCVS_CPU0_SLACK_MIN_NODE, tmp_str, NODE_MAX - 1)) {
if (!slack_node_rw_failed) {
ALOGE("Failed to read from %s", DCVS_CPU0_SLACK_MIN_NODE);
}
rc = 1;
} else {
saved_dcvs_cpu0_slack_min = atoi(tmp_str);
}
if (sysfs_read(MPDECISION_SLACK_MAX_NODE, tmp_str, NODE_MAX - 1)) {
if (!slack_node_rw_failed) {
ALOGE("Failed to read from %s", MPDECISION_SLACK_MAX_NODE);
}
rc = 1;
} else {
saved_mpdecision_slack_max = atoi(tmp_str);
}
if (sysfs_read(MPDECISION_SLACK_MIN_NODE, tmp_str, NODE_MAX - 1)) {
if(!slack_node_rw_failed) {
ALOGE("Failed to read from %s", MPDECISION_SLACK_MIN_NODE);
}
rc = 1;
} else {
saved_mpdecision_slack_min = atoi(tmp_str);
}
/* Write new values. */
if (saved_dcvs_cpu0_slack_max != -1) {
snprintf(tmp_str, NODE_MAX, "%d", 10 * saved_dcvs_cpu0_slack_max);
if (sysfs_write(DCVS_CPU0_SLACK_MAX_NODE, tmp_str) != 0) {
if (!slack_node_rw_failed) {
ALOGE("Failed to write to %s", DCVS_CPU0_SLACK_MAX_NODE);
}
rc = 1;
}
}
if (saved_dcvs_cpu0_slack_min != -1) {
snprintf(tmp_str, NODE_MAX, "%d", 10 * saved_dcvs_cpu0_slack_min);
if (sysfs_write(DCVS_CPU0_SLACK_MIN_NODE, tmp_str) != 0) {
if(!slack_node_rw_failed) {
ALOGE("Failed to write to %s", DCVS_CPU0_SLACK_MIN_NODE);
}
rc = 1;
}
}
if (saved_mpdecision_slack_max != -1) {
snprintf(tmp_str, NODE_MAX, "%d", 10 * saved_mpdecision_slack_max);
if (sysfs_write(MPDECISION_SLACK_MAX_NODE, tmp_str) != 0) {
if(!slack_node_rw_failed) {
ALOGE("Failed to write to %s", MPDECISION_SLACK_MAX_NODE);
}
rc = 1;
}
}
if (saved_mpdecision_slack_min != -1) {
snprintf(tmp_str, NODE_MAX, "%d", 10 * saved_mpdecision_slack_min);
if (sysfs_write(MPDECISION_SLACK_MIN_NODE, tmp_str) != 0) {
if(!slack_node_rw_failed) {
ALOGE("Failed to write to %s", MPDECISION_SLACK_MIN_NODE);
}
rc = 1;
}
}
}
slack_node_rw_failed = rc;
}
} else {
/* Display on. */
if ((strncmp(governor, ONDEMAND_GOVERNOR, strlen(ONDEMAND_GOVERNOR)) == 0) &&
(strlen(governor) == strlen(ONDEMAND_GOVERNOR))) {
undo_hint_action(DISPLAY_STATE_HINT_ID);
display_hint_sent = 0;
} else if ((strncmp(governor, INTERACTIVE_GOVERNOR, strlen(INTERACTIVE_GOVERNOR)) == 0) &&
(strlen(governor) == strlen(INTERACTIVE_GOVERNOR))) {
undo_hint_action(DISPLAY_STATE_HINT_ID);
display_hint_sent = 0;
} else if ((strncmp(governor, MSMDCVS_GOVERNOR, strlen(MSMDCVS_GOVERNOR)) == 0) &&
(strlen(governor) == strlen(MSMDCVS_GOVERNOR))) {
if (saved_interactive_mode == -1 || saved_interactive_mode == 0) {
/* Display turned on. Restore if possible. */
if (saved_dcvs_cpu0_slack_max != -1) {
snprintf(tmp_str, NODE_MAX, "%d", saved_dcvs_cpu0_slack_max);
if (sysfs_write(DCVS_CPU0_SLACK_MAX_NODE, tmp_str) != 0) {
if (!slack_node_rw_failed) {
ALOGE("Failed to write to %s", DCVS_CPU0_SLACK_MAX_NODE);
}
rc = 1;
}
}
if (saved_dcvs_cpu0_slack_min != -1) {
snprintf(tmp_str, NODE_MAX, "%d", saved_dcvs_cpu0_slack_min);
if (sysfs_write(DCVS_CPU0_SLACK_MIN_NODE, tmp_str) != 0) {
if (!slack_node_rw_failed) {
ALOGE("Failed to write to %s", DCVS_CPU0_SLACK_MIN_NODE);
}
rc = 1;
}
}
if (saved_mpdecision_slack_max != -1) {
snprintf(tmp_str, NODE_MAX, "%d", saved_mpdecision_slack_max);
if (sysfs_write(MPDECISION_SLACK_MAX_NODE, tmp_str) != 0) {
if (!slack_node_rw_failed) {
ALOGE("Failed to write to %s", MPDECISION_SLACK_MAX_NODE);
}
rc = 1;
}
}
if (saved_mpdecision_slack_min != -1) {
snprintf(tmp_str, NODE_MAX, "%d", saved_mpdecision_slack_min);
if (sysfs_write(MPDECISION_SLACK_MIN_NODE, tmp_str) != 0) {
if (!slack_node_rw_failed) {
ALOGE("Failed to write to %s", MPDECISION_SLACK_MIN_NODE);
}
rc = 1;
}
}
}
slack_node_rw_failed = rc;
}
}
saved_interactive_mode = !!on;
}
static ssize_t get_number_of_platform_modes(struct power_module *module) {
return PLATFORM_SLEEP_MODES;
}
static int get_voter_list(struct power_module *module, size_t *voter) {
voter[0] = XO_VOTERS;
voter[1] = VMIN_VOTERS;
return 0;
}
static int extract_stats(uint64_t *list, char *file,
unsigned int num_parameters, unsigned int index) {
FILE *fp;
ssize_t read;
size_t len;
char *line;
int ret;
fp = fopen(file, "r");
if (fp == NULL) {
ret = -errno;
ALOGE("%s: failed to open: %s", __func__, strerror(errno));
return ret;
}
for (line = NULL, len = 0;
((read = getline(&line, &len, fp) != -1) && (index < num_parameters));
free(line), line = NULL, len = 0) {
uint64_t value;
char* offset;
size_t begin = strspn(line, " \t");
if (strncmp(line + begin, parameter_names[index], strlen(parameter_names[index]))) {
continue;
}
offset = memchr(line, ':', len);
if (!offset) {
continue;
}
if (!strcmp(file, RPM_MASTER_STAT)) {
/* RPM_MASTER_STAT is reported in hex */
sscanf(offset, ":%" SCNx64, &value);
/* Duration is reported in rpm SLEEP TICKS */
if (!strcmp(parameter_names[index], "xo_accumulated_duration")) {
value /= RPM_CLK;
}
} else {
/* RPM_STAT is reported in decimal */
sscanf(offset, ":%" SCNu64, &value);
}
list[index] = value;
index++;
}
free(line);
fclose(fp);
return 0;
}
static int get_platform_low_power_stats(struct power_module *module,
power_state_platform_sleep_state_t *list) {
uint64_t stats[sizeof(parameter_names)] = {0};
int ret;
if (!list) {
return -EINVAL;
}
ret = extract_stats(stats, RPM_STAT, RPM_PARAMETERS, 0);
if (ret) {
return ret;
}
ret = extract_stats(stats, RPM_MASTER_STAT, NUM_PARAMETERS, RPM_PARAMETERS);
if (ret) {
return ret;
}
/* Update statistics for XO_shutdown */
strcpy(list[0].name, "XO_shutdown");
list[0].total_transitions = stats[0];
list[0].residency_in_msec_since_boot = stats[1];
list[0].supported_only_in_suspend = false;
list[0].number_of_voters = XO_VOTERS;
/* Update statistics for APSS voter */
strcpy(list[0].voters[0].name, "APSS");
list[0].voters[0].total_time_in_msec_voted_for_since_boot = stats[4];
list[0].voters[0].total_number_of_times_voted_since_boot = stats[5];
/* Update statistics for MPSS voter */
strcpy(list[0].voters[1].name, "MPSS");
list[0].voters[1].total_time_in_msec_voted_for_since_boot = stats[6];
list[0].voters[1].total_number_of_times_voted_since_boot = stats[7];
/* Update statistics for ADSP voter */
strcpy(list[0].voters[2].name, "ADSP");
list[0].voters[2].total_time_in_msec_voted_for_since_boot = stats[8];
list[0].voters[2].total_number_of_times_voted_since_boot = stats[9];
/* Update statistics for SLPI voter */
strcpy(list[0].voters[3].name, "SLPI");
list[0].voters[3].total_time_in_msec_voted_for_since_boot = stats[10];
list[0].voters[3].total_number_of_times_voted_since_boot = stats[11];
/* Update statistics for VMIN state */
strcpy(list[1].name, "VMIN");
list[1].total_transitions = stats[2];
list[1].residency_in_msec_since_boot = stats[3];
list[1].supported_only_in_suspend = false;
list[1].number_of_voters = VMIN_VOTERS;
return 0;
}
static int power_open(const hw_module_t* module, const char* name,
hw_device_t** device)
{
ALOGD("%s: enter; name=%s", __FUNCTION__, name);
int retval = 0; /* 0 is ok; -1 is error */
if (strcmp(name, POWER_HARDWARE_MODULE_ID) == 0) {
power_module_t *dev = (power_module_t *)calloc(1,
sizeof(power_module_t));
if (dev) {
/* Common hw_device_t fields */
dev->common.tag = HARDWARE_MODULE_TAG;
dev->common.module_api_version = POWER_MODULE_API_VERSION_0_5;
dev->common.module_api_version = HARDWARE_HAL_API_VERSION;
dev->init = power_init;
dev->powerHint = power_hint;
dev->setInteractive = set_interactive;
dev->get_number_of_platform_modes = get_number_of_platform_modes;
dev->get_platform_low_power_stats = get_platform_low_power_stats;
dev->get_voter_list = get_voter_list;
*device = (hw_device_t*)dev;
} else
retval = -ENOMEM;
} else {
retval = -EINVAL;
}
ALOGD("%s: exit %d", __FUNCTION__, retval);
return retval;
}
static struct hw_module_methods_t power_module_methods = {
.open = power_open,
};
struct power_module HAL_MODULE_INFO_SYM = {
.common = {
.tag = HARDWARE_MODULE_TAG,
.module_api_version = POWER_MODULE_API_VERSION_0_5,
.hal_api_version = HARDWARE_HAL_API_VERSION,
.id = POWER_HARDWARE_MODULE_ID,
.name = "QCOM Power HAL",
.author = "Qualcomm",
.methods = &power_module_methods,
},
.init = power_init,
.powerHint = power_hint,
.setInteractive = set_interactive,
.get_number_of_platform_modes = get_number_of_platform_modes,
.get_platform_low_power_stats = get_platform_low_power_stats,
.get_voter_list = get_voter_list
};

178
power/powerhintparser.c Normal file
View File

@@ -0,0 +1,178 @@
/* Copyright (c) 2016-2017, The Linux Foundation. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials provided
* with the distribution.
* * Neither the name of The Linux Foundation nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
#include <cutils/log.h>
#include <fcntl.h>
#include <string.h>
#include <cutils/properties.h>
#include <libxml/parser.h>
#include <libxml/tree.h>
#include "powerhintparser.h"
#define LOG_TAG "QCOM PowerHAL"
int parsePowerhintXML() {
xmlDocPtr doc;
xmlNodePtr currNode;
const char *opcode_str, *value_str, *type_str;
int opcode = 0, value = 0, type = 0;
int numParams = 0;
static int hintCount;
if(access(POWERHINT_XML, F_OK) < 0) {
return -1;
}
doc = xmlReadFile(POWERHINT_XML, "UTF-8", XML_PARSE_RECOVER);
if(!doc) {
ALOGE("Document not parsed successfully");
return -1;
}
currNode = xmlDocGetRootElement(doc);
if(!currNode) {
ALOGE("Empty document");
xmlFreeDoc(doc);
xmlCleanupParser();
return -1;
}
// Confirm the root-element of the tree
if(xmlStrcmp(currNode->name, BAD_CAST "Powerhint")) {
ALOGE("document of the wrong type, root node != root");
xmlFreeDoc(doc);
xmlCleanupParser();
return -1;
}
currNode = currNode->xmlChildrenNode;
for(; currNode != NULL; currNode=currNode->next) {
if(currNode->type != XML_ELEMENT_NODE)
continue;
xmlNodePtr node = currNode;
if(hintCount == MAX_HINT) {
ALOGE("Number of hints exceeded the max count of %d\n",MAX_HINT);
break;
}
if(!xmlStrcmp(node->name, BAD_CAST "Hint")) {
if(xmlHasProp(node, BAD_CAST "type")) {
type_str = (const char*)xmlGetProp(node, BAD_CAST "type");
if (type_str == NULL)
{
ALOGE("xmlGetProp failed on type");
xmlFreeDoc(doc);
xmlCleanupParser();
return -1;
}
type = strtol(type_str, NULL, 16);
}
node = node->children;
while(node != NULL) {
if(!xmlStrcmp(node->name, BAD_CAST "Resource")) {
if(xmlHasProp(node, BAD_CAST "opcode")) {
opcode_str = (const char*)xmlGetProp(node, BAD_CAST "opcode");
if (opcode_str == NULL)
{
ALOGE("xmlGetProp failed on opcode");
xmlFreeDoc(doc);
xmlCleanupParser();
return -1;
}
opcode = strtol(opcode_str, NULL, 16);
}
if(xmlHasProp(node, BAD_CAST "value")) {
value_str = (const char*)xmlGetProp(node, BAD_CAST "value");
if (value_str == NULL)
{
ALOGE("xmlGetProp failed on value");
xmlFreeDoc(doc);
xmlCleanupParser();
return -1;
}
value = strtol(value_str, NULL, 16);
}
if(opcode > 0) {
if(numParams < (MAX_PARAM-1)) {
powerhint[hintCount].paramList[numParams++] = opcode;
powerhint[hintCount].paramList[numParams++] = value;
} else {
ALOGE("Maximum parameters exceeded for Hint ID %x\n",type);
opcode = value = 0;
break;
}
}
opcode = value = 0;
}
node = node->next;
}
powerhint[hintCount].type = type;
powerhint[hintCount].numParams = numParams;
numParams = 0;
}
hintCount++;
}
xmlFreeDoc(doc);
xmlCleanupParser();
return 0;
}
int* getPowerhint(int hint_id, int *params) {
int *result = NULL;
if(!hint_id)
return result;
ALOGV("Powerhal hint received=%x\n",hint_id);
if(!powerhint[0].numParams) {
parsePowerhintXML();
}
for(int i = 0; i < MAX_HINT; i++) {
if(hint_id == powerhint[i].type) {
*params = powerhint[i].numParams;
result = powerhint[i].paramList;
break;
}
}
/*for (int j = 0; j < *params; j++)
ALOGI("Powerhal resource again%x = \n", result[j]);*/
return result;
}

48
power/powerhintparser.h Normal file
View File

@@ -0,0 +1,48 @@
/* Copyright (c) 2016, The Linux Foundation. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials provided
* with the distribution.
* * Neither the name of The Linux Foundation nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
#ifndef __POWERHINTPARSER__
#define __POWERHINTPARSER__
#define POWERHINT_XML "/vendor/etc/powerhint.xml"
#define MAX_HINT 7
#define MAX_PARAM 30
typedef struct perflock_param_t {
int type;
int numParams;
int paramList[MAX_PARAM];//static limit on number of hints - 15
}perflock_param_t;
static perflock_param_t powerhint[MAX_HINT];
int parsePowerhintXML();
int *getPowerhint(int, int*);
#endif /* __POWERHINTPARSER__ */

326
power/utils.c Normal file
View File

@@ -0,0 +1,326 @@
/*
* Copyright (c) 2012-2013,2015-2016, The Linux Foundation. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
* * * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials provided
* with the distribution.
* * Neither the name of The Linux Foundation nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#define LOG_NIDEBUG 0
#include <dlfcn.h>
#include <fcntl.h>
#include <errno.h>
#include <stdlib.h>
#include <string.h>
#include "utils.h"
#include "list.h"
#include "hint-data.h"
#include "power-common.h"
#define LOG_TAG "QCOM PowerHAL"
#include <utils/Log.h>
static void *qcopt_handle;
static int (*perf_lock_acq)(unsigned long handle, int duration,
int list[], int numArgs);
static int (*perf_lock_rel)(unsigned long handle);
static struct list_node active_hint_list_head;
static void *get_qcopt_handle()
{
char qcopt_lib_path[PATH_MAX] = {0};
void *handle = NULL;
dlerror();
if (property_get("ro.vendor.extension_library", qcopt_lib_path,
NULL)) {
handle = dlopen(qcopt_lib_path, RTLD_NOW);
if (!handle) {
ALOGE("Unable to open %s: %s\n", qcopt_lib_path,
dlerror());
}
}
return handle;
}
static void __attribute__ ((constructor)) initialize(void)
{
qcopt_handle = get_qcopt_handle();
if (!qcopt_handle) {
ALOGE("Failed to get qcopt handle.\n");
} else {
/*
* qc-opt handle obtained. Get the perflock acquire/release
* function pointers.
*/
perf_lock_acq = dlsym(qcopt_handle, "perf_lock_acq");
if (!perf_lock_acq) {
ALOGE("Unable to get perf_lock_acq function handle.\n");
}
perf_lock_rel = dlsym(qcopt_handle, "perf_lock_rel");
if (!perf_lock_rel) {
ALOGE("Unable to get perf_lock_rel function handle.\n");
}
}
}
static void __attribute__ ((destructor)) cleanup(void)
{
if (qcopt_handle) {
if (dlclose(qcopt_handle))
ALOGE("Error occurred while closing qc-opt library.");
}
}
int sysfs_read(char *path, char *s, int num_bytes)
{
char buf[80];
int count;
int ret = 0;
int fd = open(path, O_RDONLY);
if (fd < 0) {
strerror_r(errno, buf, sizeof(buf));
ALOGE("Error opening %s: %s\n", path, buf);
return -1;
}
if ((count = read(fd, s, num_bytes - 1)) < 0) {
strerror_r(errno, buf, sizeof(buf));
ALOGE("Error writing to %s: %s\n", path, buf);
ret = -1;
} else {
s[count] = '\0';
}
close(fd);
return ret;
}
int sysfs_write(char *path, char *s)
{
char buf[80];
int len;
int ret = 0;
int fd = open(path, O_WRONLY);
if (fd < 0) {
strerror_r(errno, buf, sizeof(buf));
ALOGE("Error opening %s: %s\n", path, buf);
return -1 ;
}
len = write(fd, s, strlen(s));
if (len < 0) {
strerror_r(errno, buf, sizeof(buf));
ALOGE("Error writing to %s: %s\n", path, buf);
ret = -1;
}
close(fd);
return ret;
}
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 {
// Strip newline at the end.
int len = strlen(governor);
len--;
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;
}
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 (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.");
}
}
#endif
}
int interaction_with_handle(int lock_handle, int duration, int num_args, int opt_list[])
{
#ifdef INTERACTION_BOOST
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.");
}
}
return lock_handle;
#else
return 0;
#endif
}
void release_request(int 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)
{
if (qcopt_handle) {
struct hint_data temp_hint_data = {
.hint_id = hint_id
};
struct list_node *found_node = find_node(&active_hint_list_head,
&temp_hint_data);
if (found_node) {
ALOGE("hint ID %d already active", hint_id);
return;
}
if (perf_lock_acq) {
/* Acquire an indefinite lock for the requested 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));
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;
}
new_hint->hint_id = hint_id;
new_hint->perflock_handle = lock_handle;
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);
ALOGE("Failed to process hint.");
}
} else {
/* Can't keep track of this lock. Release it. */
if (perf_lock_rel)
perf_lock_rel(lock_handle);
ALOGE("Failed to process hint.");
}
}
}
}
}
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
};
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);
if (found_hint_data) {
if (perf_lock_rel(found_hint_data->perflock_handle) == -1)
ALOGE("Perflock release failed: %d", hint_id);
}
if (found_node->data) {
/* We can free the hint-data for this node. */
free(found_node->data);
}
remove_list_node(&active_hint_list_head, found_node);
ALOGV("Undo of hint ID %d succeeded", hint_id);
} else {
ALOGE("Invalid hint ID: %d", hint_id);
}
}
}
}
/*
* Used to release initial lock holding
* two cores online when the display is on
*/
void undo_initial_hint_action()
{
if (qcopt_handle) {
if (perf_lock_rel) {
perf_lock_rel(1);
}
}
}

46
power/utils.h Normal file
View File

@@ -0,0 +1,46 @@
/*
* Copyright (c) 2012-2013,2015-2016, The Linux Foundation. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
* * * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials provided
* with the distribution.
* * Neither the name of The Linux Foundation nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include <cutils/properties.h>
int sysfs_read(char *path, char *s, int num_bytes);
int sysfs_write(char *path, char *s);
int get_scaling_governor(char governor[], int size);
int get_scaling_governor_check_cores(char governor[], int size,int core_num);
int is_interactive_governor(char*);
void vote_ondemand_io_busy_off();
void unvote_ondemand_io_busy_off();
void vote_ondemand_sdf_low();
void unvote_ondemand_sdf_low();
void perform_hint_action(int hint_id, int resource_values[],
int num_resources);
void undo_hint_action(int hint_id);
void release_request(int lock_handle);
int interaction_with_handle(int lock_handle, int duration, int num_args, int opt_list[]);

103
powerhint.xml Executable file
View File

@@ -0,0 +1,103 @@
<?xml version="1.0" encoding="utf-8" ?>
<!--
/* Copyright (c) 2016, The Linux Foundation. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials provided
* with the distribution.
* * Neither the name of The Linux Foundation nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
-->
<Powerhint>
<Hint type="0x0E00"> <!--preview-->
<Resource opcode="0x41400000" value="0x4" /> <!-- B CPU - above_hispeed_delay of 40 ms -->
<Resource opcode="0x41410000" value="0x5F" /> <!-- B CPU - go hispeed load 95 -->
<Resource opcode="0x41414000" value="0x22C"/> <!-- B CPU - hispeed freq of 556 MHz -->
<Resource opcode="0x41420000" value="0x5A" /> <!-- B CPU - target load of 90 -->
<Resource opcode="0x41400100" value="0x4" /> <!-- L CPU - above_hispeed_delay of 40 ms -->
<Resource opcode="0x41410100" value="0x5F" /> <!-- L CPU - go hispeed load 95 -->
<Resource opcode="0x41414100" value="0x22C"/> <!-- L CPU - hispeed freq of 556 MHz- -->
<Resource opcode="0x41420100" value="0x5A" /> <!-- L CPU - target load of 90 -->
<Resource opcode="0x41810000" value="0x9C4"/> <!-- CPUBW low power ceil mpbs of 2500 -->
<Resource opcode="0x41814000" value="0x32" /> <!-- CPUBW low power io percent of 50 -->
</Hint>
<Hint type="0x0A00"> <!--video encode 30 fps-->
<Resource opcode="0x41400000" value="0x4" /> <!-- B CPU - above_hispeed_delay of 40 ms -->
<Resource opcode="0x41410000" value="0x5F" /> <!-- B CPU - go hispeed load 95 -->
<Resource opcode="0x41414000" value="0x326"/> <!-- B CPU - hispeed freq of 806 MHz -->
<Resource opcode="0x41420000" value="0x5A" /> <!-- B CPU - target load of 90 -->
<Resource opcode="0x41400100" value="0x4" /> <!-- L CPU - above_hispeed_delay of 40 ms -->
<Resource opcode="0x41410100" value="0x5F" /> <!-- L CPU - go hispeed load 95 -->
<Resource opcode="0x41414100" value="0x22C"/> <!-- L CPU - hispeed freq of 556 MHz- -->
<Resource opcode="0x41420100" value="0x5A" /> <!-- L CPU - target load of 90 -->
<Resource opcode="0x41810000" value="0x9C4"/> <!-- CPUBW low power ceil mpbs of 2500 -->
<Resource opcode="0x41814000" value="0x32" /> <!-- CPUBW low power io percent of 50 -->
<Resource opcode="0x4180C000" value="0x0" /> <!-- CPUBW disable hysteresis -->
<Resource opcode="0x41820000" value="0xA" /> <!-- CPUBW sample_ms of 10ms -->
<Resource opcode="0x41438100" value="0x0" /> <!-- L CPU - disable ignore_hispeed_notif -->
<Resource opcode="0x41438000" value="0x0" /> <!-- B CPU - disable ignore_hispeed_notif -->
</Hint>
<Hint type="0x0B00"> <!--video decode-->
<Resource opcode="0x41400100" value="0x4" /> <!-- L CPU - Above Hispeed Delay of 40ms -->
<Resource opcode="0x41410100" value="0x5F" /> <!-- L CPU - Go Hispeed Delay of 95 -->
<Resource opcode="0x41414100" value="0x2D9"/> <!-- L CPU - Hispeed Freq of 768 MHz -->
<Resource opcode="0x41420100" value="0x5A" /> <!-- L CPU - Target Loads of 90 -->
<Resource opcode="0x41400000" value="0x4" /> <!-- B CPU - Above Hispeed Delay of 40ms -->
<Resource opcode="0x41410000" value="0x5F" /> <!-- B CPU - Go Hispeed Load of 95 -->
<Resource opcode="0x41414000" value="0x2D9"/> <!-- B CPU - Hispeed Freq of 729 MHz -->
<Resource opcode="0x41420000" value="0x5A" /> <!-- B CPU - Target Load of 90 -->
</Hint>
<Hint type="0x0F00"> <!--sustained performance-->
<Resource opcode="0x40800000" value="0x0"/> <!-- B CPU - Cluster min freq uncapped -->
<Resource opcode="0x40800100" value="0x0"/> <!-- L CPU - Cluster min freq uncapped -->
<Resource opcode="0x40804000" value="0x4E0"/> <!-- B CPU - Cluster max freq ~1.2 GHz -->
<Resource opcode="0x40804100" value="0x4E0"/> <!-- L CPU - Cluster max freq ~1.2 Ghz -->
<Resource opcode="0x4280C000" value="0xB4"/> <!-- GPU - min freq 180 Mhz -->
<Resource opcode="0x42810000" value="0x156"/> <!-- GPU - max freq 342 Mhz -->
<Resource opcode="0x42814000" value="0x0"/> <!-- GPUBW freq uncapped -->
</Hint>
<Hint type="0x1000"> <!--vr mode-->
<Resource opcode="0x40800000" value="0x579"/> <!-- B CPU - Cluster min freq ~1.4 Ghz -->
<Resource opcode="0x40800100" value="0x579"/> <!-- L CPU - Cluster min freq ~1.4 Ghz -->
<Resource opcode="0x40804000" value="0x579"/> <!-- B CPU - Cluster max freq ~1.4 Ghz -->
<Resource opcode="0x40804100" value="0x579"/> <!-- L CPU - Cluster max freq ~1.4 Ghz -->
<Resource opcode="0x4280C000" value="0x203"/> <!-- GPU - min freq 510 Mhz -->
<Resource opcode="0x42810000" value="0x203"/> <!-- GPU - max freq 510 Mhz -->
<Resource opcode="0x42814000" value="0x1E4F"/> <!-- GPUBW freq 775 Mhz-->
</Hint>
<Hint type="0x1001"> <!--vr mode sustained performance-->
<Resource opcode="0x40800000" value="0x4E0"/> <!-- B CPU - Cluster min freq ~1.2 Ghz -->
<Resource opcode="0x40800100" value="0x4E0"/> <!-- L CPU - Cluster min freq ~1.2 Ghz -->
<Resource opcode="0x40804000" value="0x4E0"/> <!-- B CPU - Cluster max freq ~1.2 Ghz -->
<Resource opcode="0x40804100" value="0x4E0"/> <!-- L CPU - Cluster max freq ~1.2 Ghz -->
<Resource opcode="0x4280C000" value="0x156"/> <!-- GPU - min freq 342 Mhz -->
<Resource opcode="0x42810000" value="0x156"/> <!-- GPU - max freq 342 Mhz -->
<Resource opcode="0x42814000" value="0x1E4F"/> <!-- GPUBW freq 775 Mhz -->
</Hint>
<Hint type="0x1A00"> <!--interaction-->
<Resource opcode="0x40800000" value="0x44C"/> <!-- B CPU - Cluster min freq ~1.1 Ghz -->
<Resource opcode="0x40800100" value="0x44C"/> <!-- L CPU - Cluster min freq ~1.1 Ghz -->
</Hint>
</Powerhint>

View File

@@ -9,6 +9,7 @@ type sysfs_rmtfs, sysfs_type, fs_type;
type sysfs_soc, sysfs_type, fs_type;
type debugfs_rmt_storage, debugfs_type, fs_type;
type debugfs_kgsl, debugfs_type, fs_type;
type debugfs_rpm, debugfs_type, fs_type;
type smlog_dump_file, file_type, data_file_type;

View File

@@ -86,6 +86,10 @@
/sys/bus/msm_subsys(/.*)? u:object_r:sysfs_msm_subsys:s0
/sys/module/subsystem_restart u:object_r:sysfs_msm_subsys_restart:s0
# files in debugfs
/sys/kernel/debug/rpm_stats u:object_r:debugfs_rpm:s0
/sys/kernel/debug/rpm_master_stats u:object_r:debugfs_rpm:s0
# files in /system
/system/bin/init\.power\.sh u:object_r:init_power_exec:s0
/system/bin/init\.radio\.sh u:object_r:init_radio_exec:s0

View File

@@ -0,0 +1,3 @@
allow hal_power_default perfd_socket:sock_file write;
allow hal_power_default debugfs_rpm:file { open read getattr };