Debian Codegraph @

prov/efa/test/efa_unit_test_cntr.c

raw
1 /* SPDX-License-Identifier: BSD-2-Clause OR GPL-2.0-only */
2 /* SPDX-FileCopyrightText: Copyright Amazon.com, Inc. or its affiliates. All rights reserved. */
3 #include "efa_unit_tests.h"
4 #include "efa_cntr.h"
5
6 /**
7 * @brief get the length of the ibv_cq_poll_list for a given efa_rdm_cq
8 *
9 * @param cq_fid cq fid
10 * @return int the length of the ibv_cq_poll_list
11 */
12 static
13 int test_efa_cntr_get_ibv_cq_poll_list_length(struct fid_cntr *cntr_fid)
14 {
15 int i = 0;
16 struct dlist_entry *item;
17 struct efa_cntr *cntr;
18
19 cntr = container_of(cntr_fid, struct efa_cntr, util_cntr.cntr_fid.fid);
20 dlist_foreach(&cntr->ibv_cq_poll_list, item) {
21 i++;
22 }
23
24 return i;
25 }
26
27 /**
28 * @brief Check the length of ibv_cq_poll_list in cntr when 1 cq is bind to 1 ep
29 * as both tx/rx cq.
30 *
31 * @param state struct efa_resource that is managed by the framework
32 */
33 static
34 void test_efa_cntr_ibv_cq_poll_list_same_tx_rx_cq_single_ep_impl(struct efa_resource *resource)
35 {
36 struct fid_cntr *cntr;
37 struct fi_cntr_attr cntr_attr = {0};
38
39 assert_int_equal(fi_cntr_open(resource->domain, &cntr_attr, &cntr, NULL), 0);
40
41 /* TODO: expand this test to all flags */
42 assert_int_equal(fi_ep_bind(resource->ep, &cntr->fid, FI_TRANSMIT), 0);
43
44 assert_int_equal(fi_enable(resource->ep), 0);
45
46 /* efa_unit_test_resource_construct binds single OFI CQ as both tx/rx cq of ep */
47 assert_int_equal(test_efa_cntr_get_ibv_cq_poll_list_length(cntr), 1);
48
49 /* ep must be closed before cq/av/eq... */
50 fi_close(&resource->ep->fid);
51 resource->ep = NULL;
52
53 fi_close(&cntr->fid);
54 }
55
56 void test_efa_cntr_ibv_cq_poll_list_same_tx_rx_cq_single_ep(struct efa_resource **state)
57 {
58 struct efa_resource *resource = *state;
59
60 efa_unit_test_resource_construct_ep_not_enabled(resource, FI_EP_RDM, EFA_DIRECT_FABRIC_NAME);
61 test_efa_cntr_ibv_cq_poll_list_same_tx_rx_cq_single_ep_impl(resource);
62 }
63
64 void test_efa_rdm_cntr_ibv_cq_poll_list_same_tx_rx_cq_single_ep(struct efa_resource **state)
65 {
66 struct efa_resource *resource = *state;
67
68 efa_unit_test_resource_construct_ep_not_enabled(resource, FI_EP_RDM, EFA_FABRIC_NAME);
69 test_efa_cntr_ibv_cq_poll_list_same_tx_rx_cq_single_ep_impl(resource);
70 }
71
72 /**
73 * @brief Check the length of ibv_cq_poll_list in cntr when separate tx/rx cq is bind to 1 ep.
74 *
75 * @param state struct efa_resource that is managed by the framework
76 */
77 static
78 void test_efa_cntr_ibv_cq_poll_list_separate_tx_rx_cq_single_ep_impl(struct efa_resource *resource)
79 {
80 struct fid_cq *txcq, *rxcq;
81 struct fi_cq_attr cq_attr = {0};
82 struct fid_cntr *cntr;
83 struct fi_cntr_attr cntr_attr = {0};
84
85 assert_int_equal(fi_cq_open(resource->domain, &cq_attr, &txcq, NULL), 0);
86
87 assert_int_equal(fi_ep_bind(resource->ep, &txcq->fid, FI_SEND), 0);
88
89 assert_int_equal(fi_cq_open(resource->domain, &cq_attr, &rxcq, NULL), 0);
90
91 assert_int_equal(fi_ep_bind(resource->ep, &rxcq->fid, FI_RECV), 0);
92
93 assert_int_equal(fi_cntr_open(resource->domain, &cntr_attr, &cntr, NULL), 0);
94
95 /* TODO: expand this test to all flags */
96 assert_int_equal(fi_ep_bind(resource->ep, &cntr->fid, FI_TRANSMIT), 0);
97
98 assert_int_equal(fi_enable(resource->ep), 0);
99
100 assert_int_equal(test_efa_cntr_get_ibv_cq_poll_list_length(cntr), 2);
101
102 /* ep must be closed before cq/av/eq... */
103 fi_close(&resource->ep->fid);
104 resource->ep = NULL;
105 fi_close(&txcq->fid);
106 fi_close(&rxcq->fid);
107 fi_close(&cntr->fid);
108 }
109
110 void test_efa_cntr_ibv_cq_poll_list_separate_tx_rx_cq_single_ep(struct efa_resource **state)
111 {
112 struct efa_resource *resource = *state;
113
114 efa_unit_test_resource_construct_no_cq_and_ep_not_enabled(resource, FI_EP_RDM, EFA_DIRECT_FABRIC_NAME);
115 test_efa_cntr_ibv_cq_poll_list_separate_tx_rx_cq_single_ep_impl(resource);
116 }
117
118 void test_efa_rdm_cntr_ibv_cq_poll_list_separate_tx_rx_cq_single_ep(struct efa_resource **state)
119 {
120 struct efa_resource *resource = *state;
121
122 efa_unit_test_resource_construct_no_cq_and_ep_not_enabled(resource, FI_EP_RDM, EFA_FABRIC_NAME);
123 test_efa_cntr_ibv_cq_poll_list_separate_tx_rx_cq_single_ep_impl(resource);
124 }
125
126 void test_efa_rdm_cntr_post_initial_rx_pkts(struct efa_resource **state)
127 {
128 struct efa_resource *resource = *state;
129 struct efa_rdm_ep *efa_rdm_ep;
130 struct fid_cntr *cntr;
131 struct fi_cntr_attr cntr_attr = {0};
132 struct efa_cntr *efa_cntr;
133 uint64_t cnt;
134
135 efa_unit_test_resource_construct_ep_not_enabled(resource, FI_EP_RDM, EFA_FABRIC_NAME);
136 efa_rdm_ep = container_of(resource->ep, struct efa_rdm_ep, base_ep.util_ep.ep_fid);
137
138 /* At this time, rx pkts are not growed and posted */
139 assert_int_equal(efa_rdm_ep->efa_rx_pkts_to_post, 0);
140 assert_int_equal(efa_rdm_ep->efa_rx_pkts_posted, 0);
141 assert_int_equal(efa_rdm_ep->efa_rx_pkts_held, 0);
142
143 assert_int_equal(fi_cntr_open(resource->domain, &cntr_attr, &cntr, NULL), 0);
144
145 /* TODO: expand this test to all flags */
146 assert_int_equal(fi_ep_bind(resource->ep, &cntr->fid, FI_TRANSMIT), 0);
147
148 assert_int_equal(fi_enable(resource->ep), 0);
149
150 efa_cntr = container_of(cntr, struct efa_cntr, util_cntr.cntr_fid);
151
152 /* cntr read need to scan the ep list since a ep is bind */
153 assert_true(efa_cntr->need_to_scan_ep_list);
154
155 cnt = fi_cntr_read(cntr);
156 /* No completion should be read */
157 assert_int_equal(cnt, 0);
158
159 /* At this time, rx pool size number of rx pkts are posted */
160 assert_int_equal(efa_rdm_ep->efa_rx_pkts_posted, efa_rdm_ep_get_rx_pool_size(efa_rdm_ep));
161 assert_int_equal(efa_rdm_ep->efa_rx_pkts_to_post, 0);
162 assert_int_equal(efa_rdm_ep->efa_rx_pkts_held, 0);
163
164 /* scan is done */
165 assert_false(efa_cntr->need_to_scan_ep_list);
166 /* ep must be closed before cq/av/eq... */
167 fi_close(&resource->ep->fid);
168 resource->ep = NULL;
169
170 fi_close(&cntr->fid);
171 }