Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 90f04569 authored by Chitti Babu Theegala's avatar Chitti Babu Theegala Committed by Linux Build Service Account
Browse files

performance: Add Performance class and PerfLock API.

New Performance class with PerfLock APIs to allow
system level performance optimizations to be toggled.

Change-Id: Ibc7eaeb3c2b94abca1125786f73ea97201e41830
parent 86d9c0b4
Loading
Loading
Loading
Loading
+31 −0
Original line number Diff line number Diff line
LOCAL_PATH := $(call my-dir)

include $(CLEAR_VARS)

LOCAL_SRC_FILES := \
            $(call all-subdir-java-files)

LOCAL_MODULE_TAGS := optional

LOCAL_MODULE:= org.codeaurora.Performance

# This will install the file in /system/framework
LOCAL_MODULE_PATH := $(TARGET_OUT_JAVA_LIBRARIES)

include $(BUILD_JAVA_LIBRARY)

# ====  permissions ========================
include $(CLEAR_VARS)

LOCAL_MODULE := org.codeaurora.Performance.xml

LOCAL_MODULE_TAGS := optional

LOCAL_MODULE_CLASS := ETC

# This will install the file in /system/etc/permissions
LOCAL_MODULE_PATH := $(TARGET_OUT_ETC)/permissions

LOCAL_SRC_FILES := $(LOCAL_MODULE)

include $(BUILD_PREBUILT)
+111 −0
Original line number Diff line number Diff line
/*
 * Copyright (c) 2011-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 BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "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.
 */

package org.codeaurora;

import android.util.Log;

public class Performance
{
    private static final String TAG = "Perf";

    /** &hide */
    public Performance() {
        //Log.d(TAG, "Perf module initialized");
    }

    /* The following defined constants are to be used for PerfLock APIs*/
    /** @hide */ public static final int PWR_CLSP_A = 1100;
    /** @hide */ public static final int HEAP_OPT_A = 2100;

    /** @hide */ public static final int CPUS_ON_LVL_MAX = 3900;
    /** @hide */ public static final int CPUS_ON_LVL_3 = 3300;
    /** @hide */ public static final int CPUS_ON_LVL_2 = 3200;
    /** @hide */ public static final int CPUS_ON_LVL_1 = 3100;

    /** @hide */ public static final int CPU0_FREQ_LVL_NONTURBO = 4200;
    /** @hide */ public static final int CPU0_FREQ_LVL_TURBO = 4300;
    /** @hide */ public static final int CPU0_FREQ_LVL_MAX = 4900;

    /** @hide */ public static final int CPU1_FREQ_LVL_NONTURBO = 5200;
    /** @hide */ public static final int CPU1_FREQ_LVL_TURBO = 5300;
    /** @hide */ public static final int CPU1_FREQ_LVL_MAX = 5900;

    /* The following are the PerfLock API return values*/
    /** @hide */ public static final int REQUEST_FAILED = 0;
    /** @hide */ public static final int REQUEST_SUCCEEDED = 1;
    /** @hide */ public static final int REQUEST_PENDING = 2;

    private int HANDLE = 0;

    /* The following two functions are the PerfLock APIs*/
    /** &hide */
    public int perfLockAcquire(int... list) {
        if (HANDLE == 0)
            HANDLE = native_perf_lock_acq(list);
        if (HANDLE > 0)
            return REQUEST_SUCCEEDED;
        return REQUEST_FAILED;
    }

    /** &hide */
    public int perfLockRelease() {
        int rc = 0;
        if (HANDLE > 0)
            rc = native_perf_lock_rel(HANDLE);
            if (rc > 0)
                HANDLE = 0;
        return rc;
    }

    /* The following are for internal use only */
    /** @hide */ public static final int CPUOPT_CPU0_PWRCLSP = 1;
    /** @hide */ public static final int CPUOPT_CPU0_FREQMIN = 2;
    /** @hide */ public static final int CPUOPT_CPU1_FREQMIN = 3;

    /** &hide */
    public void cpuBoost(int ntasks) {
        native_cpu_boost(ntasks);
    }

    /** &hide */
    public int cpuSetOptions(int reqType, int reqValue) {
        return native_cpu_setoptions(reqType, reqValue);
    }

    /** &hide */
    protected void finalize() {
        native_deinit();
    }

    private native int  native_perf_lock_acq(int list[]);
    private native int  native_perf_lock_rel(int handle);
    private native void native_cpu_boost(int ntasks);
    private native int  native_cpu_setoptions(int reqtype, int reqvalue);
    private native void native_deinit();
}
+131 −0
Original line number Diff line number Diff line
Copyright (c) 2011-2012, The Linux Foundation. All rights reserved.

Redistribution and use in source form and compiled forms (SGML, HTML,
PDF, PostScript, RTF and so forth) with or without modification, are
permitted provided that the following conditions are met:

Redistributions in source form must retain the above copyright
notice, this list of conditions and the following disclaimer as the
first lines of this file unmodified.

Redistributions in compiled form (transformed to other DTDs,
converted to PDF, PostScript, RTF and other formats) 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.

THIS DOCUMENTATION IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE AND
NON-INFRINGEMENT ARE DISCLAIMED. IN NO EVENT SHALL THE FREEBSD
DOCUMENTATION PROJECT 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 DOCUMENTATION, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
DAMAGE.

==================================
  Description
==================================

The PerfLock APIs can be used in either the framework or in packaged applications.
The APIs toggle system performance optimizations based upon level requested.

==================================
  PerfLock APIs
==================================

The following two methods are the PerfLock APIs

1. perfLockAcquire(int... args)

    Toggle on all optimizations requested.

    Description: Call perfLockAcquire with the list of optimizations required.
                 perfLockAcquire accepts variable number of arguments, enter all
                 optimizations required at once.

                 See next section below for the optimizations supported.

    Limitations: Only the first five optimizations will be performed.
                 You are only allowed to choose one optimization from each of the
                 numbered sections in the table below.

                 Incorrect or unsupported optimizations will be ignored.

    Returns: REQUEST_SUCCEEDED or REQUEST_FAILED.

2. perfLockRelease()

    Toggle off all optimizations requested.

    Returns: REQUEST_SUCCEEDED or REQUEST_FAILED.

=============================
  Optimizations Supported
=============================

The following resource optimizations are supported for MSM8960:

 =============================================================================
|         |                         |                                         |
| Section | Optimization            | Description                             |
|         |                         |                                         |
 =============================================================================
|    1    | PWR_CLSP_A              | Disables all power collapse             |
|         |                         |                                         |
 =============================================================================
|    2    | HEAP_OPT_A              | Optimizes heap parameters               |
|         |                         |                                         |
 =============================================================================
|    3    | CPUS_ON_LVL_MAX         | Turn on all additional cores            |
|         |_________________________|_________________________________________|
|         | CPUS_ON_LVL_3           | Turn on three additional cores          |
|         |_________________________|_________________________________________|
|         | CPUS_ON_LVL_2           | Turn on two additional cores            |
|         |_________________________|_________________________________________|
|         | CPUS_ON_LVL_1           | Turn on one additional core             |
|         |                         |                                         |
 =============================================================================
|    4    | CPU0_FREQ_LVL_MAX       | Set CPU0 minimum frequency to MAX       |
|         |_________________________|_________________________________________|
|         | CPU0_FREQ_LVL_TURBO     | Set CPU0 minimum frequency to 1512 Mhz  |
|         |_________________________|_________________________________________|
|         |  CPU0_FREQ_LVL_NONTURBO | Set CPU0 minimum frequency to 1026 Mhz  |
|         |                         |                                         |
 =============================================================================
|    5    | CPU1_FREQ_LVL_MAX       | Set CPU1 minimum frequency to MAX       |
|         |_________________________|_________________________________________|
|         | CPU1_FREQ_LVL_TURBO     | Set CPU1 minimum frequency to 1512 Mhz  |
|         |_________________________|_________________________________________|
|         | CPU1_FREQ_LVL_NONTURBO  | Set CPU1 minimum frequency to 1026 Mhz  |
|         |                         |                                         |
 =============================================================================

=====================================
  PerfLock API usage in framework
=====================================

1. Add "import org.codeaurora.Performance;" in your Java source file
2. Create the Performance class object
3. Use "perfLockAcquire" to request the optmizations required
4. Use "perfLockRelease" to toggle the optimizations off
______________________________________________________________________
Example: Request PerfLock to bring up all additional cores and set the
         minimum frequency for CPU0 and CPU1 to 1026 Mhz.

   Performance mPerf = new Performance();
   mPerf.perfLockAcquire(mPerf.CPUS_ON_LVL_MAX, mPerf.CPU0_FREQ_LVL_NONTURBO, mPerf.CPU1_FREQ_LVL_NONTURBO);

   // Critical section requiring PerfLock

   mPerf.perfLockRelease();

=================================================
  PerfLock APIs usage in packaged applications
=================================================
1. Repeat above steps for using APIs in framework
2. Add "LOCAL_JAVA_LIBRARIES := org.codeaurora.Performance" to the application's Android.mk file
+35 −0
Original line number Diff line number Diff line
<?xml version="1.0" encoding="utf-8"?>
<!-- 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.

-->

<!-- This is the library that allows devices to use PerfLock APIs. -->
<permissions>
    <library name="org.codeaurora.Performance"
            file="/system/framework/org.codeaurora.Performance.jar" />
</permissions>
+3 −0
Original line number Diff line number Diff line
@@ -169,6 +169,9 @@ LOCAL_SRC_FILES:= \
	com_android_internal_os_Zygote.cpp \
	com_android_internal_util_VirtualRefBasePtr.cpp \
	com_android_internal_view_animation_NativeInterpolatorFactoryHelper.cpp
    ifeq ($(call is-vendor-board-platform,QCOM),true)
    LOCAL_SRC_FILES += org_codeaurora_Performance.cpp
    endif

LOCAL_C_INCLUDES += \
	$(JNI_H_INCLUDE) \
Loading