Skip to content

[clear] Add 'sonic-clear pfcwdstats' to clear PFC watchdog counters#4634

Open
pinky-nexthop wants to merge 1 commit into
sonic-net:masterfrom
nexthop-ai:mabel.pfcwd-clear-upstream
Open

[clear] Add 'sonic-clear pfcwdstats' to clear PFC watchdog counters#4634
pinky-nexthop wants to merge 1 commit into
sonic-net:masterfrom
nexthop-ai:mabel.pfcwd-clear-upstream

Conversation

@pinky-nexthop

@pinky-nexthop pinky-nexthop commented Jun 22, 2026

Copy link
Copy Markdown

Why I did it

There is currently no CLI to clear PFC watchdog statistics. Clearing them is needed when troubleshooting PFC storms — stale counts from a prior event make it hard to tell whether a storm is currently ongoing. show pfcwd stats displays the counters, but there is no corresponding clear command.

Addresses the PFC-watchdog-counter-clear item in #4595.

How I did it

  • scripts/pfcwdstat: new tool that zeroes the PFC_WD_QUEUE_STATS_* fields in COUNTERS_DB, following the standard counter-clear pattern (pfcstat -c, queuestat -c, …). It enumerates queues via COUNTERS_QUEUE_NAME_MAP — the same source show pfcwd stats uses — so stale stats from queues that are no longer actively monitored (STATUS=N/A) are also cleared.
  • Queues with an active storm (PFC_WD_STATUS == 'stormed') are skipped, so the in-flight DEADLOCK_DETECTED/DEADLOCK_RESTORED pair is not split (which would otherwise leave RESTORED > DETECTED once the storm ends).
  • clear/main.py: adds sonic-clear pfcwdstats, invoking pfcwdstat -c.
  • setup.py: installs scripts/pfcwdstat.
  • Unit tests for the clear command and the pfcwdstat clear logic (including the stale-stats and active-storm cases).

How to verify it

admin@sonic:~$ show pfcwd stats
        QUEUE       STATUS    STORM DETECTED/RESTORED    TX OK/DROP    RX OK/DROP    TX LAST OK/DROP    RX LAST OK/DROP
-------------  -----------  -------------------------  ------------  ------------  -----------------  -----------------
Ethernet192:3  operational                        1/1           0/0           0/0                0/0                0/0

admin@sonic:~$ sonic-clear pfcwdstats
PFC Watchdog counters cleared.

admin@sonic:~$ show pfcwd stats
  QUEUE    STATUS    STORM DETECTED/RESTORED    TX OK/DROP    RX OK/DROP    TX LAST OK/DROP    RX LAST OK/DROP
-------  --------  -------------------------  ------------  ------------  -----------------  -----------------

pytest tests/pfcwd_test.py::TestPfcwdstatClear tests/clear_test.py -k pfcwd

Manually: show pfcwd stats to see counts, sonic-clear pfcwdstats to clear them; an actively storming queue is left untouched (and reported as skipped) until the storm ends.

Which release branch to backport (provide reason below if selected)

Description for the changelog

Add sonic-clear pfcwdstats to clear PFC watchdog counters.

There is currently no CLI to clear PFC watchdog statistics. Clearing them is
needed when troubleshooting PFC storms, where stale counts from a prior event
make it hard to tell whether a storm is ongoing.

This adds:

- scripts/pfcwdstat: a new tool that zeroes the PFC_WD_QUEUE_STATS_* fields in
  COUNTERS_DB, following the standard counter-clear pattern (pfcstat -c,
  queuestat -c, ...). It enumerates queues via COUNTERS_QUEUE_NAME_MAP -- the
  same source 'show pfcwd stats' uses -- so stale stats from queues that are no
  longer actively monitored (STATUS=N/A) are also cleared.
- Queues with an active storm (PFC_WD_STATUS == 'stormed') are skipped, so the
  in-flight DEADLOCK_DETECTED/RESTORED pair is not split (which would otherwise
  leave RESTORED > DETECTED once the storm ends).
- clear/main.py: 'sonic-clear pfcwdstats', invoking 'pfcwdstat -c'.
- setup.py: install scripts/pfcwdstat.
- tests for the clear command and the pfcwdstat clear logic.

Signed-off-by: Pinky Agrawal <pinky@nexthop.ai>
@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

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.

2 participants