5 展讯Sprd设置-电池-PowerController.enterPowerSaveMode 函数接口

本文详细解析了展讯Sprd平台上的电池管理机制,包括setPowerSaveMode、onPowerSaveModeChanging和exitPowerSaveMode等接口的功能及其实现过程。文章深入探讨了PowerController类如何处理省电模式变更,以及不同省电模式下CPU参数的调整策略。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

0. 前言

  1. 上接展讯Sprd设置-电池-setPowerSaveMode
  1. 3 展讯Sprd设置-电池-onPowerSaveModeChanging接口
  1. 4 展讯Sprd设置-电池-PowerController.exitPowerSaveMode函数接口

源码走读的开始位置

  • vendor/sprd/platform/frameworks/base/services/core/java/com/android/server/power/PowerController.java

1. PowerController.handlePowerSaveModeChanged

走读的源代码,主要进行Google省电模式调用和CPU文件节点的修改。其中省电场景策略重点看 power_scene_config.xml 定义

package com.android.server.power;

public class PowerController //extends IPowerController.Stub

    private List<PowerSaveHelper> mHelpers;

    // handle the power save mode changed
    private void handlePowerSaveModeChanged(int newMode) {

        if (mInitFinished && mPowerSaveMode == newMode) return;

        // notify helpers power save mode changing
        for (int i = 0; i < mHelpers.size(); i++) {
            PowerSaveHelper helper = mHelpers.get(i);
            helper.onPowerSaveModeChanging(newMode);
        }

        exitPowerSaveMode(mPowerSaveMode);

        enterPowerSaveMode(newMode);

        if (mPowerSaveMode != newMode) {
            Slog.e(TAG, "Something error!! mPowerSaveMode change fail!!old mode:" + mPowerSaveMode
                + " new mode:" + newMode);
        }

        // notify helpers power save mode changed
        for (int i = 0; i < mHelpers.size(); i++) {
            PowerSaveHelper helper = mHelpers.get(i);
            helper.onPowerSaveModeChanged(newMode);
        }

    }

2. PowerController.enterPowerSaveMode

package com.android.server.power;

