[master] Smart Counter Poll to allow counters to work properly on Broadcom platforms.#1774
Conversation
|
/azp run |
|
Azure Pipelines will not run the associated pipelines, because the pull request was updated after the run command was issued. Review the pull request again and issue a new run command. |
|
/azp run |
|
Azure Pipelines successfully started running 1 pipeline(s). |
|
/azp run |
|
Azure Pipelines successfully started running 1 pipeline(s). |
|
WIP - adding unit test |
|
/azp run |
|
Azure Pipelines successfully started running 1 pipeline(s). |
|
/azp run |
|
Azure Pipelines successfully started running 1 pipeline(s). |
|
/azp run |
|
Azure Pipelines successfully started running 1 pipeline(s). |
|
/azp run |
|
Azure Pipelines successfully started running 1 pipeline(s). |
|
/azp run |
|
Azure Pipelines successfully started running 1 pipeline(s). |
|
/azp run |
|
Azure Pipelines successfully started running 1 pipeline(s). |
|
/azp run |
|
Azure Pipelines successfully started running 1 pipeline(s). |
|
/azp run |
|
Azure Pipelines successfully started running 1 pipeline(s). |
|
/azp run |
|
Azure Pipelines successfully started running 1 pipeline(s). |
|
Azure Pipelines successfully started running 1 pipeline(s). |
Signed-off-by: Justin Wong <jvwong@arista.com>
|
/azp run |
|
Azure Pipelines successfully started running 1 pipeline(s). |
|
/azpw retry |
|
Retrying failed(or canceled) jobs... |
|
Retrying failed(or canceled) stages in build 1156144: ✅Stage Build:
|
Aside from an unrelated regression, there are no notable regressions from running |
|
@justin-wong-ce - I re-reviewed the latest head. The earlier cleanup comments look mostly addressed and CI is green, but I still have two correctness questions before approval.
|
lolyu
left a comment
There was a problem hiding this comment.
Review: #1774 (re-review at 7627bd9)
Thanks for the thorough revision — I verified every change against the full source at this head, not just the diff. All nine findings across my earlier rounds are resolved or consciously deferred with good reason. Approving.
The two real bugs and the latent one — all fixed:
- Tombstone leak → free-list.
addGroup(1425) reusesm_freeGroupIndicesbefore appending;cleanupCounterGroupMappingreclaims the index on last-reference removal (1499). The vector no longer accumulates permanent empty-set tombstones across churn. 👍 m_failedPollsleak → fixed.removeObjectnowerase({rid, vid})before dropping the object (1514), so re-added ports get an honest DEBUG→ERROR ramp again.m_failedPollstier off-by-one → fixed. Nowuint32_t n = ++m_failedPolls[{rid, vid}]— a single lookup with cleann==1/n<=3/n==4tiers (the ERROR fires exactly once). The C++11++operator[]adaptation is functionally equivalent to thetry_emplaceI suggested.
Convention / duplication:
addGrouphelper now owns group creation at all five sites (index captured once, pre-push) — the four-spelling index inconsistency is now unwritable, and the sort-lambda is factored in.std::setcopies →const&(2008/2067/2080/2082); unqualifiedfind→std::find(2011).- The 4× erase-then-emplace block collapsed to a single
m_objectIdsMap[vid] = std::make_shared<...>at each site — cleaner than the helper I proposed. getSortedCGRefremoved entirely, which resolves the mutable-interior-pointer concern more completely than constifying it would have.
On the SWSS_LOG_ENTER build constraint: fair point, and well handled. Resolving the dedup/encapsulation items by inlining (removing the accessor, using operator[] directly) rather than adding helper functions is the right synthesis — it achieves the cleanup without paying the per-call logging overhead the CI check imposes. Noted and agreed.
One optional follow-up (non-blocking): the bulk-vs-single dispatch duplication you're leaving in place pending removal of the fallback path is a reasonable call — consider a // TODO: remove fallback path once addObjectWithCounterGroups is proven stable marker so that intent is visible in-tree to the next reader.
Nice work — the feature was sound to begin with, and the new code is now tight. LGTM.
|
Hi @justin-wong-ce for the cherrypick, could you test with 202605 and update in the description? |
I have ran the changes with 202511, 202605 sonic-mgmt is in progress - I expect more noise with that due to 202605 being newly branched. I have manually created a cherry-pick here: #1956 - I will post further updates directly there. |
|
202605 tests are in progress. Cherry pick will not be done until testing is complete with results. |
|
FYI @lolyu @vaibhavhd I have updated the PR description as well. |
|
Cherry-pick PR to 202605: #1995 |
…y on Broadcom platforms. (sonic-net#1774)" This reverts commit cda4337.
Summary
This is change is to address #1753 and the master implementation of the HLD added in sonic-net/SONiC#2190.
FlexCounter.cppassumes all ports support the same counter capabilities. This causes issues on most Broadcom platform switches as there are different types of ports on a switch that does not support the same set of counters.Fix by dynamically discovering what each interface is capable of during initialization of
syncd.For more detials please refer to the above issue and HLD.
Testing
Master testing is also done, but due to frequent changes in master tests fail on other issues depending which commit is used for testing. However, none of the issues seem related to this change.
More comprehensive testing is done on the 202511 stable branch:
Testing is done on both a
Arista-7060X6-16PE-384C-B-O128S2andArista-7260CX3-D108C8on 202511 with the tests:A full
sonic-mgmttest suite run has also been ran (202511). There are no notable fallout compared tosonic-mgmtruns without this change. This is ran on both XGS and DNX Broadcom platforms.EDIT: Jul 13, 2026
202605 Testing
Additional 202605 testing has been done.
Comparing full 202605
sonic-mgmttest results on TH5 (usingArista-7060X6-64PE) with and without these changes, there is no difference in the test results.Performance Impact:
All logic change is only done in the counter initialisation stage of FlexCounters.cpp - there is no polling logic change at all.
Therefore, any performance impact is limited to any new execution of
syncd- i.e. reboot /config reload/systemctl restart.Tested on several topologies:

This impact seems reasonable for what this offers.
The fastest operation that would cause a
syncdrestart is asystemctl restart swss, that is a operation that spans minutes. The worst real life scenario on a HwSKU with older CPU and many interfaces takes additional ~17 seconds. New, high interface-count HwSKUs only takes an extra ~2 seconds.As for memory usage - the impact is on the order of kilobytes, the impact is negligible as the system has GBs of RAM.