RDKEMW-17527: Fix for hangup issue in PowerController library#3890
RDKEMW-17527: Fix for hangup issue in PowerController library#3890yuvaramachandran-gurusamy wants to merge 10 commits intodevelopfrom
Conversation
Signed-off-by: yuvaramachandran_gurusamy <yuvaramachandran_gurusamy@comcast.com>
There was a problem hiding this comment.
Pull request overview
This PR updates the WPEFramework clientlibraries patch for the PowerController/PowerManager client to address a reported hang scenario by reworking notification (un)subscription flow and expanding callback/connection logging.
Changes:
- Renames and refactors notification registration helpers (e.g., “Thunder” notification registration) and adds subscribe/unsubscribe-all helpers during operational up/down transitions.
- Adds extensive logging around connection lifecycle and callback registration/unregistration.
- Adds per-callback timing instrumentation when dispatching notifications.
Comments suppressed due to low confidence (1)
recipes-extended/wpe-framework/wpeframework-clientlibraries/r4.4/0001-PowerManagerClient-library-implementation.patch:1044
- User callbacks are invoked while
_callbackLockis held. If a callback calls back into this library (e.g., to register/unregister callbacks), it will try to re-acquire_callbackLockand can deadlock. A safer pattern is to copy the callback list under the lock, release the lock, then invoke callbacks outside the lock.
+ _callbackLock.Lock();
+ LOGINFO(">>> Callback Lock acquired");
+ // avoid notifying operational state changed if shuting down because of Term
+ if (!_shutdown) {
+ for (auto& cb : _operationalStateChangeCallbacks) {
+ cb.callback(upAndRunning, cb.userdata);
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| +// Templated Callback list avoid code duplication, for individual callback types | ||
| +// This class expects mechanism to register / unregister for individual & unique notifications with PowerManager | ||
| +// via RegisterNotificationLocked and UnregisterNotificationLocked methods. To be implemented in PowerController (i,e PARENT) | ||
| +// via RegisterThunderNotificationLocked and UnregisterNotificationLocked methods. To be implemented in PowerController (i,e PARENT) |
| + void SubscribeAllNotificationsLocked() | ||
| + { | ||
| + _powerModeChangedCallbacks.RegisterNotificationLocked(); | ||
| + _powerModePreChangeCallbacks.RegisterNotificationLocked(); | ||
| + _deepSleepTimeoutCallbacks.RegisterNotificationLocked(); | ||
| + _networkStandbyModeChangedCallbacks.RegisterNotificationLocked(); | ||
| + _thermalModeChangedCallbacks.RegisterNotificationLocked(); | ||
| + _rebootBeginCallbacks.RegisterNotificationLocked(); | ||
| + LOGINFO("Entering ..."); | ||
| + _powerModeChangedCallbacks.RegisterNotificationInternalLocked(); | ||
| + _powerModePreChangeCallbacks.RegisterNotificationInternalLocked(); |
| + void UnsubscribeAllNotificationsLocked() | ||
| + { | ||
| + _powerModeChangedCallbacks.UnregisterNotificationLocked(true); | ||
| + _powerModePreChangeCallbacks.UnregisterNotificationLocked(true); | ||
| + _deepSleepTimeoutCallbacks.UnregisterNotificationLocked(true); | ||
| + _networkStandbyModeChangedCallbacks.UnregisterNotificationLocked(true); | ||
| + _thermalModeChangedCallbacks.UnregisterNotificationLocked(true); | ||
| + _rebootBeginCallbacks.UnregisterNotificationLocked(true); | ||
| + LOGINFO("Entering ..."); | ||
| + _powerModeChangedCallbacks.UnregisterNotificationInternalLocked(true); | ||
| + _powerModePreChangeCallbacks.UnregisterNotificationInternalLocked(true); |
| + | ||
| + LOGINFO(">>> currentState[%d], newState[%d]", currentState_, newState_); | ||
| + _callbackLock.Lock(); | ||
| + LOGINFO("Callback count: %zu", _powerModeChangedCallbacks.Count()); | ||
| + | ||
| + for (auto& cb : _powerModeChangedCallbacks) { | ||
| + auto start = std::chrono::steady_clock::now(); | ||
| + cb.callback(currentState_, newState_, cb.userdata); | ||
| + auto end = std::chrono::steady_clock::now(); | ||
| + auto duration = std::chrono::duration_cast<std::chrono::milliseconds>(end - start).count(); | ||
| + LOGINFO("Callback %p took %lld ms to process PowerModeChanged notification", cb.callback, duration); | ||
| + } | ||
| + | ||
| + _callbackLock.Unlock(); |
| + _callbackLock.Lock(); | ||
| + LOGINFO("Callback count: %zu", _powerModePreChangeCallbacks.Count()); | ||
| + | ||
| + for (auto& cb : _powerModePreChangeCallbacks) { | ||
| + auto start = std::chrono::steady_clock::now(); |
| + LOGINFO("Callback count: %zu", _rebootBeginCallbacks.Count()); | ||
| + | ||
| + for (auto& cb : _rebootBeginCallbacks) { | ||
| + auto start = std::chrono::steady_clock::now(); | ||
| + cb.callback(rebootReasonCustom.c_str(), rebootReasonOther.c_str(), rebootRequestor.c_str(), cb.userdata); | ||
| + auto end = std::chrono::steady_clock::now(); | ||
| + auto duration = std::chrono::duration_cast<std::chrono::milliseconds>(end - start).count(); | ||
| + LOGINFO("Callback %p took %lld ms to process RebootBegin notification", cb.callback, duration); | ||
| + } | ||
| + | ||
| + _callbackLock.Unlock(); |
| + LOGINFO(">>> callback: %p, userdata: %p", callback, userdata); | ||
| + | ||
| + ASSERT(nullptr != callback); | ||
| + | ||
| + if (nullptr != callback) { | ||
| + _callbackLock.Lock(); |
| + if (nullptr == _instance) { | ||
| + LOGERR("PowerController::Init failed, out of memory ?"); | ||
| + } | ||
| + else { | ||
| + LOGINFO("PowerController::Init successful"); | ||
| + } |
| + if (it == this->end()) { | ||
| + LOGINFO("Callback identifier[%p]", (void*)callback); | ||
| + this->emplace_back(callback, userdata); | ||
| + result = Core::ERROR_NONE; |
| + this->erase(it); | ||
| + result = Core::ERROR_NONE; | ||
| + UnregisterNotificationLocked(false); | ||
| + UnregisterNotificationInternalLocked(false); |
|
CCI-Build-Verified +1 |
|
CCI-Test-Verified +1 |
Signed-off-by: yuvaramachandran_gurusamy <yuvaramachandran_gurusamy@comcast.com>
|
CCI-Build-Verified +1 |
|
CCI-Test-Verified +1 |
Signed-off-by: yuvaramachandran_gurusamy <yuvaramachandran_gurusamy@comcast.com>
Rebase with develop branch
|
CCI-Build-Verified +1 |
|
CCI-Test-Verified +1 |
Signed-off-by: yuvaramachandran_gurusamy <yuvaramachandran_gurusamy@comcast.com>
…opic/RDKEMW-17527
…ideo into topic/RDKEMW-17527
|
CCI-Build-Verified +1 |
Signed-off-by: yuvaramachandran_gurusamy <yuvaramachandran_gurusamy@comcast.com>
Signed-off-by: yuvaramachandran_gurusamy <yuvaramachandran_gurusamy@comcast.com>
|
CCI-Test-Verified +1 |
Rebase with Develop branch
|
CCI-Build-Verified +1 |
3 similar comments
|
CCI-Build-Verified +1 |
|
CCI-Build-Verified +1 |
|
CCI-Build-Verified +1 |
|
CCI-Test-Verified +1 |
RDKEMW-17527: Fix for hangup issue in PowerController library
Signed-off-by: yuvaramachandran_gurusamy yuvaramachandran_gurusamy@comcast.com