Skip to content

Commit

Permalink
Hibernate Abort improvements
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 committed Apr 22, 2024
1 parent cf4fecb commit 9e38f64
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 @@ -337,8 +337,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 @@ -524,9 +524,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 @@ -739,7 +737,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 @@ -756,8 +760,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 @@ -791,7 +793,6 @@ namespace PluginHost {
local->Release();
}
}
Unlock();

return (result);
}
Expand Down Expand Up @@ -856,12 +857,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 @@ -136,10 +136,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 @@ -152,6 +157,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 9e38f64

Please sign in to comment.