public class PowerController //extends IPowerController.Stub
	extends UsageStatsManagerInternal.AppStateEventChangeListener {

    private void enterPowerSaveMode(int newMode) {
        Slog.d(TAG, "enterPowerSaveMode(), " + newMode);
        mPrePowerSaveMode = mPowerSaveMode;
        mPowerSaveMode = newMode;

        notifyPowerModeListeners(newMode);

        // send broadcast
        postModeChangeBroadcast(newMode, mPrePowerSaveMode);

        switch (newMode) {
            // 超级省电模式
            case PowerManagerEx.MODE_ULTRASAVING:
                try {
                    ActivityManager.getService().resizeStack(ActivityManager.StackId.DOCKED_STACK_ID, null, true, true, false, -1);
                } catch (RemoteException e) {
                    Slog.w(TAG, "Failed to resize stack: " + e);
                }
            // 低电量模式
            case PowerManagerEx.MODE_LOWPOWER:
                // 开启了Google省电模式
                mPowerManager.setPowerSaveMode(true);
                break;
            case PowerManagerEx.MODE_PERFORMANCE:
                break;
            // 智能省电模式
            case PowerManagerEx.MODE_SMART:
                break;
            case PowerManagerEx.MODE_POWERSAVING:
                break;
        }

        // if lowpower mode, aosp code will call powerHint() interface
        if (PowerManagerEx.MODE_LOWPOWER != mPowerSaveMode) {
            // 这里主要调整 CPU参数,主要通过文件节点修改触发模式切换,且文件节点非标准Linux节点,或自定义功能
            mLocalPowerManager.powerHint(getPowerHintMode(mPowerSaveMode),  1);
        }

    }
2.1 PowerManagerInternal.powerSaveMode
    // For power save mode
    public static final int POWER_HINT_VENDOR_MODE_NORMAL = 0x7fff0000;
    public static final int POWER_HINT_VENDOR_MODE_LOW_POWER = 0x7fff0001;
    public static final int POWER_HINT_VENDOR_MODE_POWER_SAVE = 0x7fff0002;
    public static final int POWER_HINT_VENDOR_MODE_ULTRA_POWER_SAVE = 0x7fff0003;
    public static final int POWER_HINT_VENDOR_MODE_PERFORMANCE = 0x7fff0004;

    private int getPowerHintMode(int powerSaveMode) {
        switch (powerSaveMode) {
            case PowerManagerEx.MODE_LOWPOWER:
                return PowerManagerInternal.POWER_HINT_VENDOR_MODE_LOW_POWER;
            case PowerManagerEx.MODE_PERFORMANCE:
                return PowerManagerInternal.POWER_HINT_VENDOR_MODE_PERFORMANCE;
            case PowerManagerEx.MODE_SMART:
                return PowerManagerInternal.POWER_HINT_VENDOR_MODE_NORMAL;
            case PowerManagerEx.MODE_POWERSAVING:
                return PowerManagerInternal.POWER_HINT_VENDOR_MODE_POWER_SAVE;
            case PowerManagerEx.MODE_ULTRASAVING:
                return PowerManagerInternal.POWER_HINT_VENDOR_MODE_ULTRA_POWER_SAVE;
        }
        return PowerManagerInternal.POWER_HINT_VENDOR_MODE_NORMAL;
    }

3. PowerManagerInternal mLocalPowerManager.powerHint

源码查找
root@69959bbb90c6:/home/suhuazhi/8.1/op54# grep -irn “POWER_HINT_VENDOR_MODE_ULTRA_POWER_SAVE” vendor/

  • vendor/sprd/modules/power/sprd_power.c:229: case POWER_HINT_VENDOR_MODE_ULTRA_POWER_SAVE:
3.1 头文件定义-sprd_power.h
    void (*powerHint)(struct sprd_power_module *module, power_hint_t hint,
                      void *data);
3.2 powerHint 函数实现
struct sprd_power_module power_impl = {
    ...
    .powerHint = sprd_power_hint,

};

static void sprd_power_hint(struct sprd_power_module *module, power_hint_t hint,
                             void *data)
{
    struct sprd_power_module *pm = (struct sprd_power_module *)module;
    static bool is_launching = false;

    if (CC_UNLIKELY(power_hint_enable == 0)) return;

    ALOGD_IF(DEBUG_V, "Enter %s:(%d:%d)", __func__, hint, ((data!=NULL)?(*(int*)data):0));
    pthread_mutex_lock(&pm->lock);
    if (CC_UNLIKELY(!pm->init_done)) {
        pthread_mutex_unlock(&pm->lock);
        ALOGE("%s: power hint is not inited", __func__);
        return;
    }

    // TODO: delete to support boost for all modes
    // Do not support boost in non-normal mode
    if ((power_mode != POWER_HINT_VENDOR_MODE_NORMAL)
        && (hint < POWER_HINT_VENDOR_MODE_NORMAL || hint > POWER_HINT_VENDOR_SCREEN_ON)) {
        pthread_mutex_unlock(&pm->lock);
        return;
    }

    switch (hint) {
        case POWER_HINT_INTERACTION:
        {
            /*
             * 23       15          0
             * +---------+----------+
             * |  subtype|  duration|
             * +---------+----------+
             */
            int duration = 0;
            int action_subtype = 0;

            if (data != NULL) {
                duration = *((int*)data) & 0xffff;
                action_subtype = (*((int*)data) & 0xff0000) >> 16;
            }

            if (duration < BOOST_DURATION_DEFAULT || duration > BOOST_DURATION_MAX)
                duration = BOOST_DURATION_DEFAULT;

            if (data != NULL) {
                ALOGD("POWER_HINT_INTERACTION: data=0x%x, subtype=%d, duration=%d",
                    *((int*)data), action_subtype, duration);
            } else {
                ALOGD("POWER_HINT_INTERACTION: data=0x00, subtype=%d, duration=%d",
                    action_subtype, duration);
            }

            if (!is_in_interactive && action_subtype == INTERACTION_SUBTYPE_LAUNCH) {
                ALOGE("interactive=false, don't do LAUNCH boost!!!");
                break;
            }

            boost(POWER_HINT_INTERACTION, action_subtype, 1, duration);
            break;
        }
        case POWER_HINT_LAUNCH:
        {
            bool launch = (data != NULL)? true: false;

            if (!is_in_interactive) {
                ALOGD("Screenoff don't do LAUNCH boost!!!");
                break;
            }

            if (is_launching == launch) break;

            is_launching = launch;
            boost(POWER_HINT_LAUNCH, 0, (is_launching? 1: 0), 0);
            break;
        }
        case POWER_HINT_VSYNC:
            break;
        case POWER_HINT_SUSTAINED_PERFORMANCE:
            break;
        case POWER_HINT_VR_MODE:
            break;
        case POWER_HINT_VIDEO_DECODE:
            break;
        case POWER_HINT_VIDEO_ENCODE:
            if (data != NULL) {
                int state =  *((int*)data) & 0xffff;
                ALOGE("POWER_HINT_VIDEO_ENCODE: %d", state);

                if (state == 1) {
                    /* Video encode started */
                    boost(hint, 0, 1, 0);
                } else if (state == 0) {
                    /* Video encode stopped */
                    boost(hint, 0, 0, 0);
                }
            }
            break;
        case POWER_HINT_VENDOR:
            if (data == NULL) break;

            handle_power_hint_vendor(*((int*)data));
            break;
        case POWER_HINT_LOW_POWER:// 低电量模式
        case POWER_HINT_VENDOR_MODE_NORMAL:// 普通模式
        case POWER_HINT_VENDOR_MODE_LOW_POWER:// 厂商低电量模式
        case POWER_HINT_VENDOR_MODE_POWER_SAVE:// 厂商省电模式
        case POWER_HINT_VENDOR_MODE_ULTRA_POWER_SAVE:// 厂商超级省电模式
        case POWER_HINT_VENDOR_MODE_PERFORMANCE:// 厂商性能模式
            if (((power_mode == hint) && (data != NULL)) || ((power_mode != hint) && (data == NULL)))
                break;

            handle_power_mode_switch(hint, (data != NULL)? 1: 0, 0);
            break;
        default: {
            int duration = 0;
            int action_subtype = 0;

            if (data != NULL) {
                duration = *((int*)data) & 0xffff;
                if (duration == 1 || duration == 0) {
                    duration = 0;
                } else if (duration < 0) {
                    break;
                } else if (duration < BOOST_DURATION_DEFAULT || duration > BOOST_DURATION_MAX) {
                    duration = BOOST_DURATION_DEFAULT;
                }
            }

            boost(hint, 0, ((data != NULL)? 1: 0), duration);
            break;
        }

    }

    pthread_mutex_unlock(&pm->lock);
    ALOGD_IF(DEBUG_V, "Exit %s:(%d:%d)", __func__, hint, ((data!=NULL)?(*(int*)data):0));
}
3.3 handle_power_mode_switch 函数实现
static void handle_power_mode_switch(int mode, int enable, int value)
{
    int ret = -1;

    if (CC_UNLIKELY((power_mode == mode && enable == 1) || (power_mode != mode && enable == 0)))
        return;

    if (enable) {
        ALOGD("switch mode: 0x%08x -> 0x%08x", power_mode, mode);
    } else {
        ALOGD("switch mode: 0x%08x -> 0x%08x", power_mode, POWER_HINT_VENDOR_MODE_NORMAL);
    }

    if (update_mode(mode, enable)) {
        if (power_mode == POWER_HINT_VENDOR_MODE_NORMAL)
            sceenoff_configed = false;

        if (is_in_interactive) {
            boost(POWER_HINT_VENDOR_SCREEN_ON, 0, 1, 0);
        } else {
            if (power_mode == POWER_HINT_VENDOR_MODE_NORMAL) {
                int is_powered = property_get_int32("sys.sprd.power.ispowered", 0);
                if (is_powered == 0) {
                    boost(POWER_HINT_VENDOR_SCREEN_OFF, 0, 1, 0);
                    sceenoff_configed = true;
                }
            } else {
                boost(POWER_HINT_VENDOR_SCREEN_OFF, 0, 1, 0);
            }
        }
    }
}
3.3 boost 函数实现
3.3.1 头文件定义
  • vendor\sprd\modules\power\common.h
int boost(int scene_id, int subtype, int enable, int data);
3.3.2 boost 函数实现
  • vendor\sprd\modules\power\common.c
/**
 * boost - boost by hint id and subtype
 * @hint_id: power hint id
 * @subtype: id subtype
 * @enable: if 0 disable boost, else enable
 * @data: include data from framework
 * return: 1 if successs, else 0
 *
 * calling some set functions according to scene config file
 */
int boost(int scene_id, int subtype, int enable, int data)
{
    char *scene_name = NULL;
    struct scene *scene = NULL;
    int index = -1;

    if (CC_UNLIKELY(current_mode == NULL)) {
        ALOGE("mode is null");
        return 0;
    }

    scene_name = scene_id_to_string(scene_id, subtype);
    if (scene_name == NULL) {
        ALOGE("scene_id_to_string(%d, %d) fail", scene_id, subtype);
        return 0;
    }

    for (int i = 0; i < current_mode->count; i++) {
       if (strcmp(scene_name, current_mode->scenes[i].name) == 0) {
           scene = &(current_mode->scenes[i]);
           break;
       }
    }
    if (scene == NULL) {
        ALOGI("Don't support %s in %s mode", scene_name, current_mode->name);
        return 0;
    }

    ALOGD_IF(DEBUG, "###%s %s scene bgn###", enable?"Enter": "Exit", scene_name);
    _boost(scene, enable, data);
    ALOGD_IF(DEBUG, "###%s %s scene end###", enable?"Enter": "Exit", scene_name);
    return 1;
}

3.3.3 _boost(scene, enable, data) 函数实现

主要进行写文件节点操作

static int _boost(const struct scene *scene, int enable, int data)
{
    struct path_file *path_file = NULL;
    struct file *file = NULL;
    struct set *set = NULL;
    bool found = false;
#ifdef BOOST_SPECIFICED
    struct boost_entry boost_entrys[NUM_RESOURCE_MAX];
    int count = 0;

    memset(boost_entrys, 0, sizeof(boost_entrys));
#endif

    if (get_or_set_default_value_to_target() == 0)
        return 0;

    if (get_default_value_for_subsys() == 0)
        return 0;

    for (int i = 0; i < scene->count; i++) {
        found = false;
        set = &(scene->sets[i]);
        for (int j = 0; j < resources.count; j++) {
            if (strcmp(set->path, resources.path_files[j].path) == 0) {
                path_file = &(resources.path_files[j]);
                for (int k = 0; k < path_file->count; k++) {
                    if (strcmp(set->file, path_file->files[k].name) == 0) {
                        file = &(path_file->files[k]);
                        strncpy(file->value.target_value, set->value, LEN_VALUE_MAX);
                        found = true;
#ifdef BOOST_SPECIFICED
                        boost_entrys[count].path = path_file->path;
                        boost_entrys[count++].file = file;
#endif
                        break;
                    }
                }
            }
            if (found)
                break;
        }

        if (!found) {
            ALOGE("!!!Undefined resource %s/%s", set->path, set->file);
            return 0;
        }
    }

    // Maybe the scene don't hava set node
    if (!found) return 0;

#ifdef BOOST_SPECIFICED
    for (int i = 0; i < count; i++) {
        file = boost_entrys[i].file;
        file->set(enable, data, boost_entrys[i].path, file);
    }
#else
    for (int i = 0; i < resources.count; i++) {
        for (int j = 0; j < resources.path_files[i].count; j++) {
            file = &(resources.path_files[i].files[j]);
            if (file->set != NULL && (strlen(file->value.target_value) != 0))
                file->set(enable, data, resources.path_files[i].path, file);
        }
    }
#endif

    return 1;
}

  • 关注下 scene 结构体 vendor\sprd\modules\power\config.h
#include <linux/time.h>

#include "common.h"

// Define the path of config file
#define PATH_SCENE_CONFIG                 "/vendor/etc/power_scene_config.xml"
#define PATH_SCENE_ID_DEFINE              "/vendor/etc/power_scene_id_define.txt"
#define PATH_RESOURCE_FILE_INFO           "/vendor/etc/power_resource_file_info.xml"

#define MODE_PATH                         "/power/mode"
#define RESOURCE_FILE_PATH                "/resources/file"
#define RESOURCE_SUBSYS_PATH              "/resources/subsys"


#define LEN_SCENE_NAME_MAX                40


/**
 * struct scene - record the configuration of a scene
 * @name: the scene name
 * @count: the number of element in sets array
 * @sets: the configuration of the scene
 */
struct scene {
    char name[LEN_SCENE_NAME_MAX];
    int count;
    struct set sets[NUM_FILE_MAX];
};

故上述的含义

  • boost(POWER_HINT_VENDOR_SCREEN_ON, 0, 1, 0);
    POWER_HINT_VENDOR_SCREEN_ON = 0x7fff0030,
    
    0x7fff0030 0x00000000 screen_on
    

  • boost(POWER_HINT_VENDOR_SCREEN_OFF, 0, 1, 0);
    POWER_HINT_VENDOR_SCREEN_OFF = 0x7fff0031,
    0x7fff0031 0x00000000 screen_off
    
    <scene name="screen_off" >
        <set path="/sys/devices/system/cpu/cpuhotplug" file="dynamic_load_disable" value="0" />
        <set path="subsys" file="cpufreq" value="conf_3" />
    </scene>

即 修改/sys/devices/system/cpu/cpuhotplug/dynamic_load_disable 节点值,该节点非标准节点配置

4. 省电场景配置文件

4.1 power_scene_config.xml
<?xml version="1.0" encoding="utf-8"?>
<!--
/*
 * Copyright (C) 2012 The Androscene Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
 -->

<power>
    <mode name="normal">// 正常模式下的CPU参数配置
        <scene name="interaction_touch" >
            <set path="subsys" file="cpufreq" value="conf_2" />
        </scene>
        <scene name="interaction_launch">
            <set path="subsys" file="cpufreq" value="conf_2" />
            <set path="/sys/class/devfreq/scene-frequency/sprd_governor" file="scene_boost_dfs" value="max" />
        </scene>
        <scene name="interaction_fling">
            <set path="subsys" file="cpufreq" value="conf_2" />
        </scene>
        <scene name="interaction_other">
            <set path="/sys/devices/system/cpu/cpuhotplug" file="cluster0_core_min_limit" value="4" />
            <set path="/sys/devices/system/cpu/cpuhotplug" file="cluster0_core_max_limit" value="4" />
            <set path="subsys" file="cpufreq" value="conf_2" />
        </scene>
        <scene name="ddr">
            <set path="/sys/class/devfreq/scene-frequency/sprd_governor" file="scene_boost_dfs" value="max" />
        </scene>
        <scene name="launch" >
            <set path="subsys" file="cpufreq" value="conf_2" />
            <set path="/sys/class/devfreq/scene-frequency/sprd_governor" file="scene_boost_dfs" value="max" />
        </scene>
        <scene name="camera_lowpower" >
            <set path="subsys" file="cpufreq" value="conf_5" />
        </scene>
        <scene name="camera_perf" >
            <set path="/sys/devices/system/cpu/cpuhotplug" file="cluster0_core_min_limit" value="4" />
            <set path="/sys/devices/system/cpu/cpuhotplug" file="cluster0_core_max_limit" value="4" />
            <set path="subsys" file="cpufreq" value="conf_2" />
            <set path="/sys/class/devfreq/scene-frequency/sprd_governor" file="scene_boost_dfs" value="max" />
        </scene>
        <scene name="performance_cts" >
            <set path="/sys/devices/system/cpu/cpuhotplug" file="cluster0_core_min_limit" value="4" />
            <set path="/sys/devices/system/cpu/cpuhotplug" file="cluster0_core_max_limit" value="4" />
            <set path="subsys" file="cpufreq" value="conf_2" />
            <set path="/sys/class/devfreq/scene-frequency/sprd_governor" file="scene_boost_dfs" value="max" />
        </scene>
        <scene name="screen_off" >
            <set path="/sys/devices/system/cpu/cpuhotplug" file="dynamic_load_disable" value="0" />
            <set path="subsys" file="cpufreq" value="conf_3" />
        </scene>
        <scene name="performance_gts" >
            <set path="/sys/devices/system/cpu/cpuhotplug" file="cluster0_core_min_limit" value="4" />
            <set path="/sys/devices/system/cpu/cpuhotplug" file="cluster0_core_max_limit" value="4" />
            <set path="subsys" file="cpufreq" value="conf_2" />
            <set path="/sys/class/devfreq/scene-frequency/sprd_governor" file="scene_boost_dfs" value="max" />
        </scene>
    </mode>
    <mode name="low_power" />
    <mode name="power_save" />
    <mode name="ultra_power_save" />
    <mode name="performance" />
</power>


4.2 power_resource_file_info.xml
<?xml version="1.0" encoding="utf-8"?>
<!--
/*
 * Copyright (C) 2012 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
 -->

<resources>
    <file path="subsys" file="cpufreq" >
        <attr name="comp_func"    value="common_subsys_comp" />
        <attr name="set_func"     value="common_subsys_set" />
        <attr name="clear_func"   value="common_subsys_clear" />
        <attr name="def_value"    value="conf_1" />
    </file>
    <file path="/sys/class/devfreq/scene-frequency/sprd_governor" file="scene_boost_dfs" no_has_def="1" >
        <attr name="comp_func"    value="common_comp_ascend_order" />
        <attr name="set_func"     value="devfreq_ddr_set" />
        <attr name="clear_func"   value="devfreq_ddr_clear" />
    </file>
    <file path="/sys/devices/system/cpu/cpuhotplug" file="cluster0_core_min_limit" >
        <attr name="comp_func"    value="common_comp_ascend_order" />
        <attr name="set_func"     value="common_set" />
        <attr name="clear_func"   value="common_clear" />
        <attr name="def_value"    value="1" />
    </file>
    <file path="/sys/devices/system/cpu/cpuhotplug" file="cluster0_core_max_limit" >
        <attr name="comp_func"    value="common_comp_ascend_order" />
        <attr name="set_func"     value="common_set" />
        <attr name="clear_func"   value="common_clear" />
        <attr name="def_value"    value="4" />
    </file>
    <file path="/sys/devices/system/cpu/cpuhotplug" file="dynamic_load_disable" >
        <attr name="comp_func"    value="common_comp_ascend_order" />
        <attr name="set_func"     value="common_set" />
        <attr name="clear_func"   value="common_clear" />
        <attr name="def_value"    value="1" />
    </file>
    <subsys name="cpufreq" >
        <inode path="/sys/devices/system/cpu/cpufreq/policy0/interactive" file="boost" def_value="0" />
        <inode path="/sys/devices/system/cpu/cpufreq/policy0/interactive" file="target_loads" />
        <inode path="/sys/devices/system/cpu/cpufreq/policy0/interactive" file="hispeed_freq" />
        <inode path="/sys/devices/system/cpu/cpufreq/policy0/interactive" file="above_hispeed_delay" />
        <inode path="/sys/devices/system/cpu/cpufreq/policy0/interactive" file="timer_slack" />
        <inode path="/sys/devices/system/cpu/cpufreq/policy0/interactive" file="min_sample_time" />
        <inode path="/sys/devices/system/cpu/cpufreq/policy0/interactive" file="io_is_busy" />
        <conf name="conf_4" priority="1" >
            <set path="/sys/devices/system/cpu/cpufreq/policy0/interactive" file="target_loads" value="90 768000:200" />
            <set path="/sys/devices/system/cpu/cpufreq/policy0/interactive" file="hispeed_freq" value="768000" />
        </conf>
        <conf name="conf_5" >
            <set path="/sys/devices/system/cpu/cpufreq/policy0/interactive" file="target_loads" value="95 900000:99" />
            <set path="/sys/devices/system/cpu/cpufreq/policy0/interactive" file="hispeed_freq" value="900000" />
            <set path="/sys/devices/system/cpu/cpufreq/policy0/interactive" file="above_hispeed_delay" value="40000" />
            <set path="/sys/devices/system/cpu/cpufreq/policy0/interactive" file="timer_slack" value="10000" />
            <set path="/sys/devices/system/cpu/cpufreq/policy0/interactive" file="min_sample_time" value="20000" />
            <set path="/sys/devices/system/cpu/cpufreq/policy0/interactive" file="io_is_busy" value="1" />
        </conf>
        <conf name="conf_3" >
            <set path="/sys/devices/system/cpu/cpufreq/policy0/interactive" file="target_loads" value="90 1100000:95" />
            <set path="/sys/devices/system/cpu/cpufreq/policy0/interactive" file="hispeed_freq" value="1100000" />
            <set path="/sys/devices/system/cpu/cpufreq/policy0/interactive" file="timer_slack" value="40000" />
            <set path="/sys/devices/system/cpu/cpufreq/policy0/interactive" file="min_sample_time" value="20000" />
            <set path="/sys/devices/system/cpu/cpufreq/policy0/interactive" file="io_is_busy" value="1" />
        </conf>
        <conf name="conf_1" >
        </conf>
        <conf name="conf_2" >
            <set path="/sys/devices/system/cpu/cpufreq/policy0/interactive" file="boost" value="1" />
        </conf>
    </subsys>
</resources>

4.3 power_scene_id_define.txt
#id        #sub_id    #scene name
0x00000001 0x00000000 vsync

0x00000002 0x00000000 interaction_other
0x00000002 0x00000001 interaction_touch
0x00000002 0x00000002 interaction_launch
0x00000002 0x00000003 interaction_fling
0x00000002 0x00000004 interaction_button

0x00000003 0x00000000 video_encode
0x00000004 0x00000000 video_decode
0x00000005 0x00000000 low_power
0x00000006 0x00000000 sustained_performance
0x00000007 0x00000000 vr_mode
0x00000008 0x00000000 launch
0x00000009 0x00000000 disable_touch

#0x7f000001 0x00000000 ddr
#0x7f000002 0x00000000 video_sync
#0x7f000003 0x00000000 video_60fps
#0x7f000004 0x00000000 video_1080p
#0x7f000005 0x00000000 mp4_playback
0x7f000006 0x00000000 screenof_mp3_playback
0x7f000007 0x00000000 camera_perf
0x7f000008 0x00000000 camera_lowpower
0x7f000009 0x00000000 camera_high_perf
#0x7f00000a 0x00000000 performance_gts
#0x7f00000b 0x00000000 performance_cts
#0x7f00000c 0x00000000 performance
#0x7f00000d 0x00000000 radio_call
#0x7f00000e 0x00000000 bt_download

0x00000010 0x00000001 ddr
0x00000010 0x00000003 video_sync
0x00000010 0x00000004 video_60fps
0x00000010 0x00000005 mp4_playback
0x00000010 0x00000008 video_1080p
0x00000010 0x00000009 camera_perf
0x00000010 0x0000000a performance_gts
0x00000010 0x0000000b performance_cts
0x00000010 0x0000000c camera_high_perf
0x00000010 0x0000000d performance
0x00000010 0x0000000e camera_lowpower
0x00000010 0x0000000f radio_call
0x00000010 0x00000010 bt_download

0x7ffe0000 0x00000000 fling_1

0x7fff0000 0x00000000 normal
0x7fff0001 0x00000000 low_power
0x7fff0002 0x00000000 power_save
0x7fff0003 0x00000000 ultra_power_save
0x7fff0004 0x00000000 performance

0x7fff0030 0x00000000 screen_on
0x7fff0031 0x00000000 screen_off

0x7fff0020 0x00000000 com.vectorunit.redcmgeplaycn.anzhi
0x7fff0021 0x00000000 com.rovio.angrybirds.badk


上述的表格和 power.h 标志位一一对应

/*
 * Copyright (C) 2012 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#ifndef ANDROID_INCLUDE_HARDWARE_POWER_H
#define ANDROID_INCLUDE_HARDWARE_POWER_H

#include <stdbool.h>
#include <stdint.h>
#include <sys/cdefs.h>
#include <sys/types.h>

#include <hardware/hardware.h>

__BEGIN_DECLS

#define POWER_MODULE_API_VERSION_0_1  HARDWARE_MODULE_API_VERSION(0, 1)
#define POWER_MODULE_API_VERSION_0_2  HARDWARE_MODULE_API_VERSION(0, 2)
#define POWER_MODULE_API_VERSION_0_3  HARDWARE_MODULE_API_VERSION(0, 3)
#define POWER_MODULE_API_VERSION_0_4  HARDWARE_MODULE_API_VERSION(0, 4)
#define POWER_MODULE_API_VERSION_0_5  HARDWARE_MODULE_API_VERSION(0, 5)

/**
 * The id of this module
 */
#define POWER_HARDWARE_MODULE_ID "power"

/*
 * Platform-level sleep state stats.
 * Maximum length of Platform-level sleep state name.
 */
#define POWER_STATE_NAME_MAX_LENGTH 100

/*
 * Platform-level sleep state stats.
 * Maximum length of Platform-level sleep state voter name.
 */
#define POWER_STATE_VOTER_NAME_MAX_LENGTH 100

/*
 * Power hint identifiers passed to (*powerHint)
 */

typedef enum {
    POWER_HINT_VSYNC = 0x00000001,
    POWER_HINT_INTERACTION = 0x00000002,
    /* DO NOT USE POWER_HINT_VIDEO_ENCODE/_DECODE!  They will be removed in
     * KLP.
     */
    POWER_HINT_VIDEO_ENCODE = 0x00000003,
    POWER_HINT_VIDEO_DECODE = 0x00000004,
    POWER_HINT_LOW_POWER = 0x00000005,
    POWER_HINT_SUSTAINED_PERFORMANCE = 0x00000006,
    POWER_HINT_VR_MODE = 0x00000007,
    POWER_HINT_LAUNCH = 0x00000008,
    POWER_HINT_DISABLE_TOUCH = 0x00000009,

    POWER_HINT_FLING_1 = 0x7ffe0000,

    // Sprd extention
    POWER_HINT_VENDOR = 0x00000010,
    /*POWER_HINT_VENDOR_DDR = 0x7f000001,
    POWER_HINT_VENDOR_CAMERA_PREVIEW = 0x7f000002,
    POWER_HINT_VENDOR_VIDEO_SYNC = 0x7f000003,
    POWER_HINT_VENDOR_VIDEO_60FPS = 0x7f000004,
    POWER_HINT_VENDOR_MP4_PLAYBACK = 0x7f000005,
    POWER_HINT_VENDOR_CAMERA_RECORD = 0x7f000006,
    POWER_HINT_VENDOR_SCREENOF_MP3_PLAYBACK = 0x7f000007,
    POWER_HINT_VENDOR_VEDIO_1080P = 0x7f000008,
    POWER_HINT_VENDOR_CAMERA_PERFORMANCE = 0x7f000009,
    POWER_HINT_VENDOR_MAX,*/

    /* For power save mode */
    POWER_HINT_VENDOR_MODE_NORMAL = 0x7fff0000,
    POWER_HINT_VENDOR_MODE_LOW_POWER = 0x7fff0001,
    POWER_HINT_VENDOR_MODE_POWER_SAVE = 0x7fff0002,
    POWER_HINT_VENDOR_MODE_ULTRA_POWER_SAVE = 0x7fff0003,
    POWER_HINT_VENDOR_MODE_PERFORMANCE = 0x7fff0004,
    POWER_HINT_VENDOR_MODE_MAX,

    POWER_HINT_VENDOR_SCREEN_ON = 0x7fff0030,
    POWER_HINT_VENDOR_SCREEN_OFF = 0x7fff0031,
} power_hint_t;

// Must be kept in sync with definitions in PowerManagerInternal.java
enum {
    POWER_HINT_VENDOR_DDR = 1,
    //POWER_HINT_VENDOR_CAMERA_PREVIEW = 2,
    POWER_HINT_VENDOR_VIDEO_SYNC = 3,
    POWER_HINT_VENDOR_VIDEO_60FPS = 4,
    POWER_HINT_VENDOR_MP4_PLAYBACK = 5,
    //POWER_HINT_VENDOR_CAMERA_RECORD = 6,
    POWER_HINT_VENDOR_SCREENOF_MP3_PLAYBACK = 7,
    POWER_HINT_VENDOR_VEDIO_1080P = 8,
    POWER_HINT_VENDOR_CAMERA_PERFORMANCE = 9,
    POWER_HINT_VENDOR_PERFORMANCE_GTS = 10,
    POWER_HINT_VENDOR_PERFORMANCE_CTS = 11,
    //POWER_HINT_VENDOR_CAMERA_HDR = 12,
    POWER_HINT_VENDOR_CAMERA_HIGH_PERFORMANCE = 12,
    POWER_HINT_VENDOR_PERFORMANCE = 13,
    POWER_HINT_VENDOR_CAMERA_LOW_POWER = 14,
    POWER_HINT_VENDOR_RADIO_CALL = 15,
    POWER_HINT_VENDOR_SCREENOFF_BT_DOWNLOAD = 16,
    POWER_HINT_VENDOR_MAX,
};

typedef enum {
    POWER_FEATURE_DOUBLE_TAP_TO_WAKE = 0x00000001
} feature_t;

/*
 * Platform-level sleep state stats:
 * power_state_voter_t struct is useful for describing the individual voters when a
 * Platform-level sleep state is chosen by aggregation of votes from multiple
 * clients/system conditions.
 *
 * This helps in attirbuting what in the device is blocking the device from
 * entering the lowest Platform-level sleep state.
 */
typedef struct {
    /*
     * Name of the voter.
     */
     char name[POWER_STATE_VOTER_NAME_MAX_LENGTH];

    /*
     * Total time in msec the voter voted for the platform sleep state since boot.
     */
     uint64_t total_time_in_msec_voted_for_since_boot;

    /*
     * Number of times the voter voted for the platform sleep state since boot.
     */
     uint64_t total_number_of_times_voted_since_boot;
} power_state_voter_t;

/*
 * Platform-level sleep state stats:
 * power_state_platform_sleep_state_t represents the Platform-level sleep state the
 * device is capable of getting into.
 *
 * SoCs usually have more than one Platform-level sleep state.
 *
 * The caller calls the get_number_of_platform_modes function to figure out the size
 * of power_state_platform_sleep_state_t array where each array element represents
 * a specific Platform-level sleep state.
 *
 * Higher the index deeper the state is i.e. lesser steady-state power is consumed
 * by the platform to be resident in that state.
 *
 * Caller allocates power_state_voter_t *voters for each Platform-level sleep state by
 * calling get_voter_list.
 */
typedef struct {
    /*
     * Platform-level Sleep state name.
     */
    char name[POWER_STATE_NAME_MAX_LENGTH];

    /*
     * Time spent in msec at this platform-level sleep state since boot.
     */
    uint64_t residency_in_msec_since_boot;

    /*
     * Total number of times system entered this state.
     */
    uint64_t total_transitions;

    /*
     * This platform-level sleep state can only be reached during system suspend.
     */
    bool supported_only_in_suspend;

    /*
     * The following fields are useful if the Platform-level sleep state
     * is chosen by aggregation votes from multiple clients/system conditions.
     * All the voters have to say yes or all the system conditions need to be
     * met to enter a platform-level sleep state.
     *
     * Setting number_of_voters to zero implies either the info is not available
     * or the system does not follow a voting mechanism to choose this
     * Platform-level sleep state.
     */
    uint32_t number_of_voters;

    /*
     * Voter list - Has to be allocated by the caller.
     *
     * Caller allocates power_state_voter_t *voters for each Platform-level sleep state
     * by calling get_voter_list.
     */
    power_state_voter_t *voters;
} power_state_platform_sleep_state_t;

/**
 * Every hardware module must have a data structure named HAL_MODULE_INFO_SYM
 * and the fields of this data structure must begin with hw_module_t
 * followed by module specific information.
 */
typedef struct power_module {
    struct hw_module_t common;

    /*
     * (*init)() performs power management setup actions at runtime
     * startup, such as to set default cpufreq parameters.  This is
     * called only by the Power HAL instance loaded by
     * PowerManagerService.
     *
     * Platform-level sleep state stats:
     * Can Also be used to initiate device specific Platform-level
     * Sleep state nodes from version 0.5 onwards.
     */
    void (*init)(struct power_module *module);

    /*
     * (*setInteractive)() performs power management actions upon the
     * system entering interactive state (that is, the system is awake
     * and ready for interaction, often with UI devices such as
     * display and touchscreen enabled) or non-interactive state (the
     * system appears asleep, display usually turned off).  The
     * non-interactive state is usually entered after a period of
     * inactivity, in order to conserve battery power during
     * such inactive periods.
     *
     * Typical actions are to turn on or off devices and adjust
     * cpufreq parameters.  This function may also call the
     * appropriate interfaces to allow the kernel to suspend the
     * system to low-power sleep state when entering non-interactive
     * state, and to disallow low-power suspend when the system is in
     * interactive state.  When low-power suspend state is allowed, the
     * kernel may suspend the system whenever no wakelocks are held.
     *
     * on is non-zero when the system is transitioning to an
     * interactive / awake state, and zero when transitioning to a
     * non-interactive / asleep state.
     *
     * This function is called to enter non-interactive state after
     * turning off the screen (if present), and called to enter
     * interactive state prior to turning on the screen.
     */
    void (*setInteractive)(struct power_module *module, int on);

    /*
     * (*powerHint) is called to pass hints on power requirements, which
     * may result in adjustment of power/performance parameters of the
     * cpufreq governor and other controls.  The possible hints are:
     *
     * POWER_HINT_VSYNC
     *
     *     Foreground app has started or stopped requesting a VSYNC pulse
     *     from SurfaceFlinger.  If the app has started requesting VSYNC
     *     then CPU and GPU load is expected soon, and it may be appropriate
     *     to raise speeds of CPU, memory bus, etc.  The data parameter is
     *     non-zero to indicate VSYNC pulse is now requested, or zero for
     *     VSYNC pulse no longer requested.
     *
     * POWER_HINT_INTERACTION
     *
     *     User is interacting with the device, for example, touchscreen
     *     events are incoming.  CPU and GPU load may be expected soon,
     *     and it may be appropriate to raise speeds of CPU, memory bus,
     *     etc.  The data parameter is the estimated length of the interaction
     *     in milliseconds, or 0 if unknown.
     *
     * POWER_HINT_LOW_POWER
     *
     *     Low power mode is activated or deactivated. Low power mode
     *     is intended to save battery at the cost of performance. The data
     *     parameter is non-zero when low power mode is activated, and zero
     *     when deactivated.
     *
     * POWER_HINT_SUSTAINED_PERFORMANCE
     *
     *     Sustained Performance mode is actived or deactivated. Sustained
     *     performance mode is intended to provide a consistent level of
     *     performance for a prolonged amount of time. The data parameter is
     *     non-zero when sustained performance mode is activated, and zero
     *     when deactivated.
     *
     * POWER_HINT_VR_MODE
     *
     *     VR Mode is activated or deactivated. VR mode is intended to
     *     provide minimum guarantee for performance for the amount of time the
     *     device can sustain it. The data parameter is non-zero when the mode
     *     is activated and zero when deactivated.
     *
     * POWER_HINT_DISABLE_TOUCH
     *
     *     When device enters some special modes, e.g. theater mode in Android
     *     Wear, there is no touch interaction expected between device and user.
     *     Touch controller could be disabled in those modes to save power.
     *     The data parameter is non-zero when touch could be disabled, and zero
     *     when touch needs to be re-enabled.
     *
     * A particular platform may choose to ignore any hint.
     *
     * availability: version 0.2
     *
     */
    void (*powerHint)(struct power_module *module, power_hint_t hint,
                      void *data);

    /*
     * (*setFeature) is called to turn on or off a particular feature
     * depending on the state parameter. The possible features are:
     *
     * FEATURE_DOUBLE_TAP_TO_WAKE
     *
     *    Enabling/Disabling this feature will allow/disallow the system
     *    to wake up by tapping the screen twice.
     *
     * availability: version 0.3
     *
     */
    void (*setFeature)(struct power_module *module, feature_t feature, int state);

    /*
     * Platform-level sleep state stats:
     * Report cumulative info on the statistics on platform-level sleep states since boot.
     *
     * Caller of the function queries the get_number_of_sleep_states and allocates the
     * memory for the power_state_platform_sleep_state_t *list before calling this function.
     *
     * power_stats module is responsible to assign values to all the fields as
     * necessary.
     *
     * Higher the index deeper the state is i.e. lesser steady-state power is consumed
     * by the platform to be resident in that state.
     *
     * The function returns 0 on success or negative value -errno on error.
     * EINVAL - *list is NULL.
     * EIO - filesystem nodes access error.
     *
     * availability: version 0.5
     */
    int (*get_platform_low_power_stats)(struct power_module *module,
        power_state_platform_sleep_state_t *list);

    /*
     * Platform-level sleep state stats:
     * This function is called to determine the number of platform-level sleep states
     * for get_platform_low_power_stats.
     *
     * The value returned by this function is used to allocate memory for
     * power_state_platform_sleep_state_t *list for get_platform_low_power_stats.
     *
     * The number of parameters must not change for successive calls.
     *
     * Return number of parameters on success or negative value -errno on error.
     * EIO - filesystem nodes access error.
     *
     * availability: version 0.5
     */
    ssize_t (*get_number_of_platform_modes)(struct power_module *module);

    /*
     * Platform-level sleep state stats:
     * Provides the number of voters for each of the Platform-level sleep state.
     *
     * Caller uses this function to allocate memory for the power_state_voter_t list.
     *
     * Caller has to allocate the space for the *voter array which is
     * get_number_of_platform_modes() long.
     *
     * Return 0 on success or negative value -errno on error.
     * EINVAL - *voter is NULL.
     * EIO - filesystem nodes access error.
     *
     * availability: version 0.5
     */
    int (*get_voter_list)(struct power_module *module, size_t *voter);

} power_module_t;


__END_DECLS

#endif  // ANDROID_INCLUDE_HARDWARE_POWER_H

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

法迪

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值