From 4010460cbe103c766a8dd514643f9cf5dbac8e36 Mon Sep 17 00:00:00 2001 From: Timon Kruiper Date: Thu, 18 Sep 2025 11:35:00 +0200 Subject: [PATCH] pyverbs: Release Python GIL when calling blocking CMID functions This releases the Python GIL when calling the following functions: - rdma_get_request (CMID.get_request) - rdma_get_send_comp (CMID.get_send_comp) - rdma_get_recv_comp (CMID.get_recv_comp) This allows the user to create a functional multithreaded Python application using the PyVerbs API. Signed-off-by: Timon Kruiper --- pyverbs/cmid.pyx | 9 ++++++--- pyverbs/librdmacm.pxd | 6 +++--- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/pyverbs/cmid.pyx b/pyverbs/cmid.pyx index 371ee2ee3..1b38ce6eb 100644 --- a/pyverbs/cmid.pyx +++ b/pyverbs/cmid.pyx @@ -446,7 +446,8 @@ cdef class CMID(PyverbsCM): :return: New CMID representing the connection request. """ to_conn = CMID() - ret = cm.rdma_get_request(self.id, &to_conn.id) + with nogil: + ret = cm.rdma_get_request(self.id, &to_conn.id) if ret != 0: raise PyverbsRDMAErrno('Failed to get request, no connection established') self.ctx = Context(cmid=to_conn) @@ -776,7 +777,8 @@ cdef class CMID(PyverbsCM): :return: The retrieved WC or None if there is no completions """ cdef v.ibv_wc wc - ret = cm.rdma_get_recv_comp(self.id, &wc) + with nogil: + ret = cm.rdma_get_recv_comp(self.id, &wc) if ret < 0: raise PyverbsRDMAErrno('Failed to retrieve receive completion') elif ret == 0: @@ -794,7 +796,8 @@ cdef class CMID(PyverbsCM): :return: The retrieved WC or None if there is no completions """ cdef v.ibv_wc wc - ret = cm.rdma_get_send_comp(self.id, &wc) + with nogil: + ret = cm.rdma_get_send_comp(self.id, &wc) if ret < 0: raise PyverbsRDMAErrno('Failed to retrieve send completion') elif ret == 0: diff --git a/pyverbs/librdmacm.pxd b/pyverbs/librdmacm.pxd index 0d6fa912f..b901f4d7e 100644 --- a/pyverbs/librdmacm.pxd +++ b/pyverbs/librdmacm.pxd @@ -109,7 +109,7 @@ cdef extern from '': int rdma_destroy_id(rdma_cm_id *id) int rdma_get_remote_ece(rdma_cm_id *id, ibv_ece *ece) int rdma_set_local_ece(rdma_cm_id *id, ibv_ece *ece) - int rdma_get_request(rdma_cm_id *listen, rdma_cm_id **id) + int rdma_get_request(rdma_cm_id *listen, rdma_cm_id **id) nogil int rdma_bind_addr(rdma_cm_id *id, sockaddr *addr) int rdma_resolve_addr(rdma_cm_id *id, sockaddr *src_addr, sockaddr *dst_addr, int timeout_ms) @@ -149,8 +149,8 @@ cdef extern from '': int rdma_post_write(rdma_cm_id *id, void *context, void *addr, size_t length, ibv_mr *mr, int flags, uint64_t remote_addr, uint32_t rkey) - int rdma_get_send_comp(rdma_cm_id *id, ibv_wc *wc) - int rdma_get_recv_comp(rdma_cm_id *id, ibv_wc *wc) + int rdma_get_send_comp(rdma_cm_id *id, ibv_wc *wc) nogil + int rdma_get_recv_comp(rdma_cm_id *id, ibv_wc *wc) nogil ibv_mr *rdma_reg_msgs(rdma_cm_id *id, void *addr, size_t length) ibv_mr *rdma_reg_read(rdma_cm_id *id, void *addr, size_t length) ibv_mr *rdma_reg_write(rdma_cm_id *id, void *addr, size_t length)