MTK平台CPU/GPU动态调频的实现之PerfService的源码分析

本文深入分析了MTK平台中PerfService如何实现CPU和GPU的动态调频。从SystemServer启动PerfService服务的过程开始,探讨了PerfServiceManager的实例化和其与IPerfServiceManager接口的关系。此外,还介绍了perfservapplist.txt和perfservscntbl.txt两个配置文件,用于自定义应用白名单和场景设置,以实现不同应用和场景下的性能调整策略。

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

Zygote进程启动后会启动System进程,在System进程启动过程中会启动系统中的关键服务,如AMS、PMS以及这里要分析的PerfService。先看下流程图:


SystemServer启动PerfService服务是通过实例化PerfServiceImpl的对象perfService,并把该服务的Binder对象添加到ServiceManager中。

先看SystemServer类中的startOtherServices方法:

private void startOtherServices() {
    . . .
    PerfServiceStateNotifier perfServiceNotifier = null;
    IPerfServiceManager perfServiceMgr = null;
    . . .
    if (mFactoryTestMode != FactoryTest.FACTORY_TEST_LOW_LEVEL) {
        . . .
        /// M: add for PerfService feature @{
        if (SystemProperties.get("ro.mtk_perfservice_support").equals("1")) {
            try {
                Slog.i(TAG, "PerfService state notifier");
                // 实例化PerfService的状态通知者
                perfServiceNotifier = new PerfServiceStateNotifier();
                // 把通知者注册到AMS的观察者中,有状态变化时会通知所有注册过的通知者
                mActivityManagerService.registerActivityStateNotifier(perfServiceNotifier);
            } catch (Throwable e) {
                Slog.e(TAG, "FAIL starting PerfServiceStateNotifier", e);
            }

            // Create PerfService manager thread and add service
            try {
                // 实例化PerfServiceManager线程
                perfServiceMgr = new PerfServiceManager(context);

                IPerfService perfService = null;
                // 实例化服务
                perfService = new PerfServiceImpl(context, perfServiceMgr);

                Slog.d("perfservice", "perfService=" + perfService);
                if (perfService != null) {
                    // 把服务添加到ServiceManager中
                    ServiceManager.addService(Context.MTK_PERF_SERVICE, perfService.asBinder());
                }

            } catch (Throwable e) {
                Slog.e(TAG, "perfservice Failure starting PerfService", e);
            }
        }
        /// @}
        . . .
    }
    . . .

    /// M: add for hdmi feature
    final IPerfServiceManager perfServiceF = perfServiceMgr;

    // We now tell the activity manager it is okay to run third party
    // code.  It will call back into us once it has gotten to the state
    // where third party code can really run (but before it has actually
    // started launching the initial applications), for us to complete our
    // initialization.
    mActivityManagerService.systemReady(new Runnable() {
        @Override
        public void run() {
            Slog.i(TAG, "Making services ready");
            . . .
            /// M: add for PerfService feature @{
            if (SystemProperties.get("ro.mtk_perfservice_support").equals("1")) {
                // Notify PerfService manager of system ready
                try {
                    Trace.traceBegin(Trace.TRACE_TAG_SYSTEM_SERVER, "MakePerfServiceReady");
                    // 系统启动后回调IPerfServiceManager的systemReady方法
                    if (perfServiceF != null) perfServiceF.systemReady();
                    Trace.traceEnd(Trace.TRACE_TAG_SYSTEM_SERVER);
                } catch (Throwable e) {
                    reportWtf("making PerfServiceManager ready", e);
                }
            }
            /// @}
            . . .
        }
    });
    . . .
}
再看PerfServiceStateNotifier类,先看下它实现的接口IActivityStateNotifier:

public interface IActivityStateNotifier {

    public enum ActivityState {
        Paused,
        Resumed,
        Destroyed,
        Stopped
    }

    /**
     * Notify activity state change.
     *
     * @param packageName The target package name.
     * @param pid The process id package belongs to.
     * @param className The class name of the package.
     * @param ac
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值