From d1f582c291e7fa24ab897d4c412c5a8e08bf625d Mon Sep 17 00:00:00 2001 From: Sonic Build Admin Date: Thu, 2 Jul 2026 15:34:17 +0000 Subject: [PATCH] Cast workaround for N/A counter values from 202412 ### Description of PR Summary: Casting workaround for N/A counters on management ports on Broadcom platforms. This impacts all hwsku-topo combos that uses management ports (including TH5). Casting from: https://github.com/Azure/sonic-sairedis.msft/pull/69 Proper fix under review at: master: https://github.com/sonic-net/sonic-sairedis/pull/1774 202511: https://github.com/sonic-net/sonic-sairedis/pull/1862 202605: https://github.com/sonic-net/sonic-sairedis/pull/1956 Fixes #1753 (temporary fix) ### Type of change - [x] Bug fix - [ ] New feature - [ ] Refactor / cleanup - [ ] Documentation update - [ ] Test improvement ### Approach #### What is the motivation for this PR? To fix `N/A` counters on management ports on Broadcom platforms. ##### Work item tracking - Microsoft ADO **(number only)**: #### How did you do it? Temporarily fill in `0` values for counters that are supported in the usual interfaces but not supported in the management ports. #### How did you verify/test it? `show interface counters` no longer show `N/A` counters. #### Any platform specific information? Broadcom only. ### Documentation Signed-off-by: Sonic Build Admin --- syncd/FlexCounter.cpp | 41 ++++++++++++++++++++++------------------- 1 file changed, 22 insertions(+), 19 deletions(-) diff --git a/syncd/FlexCounter.cpp b/syncd/FlexCounter.cpp index 948c0b2b40..15d7d971de 100644 --- a/syncd/FlexCounter.cpp +++ b/syncd/FlexCounter.cpp @@ -990,24 +990,24 @@ class CounterContext : public BaseCounterContext auto rid = rids[i]; auto vid = vids[i]; std::vector stats(counter_ids.size()); - if (collectData(rid, counter_ids, effective_stats_mode, false, stats)) { - - auto it_vid = m_objectIdsMap.find(vid); - if (it_vid != m_objectIdsMap.end()) - { - // Remove and re-add if vid already exists - m_objectIdsMap.erase(it_vid); - } - - auto counter_data = std::make_shared>(rid, counter_ids); - m_objectIdsMap.emplace(vid, counter_data); - - SWSS_LOG_INFO("Fallback to single call for object 0x%" PRIx64, vid); - } else { - SWSS_LOG_WARN("%s RID %s can't provide the statistic", m_name.c_str(), sai_serialize_object_id(rid).c_str()); + if (!collectData(rid, counter_ids, effective_stats_mode, false, stats)) + { + // Workaround for N/A Counters on Broadcom management ports + // Adding VIDs with unsupported counters to objectIdsMap to unblock testing + // Please see https://github.com/sonic-net/sonic-sairedis/issues/1753 for details + SWSS_LOG_INFO("counter read failed on RID 0x%" PRIx64 " on intf 0x%" PRIx64 ", adding to objectIdsMap regardless", rid, vid); + } + auto it_vid = m_objectIdsMap.find(vid); + if (it_vid != m_objectIdsMap.end()) + { + // Remove and re-add if vid already exists + m_objectIdsMap.erase(it_vid); } - } + auto counter_data = std::make_shared>(rid, counter_ids); + m_objectIdsMap.emplace(vid, counter_data); + SWSS_LOG_INFO("Fallback to single call for object 0x%" PRIx64, vid); + } return; } @@ -1159,10 +1159,13 @@ class CounterContext : public BaseCounterContext kv.second->getStatsMode() == SAI_STATS_MODE_READ_AND_CLEAR) ? SAI_STATS_MODE_READ_AND_CLEAR : SAI_STATS_MODE_READ; } - std::vector stats(statIds.size()); - if (!collectData(rid, statIds, effective_stats_mode, true, stats)) + // Workaround for N/A Counters on Broadcom management ports + // Using '0' for unsupported counters to unblock testing + // Please see https://github.com/sonic-net/sonic-sairedis/issues/1753 for details + std::vector stats(statIds.size(), 0); + if (!collectData(rid, statIds, effective_stats_mode, false, stats)) { - continue; + SWSS_LOG_INFO("counter read failed on RID 0x%" PRIx64 " on intf 0x%" PRIx64 ", filling with '0' value", rid, vid); } std::vector values;