Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions inc/saiswitch.h
Original file line number Diff line number Diff line change
Expand Up @@ -3616,6 +3616,32 @@ typedef enum _sai_switch_attr_t
*/
SAI_SWITCH_ATTR_PERFMON_LIST,

/**
* @brief List of raw (non-rounded) temperature readings from all sensors.
*
* Values should be interpreted along with SAI_SWITCH_ATTR_TEMP_BASE_TEN_PRECISION.
* Companion to SAI_SWITCH_ATTR_TEMP_LIST (which returns rounded Celsius).
*
* @type sai_s32_list_t
* @flags READ_ONLY
*/

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.

The commit added a new tag @precision. You can define the precision in SAI_SWITCH_ATTR_TEMP_LIST_RAW and no need SAI_SWITCH_ATTR_TEMP_BASE_TEN_PRECISION. You can get the precision from the meta data attr->valuePrecision.
See the examples in https://github.com/opencomputeproject/SAI/blob/master/experimental/saiexperimentalotnoa.h

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Thank you for the suggestion. The @precision tag is a compile-time constant in the metadata — it is hardcoded at attribute definition time and cannot change at runtime.

In our case, the temperature resolution is hardware and platform dependent and must be queried at runtime. SAI_SWITCH_ATTR_TEMP_BASE_TEN_PRECISION is a READ_ONLY attribute that the driver reports dynamically, allowing consumers to adapt without any code or metadata change as platforms evolve.

So yes, @precision would still be hardcoded — just in a different place.

@jjin62 jjin62 Jun 30, 2026

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.

I see. But we can always put a conservative @precision, like 6 to cover all the vendors. Two attributes for one value implies much semantics and is error prone. Just my 2 cents.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

I understand the point, but a conservative fixed @precision like 6 means every consumer always multiplies by 10^-6 - even when the hardware only reports tenths of a degree. This would silently produce incorrect values on platforms that don't match that precision, with no way to detect the mismatch at runtime.
With SAI_SWITCH_ATTR_TEMP_BASE_TEN_PRECISION, the driver reports exactly what the hardware delivers — no guessing, no silent error. The cost is one extra attribute query; the benefit is guaranteed correctness across all platforms without any consumer-side assumptions.

SAI_SWITCH_ATTR_TEMP_LIST_RAW,

/**
* @brief Power-of-10 exponent for raw temperature precision.
*
* Defines the scale of values in SAI_SWITCH_ATTR_TEMP_LIST_RAW.
* Formula: actual_celsius = raw_value * (10 ^ precision)
* Examples:
* precision = 0 => values already in whole Celsius (same as TEMP_LIST)
* precision = -1 => values in 0.1 degrees C steps (445 = 44.5 degrees C)
* precision = -2 => values in 0.01 degrees C steps
*
* @type sai_int8_t
* @flags READ_ONLY
*/
SAI_SWITCH_ATTR_TEMP_BASE_TEN_PRECISION,

/**
* @brief End of attributes
*/
Expand Down
Loading