Skip to content

Conversation

@mssonicbld
Copy link
Collaborator

Description

HLD: https://github.com/sonic-net/SONiC/blob/master/doc/smart-switch/graceful-shutdown/graceful-shutdown.md
These changes build upon enhancements in sonic-platform-daemons#667

This PR introduces graceful shutdown and startup orchestration across SONiC platform daemons to ensure safe DPU and peripheral module transitions during reboot or administrative state changes.

Key updates include:

  • Integration of ModuleBase lifecycle methods (module_pre_shutdown, module_post_startup, and set_admin_state_gracefully) into platform daemons.
  • Move graceful handling of PCIe detach/reattach and sensor reload sequences into set_admin_state_gracefully.
  • State tracking in CHASSIS_MODULE_TABLE via STATE_DB to synchronize transition state across processes.
  • File-based operation locks to prevent concurrent access to shared hardware resources.

Motivation and Context

Platform daemons currently perform shutdown and startup independently, leading to:

  • Race conditions during DPU detachment.
  • Inconsistent Redis state across PMON daemons.
  • Uncoordinated sensor and PCIe transitions during reboot.

This change introduces a unified graceful shutdown framework for SmartSwitch modules.
It ensures predictable module transitions, preserves hardware health, and supports orchestrated restarts without transient hardware errors.

How Has This Been Tested?

Testing performed on both DPU-enabled (SmartSwitch).

Functional validation

  • Verified end-to-end reboot flow with DPU detach/reattach sequence.
  • PCIe state (detaching/attaching) reflected in STATE_DB.
  • pcied daemon logs confirm ordered detach before reboot and reattach after startup.
  • Confirmed no stale Redis entries or orphaned locks post-reboot.

Unit tests executed

  • tests/test_DaemonPcied.py
  • tests/test_chassisd_graceful.py

Coverage includes:

  • Transition flag handling
  • Timeout behavior
  • DB write/read operations
  • Graceful admin state flow

Manual validation

Additional Information (Optional)

…daemons

<!-- Provide a general summary of your changes in the Title above -->

#### Description
<!--
     Describe your changes in detail
-->

HLD: https://github.com/sonic-net/SONiC/blob/master/doc/smart-switch/graceful-shutdown/graceful-shutdown.md
These changes build upon enhancements in [`sonic-platform-daemons#667`](sonic-net#667)

This PR introduces **graceful shutdown and startup orchestration** across SONiC platform daemons to ensure safe DPU and peripheral module transitions during reboot or administrative state changes.

Key updates include:
- Integration of `ModuleBase` lifecycle methods (`module_pre_shutdown`, `module_post_startup`, and `set_admin_state_gracefully`) into platform daemons.
- Move graceful handling of PCIe detach/reattach and sensor reload sequences into set_admin_state_gracefully.
- State tracking in `CHASSIS_MODULE_TABLE` via `STATE_DB` to synchronize transition state across processes.
- File-based operation locks to prevent concurrent access to shared hardware resources.

#### Motivation and Context
<!--
     Why is this change required? What problem does it solve?
     If this pull request closes/resolves an open Issue, make sure you
     include the text "fixes #xxxx", "closes #xxxx" or "resolves #xxxx" here
-->

Platform daemons currently perform shutdown and startup independently, leading to:
- Race conditions during DPU detachment.
- Inconsistent Redis state across PMON daemons.
- Uncoordinated sensor and PCIe transitions during reboot.

This change introduces a unified **graceful shutdown framework** for SmartSwitch modules.
It ensures predictable module transitions, preserves hardware health, and supports orchestrated restarts without transient hardware errors.

#### How Has This Been Tested?
<!--
     Please describe in detail how you tested your changes.
     Include details of your testing environment, and the tests you ran to
     see how your change affects other areas of the code, etc.
-->

Testing performed on both **DPU-enabled (SmartSwitch)**.

**Functional validation**
- Verified end-to-end reboot flow with DPU detach/reattach sequence.
- PCIe state (`detaching/attaching`) reflected in `STATE_DB`.
- `pcied` daemon logs confirm ordered detach before reboot and reattach after startup.
- Confirmed no stale Redis entries or orphaned locks post-reboot.

**Unit tests executed**

- tests/test_DaemonPcied.py
- tests/test_chassisd_graceful.py

Coverage includes:
- Transition flag handling
- Timeout behavior
- DB write/read operations
- Graceful admin state flow

**Manual validation**

#### Additional Information (Optional)
@mssonicbld
Copy link
Collaborator Author

Original PR: #703

@mssonicbld
Copy link
Collaborator Author

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant