Skip to content

Commit

Permalink
Hibernate Abort improvements (rdkcentral#1577)
Browse files Browse the repository at this point in the history
- fixed logging and return in case of late abortion
 - quicker for multi process plugins
  • Loading branch information
adrianM27 authored Apr 22, 2024
1 parent 3477427 commit 932dee7
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 15 deletions.
22 changes: 12 additions & 10 deletions Source/WPEFramework/PluginServer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -344,8 +344,8 @@ namespace PluginHost {
Unlock();
result = Core::ERROR_ILLEGAL_STATE;
} else if (currentState == IShell::state::HIBERNATED) {
Unlock();
result = Wakeup(3000);
Unlock();
} else if ((currentState == IShell::state::DEACTIVATED) || (currentState == IShell::state::PRECONDITION)) {

// Load the interfaces, If we did not load them yet...
Expand Down Expand Up @@ -531,9 +531,7 @@ namespace PluginHost {

if(currentState == IShell::state::HIBERNATED)
{
Unlock();
uint32_t wakeupResult = Wakeup(3000);
Lock();
if(wakeupResult != Core::ERROR_NONE)
{
//Force Activated state
Expand Down Expand Up @@ -746,7 +744,13 @@ namespace PluginHost {
result = Core::ERROR_NONE;
#endif
if (result == Core::ERROR_NONE) {
SYSLOG(Logging::Startup, (_T("Hibernated plugin [%s]:[%s]"), ClassName().c_str(), Callsign().c_str()));
if (State() == IShell::state::HIBERNATED) {
SYSLOG(Logging::Startup, ("Hibernated plugin [%s]:[%s]", ClassName().c_str(), Callsign().c_str()));
} else {
// wakeup occured right after hibernation finished
SYSLOG(Logging::Startup, ("Hibernation aborted of plugin [%s]:[%s]", ClassName().c_str(), Callsign().c_str()));
result = Core::ERROR_ABORTED;
}
}
else if (State() == IShell::state::HIBERNATED) {
State(IShell::ACTIVATED);
Expand All @@ -763,8 +767,6 @@ namespace PluginHost {
uint32_t Server::Service::Wakeup(const uint32_t timeout VARIABLE_IS_NOT_USED) {
Core::hresult result = Core::ERROR_NONE;

Lock();

IShell::state currentState(State());

if (currentState != IShell::state::HIBERNATED) {
Expand Down Expand Up @@ -798,7 +800,6 @@ namespace PluginHost {
local->Release();
}
}
Unlock();

return (result);
}
Expand Down Expand Up @@ -863,12 +864,13 @@ namespace PluginHost {
Core::ProcessInfo::Iterator children(parentPID);

if (children.Count() > 0) {

while (children.Next()) {
// make sure to wakeup PIDs in opposite order to hibernation
// to quickly go over not hibernated PIDs and abort currently processed
children.Reset(false);
while (children.Previous()) {
// Wakeup children of this process
// There is no recovery path while doing Wakeup, don't care about errors
WakeupChildren(children.Current().Id(), timeout);

TRACE(Activity, (_T("Wakeup of plugin [%s] child process [%u]"), Callsign().c_str(), children.Current().Id()));
result = WakeupProcess(timeout, children.Current().Id(), _administrator.Configuration().HibernateLocator().c_str(), _T(""), &_hibernateStorage);
}
Expand Down
22 changes: 19 additions & 3 deletions Source/core/ProcessInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -157,10 +157,15 @@ namespace Core {
{
return ((_index != 0) && (_index <= _pids.size()));
}
inline void Reset()
inline void Reset(bool start = true)
{
_index = 0;
_current = _pids.begin();
if (start) {
_index = 0;
_current = _pids.begin();
} else {
_index = _pids.size() + 1;
_current = _pids.end();
}
}
bool Next()
{
Expand All @@ -173,6 +178,17 @@ namespace Core {
}
return (_index <= _pids.size());
}
bool Previous()
{
if (_index > 0) {
_index--;

if (_index > 0) {
_current--;
}
}
return (_index > 0);
}
inline ProcessInfo Current() const
{
ASSERT(IsValid() == true);
Expand Down
15 changes: 13 additions & 2 deletions Tests/unit/core/test_processinfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,22 @@ TEST(Core_ProcessInfo, simpleSet)
std::cout << "Size Resident :" << (processInfo.Resident() >> 10) << " KB" << std::endl;
std::cout << "Size Shared :" << (processInfo.Shared() >> 10) << " KB" << std::endl;

Core::ProcessInfo::Iterator childIterator = processInfo.Children();
Core::ProcessInfo::Iterator childIterator = Core::ProcessInfo(0).Children();

std::cout << "Children (" << childIterator.Count() << ") " << std::endl;
childIterator.Reset(false);
std::list<uint32_t> pids;
std::cout << "Children of PID 0 (" << childIterator.Count() << ") in revers order" << std::endl;
while (childIterator.Previous()) {
Core::ProcessInfo childProcessInfo = childIterator.Current();
std::cout << "\tName : " << childProcessInfo.Name() << " (" << childProcessInfo.Id() << "): " << childProcessInfo.Resident() << std::endl;
pids.push_front(childProcessInfo.Id());
}

std::cout << "Children of PID 0 (" << childIterator.Count() << ") " << std::endl;
while (childIterator.Next()) {
Core::ProcessInfo childProcessInfo = childIterator.Current();
std::cout << "\tName : " << childProcessInfo.Name() << " (" << childProcessInfo.Id() << "): " << childProcessInfo.Resident() << std::endl;
EXPECT_EQ(childProcessInfo.Id(),pids.front());
pids.pop_front();
}
}

0 comments on commit 932dee7

Please sign in to comment.