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

Commit d3d851f5 authored by Vince Leung's avatar Vince Leung Committed by Linux Build Service Account
Browse files

performance: Add concurrency and timer support to PerfLock.

Add timer and concurrency support to PerfLock APIs.
Update optimization codes.
Removed cpuBoost API.
Add setCpuBoost API.

Change-Id: Id81695153c7ba2d76c4fc8c95e2b1bead65c90e2
parent 90f04569
Loading
Loading
Loading
Loading
+41 −35
Original line number Diff line number Diff line
@@ -40,47 +40,59 @@ public class Performance
    }

    /* 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 ALL_CPUS_PWR_CLPS_DIS = 0x100;

    /** @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_NONTURBO_MAX = 0x20A;
    /** @hide */ public static final int CPU0_FREQ_TURBO_MAX = 0x20F;

    /** @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_NONTURBO_MAX = 0x30A;
    /** @hide */ public static final int CPU1_FREQ_TURBO_MAX = 0x30F;

    /** @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;
    /** @hide */ public static final int CPU2_FREQ_NONTURBO_MAX = 0x40A;
    /** @hide */ public static final int CPU2_FREQ_TURBO_MAX = 0x40F;

    /** @hide */ public static final int CPU3_FREQ_NONTURBO_MAX = 0x50A;
    /** @hide */ public static final int CPU3_FREQ_TURBO_MAX = 0x50F;

    /** @hide */ public static final int CPUS_ON_2 = 0x702;
    /** @hide */ public static final int CPUS_ON_3 = 0x703;
    /** @hide */ public static final int CPUS_ON_MAX = 0x704;

    /** @hide */ public static final int ALL_CPUS_FREQ_NONTURBO_MAX = 0x90A;
    /** @hide */ public static final int ALL_CPUS_FREQ_TURBO_MAX = 0x90F;

    /* 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;
    /** @hide */ public static final int REQUEST_FAILED = -1;
    /** @hide */ public static final int REQUEST_SUCCEEDED = 0;

    private int HANDLE = 0;
    /** @hide */ 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;
    public int perfLockAcquire(int duration, int... list) {
        int rc = REQUEST_SUCCEEDED;
        handle = native_perf_lock_acq(handle, duration, list);
        if (handle == 0)
            rc = REQUEST_FAILED;
        return rc;
    }

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

    /** &hide */
    public void setCpuBoost() {
        int[] configPerfLock = new int[4];
        final int DURATION_OF_PERFLOCK = 2000;

        configPerfLock[0] = ALL_CPUS_PWR_CLPS_DIS;
        configPerfLock[1] = CPUS_ON_MAX;
        configPerfLock[2] = CPU0_FREQ_TURBO_MAX;
        configPerfLock[3] = CPU1_FREQ_TURBO_MAX;

        perfLockAcquire(DURATION_OF_PERFLOCK, configPerfLock);
    }

    /* The following are for internal use only */
