Skip to content

Commit 5af327d

Browse files
author
Jaganathan Anbalagan
committed
Signed-off-by: Jaganathan Anbalagan <[email protected]>
PM statistics is collected through scheduler
1 parent 770ab71 commit 5af327d

File tree

1 file changed

+58
-51
lines changed

1 file changed

+58
-51
lines changed

sonic-xcvrd/xcvrd/pm_mgr.py

+58-51
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import threading
1212
import time
1313
import traceback
14+
import sched
1415

1516
from swsscommon import swsscommon
1617
from .xcvrd_utilities import sfp_status_helper
@@ -381,64 +382,70 @@ def beautify_pm_info_dict(self, pm_info_dict, physical_port):
381382
def task_worker(self):
382383
self.log_notice("Start Performance monitoring for 400G ZR modules")
383384
sel, asic_context = port_mapping.subscribe_port_update_event(self.namespaces, self, self.PORT_TBL_MAP)
385+
#Schedule the PM
386+
self.scheduler = sched.scheduler(time.time, time.sleep)
387+
self.scheduler.enter(self.pm_interval, 1, self.pm_update_task_worker)
388+
389+
#Run all scheduled events and handle port events
390+
while not self.task_stopping_event.is_set():
391+
port_mapping.handle_port_update_event(sel, asic_context, self.task_stopping_event, self.helper_logger, self.on_port_update_event)
392+
self.scheduler.run(blocking=False)
393+
394+
def pm_update_task_worker(self):
395+
396+
# Schedule the next run with pm_interval
397+
self.scheduler.enter(self.pm_interval, 1, self.pm_update_task_worker)
398+
#Iterate the ZR-400G port list for pm window update
399+
for lport in self.pm_port_list:
400+
asic_index = self.port_mapping_data.get_asic_id_for_logical_port(lport)
401+
if asic_index is None:
402+
continue
403+
404+
physical_port = self.port_mapping_data.get_logical_to_physical(lport)[0]
405+
if not physical_port:
406+
continue
384407

385-
# Start loop to update PM stats info to DB periodically for PM interval time, default is 60sec
386-
while not self.task_stopping_event.wait(self.pm_interval):
387-
388-
# Handle port change event from main thread
389-
port_mapping.handle_port_update_event(sel, asic_context, self.task_stopping_event, self, self.on_port_update_event)
390-
for lport in self.pm_port_list:
391-
asic_index = self.port_mapping_data.get_asic_id_for_logical_port(lport)
392-
if asic_index is None:
393-
continue
394-
395-
physical_port = self.port_mapping_data.get_logical_to_physical(lport)[0]
396-
if not physical_port:
408+
#skip if sfp obj or sfp is not present
409+
sfp = self.platform_chassis.get_sfp(physical_port)
410+
if sfp is not None:
411+
if not sfp.get_presence():
397412
continue
413+
else:
414+
continue
398415

399-
#skip if sfp obj or sfp is not present
400-
sfp = self.platform_chassis.get_sfp(physical_port)
401-
if sfp is not None:
402-
if not sfp.get_presence():
403-
continue
404-
else:
405-
continue
416+
if self.get_port_admin_status(lport) != 'up':
417+
continue
406418

407-
if self.get_port_admin_status(lport) != 'up':
419+
if not sfp_status_helper.detect_port_in_error_status(lport, self.xcvr_table_helper.get_status_tbl(asic_index)):
420+
try:
421+
pm_hw_data = self.get_transceiver_pm(physical_port)
422+
except (KeyError, TypeError) as e:
423+
#continue to process next port since execption could be raised due to port reset, transceiver removal
424+
self.log_warning("Got exception {} while reading pm stats for port {}, ignored".format(repr(e), lport))
408425
continue
409426

410-
if not sfp_status_helper.detect_port_in_error_status(lport, self.xcvr_table_helper.get_status_tbl(asic_index)):
411-
try:
412-
pm_hw_data = self.get_transceiver_pm(physical_port)
413-
except (KeyError, TypeError) as e:
414-
#continue to process next port since execption could be raised due to port reset, transceiver removal
415-
self.log_warning("Got exception {} while reading pm stats for port {}, ignored".format(repr(e), lport))
416-
continue
417-
418-
if not pm_hw_data:
419-
continue
427+
if not pm_hw_data:
428+
continue
420429

421-
self.beautify_pm_info_dict(pm_hw_data, physical_port)
422-
423-
# Update 60Sec PM time window slots
424-
start_window = WINDOW_60SEC_START_NUM
425-
end_window = WINDOW_60SEC_END_NUM
426-
pm_win_itrvl_in_secs = TIME_60SEC_IN_SECS
427-
self.pm_window_update_to_DB(lport, asic_index, start_window, end_window, pm_win_itrvl_in_secs, pm_hw_data)
428-
429-
# Update 15min PM time window slots
430-
start_window = WINDOW_15MIN_START_NUM
431-
end_window = WINDOW_15MIN_END_NUM
432-
pm_win_itrvl_in_secs = TIME_15MIN_IN_SECS
433-
self.pm_window_update_to_DB(lport, asic_index, start_window, end_window, pm_win_itrvl_in_secs, pm_hw_data)
434-
435-
# Update 24hrs PM time window slots
436-
start_window = WINDOW_24HRS_START_NUM
437-
end_window = WINDOW_24HRS_END_NUM
438-
pm_win_itrvl_in_secs = TIME_24HRS_IN_SECS
439-
self.pm_window_update_to_DB(lport, asic_index, start_window, end_window, pm_win_itrvl_in_secs, pm_hw_data)
440-
441-
self.log_notice("Stop Performance Monitoring")
430+
self.beautify_pm_info_dict(pm_hw_data, physical_port)
431+
432+
# Update 60Sec PM time window slots
433+
start_window = WINDOW_60SEC_START_NUM
434+
end_window = WINDOW_60SEC_END_NUM
435+
pm_win_itrvl_in_secs = TIME_60SEC_IN_SECS
436+
self.pm_window_update_to_DB(lport, asic_index, start_window, end_window, pm_win_itrvl_in_secs, pm_hw_data)
437+
438+
# Update 15min PM time window slots
439+
start_window = WINDOW_15MIN_START_NUM
440+
end_window = WINDOW_15MIN_END_NUM
441+
pm_win_itrvl_in_secs = TIME_15MIN_IN_SECS
442+
self.pm_window_update_to_DB(lport, asic_index, start_window, end_window, pm_win_itrvl_in_secs, pm_hw_data)
443+
444+
# Update 24hrs PM time window slots
445+
start_window = WINDOW_24HRS_START_NUM
446+
end_window = WINDOW_24HRS_END_NUM
447+
pm_win_itrvl_in_secs = TIME_24HRS_IN_SECS
448+
self.pm_window_update_to_DB(lport, asic_index, start_window, end_window, pm_win_itrvl_in_secs, pm_hw_data)
442449

443450
def run(self):
444451
if self.task_stopping_event.is_set():

0 commit comments

Comments
 (0)