1
1
#
2
- # Copyright (c) 2019-2024 NVIDIA CORPORATION & AFFILIATES.
2
+ # SPDX-FileCopyrightText: NVIDIA CORPORATION & AFFILIATES
3
+ # Copyright (c) 2019-2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
3
4
# Apache-2.0
4
5
#
5
6
# Licensed under the Apache License, Version 2.0 (the "License");
26
27
from sonic_platform_base .thermal_base import ThermalBase
27
28
from sonic_py_common .logger import Logger
28
29
import copy
30
+ import glob
29
31
import os
32
+ import re
30
33
31
34
from .device_data import DeviceDataManager
32
35
from . import utils
133
136
"temperature" : "sodimm{}_temp_input" ,
134
137
"high_threshold" : "sodimm{}_temp_max" ,
135
138
"high_critical_threshold" : "sodimm{}_temp_crit" ,
136
- "type" : "indexable" ,
139
+ "search_pattern" : '/run/hw-management/thermal/sodimm*_temp_input' ,
140
+ 'index_pattern' : r'sodimm(\d+)_temp_input' ,
141
+ "type" : "discrete" ,
137
142
}
138
143
],
139
144
'linecard thermals' : {
@@ -153,21 +158,22 @@ def initialize_chassis_thermals():
153
158
rules = THERMAL_NAMING_RULE ['chassis thermals' ]
154
159
position = 1
155
160
for rule in rules :
156
- if 'type' in rule and rule ['type' ] == 'indexable' :
161
+ thermal_type = rule .get ('type' )
162
+ if thermal_type == 'indexable' :
157
163
count = 0
158
164
if 'Gearbox' in rule ['name' ]:
159
165
count = DeviceDataManager .get_gearbox_count ('/run/hw-management/config' )
160
166
elif 'CPU Core' in rule ['name' ]:
161
167
count = DeviceDataManager .get_cpu_thermal_count ()
162
- elif 'SODIMM' in rule ['name' ]:
163
- count = DeviceDataManager .get_sodimm_thermal_count ()
164
168
if count == 0 :
165
169
logger .log_debug ('Failed to get thermal object count for {}' .format (rule ['name' ]))
166
170
continue
167
171
168
172
for index in range (count ):
169
173
thermal_list .append (create_indexable_thermal (rule , index , CHASSIS_THERMAL_SYSFS_FOLDER , position ))
170
174
position += 1
175
+ elif thermal_type == 'discrete' :
176
+ thermal_list .extend (create_discrete_thermal (rule ))
171
177
else :
172
178
thermal_object = create_single_thermal (rule , CHASSIS_THERMAL_SYSFS_FOLDER , position )
173
179
if thermal_object :
@@ -274,6 +280,23 @@ def create_single_thermal(rule, sysfs_folder, position, presence_cb=None):
274
280
return RemovableThermal (name , temp_file , high_th_file , high_crit_th_file , high_th_default , high_crit_th_default , scale , position , presence_cb )
275
281
276
282
283
+ def create_discrete_thermal (rule ):
284
+ search_pattern = rule .get ('search_pattern' )
285
+ index_pattern = rule .get ('index_pattern' )
286
+ position = 1
287
+ thermal_list = []
288
+ for file_path in glob .iglob (search_pattern ):
289
+ file_name = os .path .basename (file_path )
290
+ match = re .search (index_pattern , file_name )
291
+ if not match :
292
+ logger .log_error (f'Failed to extract index from { file_name } using pattern { index_pattern } ' )
293
+ continue
294
+ index = int (match .group (1 ))
295
+ thermal_list .append (create_indexable_thermal (rule , index - 1 , CHASSIS_THERMAL_SYSFS_FOLDER , position ))
296
+ position += 1
297
+ return thermal_list
298
+
299
+
277
300
def _check_thermal_sysfs_existence (file_path , presence_cb ):
278
301
if presence_cb :
279
302
status , _ = presence_cb ()
0 commit comments