Skip to content

Add per-port counter discovery toggle argument - #2000

Merged
lolyu merged 4 commits into
sonic-net:masterfrom
justin-wong-ce:genFix
Aug 3, 2026
Merged

Add per-port counter discovery toggle argument#2000
lolyu merged 4 commits into
sonic-net:masterfrom
justin-wong-ce:genFix

Conversation

@justin-wong-ce

@justin-wong-ce justin-wong-ce commented Jul 20, 2026

Copy link
Copy Markdown
Contributor

Description of PR

Summary:
Add an argument to syncd to toggle between the new per-port counter discovery feature in FlexCounter or to use the legacy method.

This is a part 1 of 2 fix in addressing sonic-net/sonic-buildimage#28460. There are two fix methods under consideration, this part is generic to both methods.

Fixes # (issue)
Partially Fixes sonic-net/sonic-buildimage#28460

Needs backport to 202605.

Type of change

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

Approach

What is the motivation for this PR?

In #1774 , a new counter support discovery method is introduced for being able to read counter support for platforms where different ports can have different capabilities.
The method worked well for some platforms, not so much for some others.

This change adds an argument to syncd so there is the capability to toggle the per-port counter discovery. The argument will default to false so the legacy code path is used by default.

Since there is now an option to toggle the code path on or off, there is no longer a need for a runtime fallback.

Work item tracking
  • Microsoft ADO (number only):

How did you do it?

Add an argument to syncd as well as the logic needed to read the argument in various files in syncd.
Unit tests are also updated to account for the new argument, as well as mocking the use of this argument for unit tests that only test for per-port discovery logic.

How did you verify/test it?

Unit tests passes on both master and with the change casted to 202605.
syncd is also able to boot on physical hardware and enter the expected code path based on whether the argument was provided for launch or not.

Any platform specific information?

Generic

Documentation

Add an argument to toggle the per-port counter discovery feature in
syncd_init_common.sh

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

Copy link
Copy Markdown
Collaborator

/azp run

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
There may be pipelines that require an authorized user to comment /azp run to 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).

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).

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.

Overall this is a clean, well-scoped change and the default-false gating is the right call given #1774's platform regressions. A few comments below — the main substantive one is the removal of the exception-based fallback. Not blocking, leaving as COMMENT.

1. Removal of the try/catch fallback (main question). Previously the code tried addObjectWithCounterGroups and fell back to addObject on exception. With this change, when -G is enabled there is no longer any exception fallback — a throw from per-port discovery now propagates instead of degrading gracefully. If that's intentional (opt-in only for platforms known to work), please call it out explicitly in the PR/commit so it's clear the fallback was removed deliberately, not accidentally.

2. Repeated dynamic_pointer_cast on hot paths. addCounter/bulkAddCounter now do getOptions + dynamic_pointer_cast<VendorSaiOptions> on every invocation. Consider resolving the bool once (e.g. at FlexCounter construction) to avoid the repeated cast. Minor / non-blocking.

3. Backport / part-2 dependency. PR notes this is "part 1 of 2" and needs backport to 202605. Worth confirming part 2 (the actual per-port fix) lands before -G is flipped on in production, since this arg alone is inert.

@justin-wong-ce

justin-wong-ce commented Jul 23, 2026

Copy link
Copy Markdown
Contributor Author

1. Removal of the try/catch fallback (main question). Previously the code tried addObjectWithCounterGroups and fell back to addObject on exception. With this change, when -G is enabled there is no longer any exception fallback — a throw from per-port discovery now propagates instead of degrading gracefully. If that's intentional (opt-in only for platforms known to work), please call it out explicitly in the PR/commit so it's clear the fallback was removed deliberately, not accidentally.

Ack, added to PR description

2. Repeated dynamic_pointer_cast on hot paths. addCounter/bulkAddCounter now do getOptions + dynamic_pointer_cast<VendorSaiOptions> on every invocation. Consider resolving the bool once (e.g. at FlexCounter construction) to avoid the repeated cast. Minor / non-blocking.

Leaving it as is as adding the initialization to FlexCounter constructor an adding another variable to store class-wide is unecessarily complicated for a simple one-time toggle.

3. Backport / part-2 dependency. PR notes this is "part 1 of 2" and needs backport to 202605. Worth confirming part 2 (the actual per-port fix) lands before -G is flipped on in production, since this arg alone is inert.

Yes

@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.

LGTM

@justin-wong-ce

Copy link
Copy Markdown
Contributor Author

Reminder this needs backport to 202605.

@lolyu
lolyu merged commit 9b375e4 into sonic-net:master Aug 3, 2026
19 checks passed
@mssonicbld

Copy link
Copy Markdown
Collaborator

This PR has backport request label(s) for branch(es): 202605, but is missing required test information. Please make sure you tick the tested branch(es) in the Tested branch section and provide test evidence (e.g., 202605: <test result>) in the Test result section as well in your PR description.

---Powered by SONiC BuildBot

@mssonicbld

Copy link
Copy Markdown
Collaborator

The change is not in 202605 yet. @justin-wong-ce, please manually create the cherry pick PR for branch 202605.
You can ping the release branch owner(github account: vaibhavhd) to approve your cherry pick PR.
If this change is already in 202605, please comment "already in 202605". Thanks!

