Skip to content

Commit be55ed4

Browse files
committed
[AS5835-54T] add thermal thresholds and cpu temp
Signed-off-by: Sean Wu <[email protected]>
1 parent c543342 commit be55ed4

File tree

2 files changed

+95
-48
lines changed

2 files changed

+95
-48
lines changed

device/accton/x86_64-accton_as5835_54t-r0/sonic_platform/chassis.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ def __initialize_psu(self):
7878

7979
def __initialize_thermals(self):
8080
from sonic_platform.thermal import Thermal
81+
self._thermal_list.append(Thermal(is_cpu=True))
8182
for index in range(0, NUM_THERMAL):
8283
thermal = Thermal(index)
8384
self._thermal_list.append(thermal)

device/accton/x86_64-accton_as5835_54t-r0/sonic_platform/thermal.py

Lines changed: 94 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,16 @@
99
import os
1010
import os.path
1111
import glob
12+
from collections import namedtuple
1213

1314
try:
1415
from sonic_platform_base.thermal_base import ThermalBase
1516
except ImportError as e:
1617
raise ImportError(str(e) + "- required module not found")
1718

19+
Threshold = namedtuple('Threshold', ['high_crit', 'high_err', 'high_warn',
20+
'low_warn', 'low_err', 'low_crit'], defaults=[0]*6)
21+
1822
PSU_I2C_PATH = "/sys/bus/i2c/devices/{}-00{}/"
1923
PSU_HWMON_I2C_MAPPING = {
2024
0: {
@@ -38,20 +42,44 @@
3842
},
3943
}
4044

41-
THERMAL_NAME_LIST = ["CPU Board 0x4B", "Main Board 0x4C",
42-
"Main Board 0x49", "Main Board 0x4A"]
43-
44-
PSU_THERMAL_NAME_LIST = ["PSU-1 temp sensor 1", "PSU-2 temp sensor 1"]
45+
THERMAL_NAME_LIST = ("CPU Board 0x4B", "Main Board 0x4C",
46+
"Main Board 0x49", "Main Board 0x4A")
47+
CPU_THERMAL_NAME = "CPU Core temp"
48+
PSU_THERMAL_NAME_LIST = ("PSU-1 temp sensor 1", "PSU-2 temp sensor 1")
4549

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

52+
def is_fan_dir_F2B():
53+
from sonic_platform.platform import Platform
54+
fan = Platform().get_chassis().get_fan(0)
55+
return fan.get_direction().lower() == fan.FAN_DIRECTION_EXHAUST
56+
57+
4858
class Thermal(ThermalBase):
4959
"""Platform-specific Thermal class"""
50-
51-
def __init__(self, thermal_index=0, is_psu=False, psu_index=0):
60+
THRESHOLDS_F2B = {
61+
0: Threshold(70.0, 65.0, 65.0),
62+
1: Threshold(67.0, 62.0, 62.0),
63+
2: Threshold(58.0, 53.0, 53.0),
64+
3: Threshold(61.0, 56.0, 56.0),
65+
}
66+
THRESHOLDS_B2F = {
67+
0: Threshold(57.0, 52.0, 52.0),
68+
1: Threshold(66.0, 61.0, 61.0),
69+
2: Threshold(60.0, 55.0, 55.0),
70+
3: Threshold(59.0, 54.0, 54.0),
71+
}
72+
THRESHOLDS = None
73+
74+
def __init__(self, thermal_index=0, is_psu=False, psu_index=0, is_cpu=False):
5275
self.index = thermal_index
5376
self.is_psu = is_psu
5477
self.psu_index = psu_index
78+
self.is_cpu = is_cpu
79+
80+
if self.is_cpu:
81+
self.cpu_paths = glob.glob('/sys/devices/platform/coretemp.0/hwmon/hwmon*/temp*_input')
82+
self.cpu_path_idx = 0
5583

5684
if self.is_psu:
5785
psu_i2c_bus = PSU_HWMON_I2C_MAPPING[psu_index]["num"]
@@ -97,21 +125,39 @@ def __get_temp(self, temp_file):
97125
else:
98126
return 0
99127

