summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid Ng <dave@codeaurora.org>2011-11-10 13:00:09 -0800
committerGiulio Cervera <giulio.cervera@gmail.com>2012-03-23 22:45:42 +0100
commit4849e25131ae6fdaa6ac1129f7109791eb3f8174 (patch)
treea2119c2d7ea32691c7aaeac1213a533abf33ebe3
parentfababf511b11a0a4d8007865fc93fef88e707ed9 (diff)
downloadframeworks_base-4849e25131ae6fdaa6ac1129f7109791eb3f8174.zip
frameworks_base-4849e25131ae6fdaa6ac1129f7109791eb3f8174.tar.gz
frameworks_base-4849e25131ae6fdaa6ac1129f7109791eb3f8174.tar.bz2
performance: Add Performance class
New Performance class to allow system CPU control Change-Id: Ie476aefcec7fc20cab8d747ef7c3994b26fcbb62
-rw-r--r--core/java/org/codeaurora/Performance.java54
-rwxr-xr-xcore/jni/Android.mk7
-rw-r--r--core/jni/AndroidRuntime.cpp7
-rw-r--r--core/jni/org_codeaurora_Performance.cpp143
4 files changed, 210 insertions, 1 deletions
diff --git a/core/java/org/codeaurora/Performance.java b/core/java/org/codeaurora/Performance.java
new file mode 100644
index 0000000..5a78f23
--- /dev/null
+++ b/core/java/org/codeaurora/Performance.java
@@ -0,0 +1,54 @@
+/*
+ * Copyright (c) 2011, 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:
+ * * 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 Code Aurora 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");
+ }
+
+ /** &hide */
+ protected void finalize() {
+ native_deinit();
+ }
+
+ /** &hide */
+ public void cpuBoost(int ntasks) {
+ native_cpu_boost(ntasks);
+ }
+
+ private native void native_cpu_boost(int ntasks);
+ private native void native_deinit();
+}
diff --git a/core/jni/Android.mk b/core/jni/Android.mk
index b46c11f..3902a64 100755
--- a/core/jni/Android.mk
+++ b/core/jni/Android.mk
@@ -155,7 +155,12 @@ LOCAL_SRC_FILES:= \
android_app_backup_FullBackup.cpp \
android_content_res_ObbScanner.cpp \
android_content_res_Configuration.cpp \
- android_animation_PropertyValuesHolder.cpp
+ android_animation_PropertyValuesHolder.cpp
+
+ifeq ($(BOARD_USES_QCOM_HARDWARE),true)
+ LOCAL_CFLAGS += -DQCOM_HARDWARE
+ LOCAL_SRC_FILES += org_codeaurora_Performance.cpp
+endif
LOCAL_C_INCLUDES += \
$(JNI_H_INCLUDE) \
diff --git a/core/jni/AndroidRuntime.cpp b/core/jni/AndroidRuntime.cpp
index c00e6c9..b5a6b37 100644
--- a/core/jni/AndroidRuntime.cpp
+++ b/core/jni/AndroidRuntime.cpp
@@ -177,6 +177,9 @@ extern int register_android_content_res_ObbScanner(JNIEnv* env);
extern int register_android_content_res_Configuration(JNIEnv* env);
extern int register_android_animation_PropertyValuesHolder(JNIEnv *env);
extern int register_com_android_internal_content_NativeLibraryHelper(JNIEnv *env);
+#ifdef QCOM_HARDWARE
+extern int register_org_codeaurora_Performance(JNIEnv *env);
+#endif
static AndroidRuntime* gCurRuntime = NULL;
@@ -1203,6 +1206,10 @@ static const RegJNIRec gRegJNI[] = {
REG_JNI(register_android_animation_PropertyValuesHolder),
REG_JNI(register_com_android_internal_content_NativeLibraryHelper),
+
+#ifdef QCOM_HARDWARE
+ REG_JNI(register_org_codeaurora_Performance),
+#endif
};
/*
diff --git a/core/jni/org_codeaurora_Performance.cpp b/core/jni/org_codeaurora_Performance.cpp
new file mode 100644
index 0000000..6a562be
--- /dev/null
+++ b/core/jni/org_codeaurora_Performance.cpp
@@ -0,0 +1,143 @@
+/*
+ * Copyright (c) 2011, 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:
+ * * 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 Code Aurora 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.
+ */
+
+#define LOG_TAG "ANDR-PERF-JNI"
+
+#include "jni.h"
+#include "JNIHelp.h"
+#include <android_runtime/AndroidRuntime.h>
+
+#include <dlfcn.h>
+#include <limits.h>
+#include <string.h>
+
+#include <cutils/properties.h>
+#include <utils/Log.h>
+
+#define LIBRARY_PATH_PREFIX "/system/lib/"
+
+namespace android
+{
+
+// ----------------------------------------------------------------------------
+
+static void (*cpu_boost)(int) = NULL;
+static void *dlhandle = NULL;
+
+// ----------------------------------------------------------------------------
+
+static void
+org_codeaurora_performance_native_init()
+{
+ const char *rc;
+ void (*init)(void);
+ char buf[PROPERTY_VALUE_MAX];
+ int len;
+
+ /* Retrieve name of vendor extension library */
+ if (property_get("ro.vendor.extension_library", buf, NULL) <= 0) {
+ return;
+ }
+
+ /* Sanity check - ensure */
+ buf[PROPERTY_VALUE_MAX-1] = '\0';
+ if ((strncmp(buf, LIBRARY_PATH_PREFIX, sizeof(LIBRARY_PATH_PREFIX) - 1) != 0)
+ ||
+ (strstr(buf, "..") != NULL)) {
+ return;
+ }
+
+ dlhandle = dlopen(buf, RTLD_NOW | RTLD_LOCAL);
+ if (dlhandle == NULL) {
+ return;
+ }
+
+ dlerror();
+
+ *(void **) (&cpu_boost) = dlsym(dlhandle, "perf_cpu_boost");
+ if ((rc = dlerror()) != NULL) {
+ goto cleanup;
+ }
+ *(void **) (&init) = dlsym(dlhandle, "libqc_opt_init");
+ if ((rc = dlerror()) != NULL) {
+ goto cleanup;
+ }
+ (*init)();
+ return;
+
+cleanup:
+ cpu_boost = NULL;
+ if (dlhandle) {
+ dlclose(dlhandle);
+ dlhandle = NULL;
+ }
+}
+
+static void
+org_codeaurora_performance_native_deinit(JNIEnv *env, jobject clazz)
+{
+ void (*deinit)(void);
+
+ if (dlhandle) {
+ cpu_boost = NULL;
+
+ *(void **) (&deinit) = dlsym(dlhandle, "libqc_opt_deinit");
+ if (deinit) {
+ (*deinit)();
+ }
+
+ dlclose(dlhandle);
+ dlhandle = NULL;
+ }
+}
+
+static void
+org_codeaurora_performance_native_cpu_boost(JNIEnv *env, jobject clazz, jint ntasks)
+{
+ if (cpu_boost) {
+ (*cpu_boost)(ntasks);
+ }
+}
+
+// ----------------------------------------------------------------------------
+
+static JNINativeMethod gMethods[] = {
+ {"native_cpu_boost", "(I)V", (void *)org_codeaurora_performance_native_cpu_boost},
+ {"native_deinit", "()V", (void *)org_codeaurora_performance_native_deinit},
+};
+
+
+int register_org_codeaurora_Performance(JNIEnv *env)
+{
+ org_codeaurora_performance_native_init();
+
+ return AndroidRuntime::registerNativeMethods(env,
+ "org/codeaurora/Performance", gMethods, NELEM(gMethods));
+}
+
+} // namespace android