diff options
author | Jason Sams <rjsams@android.com> | 2009-12-10 16:45:22 -0800 |
---|---|---|
committer | Android Git Automerger <android-git-automerger@android.com> | 2009-12-10 16:45:22 -0800 |
commit | 8f31c23021a3f8164eee08cf904c3f083ddfc3d2 (patch) | |
tree | e8a04c30bad81e1b6ea73e896905ec2b04cbd4a0 /libs/rs | |
parent | ae5bd2b9cc36a21b890ded808d9374ab02364d1d (diff) | |
parent | 57ce0888fcb1376b385c3dab5e4262793acaaf16 (diff) | |
download | frameworks_base-8f31c23021a3f8164eee08cf904c3f083ddfc3d2.zip frameworks_base-8f31c23021a3f8164eee08cf904c3f083ddfc3d2.tar.gz frameworks_base-8f31c23021a3f8164eee08cf904c3f083ddfc3d2.tar.bz2 |
am 57ce0888: Merge change Id22c0137 into eclair
Merge commit '57ce0888fcb1376b385c3dab5e4262793acaaf16' into eclair-mr2
* commit '57ce0888fcb1376b385c3dab5e4262793acaaf16':
Throttle low priority RS threads by sleeping once per frame to avoid starving other apps.
Diffstat (limited to 'libs/rs')
-rw-r--r-- | libs/rs/rsContext.cpp | 60 | ||||
-rw-r--r-- | libs/rs/rsContext.h | 8 | ||||
-rw-r--r-- | libs/rs/rsScript.h | 2 | ||||
-rw-r--r-- | libs/rs/rsScriptC.cpp | 6 | ||||
-rw-r--r-- | libs/rs/rsScriptC.h | 2 |
5 files changed, 45 insertions, 33 deletions
diff --git a/libs/rs/rsContext.cpp b/libs/rs/rsContext.cpp index 52074ca..3652f0a 100644 --- a/libs/rs/rsContext.cpp +++ b/libs/rs/rsContext.cpp @@ -113,14 +113,14 @@ void Context::deinitEGL() } -bool Context::runScript(Script *s, uint32_t launchID) +uint32_t Context::runScript(Script *s, uint32_t launchID) { ObjectBaseRef<ProgramFragment> frag(mFragment); ObjectBaseRef<ProgramVertex> vtx(mVertex); ObjectBaseRef<ProgramFragmentStore> store(mFragmentStore); ObjectBaseRef<ProgramRaster> raster(mRaster); - bool ret = s->run(this, launchID); + uint32_t ret = s->run(this, launchID); mFragment.set(frag); mVertex.set(vtx); @@ -130,11 +130,9 @@ bool Context::runScript(Script *s, uint32_t launchID) } -bool Context::runRootScript() +uint32_t Context::runRootScript() { - if (props.mLogTimes) { - timerSet(RS_TIMER_CLEAR_SWAP); - } + timerSet(RS_TIMER_CLEAR_SWAP); rsAssert(mRootScript->mEnviroment.mIsRoot); eglQuerySurface(mEGL.mDisplay, mEGL.mSurface, EGL_WIDTH, &mEGL.mWidth); @@ -154,11 +152,9 @@ bool Context::runRootScript() glClear(GL_COLOR_BUFFER_BIT); } - if (this->props.mLogTimes) { - timerSet(RS_TIMER_SCRIPT); - } + timerSet(RS_TIMER_SCRIPT); mStateFragmentStore.mLast.clear(); - bool ret = runScript(mRootScript.get(), 0); + uint32_t ret = runScript(mRootScript.get(), 0); GLenum err = glGetError(); if (err != GL_NO_ERROR) { @@ -212,13 +208,19 @@ void Context::timerPrint() total += mTimers[ct]; } uint64_t frame = mTimeFrame - mTimeLastFrame; + mTimeMSLastFrame = frame / 1000000; + mTimeMSLastScript = mTimers[RS_TIMER_SCRIPT] / 1000000; + mTimeMSLastSwap = mTimers[RS_TIMER_CLEAR_SWAP] / 1000000; - LOGV("RS: Frame (%lli), Script %2.1f (%lli), Clear & Swap %2.1f (%lli), Idle %2.1f (%lli), Internal %2.1f (%lli)", - frame / 1000000, - 100.0 * mTimers[RS_TIMER_SCRIPT] / total, mTimers[RS_TIMER_SCRIPT] / 1000000, - 100.0 * mTimers[RS_TIMER_CLEAR_SWAP] / total, mTimers[RS_TIMER_CLEAR_SWAP] / 1000000, - 100.0 * mTimers[RS_TIMER_IDLE] / total, mTimers[RS_TIMER_IDLE] / 1000000, - 100.0 * mTimers[RS_TIMER_INTERNAL] / total, mTimers[RS_TIMER_INTERNAL] / 1000000); + + if (props.mLogTimes) { + LOGV("RS: Frame (%i), Script %2.1f (%i), Clear & Swap %2.1f (%i), Idle %2.1f (%lli), Internal %2.1f (%lli)", + mTimeMSLastFrame, + 100.0 * mTimers[RS_TIMER_SCRIPT] / total, mTimeMSLastScript, + 100.0 * mTimers[RS_TIMER_CLEAR_SWAP] / total, mTimeMSLastSwap, + 100.0 * mTimers[RS_TIMER_IDLE] / total, mTimers[RS_TIMER_IDLE] / 1000000, + 100.0 * mTimers[RS_TIMER_INTERNAL] / total, mTimers[RS_TIMER_INTERNAL] / 1000000); + } } void Context::setupCheck() @@ -242,6 +244,7 @@ void * Context::threadProc(void *vrsc) rsc->mNativeThreadId = gettid(); setpriority(PRIO_PROCESS, rsc->mNativeThreadId, ANDROID_PRIORITY_DISPLAY); + rsc->mThreadPriority = ANDROID_PRIORITY_DISPLAY; rsc->props.mLogTimes = getProp("debug.rs.profile"); rsc->props.mLogScripts = getProp("debug.rs.script"); @@ -279,22 +282,26 @@ void * Context::threadProc(void *vrsc) mDraw &= (rsc->mRootScript.get() != NULL); mDraw &= (rsc->mWndSurface != NULL); + uint32_t targetTime = 0; if (mDraw) { - mDraw = rsc->runRootScript() && !rsc->mPaused; - if (rsc->props.mLogTimes) { - rsc->timerSet(RS_TIMER_CLEAR_SWAP); - } + targetTime = rsc->runRootScript(); + mDraw = targetTime && !rsc->mPaused; + rsc->timerSet(RS_TIMER_CLEAR_SWAP); eglSwapBuffers(rsc->mEGL.mDisplay, rsc->mEGL.mSurface); - if (rsc->props.mLogTimes) { - rsc->timerFrame(); - rsc->timerSet(RS_TIMER_INTERNAL); - rsc->timerPrint(); - rsc->timerReset(); - } + rsc->timerFrame(); + rsc->timerSet(RS_TIMER_INTERNAL); + rsc->timerPrint(); + rsc->timerReset(); } if (rsc->mObjDestroy.mNeedToEmpty) { rsc->objDestroyOOBRun(); } + if (rsc->mThreadPriority > 0 && targetTime) { + int32_t t = (targetTime - (int32_t)(rsc->mTimeMSLastScript + rsc->mTimeMSLastSwap)) * 1000; + if (t > 0) { + usleep(t); + } + } } LOGV("RS Thread exiting"); @@ -330,6 +337,7 @@ void Context::setPriority(int32_t p) // the wallpapers can become completly unresponsive at times. // This is probably not what we want for something the user is actively // looking at. + mThreadPriority = p; #if 0 SchedPolicy pol = SP_FOREGROUND; if (p > 0) { diff --git a/libs/rs/rsContext.h b/libs/rs/rsContext.h index 4e0f653..1770ee6 100644 --- a/libs/rs/rsContext.h +++ b/libs/rs/rsContext.h @@ -105,7 +105,7 @@ public: uint32_t getMessageToClient(void *data, size_t *receiveLen, size_t bufferLen, bool wait); bool sendMessageToClient(void *data, uint32_t cmdID, size_t len, bool waitForSpace); - bool runScript(Script *s, uint32_t launchID); + uint32_t runScript(Script *s, uint32_t launchID); void initToClient(); void deinitToClient(); @@ -194,6 +194,7 @@ protected: uint32_t mWidth; uint32_t mHeight; + int32_t mThreadPriority; bool mRunning; bool mExit; @@ -226,7 +227,7 @@ private: void initEGL(); void deinitEGL(); - bool runRootScript(); + uint32_t runRootScript(); static void * threadProc(void *); @@ -241,6 +242,9 @@ private: uint64_t mTimeLast; uint64_t mTimeFrame; uint64_t mTimeLastFrame; + uint32_t mTimeMSLastFrame; + uint32_t mTimeMSLastScript; + uint32_t mTimeMSLastSwap; }; } diff --git a/libs/rs/rsScript.h b/libs/rs/rsScript.h index bc40854..5f4a536 100644 --- a/libs/rs/rsScript.h +++ b/libs/rs/rsScript.h @@ -70,7 +70,7 @@ public: virtual void setupScript() = 0; - virtual bool run(Context *, uint32_t launchID) = 0; + virtual uint32_t run(Context *, uint32_t launchID) = 0; }; diff --git a/libs/rs/rsScriptC.cpp b/libs/rs/rsScriptC.cpp index 073d98b..f11b862 100644 --- a/libs/rs/rsScriptC.cpp +++ b/libs/rs/rsScriptC.cpp @@ -60,7 +60,7 @@ void ScriptC::setupScript() } -bool ScriptC::run(Context *rsc, uint32_t launchIndex) +uint32_t ScriptC::run(Context *rsc, uint32_t launchIndex) { Context::ScriptTLSStruct * tls = (Context::ScriptTLSStruct *)pthread_getspecific(Context::gThreadTLSKey); @@ -85,9 +85,9 @@ bool ScriptC::run(Context *rsc, uint32_t launchIndex) } setupScript(); - bool ret = false; + uint32_t ret = 0; tls->mScript = this; - ret = mProgram.mScript(launchIndex) != 0; + ret = mProgram.mScript(launchIndex); tls->mScript = NULL; return ret; } diff --git a/libs/rs/rsScriptC.h b/libs/rs/rsScriptC.h index 69afc18..35abadf 100644 --- a/libs/rs/rsScriptC.h +++ b/libs/rs/rsScriptC.h @@ -55,7 +55,7 @@ public: ACCscript* mAccScript; virtual void setupScript(); - virtual bool run(Context *, uint32_t launchID); + virtual uint32_t run(Context *, uint32_t launchID); }; class ScriptCState |