Ejemplo n.º 1
0
def poll_cq_ex(cqex, count=1, data=None):
    """
    Poll <count> completions from the extended CQ.
    :param cq: CQEX to poll from
    :param count: How many completions to poll
    :param data: In case of a work request with immediate, the immediate data
                 to be compared after poll
    :return: None
    """
    poll_attr = PollCqAttr()
    ret = cqex.start_poll(poll_attr)
    while ret == 2:  # ENOENT
        ret = cqex.start_poll(poll_attr)
    if ret != 0:
        raise PyverbsRDMAErrno('Failed to poll CQ')
    count -= 1
    if cqex.status != e.IBV_WC_SUCCESS:
        raise PyverbsRDMAErrno(
            'Completion status is {s}'.format(s=cqex.status))
    if data:
        assert data == socket.ntohl(cqex.read_imm_data())
    # Now poll the rest of the packets
    while count > 0:
        ret = cqex.poll_next()
        while ret == 2:
            ret = cqex.poll_next()
        if ret != 0:
            raise PyverbsRDMAErrno('Failed to poll CQ')
        if cqex.status != e.IBV_WC_SUCCESS:
            raise PyverbsRDMAErrno(
                'Completion status is {s}'.format(s=cqex.status))
        if data:
            assert data == socket.ntohl(cqex.read_imm_data())
        count -= 1
    cqex.end_poll()
Ejemplo n.º 2
0
    def poll_cq_ex(self, cqex, is_server=True, to_valid=True):
        start = time.perf_counter()
        poll_attr = PollCqAttr()
        ret = cqex.start_poll(poll_attr)
        while ret == 2 and (time.perf_counter() - start < u.POLL_CQ_TIMEOUT):
            ret = cqex.start_poll(poll_attr)
        if ret != 0:
            raise PyverbsRDMAErrno('Failed to poll CQ - got a timeout')
        if cqex.status != e.IBV_WC_SUCCESS:
            raise PyverbsError(f'Completion status is {cqex.status}')
        actual_cqe_dict = {}
        if to_valid:
            recv_flags = cqex.read_wc_flags()
            recv_opcode = cqex.read_opcode()
            actual_cqe_dict = {'wr_id': cqex.wr_id, 'opcode': cqex.read_opcode(),
                               'wc_flags': cqex.read_wc_flags()}
            if is_server:
                actual_cqe_dict['tag'] = cqex.read_tm_info().tag
            if recv_opcode == e.IBV_WC_TM_RECV and not \
                    (recv_flags & (e.IBV_WC_TM_MATCH | e.IBV_WC_TM_DATA_VALID)):
                # In case of receiving unexpected tag, HW doesn't return such wc_flags
                # updadte unexpected count and sync is required.
                self.server.unexp_cnt += 1
                cqex.end_poll()
                self.post_sync()
                return actual_cqe_dict
            if recv_opcode == e.IBV_WC_TM_ADD and (recv_flags & e.IBV_WC_TM_SYNC_REQ):
                # These completion is complemented by the IBV_WC_TM_SYNC_REQ flag,
                # which indicates whether further HW synchronization is needed.
                cqex.end_poll()
                self.post_sync()
                return actual_cqe_dict

        cqex.end_poll()
        return actual_cqe_dict
Ejemplo n.º 3
0
 def test_reg_mr_bad_flow(self):
     """ Verify that trying to register a MR with None PD fails """
     try:
         mr = MR(None, random.randint(0, 10000), u.get_access_flags())
     except TypeError as te:
         assert 'expected pyverbs.pd.PD' in te.args[0]
         assert 'got NoneType' in te.args[0]
     else:
         raise PyverbsRDMAErrno('Created a MR with None PD')
Ejemplo n.º 4
0
 def test_reg_mr_bad_flow():
     """ Verify that trying to register a MR with None PD fails """
     try:
         # Use the simplest access flags necessary
         MR(None, random.randint(0, 10000), e.IBV_ACCESS_LOCAL_WRITE)
     except TypeError as te:
         assert 'expected pyverbs.pd.PD' in te.args[0]
         assert 'got NoneType' in te.args[0]
     else:
         raise PyverbsRDMAErrno('Created a MR with None PD')
Ejemplo n.º 5
0
 def test_create_pd_none_ctx():
     """
     Verify that PD can't be created with a None context
     """
     try:
         PD(None)
     except TypeError as te:
         assert 'must not be None' in te.args[0]
     else:
         raise PyverbsRDMAErrno('Created a PD with None context')
Ejemplo n.º 6
0
 def test_create_pd_none_ctx():
     """
     Verify that PD can't be created with a None context
     """
     try:
         PD(None)
     except TypeError as te:
         assert 'expected pyverbs.device.Context' in te.args[0]
         assert 'got NoneType' in te.args[0]
     else:
         raise PyverbsRDMAErrno('Created a PD with None context')
Ejemplo n.º 7
0
    def test_create_cq(self):
        for cq_size in [1, self.attr.max_cqe/2, self.attr.max_cqe]:
            for comp_vector in range(0, min(2, self.ctx.num_comp_vectors)):
                try:
                    cq = CQ(self.ctx, cq_size, None, None, comp_vector)
                    cq.close()
                except PyverbsRDMAError as ex:
                    cq_attr = f'cq_size={cq_size}, comp_vector={comp_vector}'
                    raise PyverbsRDMAErrno(f'Failed to create a CQ with {cq_attr}')

        # Create CQ with Max value of comp_vector.
        max_cqs_comp_vector = self.ctx.num_comp_vectors - 1
        cq = CQ(self.ctx, self.ctx.num_comp_vectors, None, None, max_cqs_comp_vector)
Ejemplo n.º 8
0
    def process_async_events(self, fd):
        from tests.mlx5_prm_structs import EventType

        cc = 0
        ret = os.read(fd, 8)
        if not ret:
            raise PyverbsRDMAErrno('Failed to read FD')
        eqe = self.get_eqe(cc)
        while eqe:
            if eqe.event_type == EventType.PORT_STATE_CHANGE:
                self.logger.debug('Caught port state change event')
                return eqe.event_type
            elif eqe.event_type == EventType.CQ_ERROR:
                raise PyverbsRDMAError('Event type Error')
            cc = self.update_cc(cc + 1)
            eqe = self.get_eqe(cc)
        self.update_ci(cc, 1)