Skip to content

[sonic_xcvr] Cache static CMIS support/identity fields to optimize EEPROM reads#710

Open
aditya-nexthop wants to merge 2 commits into
sonic-net:masterfrom
nexthop-ai:cache-static-cmis-support-identity
Open

[sonic_xcvr] Cache static CMIS support/identity fields to optimize EEPROM reads#710
aditya-nexthop wants to merge 2 commits into
sonic-net:masterfrom
nexthop-ai:cache-static-cmis-support-identity

Conversation

@aditya-nexthop

@aditya-nexthop aditya-nexthop commented Jul 14, 2026

Copy link
Copy Markdown
Contributor

Description

Cache static CMIS support/identity/capability fields so they are read from the module EEPROM once and reused, instead of being re-read on every DOM/status poll cycle.

Changes:

  • Cache static getters by applying the @read_only_cached_api_return
    decorator (caches until the getter returns a non-None, non-empty value) to
    the CMIS advertisement getters that expose static, read-only fields

  • Add a cached _get_tx_bias_scale_raw() helper. The TX bias scaling
    exponent is a static per-module advertisement, but it was read from EEPROM on
    every get_tx_bias() and get_transceiver_threshold_info() call. Both paths
    now go through the cached helper.

  • Return None on failed reads instead of freezing a default. Because the
    cache only stores non-None results, getters now return the raw None on a
    transient read failure so the value is re-read on the next call rather than
    caching a wrong default.

  • Update callers for the new get_supported_power_config contract
    (c_cmis.py): set_tx_power() and get_transceiver_info() now use
    self.get_supported_power_config() or (None, None) to safely unpack when the read fails.

Motivation and Context

These fields (support flags, module identity/interface, and capability
advertisements) are static for the lifetime of a plugged-in module, yet they
were being re-read from the EEPROM on every DOM/status polling cycle. On a
platform with many transceivers this adds redundant I2C/EEPROM traffic and
latency to the hot polling loop.

Caching them behind @read_only_cached_api_return reads each field once and serves subsequent calls from memory, cutting EEPROM reads in the per-cycle DOM path. Returning None on a failed read (instead of a hard-coded False / (None, None)) ensures a transient read failure is not cached permanently — the cache re-reads on the next call once the module responds.

How Has This Been Tested?

  • Updated existing unit tests in tests/sonic_xcvr/test_cmis.py to reflect the
    new None-on-failed-read behavior:
    • test_get_diag_page_support: a None read now expects None (previously
      False).
    • test_is_cdb_supported: a None read now expects None (previously
      False).
  • Covered by the caching unit tests in tests/sonic_xcvr/test_cmis_cache.py,
    which validate that decorated getters are cached and can be cleared.
  • Full sonic_xcvr pytest suite run locally.

Additional Information (Optional)

Signed-off-by: Aditya Bhiday <aditya@nexthop.ai>
@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).

@aditya-nexthop
aditya-nexthop marked this pull request as ready for review July 14, 2026 20:59
@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
There may be pipelines that require an authorized user to comment /azp run to run.

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