@@ -88,11 +100,6 @@ public class Performance
    /** @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);
@@ -103,9 +110,8 @@ public class Performance
        native_deinit();
    }

    private native int  native_perf_lock_acq(int list[]);
    private native int  native_perf_lock_acq(int handle, int duration, 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();
}
+118 −61
Original line number Diff line number Diff line
@@ -27,105 +27,162 @@ THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
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 will always run the highest level of optimization requested.

==================================
NOTE: Each instance of the Performance class object will serve one unique PerfLock request.
      Therefore, a new Performance class object will need to be created for every
      unique request for PerfLock.

Please read through the following carefully to understand the proper usage of this API.

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

The following two methods are the PerfLock APIs

1. perfLockAcquire(int... args)
1. perfLockAcquire(int duration, int... args)

    Description:

        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.
    Arguments:

                 See next section below for the optimizations supported.
        duration: The maximum amount of time required to hold the lock.
                  Only a positive integer value in milliseconds will be accepted.
                  You may explicitly call perfLockRelease before the timer expires.

    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.
        args: Enter all optimizations required. Only the optimizations in the
              table below are supported. You can only choose one optimization
              from each of the numbered sections in the table. Incorrect or
              unsupported optimizations will be ignored.

                 Incorrect or unsupported optimizations will be ignored.
              NOTE: Enter the optimizations required in the order they appear in the table.

    Returns: REQUEST_SUCCEEDED or REQUEST_FAILED.
    Returns: On success, a non-zero integer handle is returned, you must store this.
             On error, a NULL pointer is returned.

2. perfLockRelease()
2. perfLockRelease() [OPTIONAL]

    Description:

        Toggle off all optimizations requested.
        Use this function if you want to release before the time duration ends.

    Arguments: None.

    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             |
 ========================================================================================
|    1    | ALL_CPUS_PWR_CLPS_DIS           | Disables power collapse on all CPUs        |
|         |                                 |                                            |
 ========================================================================================
|    2    | CPUS_ON_MAX                     | Minimum of four cores on                   |
|         |_________________________________|____________________________________________|
|         | CPUS_ON_3                       | Minimum of three cores on                  |
|         |_________________________________|____________________________________________|
|         | CPUS_ON_2                       | Minimum of two cores on                    |
|         |                                 |                                            |
 =============================================================================
|    2    | HEAP_OPT_A              | Optimizes heap parameters               |
 ========================================================================================
|    3    | CPU0_FREQ_LVL_TURBO_MAX         | Set CPU0 minimum frequency to 1512 Mhz     |
|         |_________________________________|____________________________________________|
|         | CPU0_FREQ_LVL_NONTURBO_MAX      | Set CPU0 minimum frequency to 1026 Mhz     |
|         |                                 |                                            |
 =============================================================================
|    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    | CPU1_FREQ_LVL_TURBO_MAX         | Set CPU1 minimum frequency to 1512 Mhz     |
|         |_________________________________|____________________________________________|
|         | CPU1_FREQ_LVL_NONTURBO_MAX      | Set CPU1 minimum frequency to 1026 Mhz     |
|         |                                 |                                            |
 =============================================================================
|    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    | CPU2_FREQ_LVL_TURBO_MAX         | Set CPU2 minimum frequency to 1512 Mhz     |
|         |_________________________________|____________________________________________|
|         | CPU2_FREQ_LVL_NONTURBO_MAX      | Set CPU2 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  |
 ========================================================================================
|    6    | CPU3_FREQ_LVL_TURBO_MAX         | Set CPU3 minimum frequency to 1512 Mhz     |
|         |_________________________________|____________________________________________|
|         | CPU3_FREQ_LVL_NONTURBO_MAX      | Set CPU3 minimum frequency to 1026 Mhz     |
|         |                                 |                                            |
 =============================================================================
 ========================================================================================
|    7    | ALL_CPUS_FREQ_LVL_TURBO_MAX     | Set all online CPUs frequency to 1512 Mhz  |
|         |_________________________________|__________________________   _______________|
|         | ALL_CPUS_FREQ_LVL_NONTURBO_MAX  | Set all online CPUs 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
   and store the returned handle into an int variable.

4. Use "perfLockRelease" to toggle the optimizations off
   NOTE: perfLockRelease is optional but required if the duration
         of acquisition is unknown (ie. 0).
______________________________________________________________________
Example: Request PerfLock for minimum of two cores and set the
         minimum frequency for CPU0 and CPU1 to 1026 Mhz for three seconds.

   Performance mPerf = new Performance();

   mPerf.perfLockAcquire(3000, mPerf.CPUS_ON_2, \
                       mPerf.CPU0_FREQ_LVL_NONTURBO_MAX, mPerf.CPU1_FREQ_LVL_NONTURBO_MAX);

   // Critical section requiring PerfLock

NOTE: perfLockRelease is not required since PerfLock will automatically
      release after three seconds.
______________________________________________________________________
Example: Request PerfLock to bring up all additional cores and set the
         minimum frequency for CPU0 and CPU1 to 1026 Mhz.
Example: Request PerfLock for minimum of three cores in one section.
         Set duration for five seconds and release before that if possible.

         Request PerfLock for minimum of two cores in another section.
         Set duration for three seconds and release before that if possible.

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

   mPerf.perfLockAcquire(5000, mPerf.CPUS_ON_3);

   // Critical section requiring PerfLock

   mPerf.perfLockRelease();

=================================================
   // other code in between

   sPerf.perfLockAcquire(3000, sPerf.CPUS_ON_2);

   // Critical section requiring PerfLock

   sPerf.perfLockRelease();

NOTE: perfLockRelease is recommended to ensure PerfLock is not held for longer
      than it needs to be.

=========================================================================================
  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
+6 −22
Original line number Diff line number Diff line
@@ -45,9 +45,8 @@ namespace android
{

// ----------------------------------------------------------------------------
static void (*cpu_boost)(int)                       = NULL;
static int  (*cpu_setoptions)(int, int)             = NULL;
static int  (*perf_lock_acq)(int[], int)            = NULL;
static int  (*perf_lock_acq)(int, int, int[], int)  = NULL;
static int  (*perf_lock_rel)(int)                   = NULL;
static void *dlhandle                               = NULL;

@@ -81,15 +80,12 @@ org_codeaurora_performance_native_init()

    dlerror();

    cpu_boost = (void (*) (int))dlsym(dlhandle, "perf_cpu_boost");
    if ((rc = dlerror()) != NULL) {
        goto cleanup;
    }
    cpu_setoptions = (int (*) (int, int))dlsym(dlhandle, "perf_cpu_setoptions");
    if ((rc = dlerror()) != NULL) {
        goto cleanup;
    }
    perf_lock_acq = (int (*) (int[], int))dlsym(dlhandle, "perf_lock_acq");

    perf_lock_acq = (int (*) (int, int, int[], int))dlsym(dlhandle, "perf_lock_acq");
    if ((rc = dlerror()) != NULL) {
        goto cleanup;
    }
@@ -107,7 +103,6 @@ org_codeaurora_performance_native_init()
    return;

cleanup:
    cpu_boost      = NULL;
    cpu_setoptions = NULL;
    perf_lock_acq  = NULL;
    perf_lock_rel  = NULL;
@@ -123,7 +118,6 @@ org_codeaurora_performance_native_deinit(JNIEnv *env, jobject clazz)
    void (*deinit)(void);

    if (dlhandle) {
        cpu_boost      = NULL;
        cpu_setoptions = NULL;
        perf_lock_acq  = NULL;
        perf_lock_rel  = NULL;
@@ -138,14 +132,6 @@ org_codeaurora_performance_native_deinit(JNIEnv *env, jobject clazz)
    }
}

static void
org_codeaurora_performance_native_cpu_boost(JNIEnv *env, jobject clazz, jint ntasks)
{
    if (cpu_boost) {
        (*cpu_boost)(ntasks);
    }
}

static jint
org_codeaurora_performance_native_cpu_setoptions(JNIEnv *env, jobject clazz,
                                                 jint reqtype, jint reqvalue)
@@ -157,7 +143,7 @@ org_codeaurora_performance_native_cpu_setoptions(JNIEnv *env, jobject clazz,
}

static jint
org_codeaurora_performance_native_perf_lock_acq(JNIEnv *env, jobject clazz, jintArray list)
org_codeaurora_performance_native_perf_lock_acq(JNIEnv *env, jobject clazz, jint handle, jint duration, jintArray list)
{
    jint listlen = env->GetArrayLength(list);
    jint buf[listlen];
@@ -168,7 +154,7 @@ org_codeaurora_performance_native_perf_lock_acq(JNIEnv *env, jobject clazz, jint
        org_codeaurora_performance_native_init();
    }
    if (perf_lock_acq) {
        return (*perf_lock_acq)(buf, listlen);
        return (*perf_lock_acq)(handle, duration, buf, listlen);
    }
    return 0;
}
@@ -184,13 +170,11 @@ org_codeaurora_performance_native_perf_lock_rel(JNIEnv *env, jobject clazz, jint
    }
    return 0;
}

// ----------------------------------------------------------------------------

static JNINativeMethod gMethods[] = {
    {"native_cpu_boost",      "(I)V",                  (void *)org_codeaurora_performance_native_cpu_boost},
    {"native_cpu_setoptions", "(II)I",                 (int *)org_codeaurora_performance_native_cpu_setoptions},
    {"native_perf_lock_acq",  "([I)I",                 (int *)org_codeaurora_performance_native_perf_lock_acq},
    {"native_perf_lock_acq",  "(II[I)I",               (int *)org_codeaurora_performance_native_perf_lock_acq},
    {"native_perf_lock_rel",  "(I)I",                  (int *)org_codeaurora_performance_native_perf_lock_rel},
    {"native_deinit",         "()V",                   (void *)org_codeaurora_performance_native_deinit},
};