Skip to content

Commit

Permalink
Fix xcvrd busy issue
Browse files Browse the repository at this point in the history
  • Loading branch information
Jostar Yang committed Oct 18, 2021
1 parent d36ffb4 commit 357f939
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
PMON_REBOOT_CAUSE_PATH = "/usr/share/sonic/platform/api_files/reboot-cause/"
REBOOT_CAUSE_FILE = "reboot-cause.txt"
PREV_REBOOT_CAUSE_FILE = "previous-reboot-cause.txt"
HOST_CHK_CMD = "docker > /dev/null 2>&1"
HOST_CHK_CMD = "which systemctl > /dev/null 2>&1"
SYSLED_FNODE = "/sys/class/leds/accton_as7712_32x_led::diag/brightness"
SYSLED_MODES = {
"0" : "STATUS_LED_COLOR_OFF",
Expand All @@ -45,7 +45,6 @@ class Chassis(ChassisBase):
def __init__(self):
ChassisBase.__init__(self)
self._api_helper = APIHelper()
self._api_helper = APIHelper()
self.is_host = self._api_helper.is_host()

self.config_data = {}
Expand All @@ -69,7 +68,8 @@ def __initialize_sfp(self):
sfp_module = Sfp(index, 'SFP')

self._sfp_list.append(sfp_module)


self._sfpevent = SfpEvent(self._sfp_list)
self.sfp_module_initialized = True

def __initialize_fan(self):
Expand Down Expand Up @@ -200,10 +200,7 @@ def get_change_event(self, timeout=0):
# SFP event
if not self.sfp_module_initialized:
self.__initialize_sfp()

status, sfp_event = SfpEvent(self._sfp_list).get_sfp_event(timeout)

return status, sfp_event
return self._sfpevent.get_sfp_event(timeout)

def get_sfp(self, index):
"""
Expand Down
45 changes: 26 additions & 19 deletions device/accton/x86_64-accton_as7712_32x-r0/sonic_platform/event.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
except ImportError as e:
raise ImportError(repr(e) + " - required module not found")

POLL_INTERVAL_IN_SEC = 1

class SfpEvent:
''' Listen to insert/remove sfp events '''
Expand All @@ -13,30 +14,38 @@ def __init__(self, sfp_list):
self._api_helper = APIHelper()
self._sfp_list = sfp_list
self._logger = Logger()
self._sfp_change_event_data = {'present': 0}

sfp_change_event_data = {'valid': 0, 'last': 0, 'present': 0}
def get_sfp_event(self, timeout=2000):
now = time.time()
port_dict = {}
change_dict = {}
change_dict['sfp'] = port_dict

if timeout < 1000:
timeout = 1000
timeout = timeout / float(1000) # Convert to secs

if now < (self.sfp_change_event_data['last'] + timeout) and self.sfp_change_event_data['valid']:
return True, change_dict

def get_presence_bitmap(self):
bitmap = 0
for sfp in self._sfp_list:
modpres = sfp.get_presence()
i=sfp.port_num-1
if modpres:
bitmap = bitmap | (1 << i)
return bitmap

def get_sfp_event(self, timeout=2000):
port_dict = {}
change_dict = {}
change_dict['sfp'] = port_dict

changed_ports = self.sfp_change_event_data['present'] ^ bitmap
if changed_ports:
if timeout < 1000:
cd_ms = 1000
else:
cd_ms = timeout

while cd_ms > 0:
bitmap = self.get_presence_bitmap()
changed_ports = self._sfp_change_event_data['present'] ^ bitmap
if changed_ports != 0:
break
time.sleep(POLL_INTERVAL_IN_SEC)
# timeout=0 means wait for event forever
if timeout != 0:
cd_ms = cd_ms - POLL_INTERVAL_IN_SEC * 1000

if changed_ports != 0:
for sfp in self._sfp_list:
i=sfp.port_num-1
if (changed_ports & (1 << i)):
Expand All @@ -47,9 +56,7 @@ def get_sfp_event(self, timeout=2000):


# Update the cache dict
self.sfp_change_event_data['present'] = bitmap
self.sfp_change_event_data['last'] = now
self.sfp_change_event_data['valid'] = 1
self._sfp_change_event_data['present'] = bitmap
return True, change_dict
else:
return True, change_dict
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ class Sfp(SfpBase):
# Path to sysfs
PLATFORM_ROOT_PATH = "/usr/share/sonic/device"
PMON_HWSKU_PATH = "/usr/share/sonic/hwsku"
HOST_CHK_CMD = "docker > /dev/null 2>&1"
HOST_CHK_CMD = "which systemctl > /dev/null 2>&1"
PLATFORM = "x86_64-accton_as7712_32x-r0"
HWSKU = "Accton-AS7712-32X"

Expand Down

0 comments on commit 357f939

Please sign in to comment.