Skip to content

Commit 8dd6dc3

Browse files
authored
Merge pull request #1734 from ShacharKagan/pyverbs-enhancements-and-fixes
pyverbs: Add WR property getters and fix cleanup errors
2 parents 43faca2 + 981e45c commit 8dd6dc3

6 files changed

Lines changed: 40 additions & 11 deletions

File tree

pyverbs/providers/mlx5/dr_action.pxd

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ cdef class DrActionPopVLan(DrAction):
4343

4444
cdef class DrActionDestAttr(PyverbsCM):
4545
cdef DrAction dest
46+
cdef DrAction reformat
4647
cdef dv.mlx5dv_dr_action_dest_attr *action_dest_attr
4748
cdef dv.mlx5dv_dr_action_dest_reformat *dest_reformat
4849

pyverbs/providers/mlx5/dr_action.pyx

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -216,14 +216,15 @@ cdef class DrActionDestAttr(PyverbsCM):
216216
super().__init__()
217217
self.dest_reformat = NULL
218218
self.action_dest_attr = NULL
219-
if action_type == mlx5dv_dr_action_dest_type.MLX5DV_DR_ACTION_DEST:
220-
self.action_dest_attr = <dv.mlx5dv_dr_action_dest_attr *> calloc(
219+
self.dest = dest
220+
self.reformat = None
221+
self.action_dest_attr = <dv.mlx5dv_dr_action_dest_attr *> calloc(
221222
1, sizeof(dv.mlx5dv_dr_action_dest_attr))
222-
if self.action_dest_attr == NULL:
223-
raise PyverbsRDMAErrno('Memory allocation for DrActionDestAttr failed.')
224-
self.action_dest_attr.type = action_type
223+
if self.action_dest_attr == NULL:
224+
raise PyverbsRDMAErrno('Memory allocation for DrActionDestAttr failed.')
225+
self.action_dest_attr.type = action_type
226+
if action_type == mlx5dv_dr_action_dest_type.MLX5DV_DR_ACTION_DEST:
225227
self.action_dest_attr.dest = dest.action
226-
self.dest = dest
227228
elif action_type == mlx5dv_dr_action_dest_type.MLX5DV_DR_ACTION_DEST_REFORMAT:
228229
self.dest_reformat = <dv.mlx5dv_dr_action_dest_reformat *> calloc(
229230
1, sizeof(dv.mlx5dv_dr_action_dest_reformat))
@@ -232,6 +233,7 @@ cdef class DrActionDestAttr(PyverbsCM):
232233
self.action_dest_attr.dest_reformat = self.dest_reformat
233234
self.action_dest_attr.dest_reformat.reformat = reformat.action
234235
self.action_dest_attr.dest_reformat.dest = dest.action
236+
self.reformat = reformat
235237
else:
236238
raise PyverbsError('Unsupported action type is provided.')
237239

@@ -248,6 +250,8 @@ cdef class DrActionDestAttr(PyverbsCM):
248250
if self.dest_reformat != NULL:
249251
free(self.dest_reformat)
250252
self.dest_reformat = NULL
253+
self.dest = None
254+
self.reformat = None
251255

252256

253257
cdef class DrActionDestArray(DrAction):
@@ -280,6 +284,11 @@ cdef class DrActionDestArray(DrAction):
280284
raise PyverbsRDMAErrno('DrActionDestArray creation failed.')
281285
free(ptr_list)
282286
domain.dr_actions.add(self)
287+
for action in dest_actions:
288+
temp_attr = <DrActionDestAttr>action
289+
temp_attr.dest.add_ref(self)
290+
if temp_attr.reformat:
291+
temp_attr.reformat.add_ref(self)
283292

284293
def __dealloc__(self):
285294
self.close()

pyverbs/providers/mlx5/dr_rule.pxd

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,4 @@ from pyverbs.base cimport PyverbsCM
99
cdef class DrRule(PyverbsCM):
1010
cdef dv.mlx5dv_dr_rule *rule
1111
cdef object dr_matcher
12+
cdef object actions

pyverbs/providers/mlx5/dr_rule.pyx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ cdef class DrRule(PyverbsCM):
3535
raise PyverbsRDMAErrno('DrRule creation failed.')
3636
for i in range(0, len(actions)):
3737
(<DrAction>actions[i]).add_ref(self)
38+
self.actions = actions
3839
matcher.add_ref(self)
3940
self.dr_matcher = matcher
4041

@@ -50,3 +51,4 @@ cdef class DrRule(PyverbsCM):
5051
raise PyverbsRDMAError('Failed to destroy DrRule.', rc)
5152
self.rule = NULL
5253
self.dr_matcher = None
54+
self.actions = None

pyverbs/wr.pyx

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,9 @@ cdef class RecvWR(PyverbsCM):
141141
def num_sge(self, val):
142142
self.recv_wr.num_sge = val
143143

144+
@property
145+
def sg_list(self):
146+
return <uintptr_t> self.recv_wr.sg_list
144147

145148
cdef class SendWR(PyverbsCM):
146149
def __init__(self, wr_id=0, opcode=e.IBV_WR_SEND, num_sge=0, imm_data=0,
@@ -238,9 +241,12 @@ cdef class SendWR(PyverbsCM):
238241
def send_flags(self, val):
239242
self.send_wr.send_flags = val
240243

241-
property sg_list:
242-
def __set__(self, SGE val not None):
243-
self.send_wr.sg_list = val.sge
244+
@property
245+
def sg_list(self):
246+
return <uintptr_t> self.send_wr.sg_list
247+
@sg_list.setter
248+
def sg_list(self, SGE val not None):
249+
self.send_wr.sg_list = val.sge
244250

245251
def set_wr_ud(self, AH ah not None, rqpn, rqkey):
246252
"""
@@ -313,6 +319,14 @@ cdef class SendWR(PyverbsCM):
313319
"""
314320
self.send_wr.qp_type.xrc.remote_srqn = remote_srqn
315321

322+
@property
323+
def rdma_remote_addr(self):
324+
return self.send_wr.wr.rdma.remote_addr
325+
326+
@property
327+
def rdma_rkey(self):
328+
return self.send_wr.wr.rdma.rkey
329+
316330
def send_flags_to_str(flags):
317331
send_flags = {e.IBV_SEND_FENCE: 'IBV_SEND_FENCE',
318332
e.IBV_SEND_SIGNALED: 'IBV_SEND_SIGNALED',

tests/test_mlx5_dc.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
import unittest
55
import errno
6+
import time
67

78
from tests.mlx5_base import Mlx5DcResources, Mlx5RDMATestCase, Mlx5DcStreamsRes
89
from pyverbs.pyverbs_error import PyverbsRDMAError
@@ -121,9 +122,10 @@ def test_dc_stream_qp_recovery(self):
121122
with self.assertRaisesRegex(PyverbsRDMAError, r'Remote access error'):
122123
u.rdma_traffic(**self.traffic_args, new_send=True,
123124
send_op=ibv_wr_opcode.IBV_WR_RDMA_WRITE)
124-
# Retry mechanism: QP state update to ERR takes time after errors occur
125+
# Poll QP state with timeout: it takes time to transition QP to ERR after errors
125126
qp_in_err_state = False
126-
for _ in range(3):
127+
start = time.perf_counter()
128+
while time.perf_counter() - start < 1.0:
127129
qp_attr, _ = self.client.qps[qp_idx].query(ibv_qp_attr_mask.IBV_QP_STATE)
128130
if qp_attr.cur_qp_state == ibv_qp_state.IBV_QPS_ERR:
129131
qp_in_err_state = True

0 commit comments

Comments
 (0)