Skip to content

Commit 727a518

Browse files
[portsyncd] fix default select timeout (#1287)
Default select timeout was set to 1 ms, causing 3-5% CPU usage when idles.
1 parent 0e0f039 commit 727a518

File tree

1 file changed

+23
-5
lines changed

1 file changed

+23
-5
lines changed

portsyncd/portsyncd.cpp

+23-5
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020
using namespace std;
2121
using namespace swss;
2222

23+
#define DEFAULT_SELECT_TIMEOUT 1000 /* ms */
24+
2325
/*
2426
* This g_portSet contains all the front panel ports that the corresponding
2527
* host interfaces needed to be created. When this LinkSync class is
@@ -103,16 +105,26 @@ int main(int argc, char **argv)
103105
{
104106
Selectable *temps;
105107
int ret;
106-
ret = s.select(&temps, 1);
108+
ret = s.select(&temps, DEFAULT_SELECT_TIMEOUT);
107109

108110
if (ret == Select::ERROR)
109111
{
110112
cerr << "Error had been returned in select" << endl;
111113
continue;
112114
}
115+
else if (ret == Select::TIMEOUT)
116+
{
117+
continue;
118+
}
119+
else if (ret != Select::OBJECT)
120+
{
121+
SWSS_LOG_ERROR("Unknown return value from Select %d", ret);
122+
continue;
123+
}
113124

114-
if (ret == Select::TIMEOUT)
125+
if (temps == static_cast<Selectable*>(&netlink))
115126
{
127+
/* on netlink message, check if PortInitDone should be sent out */
116128
if (!g_init && g_portSet.empty())
117129
{
118130
/*
@@ -134,8 +146,7 @@ int main(int argc, char **argv)
134146
handlePortConfig(p, port_cfg_map);
135147
}
136148
}
137-
138-
if (temps == (Selectable *)&portCfg)
149+
else if (temps == (Selectable *)&portCfg)
139150
{
140151
std::deque<KeyOpFieldsValuesTuple> entries;
141152
portCfg.pops(entries);
@@ -153,6 +164,11 @@ int main(int argc, char **argv)
153164
}
154165
handlePortConfig(p, port_cfg_map);
155166
}
167+
else
168+
{
169+
SWSS_LOG_ERROR("Unknown object returned by select");
170+
continue;
171+
}
156172
}
157173
}
158174
catch (const std::exception& e)
@@ -179,7 +195,9 @@ static void notifyPortConfigDone(ProducerStateTable &p)
179195

180196
bool handlePortConfigFromConfigDB(ProducerStateTable &p, DBConnector &cfgDb, bool warm)
181197
{
182-
cout << "Get port configuration from ConfigDB..." << endl;
198+
SWSS_LOG_ENTER();
199+
200+
SWSS_LOG_NOTICE("Getting port configuration from ConfigDB...");
183201

184202
Table table(&cfgDb, CFG_PORT_TABLE_NAME);
185203
std::vector<FieldValueTuple> ovalues;

0 commit comments

Comments
 (0)