@@ -226,9 +226,9 @@ static char* hostif_vlan_tag[] = {
226226 */
227227PortsOrch::PortsOrch (DBConnector *db, vector<table_name_with_pri_t > &tableNames) :
228228 Orch(db, tableNames),
229- port_stat_manager(PORT_STAT_COUNTER_FLEX_COUNTER_GROUP, StatsMode::READ, PORT_STAT_FLEX_COUNTER_POLLING_INTERVAL_MS, true ),
230- port_buffer_drop_stat_manager(PORT_BUFFER_DROP_STAT_FLEX_COUNTER_GROUP, StatsMode::READ, PORT_BUFFER_DROP_STAT_POLLING_INTERVAL_MS, true ),
231- queue_stat_manager(QUEUE_STAT_COUNTER_FLEX_COUNTER_GROUP, StatsMode::READ, QUEUE_STAT_FLEX_COUNTER_POLLING_INTERVAL_MS, true )
229+ port_stat_manager(PORT_STAT_COUNTER_FLEX_COUNTER_GROUP, StatsMode::READ, PORT_STAT_FLEX_COUNTER_POLLING_INTERVAL_MS, false ),
230+ port_buffer_drop_stat_manager(PORT_BUFFER_DROP_STAT_FLEX_COUNTER_GROUP, StatsMode::READ, PORT_BUFFER_DROP_STAT_POLLING_INTERVAL_MS, false ),
231+ queue_stat_manager(QUEUE_STAT_COUNTER_FLEX_COUNTER_GROUP, StatsMode::READ, QUEUE_STAT_FLEX_COUNTER_POLLING_INTERVAL_MS, false )
232232{
233233 SWSS_LOG_ENTER ();
234234
@@ -2012,19 +2012,21 @@ bool PortsOrch::initPort(const string &alias, const int index, const set<int> &l
20122012 vector<FieldValueTuple> fields;
20132013 fields.push_back (tuple);
20142014 m_counterTable->set (" " , fields);
2015+
20152016 // Install a flex counter for this port to track stats
2016- std::unordered_set<std::string> counter_stats;
2017- for (const auto & it: port_stat_ids)
2017+ auto flex_counters_orch = gDirectory .get <FlexCounterOrch*>();
2018+ /* Delay installing the counters if they are yet enabled
2019+ If they are enabled, install the counters immediately */
2020+ if (flex_counters_orch->getPortCountersState ())
20182021 {
2019- counter_stats.emplace (sai_serialize_port_stat (it));
2022+ auto port_counter_stats = generateCounterStats (PORT_STAT_COUNTER_FLEX_COUNTER_GROUP);
2023+ port_stat_manager.setCounterIdList (p.m_port_id , CounterType::PORT, port_counter_stats);
20202024 }
2021- port_stat_manager.setCounterIdList (p.m_port_id , CounterType::PORT, counter_stats);
2022- std::unordered_set<std::string> port_buffer_drop_stats;
2023- for (const auto & it: port_buffer_drop_stat_ids)
2025+ if (flex_counters_orch->getPortBufferDropCountersState ())
20242026 {
2025- port_buffer_drop_stats.emplace (sai_serialize_port_stat (it));
2027+ auto port_buffer_drop_stats = generateCounterStats (PORT_BUFFER_DROP_STAT_FLEX_COUNTER_GROUP);
2028+ port_buffer_drop_stat_manager.setCounterIdList (p.m_port_id , CounterType::PORT, port_buffer_drop_stats);
20262029 }
2027- port_buffer_drop_stat_manager.setCounterIdList (p.m_port_id , CounterType::PORT, port_buffer_drop_stats);
20282030
20292031 PortUpdate update = { p, true };
20302032 notify (SUBJECT_TYPE_PORT_CHANGE, static_cast <void *>(&update));
@@ -2057,8 +2059,11 @@ void PortsOrch::deInitPort(string alias, sai_object_id_t port_id)
20572059 p.m_port_id = port_id;
20582060
20592061 /* remove port from flex_counter_table for updating counters */
2060- port_stat_manager.clearCounterIdList (p.m_port_id );
2061-
2062+ auto flex_counters_orch = gDirectory .get <FlexCounterOrch*>();
2063+ if ((flex_counters_orch->getPortCountersState ()))
2064+ {
2065+ port_stat_manager.clearCounterIdList (p.m_port_id );
2066+ }
20622067 /* remove port name map from counter table */
20632068 m_counter_db->hdel (COUNTERS_PORT_NAME_MAP, alias);
20642069
@@ -4375,6 +4380,48 @@ void PortsOrch::generatePriorityGroupMapPerPort(const Port& port)
43754380 CounterCheckOrch::getInstance ().addPort (port);
43764381}
43774382
4383+ void PortsOrch::generatePortCounterMap ()
4384+ {
4385+ if (m_isPortCounterMapGenerated)
4386+ {
4387+ return ;
4388+ }
4389+
4390+ auto port_counter_stats = generateCounterStats (PORT_STAT_COUNTER_FLEX_COUNTER_GROUP);
4391+ for (const auto & it: m_portList)
4392+ {
4393+ // 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.
4394+ if (it.second .m_type != Port::Type::PHY)
4395+ {
4396+ continue ;
4397+ }
4398+ port_stat_manager.setCounterIdList (it.second .m_port_id , CounterType::PORT, port_counter_stats);
4399+ }
4400+
4401+ m_isPortCounterMapGenerated = true ;
4402+ }
4403+
4404+ void PortsOrch::generatePortBufferDropCounterMap ()
4405+ {
4406+ if (m_isPortBufferDropCounterMapGenerated)
4407+ {
4408+ return ;
4409+ }
4410+
4411+ auto port_buffer_drop_stats = generateCounterStats (PORT_BUFFER_DROP_STAT_FLEX_COUNTER_GROUP);
4412+ for (const auto & it: m_portList)
4413+ {
4414+ // 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.
4415+ if (it.second .m_type != Port::Type::PHY)
4416+ {
4417+ continue ;
4418+ }
4419+ port_buffer_drop_stat_manager.setCounterIdList (it.second .m_port_id , CounterType::PORT, port_buffer_drop_stats);
4420+ }
4421+
4422+ m_isPortBufferDropCounterMapGenerated = true ;
4423+ }
4424+
43784425void PortsOrch::doTask (NotificationConsumer &consumer)
43794426{
43804427 SWSS_LOG_ENTER ();
@@ -4958,3 +5005,22 @@ bool PortsOrch::initGearboxPort(Port &port)
49585005 return true ;
49595006}
49605007
5008+ std::unordered_set<std::string> PortsOrch::generateCounterStats (const string& type)
5009+ {
5010+ std::unordered_set<std::string> counter_stats;
5011+ if (type == PORT_STAT_COUNTER_FLEX_COUNTER_GROUP)
5012+ {
5013+ for (const auto & it: port_stat_ids)
5014+ {
5015+ counter_stats.emplace (sai_serialize_port_stat (it));
5016+ }
5017+ }
5018+ else if (type == PORT_BUFFER_DROP_STAT_FLEX_COUNTER_GROUP)
5019+ {
5020+ for (const auto & it: port_buffer_drop_stat_ids)
5021+ {
5022+ counter_stats.emplace (sai_serialize_port_stat (it));
5023+ }
5024+ }
5025+ return counter_stats;
5026+ }
0 commit comments