From 727a518159a08e245f6f37d58f796f2b9097774a Mon Sep 17 00:00:00 2001 From: Stepan Blyshchak <38952541+stepanblyschak@users.noreply.github.com> Date: Wed, 13 May 2020 23:36:45 +0300 Subject: [PATCH] [portsyncd] fix default select timeout (#1287) Default select timeout was set to 1 ms, causing 3-5% CPU usage when idles. --- portsyncd/portsyncd.cpp | 28 +++++++++++++++++++++++----- 1 file changed, 23 insertions(+), 5 deletions(-) diff --git a/portsyncd/portsyncd.cpp b/portsyncd/portsyncd.cpp index 8d618c80cb..151ac16657 100644 --- a/portsyncd/portsyncd.cpp +++ b/portsyncd/portsyncd.cpp @@ -20,6 +20,8 @@ using namespace std; using namespace swss; +#define DEFAULT_SELECT_TIMEOUT 1000 /* ms */ + /* * This g_portSet contains all the front panel ports that the corresponding * host interfaces needed to be created. When this LinkSync class is @@ -103,16 +105,26 @@ int main(int argc, char **argv) { Selectable *temps; int ret; - ret = s.select(&temps, 1); + ret = s.select(&temps, DEFAULT_SELECT_TIMEOUT); if (ret == Select::ERROR) { cerr << "Error had been returned in select" << endl; continue; } + else if (ret == Select::TIMEOUT) + { + continue; + } + else if (ret != Select::OBJECT) + { + SWSS_LOG_ERROR("Unknown return value from Select %d", ret); + continue; + } - if (ret == Select::TIMEOUT) + if (temps == static_cast(&netlink)) { + /* on netlink message, check if PortInitDone should be sent out */ if (!g_init && g_portSet.empty()) { /* @@ -134,8 +146,7 @@ int main(int argc, char **argv) handlePortConfig(p, port_cfg_map); } } - - if (temps == (Selectable *)&portCfg) + else if (temps == (Selectable *)&portCfg) { std::deque entries; portCfg.pops(entries); @@ -153,6 +164,11 @@ int main(int argc, char **argv) } handlePortConfig(p, port_cfg_map); } + else + { + SWSS_LOG_ERROR("Unknown object returned by select"); + continue; + } } } catch (const std::exception& e) @@ -179,7 +195,9 @@ static void notifyPortConfigDone(ProducerStateTable &p) bool handlePortConfigFromConfigDB(ProducerStateTable &p, DBConnector &cfgDb, bool warm) { - cout << "Get port configuration from ConfigDB..." << endl; + SWSS_LOG_ENTER(); + + SWSS_LOG_NOTICE("Getting port configuration from ConfigDB..."); Table table(&cfgDb, CFG_PORT_TABLE_NAME); std::vector ovalues;