Skip to content

Commit 76c6b03

Browse files
author
Souvik Roy
committed
Remove redundant async call in FRU collection threads (#588)
This commit removes the redundant std:async call in the detached thread launched for parsing and publishing the VPD for an individual FRU. Since we have a dedicated detached thread for each FRU, we can do VPD parse and publish in a synchronous manner from the detached thread itself, instead of launching a asynchronous task which adds unnecessary performance cost. This commit also handles any exception thrown while launching the detached thread for a FRU. Incase launching detached thread for a FRU fails, we log a PEL and continue launching threads for other FRUs. This commit addresses issue #558. Test: ``` 1. Install bitbaked image on Everest (ever6bmc) 2. After initial boot, check: - BMC State Ready - vpd-manager's CollectionStatus property should be "Completed" busctl get-property com.ibm.VPD.Manager /com/ibm/VPD/Manager com.ibm.VPD.Manager CollectionStatus s "Completed" - vpd-manager status should be running with no restarts - vpd-manager should have only 1 thread running: check "ls -la /proc/<vpd-manager PID>/task" 3. Reboot the BMC several times and repeat Step 2. ``` Change-Id: I603c64dc9b5057429a2288f0edfde6086755b851 Signed-off-by: Souvik Roy <[email protected]>
1 parent 8d35fae commit 76c6b03

File tree

2 files changed

+25
-14
lines changed

2 files changed

+25
-14
lines changed

vpd-manager/include/worker.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ class Worker
8080
* Note: Config JSON file path should be passed to worker class constructor
8181
* to make use of this API.
8282
*
83+
* @throw std::runtime_error
8384
*/
8485
void collectFrusFromJson();
8586

vpd-manager/src/worker.cpp

Lines changed: 24 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#include "backup_restore.hpp"
66
#include "configuration.hpp"
77
#include "constants.hpp"
8+
#include "event_logger.hpp"
89
#include "exceptions.hpp"
910
#include "logger.hpp"
1011
#include "parser.hpp"
@@ -1512,22 +1513,31 @@ void Worker::collectFrusFromJson()
15121513
continue;
15131514
}
15141515

1515-
std::thread{[vpdFilePath, this]() {
1516-
auto l_futureObject = std::async(&Worker::parseAndPublishVPD, this,
1517-
vpdFilePath);
1518-
1519-
std::tuple<bool, std::string> l_threadInfo = l_futureObject.get();
1516+
try
1517+
{
1518+
std::thread{[vpdFilePath, this]() {
1519+
const auto& l_parseResult = parseAndPublishVPD(vpdFilePath);
15201520

1521-
// thread returned.
1522-
m_mutex.lock();
1523-
m_activeCollectionThreadCount--;
1524-
m_mutex.unlock();
1521+
m_mutex.lock();
1522+
m_activeCollectionThreadCount--;
1523+
m_mutex.unlock();
15251524

1526-
if (!m_activeCollectionThreadCount)
1527-
{
1528-
m_isAllFruCollected = true;
1529-
}
1530-
}}.detach();
1525+
if (!m_activeCollectionThreadCount)
1526+
{
1527+
m_isAllFruCollected = true;
1528+
}
1529+
}}.detach();
1530+
}
1531+
catch (const std::exception& l_ex)
1532+
{
1533+
// TODO: Should we re-try launching thread for this FRU?
1534+
EventLogger::createSyncPel(
1535+
types::ErrorType::InvalidVpdMessage, types::SeverityType::Alert,
1536+
__FILE__, __FUNCTION__, 0,
1537+
std::string("Failed to start collection thread for FRU :[" +
1538+
vpdFilePath + "]. Error: " + l_ex.what()),
1539+
std::nullopt, std::nullopt, std::nullopt, std::nullopt);
1540+
}
15311541
}
15321542
}
15331543

0 commit comments

Comments
 (0)