100-
101-
def __set_threshold(self, file_name, temperature):
102-
if self.is_psu:
103-
return True
104-
temp_file_path = os.path.join(self.hwmon_path, file_name)
105-
for filename in glob.glob(temp_file_path):
106-
try:
107-
with open(filename, 'w') as fd:
108-
fd.write(str(temperature))
109-
fd.flush()
110-
return True
111-
except IOError as e:
112-
print("IOError")
113-
return False
114-
128+
def __get_max_temp(self, paths):
129+
max_temp = -1.0
130+
max_idx = 0
131+
for i, path in enumerate(paths):
132+
read_temp = self.__get_temp(path)
133+
if(read_temp > max_temp):
134+
max_temp = read_temp
135+
max_idx = i
136+
return max_temp, max_idx
137+
138+
def __get_cpu_threshold(self, type):
139+
path = self.cpu_paths[self.cpu_path_idx]
140+
high_warn = self.__get_temp(path.replace('_input', '_max'))
141+
if type == 'high_warn':
142+
return high_warn
143+
high_crit = self.__get_temp(path.replace('_input', '_crit'))
144+
if type == 'high_crit':
145+
return high_crit
146+
if type == 'high_err':
147+
return (high_crit + high_warn) / 2
148+
return 0
149+
150+
def __try_get_threshold(self, type):
151+
if self.THRESHOLDS is None:
152+
self.THRESHOLDS = self.THRESHOLDS_F2B if is_fan_dir_F2B() else self.THRESHOLDS_B2F
153+
154+
if self.is_cpu:
155+
return self.__get_cpu_threshold(type)
156+
157+
if self.is_psu==False and self.index in self.THRESHOLDS:
158+
return getattr(self.THRESHOLDS[self.index], type)
159+
else:
160+
return None
115161

116162
def get_temperature(self):
117163
"""
@@ -120,46 +166,25 @@ def get_temperature(self):
120166
A float number of current temperature in Celsius up to nearest thousandth
121167
of one degree Celsius, e.g. 30.125
122168
"""
169+
if self.is_cpu:
170+
cpu_temp, self.cpu_path_idx = self.__get_max_temp(self.cpu_paths)
171+
return cpu_temp
172+
123173
if not self.is_psu:
124174
temp_file = "temp{}_input".format(self.ss_index)
125175
else:
126176
temp_file = self.psu_hwmon_path + "psu_temp1_input"
127-
return self.__get_temp(temp_file)
128-
129-
def get_high_threshold(self):
130-
"""
131-
Retrieves the high threshold temperature of thermal
132-
Returns:
133-
A float number, the high threshold temperature of thermal in Celsius
134-
up to nearest thousandth of one degree Celsius, e.g. 30.125
135-
"""
136-
if self.is_psu:
137-
return 80
138177

139-
temp_file = "temp{}_max".format(self.ss_index)
140178
return self.__get_temp(temp_file)
141179

142-
def set_high_threshold(self, temperature):
143-
"""
144-
Sets the high threshold temperature of thermal
145-
Args :
146-
temperature: A float number up to nearest thousandth of one degree Celsius,
147-
e.g. 30.125
148-
Returns:
149-
A boolean, True if threshold is set successfully, False if not
150-
"""
151-
temp_file = "temp{}_max".format(self.ss_index)
152-
temperature = temperature *1000
153-
self.__set_threshold(temp_file, temperature)
154-
155-
return True
156-
157180
def get_name(self):
158181
"""
159182
Retrieves the name of the thermal device
160183
Returns:
161184
string: The name of the thermal device
162185
"""
186+
if self.is_cpu:
187+
return CPU_THERMAL_NAME
163188
if self.is_psu:
164189
return PSU_THERMAL_NAME_LIST[self.psu_index]
165190
else:
@@ -171,6 +196,8 @@ def get_presence(self):
171196
Returns:
172197
bool: True if Thermal is present, False if not
173198
"""
199+
if self.is_cpu:
200+
return True
174201
if self.is_psu:
175202
val = self.__read_txt_file(self.cpld_path + "psu_present")
176203
return int(val, 10) == 1
@@ -188,6 +215,8 @@ def get_status(self):
188215
Returns:
189216
A boolean value, True if device is operating properly, False if not
190217
"""
218+
if self.is_cpu:
219+
return True
191220
if self.is_psu:
192221
temp_file = self.psu_hwmon_path + "psu_temp_fault"
193222
return self.get_presence() and (not int(
@@ -235,3 +264,20 @@ def is_replaceable(self):
235264
"""
236265
return False
237266

267+
def get_high_critical_threshold(self):
268+
return self.__try_get_threshold('high_crit')
269+
270+
def get_low_critical_threshold(self):
271+
return self.__try_get_threshold('low_crit')
272+
273+
def get_high_threshold(self):
274+
return self.__try_get_threshold('high_err')
275+
276+
def get_low_threshold(self):
277+
return self.__try_get_threshold('low_err')
278+
279+
def get_high_warning_threshold(self):
280+
return self.__try_get_threshold('high_warn')
281+
282+
def get_low_warning_threshold(self):
283+
return self.__try_get_threshold('low_warn')

0 commit comments

Comments
 (0)