Debian Codegraph @

fabtests/prov/efa/src/efa_exhaust_mr_reg_rdm_pingpong.c

raw symbols SCIP
1 /* Copyright Amazon.com, Inc. or its affiliates. All rights reserved. */
2
3 #include <stdio.h>
4 #include <stdlib.h>
5 #include <getopt.h>
6
7 #include <rdma/fi_errno.h>
8
9 #include "shared.h"
10 #include "benchmarks/benchmark_shared.h"
11 #include "efa_exhaust_mr_reg_common.h"
12
13 static int run(int (*pingpong_func)(void))
14 {
15 int i, ret = 0;
16
17 if (!(opts.options & FT_OPT_SIZE)) {
18 for (i = 0; i < TEST_CNT; i++) {
19 if (!ft_use_size(i, opts.sizes_enabled))
20 continue;
21 opts.transfer_size = test_size[i].size;
22 init_test(&opts, test_name, sizeof(test_name));
23 ret = pingpong_func();
24 if (ret)
25 return ret;
26 }
27 } else {
28 init_test(&opts, test_name, sizeof(test_name));
29 ret = pingpong_func();
30 if (ret)
31 return ret;
32 }
33
34 return 0;
35 }
36
37 int main(int argc, char **argv)
38 {
39 int op, ret, err, mr_reg_limit;
40 size_t registered;
41 size_t alloced;
42 void **buffers = NULL;
43 struct ibv_mr **mr_reg_vec = NULL;
44 struct ibv_context *ibv_ctx = NULL;
45 struct ibv_pd *pd;
46
47 opts = INIT_OPTS;
48 opts.options |= FT_OPT_SKIP_REG_MR;
49 opts.mr_mode &= ~FI_MR_LOCAL;
50
51 hints = fi_allocinfo();
52 if (!hints)
53 return EXIT_FAILURE;
54
55 while ((op = getopt_long(argc, argv, "Uh" CS_OPTS INFO_OPTS BENCHMARK_OPTS,
56 long_opts, &lopt_idx)) != -1) {
57 switch (op) {
58 default:
59 if (!ft_parse_long_opts(op, optarg))
60 continue;
61 ft_parse_benchmark_opts(op, optarg);
62 ft_parseinfo(op, optarg, hints, &opts);
63 ft_parsecsopts(op, optarg, &opts);
64 break;
65 case 'U':
66 hints->tx_attr->op_flags |= FI_DELIVERY_COMPLETE;
67 break;
68 case '?':
69 case 'h':
70 ft_csusage(argv[0], "Ping pong client and server using RDM after exhausting MR limits on the EFA device.");
71 ft_benchmark_usage();
72 ft_longopts_usage();
73 return EXIT_FAILURE;
74 }
75 }
76
77 if (optind < argc)
78 opts.dst_addr = argv[optind];
79
80 hints->ep_attr->type = FI_EP_RDM;
81 hints->caps = FI_MSG;
82 hints->mode |= FI_CONTEXT | FI_CONTEXT2;
83 hints->domain_attr->mr_mode = opts.mr_mode;
84 hints->addr_format = opts.address_format;
85
86 ret = ft_init_fabric();
87 if (ret)
88 return ft_exit_code(ret);
89
90 /* Run progress engine to grow bounce buffers before exhausting MRs */
91 ft_force_progress();
92
93 ft_sync();
94 if (opts.dst_addr) {
95 ret = ft_efa_open_ibv_device(&ibv_ctx);
96 if (ret)
97 FT_PRINTERR("ibv_open_device", -1);
98
99 mr_reg_limit = ft_efa_get_max_mr(ibv_ctx);
100 printf("Memory registration limit on device %d\n", mr_reg_limit);
101
102 buffers = malloc(sizeof(void *) * mr_reg_limit);
103 mr_reg_vec = malloc(sizeof(struct ibv_reg_mr *) * mr_reg_limit);
104
105 err = ft_efa_setup_ibv_pd(ibv_ctx, &pd);
106 if (err)
107 FT_PRINTERR("ibv protection domain", -err);
108
109 printf("Exhausting MRs on client\n");
110 err = ft_efa_alloc_bufs(buffers, EFA_MR_REG_BUF_SIZE,
111 mr_reg_limit, &alloced);
112 if (err)
113 FT_PRINTERR("alloc bufs", -err);
114
115 err = ft_efa_register_mr_reg(pd, buffers, EFA_MR_REG_BUF_SIZE,
116 mr_reg_vec, mr_reg_limit,
117 &registered);
118 if (err)
119 FT_PRINTERR("ibv mr reg", -err);
120 }
121
122 ft_sync();
123 printf("Running pingpong test\n");
124 ret = run(pingpong);
125 if (ret)
126 goto out;
127
128 printf("Running unexpected pingpong test\n");
129 ret = run(ft_efa_unexpected_pingpong);
130
131 out:
132 if (opts.dst_addr) {
133 printf("Deregistering MRs on client\n");
134 err = ft_efa_deregister_mr_reg(mr_reg_vec, registered);
135 if (err)
136 FT_PRINTERR("ibv mr dereg", -err);
137 ft_efa_free_bufs(buffers, alloced);
138 free(buffers);
139 free(mr_reg_vec);
140 ft_efa_destroy_ibv_pd(pd);
141 ft_efa_close_ibv_device(ibv_ctx);
142 }
143
144 ft_finalize();
145 ft_free_res();
146
147 return ft_exit_code(ret);
148 }