2424import pyverbs .mem_alloc as mem
2525import pyverbs .dma_util as dma
2626
27+ EVENT_TIMEOUT = 2 # In seconds
28+ EVENT_REGISTRATION_TIMEOUT = 3 # In seconds
29+
2730
2831class Mlx5VfioResources (Mlx5DevxRcResources ):
2932 def __init__ (self , ib_port , pci_name , gid_index = None , ctx = None , activate_port_state = False ):
@@ -204,6 +207,7 @@ def vfio_process_async_events(self):
204207 events_fd = self .server .msi_vector .fd
205208 with select .epoll () as epoll_events :
206209 epoll_events .register (events_fd , select .EPOLLIN )
210+ self .reg_async_events = True
207211 while self .proc_events :
208212 for fd , event in epoll_events .poll (timeout = 0.1 ):
209213 if fd == events_fd :
@@ -248,13 +252,18 @@ def test_mlx5vfio_async_event(self):
248252 self .event_ex = []
249253 self .proc_events = True
250254 self .caught_event = False
255+ self .reg_async_events = False
251256 proc_events = Thread (target = self .vfio_process_events )
252257 proc_async_events = Thread (target = self .vfio_process_async_events )
253258 proc_events .start ()
254259 proc_async_events .start ()
255260 # Move the DevX QPs to RTS state
256261 self .pre_run ()
257262 try :
263+ start_reg_t = time .perf_counter ()
264+ while not self .reg_async_events :
265+ if time .perf_counter () - start_reg_t >= EVENT_REGISTRATION_TIMEOUT :
266+ raise PyverbsRDMAError ('Could not register async events' )
258267 # Change port state
259268 self .server .change_port_state_with_registers (PortStatus .MLX5_PORT_UP )
260269 admin_status , oper_status = self .server .query_port_state_with_registers ()
@@ -270,10 +279,12 @@ def test_mlx5vfio_async_event(self):
270279 time .sleep (1 )
271280 finally :
272281 # Stop listening to events
282+ start_event_t = time .perf_counter ()
283+ while not self .caught_event :
284+ if time .perf_counter () - start_event_t >= EVENT_TIMEOUT :
285+ raise PyverbsRDMAError ('Failed to catch an async event' )
273286 self .proc_events = False
274287 proc_events .join ()
275288 proc_async_events .join ()
276289 if self .event_ex :
277290 raise PyverbsRDMAError (f'Received unexpected vfio events: { self .event_ex } ' )
278- if not self .caught_event :
279- raise PyverbsRDMAError ('Failed to catch an async event' )
0 commit comments