Skip to content

Commit

Permalink
[AS9726-32D] Add CPU coretemp to thermal.py
Browse files Browse the repository at this point in the history
Signed-off-by: Sean Wu <sean_wu@edge-core.com>
  • Loading branch information
seanwu-ec committed Dec 9, 2021
1 parent ccfc52c commit 0d63cd7
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ def __initialize_psu(self):

def __initialize_thermals(self):
from sonic_platform.thermal import Thermal
self._thermal_list.append(Thermal(is_cpu=True))
for index in range(0, NUM_THERMAL):
thermal = Thermal(index)
self._thermal_list.append(thermal)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,11 @@
},
}

THERMAL_NAME_LIST = ["Main Board 0x48", "Main Board 0x49", "Main Board 0x4A",
"CPU Board 0x4B", "OCXO 0x4C", "Main Board 0x4F"]
THERMAL_NAME_LIST = ("Main Board 0x48", "Main Board 0x49", "Main Board 0x4A",
"CPU Board 0x4B", "OCXO 0x4C", "Main Board 0x4F")

PSU_THERMAL_NAME_LIST = ["PSU-1 temp sensor 1", "PSU-2 temp sensor 1"]
PSU_THERMAL_NAME_LIST = ("PSU-1 temp sensor 1", "PSU-2 temp sensor 1")
CPU_THERMAL_NAME = "CPU Core temp"

SYSFS_PATH = "/sys/bus/i2c/devices"

Expand Down Expand Up @@ -77,10 +78,15 @@ class Thermal(ThermalBase):
}
_thresholds = None

def __init__(self, thermal_index=0, is_psu=False, psu_index=0):
def __init__(self, thermal_index=0, is_psu=False, psu_index=0, is_cpu=False):
self.index = thermal_index
self.is_psu = is_psu
self.psu_index = psu_index
self.is_cpu = is_cpu

if self.is_cpu:
self.cpu_paths = glob.glob('/sys/devices/platform/coretemp.0/hwmon/hwmon*/temp*_input')
self.cpu_path_idx = 0

if self.is_psu:
psu_i2c_bus = PSU_HWMON_I2C_MAPPING[psu_index]["num"]
Expand Down Expand Up @@ -128,13 +134,38 @@ def __get_temp(self, temp_file):
else:
return 0

def __get_max_temp(self, paths):
max_temp = -1.0
max_idx = 0
for i, path in enumerate(paths):
read_temp = self.__get_temp(path)
if(read_temp > max_temp):
max_temp = read_temp
max_idx = i
return max_temp, max_idx

def __get_cpu_threshold(self, type):
path = self.cpu_paths[self.cpu_path_idx]
high_warn = self.__get_temp(path.replace('_input', '_max'))
if type == 'high_warn':
return high_warn
high_crit = self.__get_temp(path.replace('_input', '_crit'))
if type == 'high_crit':
return high_crit
if type == 'high_err':
return (high_crit + high_warn) / 2
return 0 # for all low_* thresholds

def _try_get_threshold(self, type):
if self.is_psu is True:
return None

if self._thresholds is None:
self._thresholds = self._thresholds_F2B if is_fan_dir_F2B() else self._thresholds_B2F

if self.is_cpu:
return self.__get_cpu_threshold(type)

if self.index in self._thresholds:
return getattr(self._thresholds[self.index], type)
else:
Expand All @@ -148,6 +179,10 @@ def get_temperature(self):
A float number of current temperature in Celsius up to nearest thousandth
of one degree Celsius, e.g. 30.125
"""
if self.is_cpu:
cpu_temp, self.cpu_path_idx = self.__get_max_temp(self.cpu_paths)
return cpu_temp

if not self.is_psu:
temp_file = "temp{}_input".format(self.ss_index)
else:
Expand All @@ -160,6 +195,9 @@ def get_name(self):
Returns:
string: The name of the thermal device
"""
if self.is_cpu:
return CPU_THERMAL_NAME

if self.is_psu:
return PSU_THERMAL_NAME_LIST[self.psu_index]
else:
Expand All @@ -171,6 +209,9 @@ def get_presence(self):
Returns:
bool: True if Thermal is present, False if not
"""
if self.is_cpu:
return True

if self.is_psu:
val = self.__read_txt_file(self.cpld_path + "psu_present")
return int(val, 10) == 1
Expand All @@ -188,6 +229,9 @@ def get_status(self):
Returns:
A boolean value, True if device is operating properly, False if not
"""
if self.is_cpu:
return True

if self.is_psu:
temp_file = self.psu_hwmon_path + "psu_temp_fault"
return self.get_presence() and (not int(
Expand Down

0 comments on commit 0d63cd7

Please sign in to comment.