forked from sonic-net/sonic-buildimage
-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Mellanox] update asic and module temperature in a thread #197
Closed
Closed
Changes from 4 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
403259e
[Mellanox] update asic and module temperature in a thread
Junchao-Mellanox f492f43
Fix review comment
Junchao-Mellanox daea57d
Fix minor issue
Junchao-Mellanox 30e3e88
align with hw-management interface
Junchao-Mellanox e7d7388
Update utils.py
Junchao-Mellanox File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
205 changes: 205 additions & 0 deletions
205
platform/mellanox/mlnx-platform-api/sonic_platform/thermal_updater.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,205 @@ | ||
# | ||
# Copyright (c) 2023 NVIDIA CORPORATION & AFFILIATES. | ||
# Apache-2.0 | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
# | ||
|
||
from . import utils | ||
from sonic_py_common import logger | ||
|
||
import sys | ||
import time | ||
|
||
sys.path.append('/run/hw-management/bin') | ||
|
||
try: | ||
import hw_management_independent_mode_update | ||
except ImportError: | ||
# For unit test only | ||
from unittest import mock | ||
keboliu marked this conversation as resolved.
Show resolved
Hide resolved
|
||
hw_management_independent_mode_update = mock.MagicMock() | ||
hw_management_independent_mode_update.thermal_data_set_asic = mock.MagicMock() | ||
hw_management_independent_mode_update.thermal_data_set_module = mock.MagicMock() | ||
hw_management_independent_mode_update.thermal_data_clean_asic = mock.MagicMock() | ||
hw_management_independent_mode_update.thermal_data_clean_module = mock.MagicMock() | ||
|
||
|
||
SFP_TEMPERATURE_SCALE = 1000 | ||
ASIC_TEMPERATURE_SCALE = 125 | ||
ASIC_DEFAULT_TEMP_WARNNING_THRESHOLD = 105000 | ||
ASIC_DEFAULT_TEMP_CRITICAL_THRESHOLD = 120000 | ||
|
||
ERROR_READ_THERMAL_DATA = -254 | ||
|
||
TC_CONFIG_FILE = '/run/hw-management/config/tc_config.json' | ||
logger = logger.Logger('thermal-updater') | ||
|
||
|
||
class ThermalUpdater: | ||
def __init__(self, sfp_list): | ||
self._sfp_list = sfp_list | ||
self._sfp_status = {} | ||
self._timer = utils.Timer() | ||
|
||
def load_tc_config(self): | ||
asic_poll_interval = 1 | ||
sfp_poll_interval = 10 | ||
data = utils.load_json_file(TC_CONFIG_FILE) | ||
if not data: | ||
logger.log_notice(f'{TC_CONFIG_FILE} does not exist, use default polling interval') | ||
|
||
if data: | ||
dev_parameters = data.get('dev_parameters') | ||
if dev_parameters is not None: | ||
asic_parameter = dev_parameters.get('asic') | ||
if asic_parameter is not None: | ||
asic_poll_interval_config = asic_parameter.get('poll_time') | ||
if asic_poll_interval_config: | ||
asic_poll_interval = int(asic_poll_interval_config) / 2 | ||
module_parameter = dev_parameters.get('module\\d+') | ||
if module_parameter is not None: | ||
sfp_poll_interval_config = module_parameter.get('poll_time') | ||
if sfp_poll_interval_config: | ||
sfp_poll_interval = int(sfp_poll_interval_config) / 2 | ||
|
||
logger.log_notice(f'ASIC polling interval: {asic_poll_interval}') | ||
self._timer.schedule(asic_poll_interval, self.update_asic) | ||
logger.log_notice(f'Module polling interval: {sfp_poll_interval}') | ||
self._timer.schedule(sfp_poll_interval, self.update_module) | ||
|
||
def start(self): | ||
self.clean_thermal_data() | ||
if not self.wait_all_sfp_ready(): | ||
logger.log_error('Failed to wait for all SFP ready, will put hw-management-tc to suspend') | ||
self.control_tc(True) | ||
return | ||
self.control_tc(False) | ||
self.load_tc_config() | ||
self._timer.start() | ||
|
||
def stop(self): | ||
self._timer.stop() | ||
self.control_tc(True) | ||
|
||
def control_tc(self, suspend): | ||
logger.log_notice(f'Set hw-management-tc to {"suspend" if suspend else "resume"}') | ||
utils.write_file('/run/hw-management/config/suspend', 1 if suspend else 0) | ||
|
||
def clean_thermal_data(self): | ||
hw_management_independent_mode_update.thermal_data_clean_asic(0) | ||
for sfp in self._sfp_list: | ||
hw_management_independent_mode_update.thermal_data_clean_module( | ||
0, | ||
sfp.sdk_index + 1 | ||
) | ||
|
||
def wait_all_sfp_ready(self): | ||
logger.log_notice('Waiting for all SFP modules ready...') | ||
max_wait_time = 60 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. test if 60 second is enough? |
||
ready_set = set() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. confirm with hw-mgmt if it is per cable control |
||
while len(ready_set) != len(self._sfp_list): | ||
for sfp in self._sfp_list: | ||
try: | ||
sfp.is_sw_control() | ||
ready_set.add(sfp) | ||
except: | ||
continue | ||
max_wait_time -= 1 | ||
if max_wait_time == 0: | ||
return False | ||
time.sleep(1) | ||
|
||
logger.log_notice('All SFP modules are ready') | ||
return True | ||
|
||
def get_asic_temp(self): | ||
temperature = utils.read_int_from_file('/sys/module/sx_core/asic0/temperature/input', default=None) | ||
return temperature * ASIC_TEMPERATURE_SCALE if temperature is not None else None | ||
|
||
def get_asic_temp_warning_threashold(self): | ||
emergency = utils.read_int_from_file('/sys/module/sx_core/asic0/temperature/emergency', default=None, log_func=None) | ||
return emergency * ASIC_TEMPERATURE_SCALE if emergency is not None else ASIC_DEFAULT_TEMP_WARNNING_THRESHOLD | ||
|
||
def get_asic_temp_critical_threashold(self): | ||
critical = utils.read_int_from_file('/sys/module/sx_core/asic0/temperature/critical', default=None, log_func=None) | ||
return critical * ASIC_TEMPERATURE_SCALE if critical is not None else ASIC_DEFAULT_TEMP_CRITICAL_THRESHOLD | ||
|
||
def update_single_module(self, sfp): | ||
try: | ||
presence = sfp.get_presence() | ||
pre_presence = self._sfp_status.get(sfp.sdk_index) | ||
if presence: | ||
temperature = sfp.get_temperature() | ||
if temperature == 0: | ||
warning_thresh = 0 | ||
critical_thresh = 0 | ||
else: | ||
warning_thresh = sfp.get_temperature_warning_threashold() | ||
critical_thresh = sfp.get_temperature_critical_threashold() | ||
temperature = ERROR_READ_THERMAL_DATA if temperature is None else int(temperature * SFP_TEMPERATURE_SCALE) | ||
warning_thresh = ERROR_READ_THERMAL_DATA if warning_thresh is None else int(warning_thresh * SFP_TEMPERATURE_SCALE) | ||
critical_thresh = ERROR_READ_THERMAL_DATA if critical_thresh is None else int(critical_thresh * SFP_TEMPERATURE_SCALE) | ||
|
||
hw_management_independent_mode_update.thermal_data_set_module( | ||
0, # ASIC index always 0 for now | ||
sfp.sdk_index + 1, | ||
temperature, | ||
warning_thresh, | ||
critical_thresh | ||
) | ||
else: | ||
if pre_presence != presence: | ||
hw_management_independent_mode_update.thermal_data_clean_module(0, sfp.sdk_index + 1) | ||
|
||
if pre_presence != presence: | ||
self._sfp_status[sfp.sdk_index] = presence | ||
except Exception as e: | ||
logger.log_error('Failed to update module {sfp.sdk_index} thermal data - {e}') | ||
hw_management_independent_mode_update.thermal_data_set_module( | ||
0, # ASIC index always 0 for now | ||
sfp.sdk_index + 1, | ||
ERROR_READ_THERMAL_DATA, | ||
ERROR_READ_THERMAL_DATA, | ||
ERROR_READ_THERMAL_DATA | ||
) | ||
|
||
def update_module(self): | ||
for sfp in self._sfp_list: | ||
self.update_single_module(sfp) | ||
|
||
def update_asic(self): | ||
try: | ||
asic_temp = self.get_asic_temp() | ||
if asic_temp: | ||
hw_management_independent_mode_update.thermal_data_set_asic( | ||
0, # ASIC index always 0 for now | ||
self.get_asic_temp(), | ||
self.get_asic_temp_warning_threashold(), | ||
self.get_asic_temp_critical_threashold() | ||
) | ||
else: | ||
hw_management_independent_mode_update.thermal_data_set_asic( | ||
0, # ASIC index always 0 for now | ||
ERROR_READ_THERMAL_DATA, | ||
self.get_asic_temp_warning_threashold(), | ||
self.get_asic_temp_critical_threashold() | ||
) | ||
except Exception as e: | ||
logger.log_error('Failed to update ASIC thermal data - {e}') | ||
hw_management_independent_mode_update.thermal_data_set_asic( | ||
0, # ASIC index always 0 for now | ||
ERROR_READ_THERMAL_DATA, | ||
ERROR_READ_THERMAL_DATA, | ||
ERROR_READ_THERMAL_DATA, | ||
) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TODO: retry reading threshold