4141
4242BASE_PATH = "/var/run/hw-management"
4343
44+
4445def get_dpu_count ():
4546 """
4647 @summary: Function gets DPU count from "{BASE_PATH}/config/dpu_num.
47- @return: # of dpus:in case of succesful read,
48+ @return: # of dpus:in case of successful read,
4849 -1 :if path does not exist, or cannot be read
4950 """
5051 dpu_count_file = os .path .join (BASE_PATH , "config" , "dpu_num" )
@@ -59,12 +60,13 @@ def get_dpu_count():
5960 print (f"Error: Could not read DPU count from { dpu_count_file } " )
6061 return - 1
6162
63+
6264def check_dpu_index (dpu_index ):
6365 """
6466 @summary: Function checks dpu index boundary.
6567 @param dpu_index: the index of the dpu , should be 1- dpu_count
66- @return: False:if # of dpu in system is unreadable or
67- dpu index is out of range (1-dpu_count),
68+ @return: False:if # of dpu in system is unreadable or
69+ dpu index is out of range (1-dpu_count),
6870 True :otherwise
6971 """
7072 dpu_count = get_dpu_count ()
@@ -78,6 +80,7 @@ def check_dpu_index(dpu_index):
7880 print (f"dpu_index { dpu_index } is out of bound 1..DPU count" )
7981 return False
8082
83+
8184def remove_file_safe (file_path ):
8285 """
8386 @summary: Function Safely removes a file if it exists.
@@ -90,11 +93,12 @@ def remove_file_safe(file_path):
9093 except Exception as e :
9194 print (f"file path didn't exist { str (file_path )} : { str (e )} " )
9295
96+
9397def create_path_safe (path ):
9498 """
9599 @summary: Function Safely create a path if it doesn't exist.
96100 @param path: path to create
97- @return: True :if path already exist or if created correctly,
101+ @return: True :if path already exist or if created correctly,
98102 False:creation of path failed.
99103 """
100104 if os .path .exists (path ) is False :
@@ -106,39 +110,40 @@ def create_path_safe(path):
106110
107111 return True
108112
113+
109114def thermal_data_dpu_cpu_core_set (dpu_index , temperature , warning_threshold = None , critical_temperature = None , fault = 0 ):
110115 """
111116 @summary: Function sets dpu's cpu core thermal data
112- @param dpu_index: dpu index
113- @param temperature: tempreture input
114- @param warning_threshold: tempreture warning threshold input
117+ @param dpu_index: dpu index
118+ @param temperature: temperature input
119+ @param warning_threshold: temperature warning threshold input
115120 @param critical_temperature: critical temperature threshold input
116- @param fault: fault input
117- @return: False:in case dpu_index is out of bound or
118- path to dpu{x} does not exist or cannot be created or
121+ @param fault: fault input
122+ @return: False:in case dpu_index is out of bound or
123+ path to dpu{x} does not exist or cannot be created or
119124 or input files cannot be created under the path or they cannot be updated.
120125 True: otherwise - writing to input files is succesful
121126 """
122127 if not check_dpu_index (dpu_index ):
123128 return False
124129
125- file_path = os .path .join (BASE_PATH , f"dpu{ dpu_index } " )
130+ file_path = os .path .join (BASE_PATH , f"dpu{ dpu_index } " )
126131 file_path_status = create_path_safe (file_path )
127132 if file_path_status is False :
128133 return False
129134
130- file_path = os .path .join (BASE_PATH , f"dpu{ dpu_index } " ,"thermal" )
135+ file_path = os .path .join (BASE_PATH , f"dpu{ dpu_index } " , "thermal" )
131136 file_path_status = create_path_safe (file_path )
132137 if file_path_status is False :
133138 return False
134139
135140 # Define file paths based on dpu_index
136- temp_input_file = os .path .join (BASE_PATH , f"dpu{ dpu_index } " ,"thermal/cpu_pack" )
137- temp_fault_file = os .path .join (BASE_PATH , f"dpu{ dpu_index } " ,"thermal/cpu_pack_fault" )
141+ temp_input_file = os .path .join (BASE_PATH , f"dpu{ dpu_index } " , "thermal/cpu_pack" )
142+ temp_fault_file = os .path .join (BASE_PATH , f"dpu{ dpu_index } " , "thermal/cpu_pack_fault" )
138143 if warning_threshold is not None :
139- temp_warning_threshold_file = os .path .join (BASE_PATH , f"dpu{ dpu_index } " ,"thermal/cpu_pack_max" )
144+ temp_warning_threshold_file = os .path .join (BASE_PATH , f"dpu{ dpu_index } " , "thermal/cpu_pack_max" )
140145 if critical_temperature is not None :
141- temp_critical_temperature_file = os .path .join (BASE_PATH , f"dpu{ dpu_index } " ,"thermal/cpu_pack_crit" )
146+ temp_critical_temperature_file = os .path .join (BASE_PATH , f"dpu{ dpu_index } " , "thermal/cpu_pack_crit" )
142147
143148 # Create the files if they don't exist and write the values
144149 try :
@@ -157,39 +162,40 @@ def thermal_data_dpu_cpu_core_set(dpu_index, temperature, warning_threshold=None
157162 print (f"Error setting thermal data for DPU CPU { dpu_index } : { str (e )} " )
158163 return False
159164
165+
160166def thermal_data_dpu_ddr_set (dpu_index , temperature , warning_threshold = None , critical_temperature = None , fault = 0 ):
161167 """
162168 @summary: Function sets dpu's ddr thermal data.
163- @param dpu_index: dpu index
164- @param temperature: tempreture input
165- @param warning_threshold: tempreture warning threshold input
169+ @param dpu_index: dpu index
170+ @param temperature: temperature input
171+ @param warning_threshold: temperature warning threshold input
166172 @param critical_temperature: critical temperature threshold input
167- @param fault: fault input
168- @return: False:in case dpu_index is out of bound or
169- path to dpu{x} does not exist or cannot be created or
173+ @param fault: fault input
174+ @return: False:in case dpu_index is out of bound or
175+ path to dpu{x} does not exist or cannot be created or
170176 or input files cannot be created under the path or they cannot be updated.
171177 True: otherwise - writing to input files is succesful
172178 """
173179 if not check_dpu_index (dpu_index ):
174180 return False
175181
176- file_path = os .path .join (BASE_PATH , f"dpu{ dpu_index } " )
182+ file_path = os .path .join (BASE_PATH , f"dpu{ dpu_index } " )
177183 file_path_status = create_path_safe (file_path )
178184 if file_path_status is False :
179185 return False
180186
181- file_path = os .path .join (BASE_PATH , f"dpu{ dpu_index } " ,"thermal" )
187+ file_path = os .path .join (BASE_PATH , f"dpu{ dpu_index } " , "thermal" )
182188 file_path_status = create_path_safe (file_path )
183189 if file_path_status is False :
184190 return False
185191
186192 # Define file paths based on dpu_index
187- temp_input_file = os .path .join (BASE_PATH , f"dpu{ dpu_index } " ,"thermal/sodimm_temp_input" )
188- temp_fault_file = os .path .join (BASE_PATH , f"dpu{ dpu_index } " ,"thermal/sodimm_temp_fault" )
193+ temp_input_file = os .path .join (BASE_PATH , f"dpu{ dpu_index } " , "thermal/sodimm_temp_input" )
194+ temp_fault_file = os .path .join (BASE_PATH , f"dpu{ dpu_index } " , "thermal/sodimm_temp_fault" )
189195 if warning_threshold is not None :
190- temp_warning_threshold_file = os .path .join (BASE_PATH , f"dpu{ dpu_index } " ,"thermal/sodimm_temp_max" )
196+ temp_warning_threshold_file = os .path .join (BASE_PATH , f"dpu{ dpu_index } " , "thermal/sodimm_temp_max" )
191197 if critical_temperature is not None :
192- temp_critical_temperature_file = os .path .join (BASE_PATH , f"dpu{ dpu_index } " ,"thermal/sodimm_temp_crit" )
198+ temp_critical_temperature_file = os .path .join (BASE_PATH , f"dpu{ dpu_index } " , "thermal/sodimm_temp_crit" )
193199
194200 # Create the files if they don't exist and write the values
195201 try :
@@ -208,39 +214,40 @@ def thermal_data_dpu_ddr_set(dpu_index, temperature, warning_threshold=None, cri
208214 print (f"Error setting thermal data for DPU DDR { dpu_index } : { str (e )} " )
209215 return False
210216
217+
211218def thermal_data_dpu_drive_set (dpu_index , temperature , warning_threshold = None , critical_temperature = None , fault = 0 ):
212219 """
213220 @summary: Function sets dpu's drive NVME thermal data.
214- @param dpu_index: dpu index
215- @param temperature: tempreture input
216- @param warning_threshold: tempreture warning threshold input
221+ @param dpu_index: dpu index
222+ @param temperature: temperature input
223+ @param warning_threshold: temperature warning threshold input
217224 @param critical_temperature: critical temperature threshold input
218- @param fault: fault input
219- @return: False:in case dpu_index is out of bound or
220- path to dpu{x} does not exist or cannot be created or
225+ @param fault: fault input
226+ @return: False:in case dpu_index is out of bound or
227+ path to dpu{x} does not exist or cannot be created or
221228 or input files cannot be created under the path or they cannot be updated.
222229 True: otherwise - writing to input files is succesful
223230 """
224231 if not check_dpu_index (dpu_index ):
225232 return False
226233
227- file_path = os .path .join (BASE_PATH , f"dpu{ dpu_index } " )
234+ file_path = os .path .join (BASE_PATH , f"dpu{ dpu_index } " )
228235 file_path_status = create_path_safe (file_path )
229236 if file_path_status is False :
230237 return False
231238
232- file_path = os .path .join (BASE_PATH , f"dpu{ dpu_index } " ,"thermal" )
239+ file_path = os .path .join (BASE_PATH , f"dpu{ dpu_index } " , "thermal" )
233240 file_path_status = create_path_safe (file_path )
234241 if file_path_status is False :
235242 return False
236243
237244 # Define file paths based on dpu_index
238- temp_input_file = os .path .join (BASE_PATH , f"dpu{ dpu_index } " ,"thermal/drivetemp" )
239- temp_fault_file = os .path .join (BASE_PATH , f"dpu{ dpu_index } " ,"thermal/drivetemp_fault" )
245+ temp_input_file = os .path .join (BASE_PATH , f"dpu{ dpu_index } " , "thermal/drivetemp" )
246+ temp_fault_file = os .path .join (BASE_PATH , f"dpu{ dpu_index } " , "thermal/drivetemp_fault" )
240247 if warning_threshold is not None :
241- temp_warning_threshold_file = os .path .join (BASE_PATH , f"dpu{ dpu_index } " ,"thermal/drivetemp_max" )
248+ temp_warning_threshold_file = os .path .join (BASE_PATH , f"dpu{ dpu_index } " , "thermal/drivetemp_max" )
242249 if critical_temperature is not None :
243- temp_critical_temperature_file = os .path .join (BASE_PATH , f"dpu{ dpu_index } " ,"thermal/drivetemp_crit" )
250+ temp_critical_temperature_file = os .path .join (BASE_PATH , f"dpu{ dpu_index } " , "thermal/drivetemp_crit" )
244251
245252 # Create the files if they don't exist and write the values
246253 try :
@@ -259,12 +266,12 @@ def thermal_data_dpu_drive_set(dpu_index, temperature, warning_threshold=None, c
259266 print (f"Error setting thermal data for DPU drive { dpu_index } : { str (e )} " )
260267 return False
261268
262- def thermal_data_dpu_cpu_core_clear (dpu_index ):
263269
270+ def thermal_data_dpu_cpu_core_clear (dpu_index ):
264271 """
265272 @summary: Function cleans dpu's cpu core thermal data.
266273 @param dpu_index: the index of the dpu , should be 1- dpu_count
267- @return: False:if # of dpu in system is unreadable or
274+ @return: False:if # of dpu in system is unreadable or
268275 dpu index is out of range (1-dpu_count),or
269276 the erase of any of the relevant files failed
270277 True :otherwise
@@ -273,10 +280,10 @@ def thermal_data_dpu_cpu_core_clear(dpu_index):
273280 return False
274281
275282 # Define file paths
276- temp_input_file = os .path .join (BASE_PATH , f"dpu{ dpu_index } " ,"thermal/cpu_pack" )
277- temp_warning_threshold_file = os .path .join (BASE_PATH , f"dpu{ dpu_index } " ,"thermal/cpu_pack_max" )
278- temp_critical_temperature_file = os .path .join (BASE_PATH , f"dpu{ dpu_index } " ,"thermal/cpu_pack_crit" )
279- temp_fault_file = os .path .join (BASE_PATH , f"dpu{ dpu_index } " ,"thermal/cpu_pack_fault" )
283+ temp_input_file = os .path .join (BASE_PATH , f"dpu{ dpu_index } " , "thermal/cpu_pack" )
284+ temp_warning_threshold_file = os .path .join (BASE_PATH , f"dpu{ dpu_index } " , "thermal/cpu_pack_max" )
285+ temp_critical_temperature_file = os .path .join (BASE_PATH , f"dpu{ dpu_index } " , "thermal/cpu_pack_crit" )
286+ temp_fault_file = os .path .join (BASE_PATH , f"dpu{ dpu_index } " , "thermal/cpu_pack_fault" )
280287 # Remove the files if they exist
281288 try :
282289 remove_file_safe (temp_input_file )
@@ -288,11 +295,12 @@ def thermal_data_dpu_cpu_core_clear(dpu_index):
288295 print (f"Error cleaning thermal data for DPU CPU { dpu_index } : { str (e )} " )
289296 return False
290297
298+
291299def thermal_data_dpu_ddr_clear (dpu_index ):
292300 """
293301 @summary: Function cleans dpu's ddr thermal data.
294302 @param dpu_index: the index of the dpu , should be 1- dpu_count
295- @return: False:if # of dpu in system is unreadable or
303+ @return: False:if # of dpu in system is unreadable or
296304 dpu index is out of range (1-dpu_count),or
297305 the erase of any of the relevant files failed
298306 True :otherwise
@@ -301,10 +309,10 @@ def thermal_data_dpu_ddr_clear(dpu_index):
301309 return False
302310
303311 # Define file paths
304- temp_input_file = os .path .join (BASE_PATH , f"dpu{ dpu_index } " ,"thermal/sodimm_temp_input" )
305- temp_warning_threshold_file = os .path .join (BASE_PATH , f"dpu{ dpu_index } " ,"thermal/sodimm_temp_max" )
306- temp_critical_temperature_file = os .path .join (BASE_PATH , f"dpu{ dpu_index } " ,"thermal/sodimm_temp_crit" )
307- temp_fault_file = os .path .join (BASE_PATH , f"dpu{ dpu_index } " ,"thermal/sodimm_temp_fault" )
312+ temp_input_file = os .path .join (BASE_PATH , f"dpu{ dpu_index } " , "thermal/sodimm_temp_input" )
313+ temp_warning_threshold_file = os .path .join (BASE_PATH , f"dpu{ dpu_index } " , "thermal/sodimm_temp_max" )
314+ temp_critical_temperature_file = os .path .join (BASE_PATH , f"dpu{ dpu_index } " , "thermal/sodimm_temp_crit" )
315+ temp_fault_file = os .path .join (BASE_PATH , f"dpu{ dpu_index } " , "thermal/sodimm_temp_fault" )
308316 # Remove the files if they exist
309317 try :
310318 remove_file_safe (temp_input_file )
@@ -316,11 +324,12 @@ def thermal_data_dpu_ddr_clear(dpu_index):
316324 print (f"Error cleaning thermal data for DPU DDR { dpu_index } : { str (e )} " )
317325 return False
318326
327+
319328def thermal_data_dpu_drive_clear (dpu_index ):
320329 """
321330 @summary: Function cleans dpu's drive NVME thermal data.
322331 @param dpu_index: the index of the dpu , should be 1- dpu_count
323- @return: False:if # of dpu in system is unreadable or
332+ @return: False:if # of dpu in system is unreadable or
324333 dpu index is out of range (1-dpu_count),or
325334 the erase of any of the relevant files failed
326335 True :otherwise
@@ -329,10 +338,10 @@ def thermal_data_dpu_drive_clear(dpu_index):
329338 return False
330339
331340 # Define file paths
332- temp_input_file = os .path .join (BASE_PATH , f"dpu{ dpu_index } " ,"thermal/drivetemp" )
333- temp_warning_threshold_file = os .path .join (BASE_PATH , f"dpu{ dpu_index } " ,"thermal/drivetemp_max" )
334- temp_critical_temperature_file = os .path .join (BASE_PATH , f"dpu{ dpu_index } " ,"thermal/drivetemp_crit" )
335- temp_fault_file = os .path .join (BASE_PATH , f"dpu{ dpu_index } " ,"thermal/drivetemp_fault" )
341+ temp_input_file = os .path .join (BASE_PATH , f"dpu{ dpu_index } " , "thermal/drivetemp" )
342+ temp_warning_threshold_file = os .path .join (BASE_PATH , f"dpu{ dpu_index } " , "thermal/drivetemp_max" )
343+ temp_critical_temperature_file = os .path .join (BASE_PATH , f"dpu{ dpu_index } " , "thermal/drivetemp_crit" )
344+ temp_fault_file = os .path .join (BASE_PATH , f"dpu{ dpu_index } " , "thermal/drivetemp_fault" )
336345 # Remove the files if they exist
337346 try :
338347 remove_file_safe (temp_input_file )
@@ -344,7 +353,7 @@ def thermal_data_dpu_drive_clear(dpu_index):
344353 print (f"Error cleaning thermal data for DPU drive { dpu_index } : { str (e )} " )
345354 return False
346355
347- #def main():
356+ # def main():
348357# """Function main."""
349358# dpu_count = get_dpu_count()
350359# print(f"DPU count {dpu_count}")
@@ -363,5 +372,5 @@ def thermal_data_dpu_drive_clear(dpu_index):
363372# thermal_data_dpu_cpu_core_clear(3)
364373# thermal_data_dpu_ddr_clear(3)
365374# thermal_data_dpu_drive_clear(3)
366- #if __name__ == "__main__":
375+ # if __name__ == "__main__":
367376# main()
0 commit comments