OSDN Git Service

make sure SF initialization is ran at target priority and correct thread group
authorMathias Agopian <mathias@google.com>
Fri, 23 Aug 2013 22:56:38 +0000 (15:56 -0700)
committerMathias Agopian <mathias@google.com>
Sat, 24 Aug 2013 00:10:32 +0000 (17:10 -0700)
SF can spawn threads (indirectly) during initialization
and we want those to be spawned at URGENT_DISPLAY_PRIORITY
(in theory they should set their own, but some code lives
in vendor libraries and doesn't).

Bug: 10430209
Change-Id: I5b3a8f979297de287614c8eafd8267bef1176e4b

services/surfaceflinger/Android.mk
services/surfaceflinger/SurfaceFlinger.cpp
services/surfaceflinger/main_surfaceflinger.cpp

index 81b0d14..3888d7e 100644 (file)
@@ -82,6 +82,7 @@ LOCAL_SRC_FILES:= \
 
 LOCAL_SHARED_LIBRARIES := \
        libsurfaceflinger \
+       libcutils \
        liblog \
        libbinder \
        libutils
index a151142..9fd3f25 100644 (file)
 #include <math.h>
 #include <dlfcn.h>
 
-#if defined(HAVE_PTHREADS)
-#include <sys/resource.h>
-#endif
-
 #include <EGL/egl.h>
 
 #include <cutils/log.h>
@@ -640,9 +636,6 @@ status_t SurfaceFlinger::postMessageSync(const sp<MessageBase>& msg,
 }
 
 void SurfaceFlinger::run() {
-#if defined(HAVE_PTHREADS)
-    setpriority(PRIO_PROCESS, 0, PRIORITY_URGENT_DISPLAY);
-#endif
     do {
         waitForEvent();
     } while (true);
index a609b6f..b161480 100644 (file)
  * limitations under the License.
  */
 
+#if defined(HAVE_PTHREADS)
+#include <sys/resource.h>
+#endif
+
+#include <cutils/sched_policy.h>
 #include <binder/IServiceManager.h>
 #include <binder/IPCThreadState.h>
 #include <binder/ProcessState.h>
@@ -27,16 +32,21 @@ int main(int argc, char** argv) {
     // binder threads to 4.
     ProcessState::self()->setThreadPoolMaxThreadCount(4);
 
+    // start the thread pool
+    sp<ProcessState> ps(ProcessState::self());
+    ps->startThreadPool();
+
     // instantiate surfaceflinger
     sp<SurfaceFlinger> flinger = new SurfaceFlinger();
 
+#if defined(HAVE_PTHREADS)
+    setpriority(PRIO_PROCESS, 0, PRIORITY_URGENT_DISPLAY);
+#endif
+    set_sched_policy(0, SP_FOREGROUND);
+
     // initialize before clients can connect
     flinger->init();
 
-    // start the thread pool
-    sp<ProcessState> ps(ProcessState::self());
-    ps->startThreadPool();
-
     // publish surface flinger
     sp<IServiceManager> sm(defaultServiceManager());
     sm->addService(String16(SurfaceFlinger::getServiceName()), flinger, false);