@@ -284,9 +284,9 @@ static char* hostif_vlan_tag[] = {
284
284
PortsOrch::PortsOrch (DBConnector *db, DBConnector *stateDb, vector<table_name_with_pri_t > &tableNames, DBConnector *chassisAppDb) :
285
285
Orch(db, tableNames),
286
286
m_portStateTable(stateDb, STATE_PORT_TABLE_NAME),
287
- port_stat_manager(PORT_STAT_COUNTER_FLEX_COUNTER_GROUP, StatsMode::READ, PORT_STAT_FLEX_COUNTER_POLLING_INTERVAL_MS, true ),
288
- port_buffer_drop_stat_manager(PORT_BUFFER_DROP_STAT_FLEX_COUNTER_GROUP, StatsMode::READ, PORT_BUFFER_DROP_STAT_POLLING_INTERVAL_MS, true ),
289
- queue_stat_manager(QUEUE_STAT_COUNTER_FLEX_COUNTER_GROUP, StatsMode::READ, QUEUE_STAT_FLEX_COUNTER_POLLING_INTERVAL_MS, true )
287
+ port_stat_manager(PORT_STAT_COUNTER_FLEX_COUNTER_GROUP, StatsMode::READ, PORT_STAT_FLEX_COUNTER_POLLING_INTERVAL_MS, false ),
288
+ port_buffer_drop_stat_manager(PORT_BUFFER_DROP_STAT_FLEX_COUNTER_GROUP, StatsMode::READ, PORT_BUFFER_DROP_STAT_POLLING_INTERVAL_MS, false ),
289
+ queue_stat_manager(QUEUE_STAT_COUNTER_FLEX_COUNTER_GROUP, StatsMode::READ, QUEUE_STAT_FLEX_COUNTER_POLLING_INTERVAL_MS, false )
290
290
{
291
291
SWSS_LOG_ENTER ();
292
292
@@ -2273,19 +2273,21 @@ bool PortsOrch::initPort(const string &alias, const string &role, const int inde
2273
2273
vector<FieldValueTuple> fields;
2274
2274
fields.push_back (tuple);
2275
2275
m_counterTable->set (" " , fields);
2276
+
2276
2277
// Install a flex counter for this port to track stats
2277
- std::unordered_set<std::string> counter_stats;
2278
- for (const auto & it: port_stat_ids)
2278
+ auto flex_counters_orch = gDirectory .get <FlexCounterOrch*>();
2279
+ /* Delay installing the counters if they are yet enabled
2280
+ If they are enabled, install the counters immediately */
2281
+ if (flex_counters_orch->getPortCountersState ())
2279
2282
{
2280
- counter_stats.emplace (sai_serialize_port_stat (it));
2283
+ auto port_counter_stats = generateCounterStats (PORT_STAT_COUNTER_FLEX_COUNTER_GROUP);
2284
+ port_stat_manager.setCounterIdList (p.m_port_id , CounterType::PORT, port_counter_stats);
2281
2285
}
2282
- port_stat_manager.setCounterIdList (p.m_port_id , CounterType::PORT, counter_stats);
2283
- std::unordered_set<std::string> port_buffer_drop_stats;
2284
- for (const auto & it: port_buffer_drop_stat_ids)
2286
+ if (flex_counters_orch->getPortBufferDropCountersState ())
2285
2287
{
2286
- port_buffer_drop_stats.emplace (sai_serialize_port_stat (it));
2288
+ auto port_buffer_drop_stats = generateCounterStats (PORT_BUFFER_DROP_STAT_FLEX_COUNTER_GROUP);
2289
+ port_buffer_drop_stat_manager.setCounterIdList (p.m_port_id , CounterType::PORT, port_buffer_drop_stats);
2287
2290
}
2288
- port_buffer_drop_stat_manager.setCounterIdList (p.m_port_id , CounterType::PORT, port_buffer_drop_stats);
2289
2291
2290
2292
PortUpdate update = { p, true };
2291
2293
notify (SUBJECT_TYPE_PORT_CHANGE, static_cast <void *>(&update));
@@ -2318,8 +2320,11 @@ void PortsOrch::deInitPort(string alias, sai_object_id_t port_id)
2318
2320
p.m_port_id = port_id;
2319
2321
2320
2322
/* remove port from flex_counter_table for updating counters */
2321
- port_stat_manager.clearCounterIdList (p.m_port_id );
2322
-
2323
+ auto flex_counters_orch = gDirectory .get <FlexCounterOrch*>();
2324
+ if ((flex_counters_orch->getPortCountersState ()))
2325
+ {
2326
+ port_stat_manager.clearCounterIdList (p.m_port_id );
2327
+ }
2323
2328
/* remove port name map from counter table */
2324
2329
m_counter_db->hdel (COUNTERS_PORT_NAME_MAP, alias);
2325
2330
@@ -5072,6 +5077,48 @@ void PortsOrch::generatePriorityGroupMapPerPort(const Port& port)
5072
5077
CounterCheckOrch::getInstance ().addPort (port);
5073
5078
}
5074
5079
5080
+ void PortsOrch::generatePortCounterMap ()
5081
+ {
5082
+ if (m_isPortCounterMapGenerated)
5083
+ {
5084
+ return ;
5085
+ }
5086
+
5087
+ auto port_counter_stats = generateCounterStats (PORT_STAT_COUNTER_FLEX_COUNTER_GROUP);
5088
+ for (const auto & it: m_portList)
5089
+ {
5090
+ // Set counter stats only for PHY ports to ensure syncd will not try to query the counter statistics from the HW for non-PHY ports.
5091
+ if (it.second .m_type != Port::Type::PHY)
5092
+ {
5093
+ continue ;
5094
+ }
5095
+ port_stat_manager.setCounterIdList (it.second .m_port_id , CounterType::PORT, port_counter_stats);
5096
+ }
5097
+
5098
+ m_isPortCounterMapGenerated = true ;
5099
+ }
5100
+
5101
+ void PortsOrch::generatePortBufferDropCounterMap ()
5102
+ {
5103
+ if (m_isPortBufferDropCounterMapGenerated)
5104
+ {
5105
+ return ;
5106
+ }
5107
+
5108
+ auto port_buffer_drop_stats = generateCounterStats (PORT_BUFFER_DROP_STAT_FLEX_COUNTER_GROUP);
5109
+ for (const auto & it: m_portList)
5110
+ {
5111
+ // Set counter stats only for PHY ports to ensure syncd will not try to query the counter statistics from the HW for non-PHY ports.
5112
+ if (it.second .m_type != Port::Type::PHY)
5113
+ {
5114
+ continue ;
5115
+ }
5116
+ port_buffer_drop_stat_manager.setCounterIdList (it.second .m_port_id , CounterType::PORT, port_buffer_drop_stats);
5117
+ }
5118
+
5119
+ m_isPortBufferDropCounterMapGenerated = true ;
5120
+ }
5121
+
5075
5122
void PortsOrch::doTask (NotificationConsumer &consumer)
5076
5123
{
5077
5124
SWSS_LOG_ENTER ();
@@ -6232,3 +6279,23 @@ void PortsOrch::voqSyncDelLagMember(Port &lag, Port &port)
6232
6279
string key = lag.m_system_lag_info .alias + " :" + port.m_system_port_info .alias ;
6233
6280
m_tableVoqSystemLagMemberTable->del (key);
6234
6281
}
6282
+
6283
+ std::unordered_set<std::string> PortsOrch::generateCounterStats (const string& type)
6284
+ {
6285
+ std::unordered_set<std::string> counter_stats;
6286
+ if (type == PORT_STAT_COUNTER_FLEX_COUNTER_GROUP)
6287
+ {
6288
+ for (const auto & it: port_stat_ids)
6289
+ {
6290
+ counter_stats.emplace (sai_serialize_port_stat (it));
6291
+ }
6292
+ }
6293
+ else if (type == PORT_BUFFER_DROP_STAT_FLEX_COUNTER_GROUP)
6294
+ {
6295
+ for (const auto & it: port_buffer_drop_stat_ids)
6296
+ {
6297
+ counter_stats.emplace (sai_serialize_port_stat (it));
6298
+ }
6299
+ }
6300
+ return counter_stats;
6301
+ }
0 commit comments