Skip to content

[202605] Smart Counter Poll to allow counters to work properly on Broadcom platforms.#1956

Open
justin-wong-ce wants to merge 5 commits into
sonic-net:202605from
justin-wong-ce:202605_counter_enhancement
Open

[202605] Smart Counter Poll to allow counters to work properly on Broadcom platforms.#1956
justin-wong-ce wants to merge 5 commits into
sonic-net:202605from
justin-wong-ce:202605_counter_enhancement

Conversation

@justin-wong-ce

Copy link
Copy Markdown
Contributor

Description of PR

Summary:
This is change is to address #1753 and to implement the HLD logic in sonic-net/SONiC#2190 to 202605.

Currently, the code assumes 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 this issue by dynamically discovering what each interface is capable of during initialization of syncd.

For more details, please refer to the referenced issue and HLD.
Fixes #1753

Type of change

  • Bug fix
  • New feature
  • Refactor / cleanup
  • Documentation update
  • Test improvement

Approach

What is the motivation for this PR?

Counters are not working on management ports on Broadcom platforms.

Work item tracking
  • Microsoft ADO (number only):

How did you do it?

Implement the HLD logic from sonic-net/SONiC#2190.

How did you verify/test it?

Testing is done on both a Arista-7060X6-16PE-384C-B-O128S2 and Arista-7260CX3-D108C8 on 202511 with the tests:

sonic-mgmt/tests/dhcp_relay/test_dhcp_counter_stress.py
sonic-mgmt/tests/drop_packets/test_drop_counters.py
sonic-mgmt/tests/drop_packets/test_configurable_drop_counters.py
sonic-mgmt/tests/gnmi/test_gnmi_countersdb.py
sonic-mgmt/tests/snmp/test_snmp_queue_counters.py

A full sonic-mgmt test suite run has also been ran. There are no notable fallout compared to sonic-mgmt runs without this change. This is ran on both XGS and DNX Broadcom platforms.

Any platform specific information?

Broadcom platforms only.

Documentation

@mssonicbld

Copy link
Copy Markdown
Collaborator

/azp run

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines successfully started running 1 pipeline(s).

@mssonicbld

Copy link
Copy Markdown
Collaborator

Hi, there are workflow run(s) waiting for approval, you may be first-time contributor. I will notify maintainers to help approve once PR is approved. Thanks!

---Powered by SONiC BuildBot

Signed-off-by: Justin Wong <jvwong@arista.com>
@justin-wong-ce
justin-wong-ce force-pushed the 202605_counter_enhancement branch from 5e06b50 to ece0295 Compare June 29, 2026 16:50
@mssonicbld

Copy link
Copy Markdown
Collaborator

/azp run

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines successfully started running 1 pipeline(s).

@justin-wong-ce justin-wong-ce changed the title Cast counter enhancement from 202511 Cast counter enhancement from 202511 to 202605 Jun 29, 2026
@justin-wong-ce

Copy link
Copy Markdown
Contributor Author

/azpw run

@mssonicbld

Copy link
Copy Markdown
Collaborator

⚠️ Notice: /azpw run only runs failed jobs now. If you want to trigger a whole pipline run, please rebase your branch or close and reopen the PR.
💡 Tip: You can also use /azpw retry to retry failed jobs directly.

Retrying failed(or canceled) jobs...

@mssonicbld

Copy link
Copy Markdown
Collaborator

Retrying failed(or canceled) stages in build 1152093:

✅Stage BuildTrixie:

  • Job amd64: retried.

mssonicbld added a commit to mssonicbld/sonic-sairedis that referenced this pull request Jul 3, 2026
<!--
Please make sure you've read and understood our contributing guidelines;
https://github.com/Azure/SONiC/blob/gh-pages/CONTRIBUTING.md

Please provide following information to help code review process a bit easier:
-->
### Description of PR
<!--
- Please include a summary of the change and which issue is fixed.
- Please also include relevant motivation and context. Where should reviewer start? background context?
- List any dependencies that are required for this change.
-->

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:
Azure/sonic-sairedis.msft#69

Proper fix under review at:
master: sonic-net#1774
202511: sonic-net#1862
202605: sonic-net#1956
Fixes sonic-net#1753 (temporary fix)

### Type of change

<!--
- Fill x for your type of change.
- e.g.
- [x] Bug fix
-->

- [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
<!--
(If it's a new feature, new test case)
Did you update documentation/Wiki relevant to your implementation?
Link to the wiki page?
-->

Signed-off-by: Sonic Build Admin <sonicbld@microsoft.com>
mssonicbld added a commit that referenced this pull request Jul 3, 2026
<!--
Please make sure you've read and understood our contributing guidelines;
https://github.com/Azure/SONiC/blob/gh-pages/CONTRIBUTING.md

Please provide following information to help code review process a bit easier:
-->
### Description of PR
<!--
- Please include a summary of the change and which issue is fixed.
- Please also include relevant motivation and context. Where should reviewer start? background context?
- List any dependencies that are required for this change.
-->

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:
Azure/sonic-sairedis.msft#69

Proper fix under review at:
master: #1774
202511: #1862
202605: #1956
Fixes #1753 (temporary fix)

### Type of change

<!--
- Fill x for your type of change.
- e.g.
- [x] Bug fix
-->

- [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
<!--
(If it's a new feature, new test case)
Did you update documentation/Wiki relevant to your implementation?
Link to the wiki page?
-->

Signed-off-by: Sonic Build Admin <sonicbld@microsoft.com>
@justin-wong-ce justin-wong-ce changed the title Cast counter enhancement from 202511 to 202605 [202605] Smart Counter Poll to allow counters to work properly on Broadcom platforms. Jul 4, 2026
List of changes made:
- Added tracking of free indicies for reuse
- Added m_failedPolls cleanup when object is removed
- Improved m_failedPolls lookup logic to only use a single lookup
- Added addGroup helper
- Used const& refs for sets instead of copies where applicable
- Removed getSortedCGRef() for to avoid performance impact from the
  SWSS_LOG_ENTER() requirement in functions
- Better clarity by changing find() -> std::find()
- Simplied erase-emplace logic by using built in [] operator logic
- Normalized key check method when dealing with maps
- Indentation fixes
- Minor optimization when iterating through counter groups in
  setupBaseCounterGroup()
- Added warning comments on parts of code where more care is required
  (consuming of const refs)
- Added unit test for m_failedPolls logic

Signed-off-by: Justin Wong <jvwong@arista.com>
Signed-off-by: Justin Wong <jvwong@arista.com>
@mssonicbld

Copy link
Copy Markdown
Collaborator

/azp run

@azure-pipelines

Copy link
Copy Markdown
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.

@mssonicbld

Copy link
Copy Markdown
Collaborator

/azp run

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines successfully started running 1 pipeline(s).

Signed-off-by: Justin Wong <jvwong@arista.com>
@mssonicbld

Copy link
Copy Markdown
Collaborator

/azp run

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines successfully started running 1 pipeline(s).

@lolyu lolyu left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why we need to manually cherry-pick this into 202605? is there any conflict?

@justin-wong-ce

Copy link
Copy Markdown
Contributor Author

why we need to manually cherry-pick this into 202605? is there any conflict?

Oh I was not able to cleanly cherry-pick to origin/202605 locally, but I had a slightly desync'd fork.
Right now the cherry-pick will work. I will close this PR when it is cherry-picked to 202605.

I wil also update the test results on both PR threads when it is available.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants