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

Commit 6afa5c05 authored by David Ng's avatar David Ng Committed by Giulio Cervera
Browse files

Add cpuSetOptions API to org.codeaurora.Performance class

Change-Id: I66f7e910f4fee0a9d443356b00b452872628d3f0
parent 4849e251
Loading
Loading
Loading
Loading
+10 −1
Original line number Diff line number Diff line
/*
 * Copyright (c) 2011, Code Aurora Forum. All rights reserved.
 * Copyright (c) 2011-2012, Code Aurora Forum. All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
@@ -49,6 +49,15 @@ public class Performance
        native_cpu_boost(ntasks);
    }

    /** @hide */ public static final int CPUOPT_CPU0_PWRCLSP = 1;
    /** @hide */ public static final int CPUOPT_CPU0_FREQMIN = 2;

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

    private native void native_cpu_boost(int ntasks);
    private native int  native_cpu_setoptions(int reqtype, int reqvalue);
    private native void native_deinit();
}
+27 −8
Original line number Diff line number Diff line
/*
 * Copyright (c) 2011, Code Aurora Forum. All rights reserved.
 * Copyright (c) 2011-2012, Code Aurora Forum. All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
@@ -47,6 +47,7 @@ namespace android
// ----------------------------------------------------------------------------

static void (*cpu_boost)(int)           = NULL;
static int  (*cpu_setoptions)(int, int) = NULL;
static void *dlhandle                   = NULL;

// ----------------------------------------------------------------------------
@@ -79,11 +80,15 @@ org_codeaurora_performance_native_init()

    dlerror();

    *(void **) (&cpu_boost) = dlsym(dlhandle, "perf_cpu_boost");
    cpu_boost = (void (*) (int))dlsym(dlhandle, "perf_cpu_boost");
    if ((rc = dlerror()) != NULL) {
        goto cleanup;
    }
    *(void **) (&init) = dlsym(dlhandle, "libqc_opt_init");
    cpu_setoptions = (int (*) (int, int))dlsym(dlhandle, "perf_cpu_setoptions");
    if ((rc = dlerror()) != NULL) {
        goto cleanup;
    }
    init = (void (*) ())dlsym(dlhandle, "libqc_opt_init");
    if ((rc = dlerror()) != NULL) {
        goto cleanup;
    }
@@ -92,6 +97,7 @@ org_codeaurora_performance_native_init()

cleanup:
    cpu_boost      = NULL;
    cpu_setoptions = NULL;
    if (dlhandle) {
        dlclose(dlhandle);
        dlhandle = NULL;
@@ -105,8 +111,9 @@ org_codeaurora_performance_native_deinit(JNIEnv *env, jobject clazz)

    if (dlhandle) {
        cpu_boost      = NULL;
        cpu_setoptions = NULL;

        *(void **) (&deinit) = dlsym(dlhandle, "libqc_opt_deinit");
        deinit = (void (*) ())dlsym(dlhandle, "libqc_opt_deinit");
        if (deinit) {
            (*deinit)();
        }
@@ -124,10 +131,22 @@ org_codeaurora_performance_native_cpu_boost(JNIEnv *env, jobject clazz, jint nta
    }
}

static jint
org_codeaurora_performance_native_cpu_setoptions(JNIEnv *env, jobject clazz,
                                                 jint reqtype, jint reqvalue)
{
    if (cpu_setoptions) {
        return (*cpu_setoptions)(reqtype, reqvalue);
    }
    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_deinit",         "()V",                   (void *)org_codeaurora_performance_native_deinit},
};