Skip to content

Commit cacff75

Browse files
padmanarayanalguohan
authored andcommitted
[devices]: Make the get_transceiver_change_event's epoll blocking S6100/Z9100 (#2459)
1 parent 43de836 commit cacff75

File tree

2 files changed

+83
-22
lines changed

2 files changed

+83
-22
lines changed

device/dell/x86_64-dell_s6100_c2538-r0/plugins/sfputil.py

Lines changed: 41 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -236,11 +236,6 @@ def __init__(self):
236236
self.port_to_eeprom_mapping[port_num] =\
237237
"No IOM"
238238

239-
self.oir_fd = open(self.OIR_FD_PATH, "r")
240-
self.epoll = select.epoll()
241-
if self.oir_fd != -1:
242-
self.epoll.register(self.oir_fd.fileno(), select.EPOLLIN)
243-
244239
SfpUtilBase.__init__(self)
245240

246241
def __del__(self):
@@ -582,13 +577,40 @@ def get_transceiver_change_event(self, timeout=0):
582577
port_dict = {}
583578
try:
584579
# We get notified when there is an SCI interrupt from GPIO SUS6
580+
# Open the sysfs file and register the epoll object
581+
self.oir_fd = open(self.OIR_FD_PATH, "r")
582+
if self.oir_fd != -1:
583+
# Do a dummy read before epoll register
584+
self.oir_fd.read()
585+
self.epoll = select.epoll()
586+
self.epoll.register(self.oir_fd.fileno(),
587+
select.EPOLLIN & select.EPOLLET)
588+
else:
589+
print("get_transceiver_change_event : unable to create fd")
590+
return False, {}
591+
585592
# Check for missed interrupts by invoking self.check_interrupts
586-
# it will update the port_dict.
587-
# Then poll for new xcvr insertion/removal and
588-
# call self.check_interrupts again and return
589-
retval, is_port_dict_updated = self.check_interrupts(port_dict)
590-
if ((retval == 0) and (is_port_dict_updated is True)):
591-
return True, port_dict
593+
# which will update the port_dict.
594+
while True:
595+
interrupt_count_start = self.get_register(self.OIR_FD_PATH)
596+
597+
retval, is_port_dict_updated = \
598+
self.check_interrupts(port_dict)
599+
if ((retval == 0) and (is_port_dict_updated is True)):
600+
return True, port_dict
601+
602+
interrupt_count_end = self.get_register(self.OIR_FD_PATH)
603+
604+
if (interrupt_count_start == 'ERR' or
605+
interrupt_count_end == 'ERR'):
606+
print("get_transceiver_change_event : \
607+
unable to retrive interrupt count")
608+
break
609+
610+
# check_interrupts() itself may take upto 100s of msecs.
611+
# We detect a missed interrupt based on the count
612+
if interrupt_count_start == interrupt_count_end:
613+
break
592614

593615
# Block until an xcvr is inserted or removed with timeout = -1
594616
events = self.epoll.poll(
@@ -599,9 +621,17 @@ def get_transceiver_change_event(self, timeout=0):
599621
self.check_interrupts(port_dict)
600622
if (retval != 0):
601623
return False, {}
624+
602625
return True, port_dict
603626
except:
604627
return False, {}
628+
finally:
629+
if self.oir_fd != -1:
630+
self.epoll.unregister(self.oir_fd.fileno())
631+
self.epoll.close()
632+
self.oir_fd.close()
633+
self.oir_fd = -1
634+
self.epoll = -1
605635

606636
return False, {}
607637

device/dell/x86_64-dell_z9100_c2538-r0/plugins/sfputil.py

Lines changed: 42 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -119,11 +119,6 @@ def __init__(self):
119119
self.port_to_i2c_mapping[x][0],
120120
self.port_to_i2c_mapping[x][1])
121121

122-
self.oir_fd = open(self.OIR_FD_PATH, "r")
123-
self.epoll = select.epoll()
124-
if self.oir_fd != -1:
125-
self.epoll.register(self.oir_fd.fileno(), select.EPOLLIN)
126-
127122
SfpUtilBase.__init__(self)
128123

129124
def __del__(self):
@@ -428,13 +423,40 @@ def get_transceiver_change_event(self, timeout=0):
428423
port_dict = {}
429424
try:
430425
# We get notified when there is an SCI interrupt from GPIO SUS6
426+
# Open the sysfs file and register the epoll object
427+
self.oir_fd = open(self.OIR_FD_PATH, "r")
428+
if self.oir_fd != -1:
429+
# Do a dummy read before epoll register
430+
self.oir_fd.read()
431+
self.epoll = select.epoll()
432+
self.epoll.register(self.oir_fd.fileno(),
433+
select.EPOLLIN & select.EPOLLET)
434+
else:
435+
print("get_transceiver_change_event : unable to create fd")
436+
return False, {}
437+
431438
# Check for missed interrupts by invoking self.check_interrupts
432-
# it will update the port_dict.
433-
# Then poll for new xcvr insertion/removal and
434-
# call self.check_interrupts again and return
435-
retval, is_port_dict_updated = self.check_interrupts(port_dict)
436-
if ((retval == 0) and (is_port_dict_updated is True)):
437-
return True, port_dict
439+
# which will update the port_dict.
440+
while True:
441+
interrupt_count_start = self.get_register(self.OIR_FD_PATH)
442+
443+
retval, is_port_dict_updated = \
444+
self.check_interrupts(port_dict)
445+
if ((retval == 0) and (is_port_dict_updated is True)):
446+
return True, port_dict
447+
448+
interrupt_count_end = self.get_register(self.OIR_FD_PATH)
449+
450+
if (interrupt_count_start == 'ERR' or
451+
interrupt_count_end == 'ERR'):
452+
print("get_transceiver_change_event : \
453+
unable to retrive interrupt count")
454+
break
455+
456+
# check_interrupts() itself may take upto 100s of msecs.
457+
# We detect a missed interrupt based on the count
458+
if interrupt_count_start == interrupt_count_end:
459+
break
438460

439461
# Block until an xcvr is inserted or removed with timeout = -1
440462
events = self.epoll.poll(
@@ -445,8 +467,17 @@ def get_transceiver_change_event(self, timeout=0):
445467
self.check_interrupts(port_dict)
446468
if (retval != 0):
447469
return False, {}
470+
448471
return True, port_dict
449472
except:
450473
return False, {}
474+
finally:
475+
if self.oir_fd != -1:
476+
self.epoll.unregister(self.oir_fd.fileno())
477+
self.epoll.close()
478+
self.oir_fd.close()
479+
self.oir_fd = -1
480+
self.epoll = -1
481+
451482
return False, {}
452483

0 commit comments

Comments
 (0)