Skip to content
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

[BFN] Refactoring and adding some functions of Thermal class (set and get thresholds and etc.) #10205

Merged
merged 29 commits into from
Apr 5, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
5d62494
Merge pull request #1 from Azure/master
VadymYashchenko Jan 12, 2022
99acd67
Merge pull request #3 from Azure/master
VadymYashchenko Jan 24, 2022
1099b7c
Merge pull request #9 from Azure/master
VadymYashchenko Feb 2, 2022
090d2c0
Merge pull request #13 from Azure/master
VadymYashchenko Mar 17, 2022
c5112bf
Revised set_high_thershold and set_low_thershold methobs in the therm…
VadymYashchenko Jan 31, 2022
524615e
Revised set_low_thershold and set_high_thershold
VadymYashchenko Feb 2, 2022
bd7be5e
Added separated files with thermal thresholds, changed platform.json and
VadymYashchenko Feb 8, 2022
09de264
Revised on code revieww
VadymYashchenko Feb 8, 2022
119d798
Reverted thermal.py
VadymYashchenko Feb 8, 2022
edeb1aa
Revised ther python.py
VadymYashchenko Feb 8, 2022
6d566aa
Revised due to code review
VadymYashchenko Feb 10, 2022
337dfe3
Added fucntion for fix the problem of tofino sensor high critical thr…
VadymYashchenko Feb 14, 2022
d461093
Revised due to code review
VadymYashchenko Feb 14, 2022
343f02b
Revised due to code review
VadymYashchenko Feb 14, 2022
0e0d0d2
Revised due to code review
VadymYashchenko Feb 14, 2022
7ce16ea
Revised only for cab18-4
VadymYashchenko Feb 17, 2022
7697573
Revised default thresholds
VadymYashchenko Feb 18, 2022
d2cee5d
Revised ther def thresholds
VadymYashchenko Feb 18, 2022
a334ca6
Revised on code review
VadymYashchenko Feb 18, 2022
93ebf5e
Revised platform.json and thermal_thresholds.json
VadymYashchenko Feb 25, 2022
5f6b31e
Code review in PR to azure (trigger CI)
VadymYashchenko Mar 10, 2022
d76dc14
Added handle of exception
VadymYashchenko Mar 16, 2022
21c950a
Revised exception handler
VadymYashchenko Mar 16, 2022
325e724
Added psu-1 thermal names to platfrom.json
VadymYashchenko Mar 25, 2022
e53a90f
Changed platform.json and thermal_thresholds.json in
VadymYashchenko Mar 28, 2022
14d301c
Merge pull request #15 from Azure/master
VadymYashchenko Mar 28, 2022
3c4d60e
Removed indentation from json file
VadymYashchenko Mar 30, 2022
9eede4c
Merge pull request #16 from Azure/master
VadymYashchenko Mar 31, 2022
0bcd159
Merge branch 'master' into fix_thermals_test
VadymYashchenko Mar 31, 2022
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
{
"thermals": [
{
"com_e_driver-i2c-4-33:cpu-temp" : [99.0, 89.0, 11.0, 1.0]
},
{
"com_e_driver-i2c-4-33:memory-temp" : [85.0, 75.0, 11.0, 1.0]
},
{
"tmp75-i2c-3-48:chip-temp" : [90.0, 80.0, 11.0, 1.0]
},
{
"tmp75-i2c-3-49:exhaust2-temp" : [80.0, 70.0, 11.0, 1.0]
},
{
"tmp75-i2c-3-4a:exhaust-temp" : [60.0, 50.0, 11.0, 1.0]
},
{
"tmp75-i2c-3-4b:intake-temp" : [60.0, 50.0, 11.0, 1.0]
},
{
"tmp75-i2c-3-4c:tofino-temp" : [99.0, 89.0, 11.0, 1.0]
},
{
"tmp75-i2c-3-4d:intake2-temp" : [60.0, 50.0, 11.0, 1.0]
},
{
"coretemp-isa-0000:package-id-0" : [80.0, 70.0, 11.0, 1.0]
},
{
"coretemp-isa-0000:core-0" : [99.0, 89.0, 11.0, 1.0]
},
{
"coretemp-isa-0000:core-1" : [99.0, 89.0, 11.0, 1.0]
},
{
"coretemp-isa-0000:core-2" : [99.0, 89.0, 11.0, 1.0]
},
{
"coretemp-isa-0000:core-3" : [99.0, 89.0, 11.0, 1.0]
},
{
"psu_driver-i2c-7-59:psu2-temp1" : [60.0, 50.0, 11.0, 1.0]
},
{
"psu_driver-i2c-7-59:psu2-temp2" : [60.0, 50.0, 11.0, 1.0]
},
{
"psu_driver-i2c-7-59:psu2-temp3" : [60.0, 50.0, 11.0, 1.0]
},
{
"psu_driver-i2c-7-5a:psu1-temp1" : [60.0, 50.0, 11.0, 1.0]
},
{
"psu_driver-i2c-7-5a:psu1-temp2" : [60.0, 50.0, 11.0, 1.0]
},
{
"psu_driver-i2c-7-5a:psu1-temp3" : [60.0, 50.0, 11.0, 1.0]
}
]
}
29 changes: 16 additions & 13 deletions device/barefoot/x86_64-accton_wedge100bf_32x-r0/platform.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,45 +57,51 @@
}
],
"thermals": [
{
"name": "com_e_driver-i2c-4-33:cpu-temp"
},
{
"name": "com_e_driver-i2c-4-33:memory-temp"
},
{
"name": "com_e_driver-i2c-4-33:cpu-temp"
"name": "psu_driver-i2c-7-59:psu2-temp1"
},
{
"name": "pfe1100-i2c-7-59:temp1"
"name": "psu_driver-i2c-7-59:psu2-temp2"
},
{
"name": "pfe1100-i2c-7-59:temp2"
"name": "psu_driver-i2c-7-5a:psu1-temp1"
},
{
"name": "pfe1100-i2c-7-5a:temp1"
"name": "psu_driver-i2c-7-5a:psu1-temp2"
},
{
"name": "pfe1100-i2c-7-5a:temp2"
"name": "tmp75-i2c-3-48:chip-temp"
},
{
"name": "tmp75-i2c-3-48:outlet-middle-temp"
"name": "tmp75-i2c-3-49:exhaust2-temp"
},
{
"name": "tmp75-i2c-3-49:inlet-middle-temp"
"name": "tmp75-i2c-3-4a:exhaust-temp"
},
{
"name": "tmp75-i2c-3-4a:inlet-left-temp"
"name": "tmp75-i2c-3-4b:intake-temp"
},
{
"name": "tmp75-i2c-3-4b:switch-temp"
"name": "tmp75-i2c-3-4c:tofino-temp"
},
{
"name": "tmp75-i2c-3-4c:inlet-right-temp"
"name": "tmp75-i2c-3-4d:intake2-temp"
},
{
"name": "tmp75-i2c-8-48:outlet-right-temp"
},
{
"name": "tmp75-i2c-8-49:outlet-left-temp"
},
{
"name": "pch_haswell-virtual-0:temp1"
},
{
"name": "coretemp-isa-0000:package-id-0"
},
Expand All @@ -110,9 +116,6 @@
},
{
"name": "coretemp-isa-0000:core-3"
},
{
"name": "pch_haswell-virtual-0:temp1"
}
],
"sfps": [
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
{
"thermals": [
{
"com_e_driver-i2c-4-33:cpu-temp" : [99.0, 89.0, 11.0, 1.0]
},
{
"com_e_driver-i2c-4-33:memory-temp" : [85.0, 75.0, 11.0, 1.0]
},
{
"psu_driver-i2c-7-59:psu2-temp1" : [50.0, 40.0, 11.0, 1.0]
},
{
"psu_driver-i2c-7-59:psu2-temp2" : [90.0, 80.0, 11.0, 1.0]
},
{
"psu_driver-i2c-7-5a:psu1-temp1" : [50.0, 40.0, 11.0, 1.0]
},
{
"psu_driver-i2c-7-5a:psu1-temp2" : [90.0, 80.0, 11.0, 1.0]
},
{
"tmp75-i2c-3-48:chip-temp" : [90.0, 80.0, 11.0, 1.0]
},
{
"tmp75-i2c-3-49:exhaust2-temp" : [80.0, 70.0, 11.0, 1.0]
},
{
"tmp75-i2c-3-4a:exhaust-temp" : [60.0, 50.0, 11.0, 1.0]
},
{
"tmp75-i2c-3-4b:intake-temp" : [60.0, 50.0, 11.0, 1.0]
},
{
"tmp75-i2c-3-4c:tofino-temp" : [99.0, 89.0, 11.0, 1.0]
},
{
"tmp75-i2c-3-4d:intake2-temp" : [60.0, 50.0, 11.0, 1.0]
},
{
"tmp75-i2c-8-48:outlet-right-temp" : [60.0, 50.0, 11.0, 1.0]
},
{
"tmp75-i2c-8-49:outlet-left-temp" : [60.0, 50.0, 11.0, 1.0]
},
{
"pch_haswell-virtual-0:temp1" : [60.0, 50.0, 11.0, 1.0]
},
{
"coretemp-isa-0000:package-id-0" : [80.0, 70.0, 11.0, 1.0]
},
{
"coretemp-isa-0000:core-0" : [99.0, 89.0, 11.0, 1.0]
},
{
"coretemp-isa-0000:core-1" : [99.0, 89.0, 11.0, 1.0]
},
{
"coretemp-isa-0000:core-2" : [99.0, 89.0, 11.0, 1.0]
},
{
"coretemp-isa-0000:core-3" : [99.0, 89.0, 11.0, 1.0]
}
]
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
try:
import subprocess

from collections import namedtuple
import json
from bfn_extensions.platform_sensors import platform_sensors_get
from sonic_platform_base.thermal_base import ThermalBase
from sonic_py_common import device_info
import logging
except ImportError as e:
raise ImportError (str(e) + "- required module not found")

Expand All @@ -18,6 +21,8 @@
temp2_input: 37.000
...
'''
Threshold = namedtuple('Threshold', ['crit', 'max', 'min', 'alarm'])

def _sensors_chip_parsed(data: str):
def kv(line):
k, v, *_ = [t.strip(': ') for t in line.split(':') if t] + ['']
Expand Down Expand Up @@ -68,27 +73,89 @@ def _value_get(d: dict, key_prefix, key_suffix=''):

# Thermal -> ThermalBase -> DeviceBase
class Thermal(ThermalBase):
_thresholds = dict()
_max_temperature = 100.0
_min_temperature = 0.0
_min_high_threshold_temperature = 35.0

def __init__(self, chip, label, index = 0):
self.__chip = chip
self.__label = label
self.__name = f"{chip}:{label}".lower().replace(' ', '-')
self.__collect_temp = []
self.__index = index
self.__high_threshold = None
self.__low_threshold = None
f = None
try:
path = device_info.get_path_to_platform_dir() + '/' + 'thermal_thresholds.json'
f = open(path)
except FileNotFoundError:
logging.warning('can not open the file')

if f is not None:
self.__get_thresholds(f)

def __get_thresholds(self, f):
def_threshold_json = json.load(f)
all_data = def_threshold_json["thermals"]
for i in all_data:
for key, value in i.items():
self._thresholds[key] = Threshold(*value)

def check_in_range(self, temperature):
temp_f = float(temperature)
return temp_f > self._min_temperature and temp_f <= self._max_temperature

def check_high_threshold(self, temperature, attr_suffix):
temp_f = float(temperature)
check_range = True
if attr_suffix == 'max':
if temp_f < self._min_high_threshold_temperature:
if self.__name in self._thresholds:
temp = self._thresholds[self.__name].max
self.set_high_threshold(temp)
check_range = False
return check_range

def __get(self, attr_prefix, attr_suffix):
sensor_data = _sensors_get().get(self.__chip, {}).get(self.__label, {})
value = _value_get(sensor_data, attr_prefix, attr_suffix)
return value if value is not None else -999.9
if value is not None and self.check_in_range(value) and self.check_high_threshold(value, attr_suffix):
return value
elif self.__name in self._thresholds and attr_prefix == 'temp':
if attr_suffix == 'crit':
return self._thresholds[self.__name].crit
elif attr_suffix == 'max':
if self.__high_threshold is None:
return self._thresholds[self.__name].max
else:
return self.__high_threshold
elif attr_suffix == 'min':
if self.__low_threshold is None:
return self._thresholds[self.__name].min
else:
return self.__low_threshold
elif attr_suffix == 'alarm':
return self._thresholds[self.__name].alarm
else:
return 1.0
else:
return 0.05

# ThermalBase interface methods:
def get_temperature(self) -> float:
temp = self.__get('temp', 'input')
self.__collect_temp.append(float(temp))
self.__collect_temp.sort()
if len(self.__collect_temp) == 3:
del self.__collect_temp[1]
return float(temp)

def get_high_threshold(self) -> float:
return float(self.__get('temp', 'max'))
if self.__high_threshold is None:
return float(self.__get('temp', 'max'))
return float(self.__high_threshold)

def get_high_critical_threshold(self) -> float:
return float(self.__get('temp', 'crit'))
Expand All @@ -113,28 +180,38 @@ def is_replaceable(self):
return False

def get_low_threshold(self) -> float:
return float(self.__get('temp', 'min'))
if self.__low_threshold is None:
return float(self.__get('temp', 'min'))
return float(self.__low_threshold)

def get_serial(self):
return 'N/A'

def get_minimum_recorded(self) -> float:
temp = self.__collect_temp[0] if len(self.__collect_temp) > 0 else 0.1
temp = self.__collect_temp[0] if len(self.__collect_temp) > 0 else self.get_temperature()
temp = temp if temp <= 100.0 else 100.0
temp = temp if temp > 0.0 else 0.1
return float(temp)

def get_maximum_recorded(self) -> float:
temp = self.__collect_temp[-1] if len(self.__collect_temp) > 0 else 100.0
temp = self.__collect_temp[-1] if len(self.__collect_temp) > 0 else self.get_temperature()
temp = temp if temp <= 100.0 else 100.0
temp = temp if temp > 0.0 else 0.1
return float(temp)

def get_position_in_parent(self):
return self.__index

def set_high_threshold(self, temperature):
if self.check_in_range(temperature):
self.__high_threshold = temperature
return True
return False

def set_low_threshold(self, temperature):
if self.check_in_range(temperature):
self.__low_threshold = temperature
return True
return False

def thermal_list_get():
Expand Down