---Powered by SONiC BuildBot

@justin-wong-ce

Copy link
Copy Markdown
Contributor Author

The change is not in 202605 yet. @justin-wong-ce, please manually create the cherry pick PR for branch 202605.You can ping the release branch owner(github account: vaibhavhd) to approve your cherry pick PR.If this change is already in 202605, please comment "already in 202605". Thanks!

---Powered by SONiC BuildBot

Ack

@justin-wong-ce

Copy link
Copy Markdown
Contributor Author

Cast PR created:
#2021

The change is not in 202605 yet. @justin-wong-ce, please manually create the cherry pick PR for branch 202605.You can ping the release branch owner(github account: vaibhavhd) to approve your cherry pick PR.If this change is already in 202605, please comment "already in 202605". Thanks!
---Powered by SONiC BuildBot

Ack

lolyu pushed a commit that referenced this pull request Aug 5, 2026
…2001)

Approach
What is the motivation for this PR?
In #1774 , a new counter support discovery method is introduced for being able to read counter support for platforms where different ports can have different capabilities.
The method worked well for some platforms, not so much for some others.

This change auto-uses the new syncd arg enablePerPortCounterDiscovery (introduced in #2000) when the broadcom ASIC type is detected in syncd_init_common.sh.

Work item tracking
Microsoft ADO (number only):
How did you do it?
Add logic in syncd_init_common.sh to auto apply the syncd arg when broadcom ASIC type is detected.

How did you verify/test it?
syncd unit tests pass on master and on 202605.
On physical hardware, an image is built with the changes cherry-picked to 202605 and tests are ran in 2 scenarios:

With the change as is
syncd_init_common.sh hotpatched to filter on another asic type.
In both scenarios, syncd enters the expected code path.
Additionally, a subset of counters-focused sonic-mgmt tests are ran. There is no test result difference compared to tests done without this change.
Tests were ran on Arista-7260CX3-D108C8 and Arista-7060X6-64PE-B-C512S2.

The list of sonic-mgmt tests ran:

test_pretest.py
dhcp_relay/test_dhcp_counter_stress.py
drop_packets/test_drop_counters.py
drop_packets/test_configurable_drop_counters.py
gnmi/test_gnmi_countersdb.py
snmp/test_snmp_queue_counters.py
test_posttest.py
To ensure no warm and fast reboot issues from any potential time increase from syncd, some reboot-related tests are also ran. The following sonic-mgmt tests pass with this change casted, tested on Arista-7260CX3-D108C8 and Arista-7060CX-32S-C32:

platform_tests/test_advanced_reboot.py::test_warm_reboot_sad*
platform_tests/test_advanced_reboot.py::test_warm_reboot_mac_jump
platform_tests/test_advanced_reboot.py::test_warm_reboot
platform_tests/test_advanced_reboot.py::test_fast_reboot
Any platform specific information?
Broadcom
lolyu pushed a commit that referenced this pull request Aug 6, 2026
Approach
What is the motivation for this PR?
In #1774 , a new counter support discovery method is introduced for being able to read counter support for platforms where different ports can have different capabilities.
The method worked well for some platforms, not so much for some others.

This change applies the new syncd arg enablePerPortCounterDiscovery (introduced in #2000) when enable_per_port_counter_discovery is populated as true in SYNCD_VARS, which is retrieved from DEVICE_METADATA in CONFIG_DB.

Work item tracking
Microsoft ADO (number only):
How did you do it?
Add logic in syncd_init_common.sh to apply the syncd arg enablePerPortCounterDiscovery when it is defined as so in SYNCD_VARS.

How did you verify/test it?
syncd unit tests pass on master and on 202605.
On physical hardware, an image is built with the changes cherry-picked to 202605 and tests are ran in 6 scenarios:
1):

ASIC check: use arg on broadcom
HWSKU config: not defined
Result: per-port counter discovery code path used
2):

ASIC check: use arg on broadcom
HWSKU config: enable_per_port_counter_discovery set to true
Result: per-port counter discovery code path used
3):

ASIC check: use arg on broadcom
HWSKU config: enable_per_port_counter_discovery set to false
Result: legacy code path used
4):

ASIC check: use arg on mellanox
HWSKU config: not defined
Result: legacy code path used
5):

ASIC check: use arg on mellanox
HWSKU config: enable_per_port_counter_discovery set to true
Result: per-port counter discovery code path used
6):

ASIC check: use arg on mellanox
HWSKU config: enable_per_port_counter_discovery set to false
Result: legacy code path used
In all 6 scenarios, syncd enters the expected code path.

Additionally, a subset of counters-focused sonic-mgmt tests are ran. There is no test result difference compared to tests done without this change.
Tests were ran on Arista-7260CX3-D108C8.

The list of sonic-mgmt tests ran:

test_pretest.py
dhcp_relay/test_dhcp_counter_stress.py
drop_packets/test_drop_counters.py
drop_packets/test_configurable_drop_counters.py
gnmi/test_gnmi_countersdb.py
snmp/test_snmp_queue_counters.py
test_posttest.py
Any platform specific information?
Broadcom
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

6 participants