author | baocheng sun <baocheng.sun@amlogic.com> | 2020-04-28 08:25:10 (GMT) |
---|---|---|
committer | sky zhou <sky.zhou@amlogic.com> | 2020-05-21 12:17:33 (GMT) |
commit | 39bbbb460aa4865daad58a92e0ccc1a2438b1cc0 (patch) | |
tree | 53caf5ad96cc6b4e8e05f92f7930bb9fbe3b18f0 | |
parent | 52b845f09d59d345f28b09be5a23830be0a8219d (diff) | |
download | hwcomposer-39bbbb460aa4865daad58a92e0ccc1a2438b1cc0.zip hwcomposer-39bbbb460aa4865daad58a92e0ccc1a2438b1cc0.tar.gz hwcomposer-39bbbb460aa4865daad58a92e0ccc1a2438b1cc0.tar.bz2 |
hwc: protect mActiveConfigId of realModeMgr in mutex when it update [1/1]
PD#SWPL-25121
Problem:
Hardware composer crashes when display mode is changed
Solution:
The mActiveModeId of realModeMgr is reset in hotplug process thread.
Then it is read by another thread which got a invalid value.
Protect it in mutex when it update
Verify:
sabrina
Change-Id: I93307e4d538bdee79325af4e54784a37902b33b1
Signed-off-by: baocheng sun <baocheng.sun@amlogic.com>
-rw-r--r-- | common/hwc/HwcVsync.cpp | 4 | ||||
-rw-r--r-- | hwc2/RealModeMgr.cpp | 12 | ||||
-rw-r--r-- | hwc2/RealModeMgr.h | 5 |
3 files changed, 15 insertions, 6 deletions
diff --git a/common/hwc/HwcVsync.cpp b/common/hwc/HwcVsync.cpp index 831255d..e61b06b 100644 --- a/common/hwc/HwcVsync.cpp +++ b/common/hwc/HwcVsync.cpp @@ -115,8 +115,8 @@ void * HwcVsync::vsyncThread(void * data) { if (pThis->mEnabled && ret == 0 && pThis->mObserver) { pThis->mObserver->onVsync(timestamp); } else { - MESON_LOGE("HwcVsync vsync callback fail (%p)-(%d)-(%p)", - pThis, ret, pThis->mObserver); + if (ret != 0) + MESON_LOGE("wait for hw vsync error:%d", ret); } } return NULL; diff --git a/hwc2/RealModeMgr.cpp b/hwc2/RealModeMgr.cpp index c33b389..543e671 100644 --- a/hwc2/RealModeMgr.cpp +++ b/hwc2/RealModeMgr.cpp @@ -26,6 +26,7 @@ static const drm_mode_info_t defaultMode = { }; RealModeMgr::RealModeMgr() { + mCallOnHotPlug = true; } RealModeMgr::~RealModeMgr() { @@ -72,6 +73,7 @@ void RealModeMgr::reset() { } int32_t RealModeMgr::update() { + std::lock_guard<std::mutex> lock(mMutex); bool useFakeMode = true; drm_mode_info_t realMode; std::map<uint32_t, drm_mode_info_t> supportModes; @@ -81,7 +83,6 @@ int32_t RealModeMgr::update() { reset(); #endif if (mConnector->isConnected()) { - std::lock_guard<std::mutex> lock(mMutex); mConnector->getModes(supportModes); if (mCrtc->getMode(realMode) == 0) { if (realMode.name[0] != 0) { @@ -192,7 +193,7 @@ int32_t RealModeMgr::getActiveConfig(uint32_t * outConfig, int32_t caller __unus #else *outConfig = 0; #endif - MESON_LOGV("%s ActiveConfigid=%d", __func__, *outConfig); + MESON_LOGV("[%s] ActiveConfigid=%d", __func__, *outConfig); return HWC2_ERROR_NONE; } @@ -203,6 +204,7 @@ int32_t RealModeMgr::setActiveConfig(uint32_t config) { std::map<uint32_t, drm_mode_info_t>::iterator it = mModes.find(config); + MESON_LOGV("[%s] %d", __func__, config); if (it != mModes.end()) { drm_mode_info_t cfg = it->second; @@ -212,6 +214,8 @@ int32_t RealModeMgr::setActiveConfig(uint32_t config) { return HWC2_ERROR_NONE; } + mCallOnHotPlug = false; + mConnector->setMode(cfg); mCrtc->setMode(cfg); } else { MESON_LOGE("set invalild active config (%d)", config); @@ -225,6 +229,10 @@ int32_t RealModeMgr::setActiveConfig(uint32_t config) { return HWC2_ERROR_NONE; } +void RealModeMgr::resetTags() { + mCallOnHotPlug = true; +}; + void RealModeMgr::dump(String8 & dumpstr) { dumpstr.appendFormat("RealModeMgr:(%s)\n", mCurMode.name); dumpstr.append("---------------------------------------------------------" diff --git a/hwc2/RealModeMgr.h b/hwc2/RealModeMgr.h index afd2ee6..4c36b56 100644 --- a/hwc2/RealModeMgr.h +++ b/hwc2/RealModeMgr.h @@ -31,7 +31,7 @@ public: void setDisplayResources(std::shared_ptr<HwDisplayCrtc> & crtc, std::shared_ptr<HwDisplayConnector> & connector); int32_t update(); - bool needCallHotPlug() {return true;}; + bool needCallHotPlug() { return mCallOnHotPlug; }; int32_t getDisplayMode(drm_mode_info_t & mode); int32_t getDisplayConfigs(uint32_t * outNumConfigs, uint32_t * outConfigs); @@ -39,7 +39,7 @@ public: int32_t* outValue, int32_t caller); int32_t getActiveConfig(uint32_t * outConfig, int32_t caller); int32_t setActiveConfig(uint32_t config); - void resetTags(){}; + void resetTags(); void dump(String8 & dumpstr); protected: @@ -55,6 +55,7 @@ protected: std::map<uint32_t, drm_mode_info_t> mModes; drm_mode_info_t mCurMode; uint32_t mActiveConfigId; + bool mCallOnHotPlug; // protect mMode and mActiveConfigId std::mutex mMutex; |