File: bw.c

package info (click to toggle)
mpich 5.0.0-1
  • links: PTS, VCS
  • area: main
  • in suites: experimental
  • size: 251,828 kB
  • sloc: ansic: 1,323,147; cpp: 82,869; f90: 72,420; javascript: 40,763; perl: 28,296; sh: 19,399; python: 16,191; xml: 14,418; makefile: 9,468; fortran: 8,046; java: 4,635; pascal: 352; asm: 324; ruby: 176; awk: 27; lisp: 19; php: 8; sed: 4
file content (263 lines) | stat: -rw-r--r-- 5,747 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
/*
 * Copyright (c) 2019 Intel Corporation.  All rights reserved.
 *
 * This software is available to you under the BSD license
 * below:
 *
 *     Redistribution and use in source and binary forms, with or
 *     without modification, are permitted provided that the following
 *     conditions are met:
 *
 *      - Redistributions of source code must retain the above
 *        copyright notice, this list of conditions and the following
 *        disclaimer.
 *
 *      - Redistributions in binary form must reproduce the above
 *        copyright notice, this list of conditions and the following
 *        disclaimer in the documentation and/or other materials
 *        provided with the distribution.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 * SOFTWARE.
 */

#include <stdio.h>
#include <stdlib.h>
#include <getopt.h>
#include <unistd.h>

#include <shared.h>

int sleep_time = 0;

static ssize_t post_one_tx(struct ft_context *msg)
{
	ssize_t ret;

	if (ft_check_opts(FT_OPT_VERIFY_DATA | FT_OPT_ACTIVE)) {
		ret = ft_fill_buf(msg->buf + ft_tx_prefix_size(),
				  opts.transfer_size);
		if (ret)
			return ret;
	}

	return ft_post_tx_buf(ep, remote_fi_addr, opts.transfer_size,
			      NO_CQ_DATA, &msg->context, msg->buf,
			      msg->desc, 0);
}

static ssize_t wait_check_rx_bufs(void)
{
	ssize_t ret;
	int i;

	ret = ft_get_rx_comp(rx_seq);
	if (ret)
		return ret;

	if (!ft_check_opts(FT_OPT_VERIFY_DATA | FT_OPT_ACTIVE))
		return 0;

	for (i = 0; i < opts.window_size; i++) {
		ret = ft_check_buf((char *) rx_ctx_arr[i].buf +
				   ft_rx_prefix_size(), opts.transfer_size);
		if (ret)
			return ret;
	}

	return 0;
}

static int post_rx_sync(void)
{
	int ret;

	ret = ft_post_rx(ep, rx_size, &rx_ctx);
	if (ret)
		return ret;

	if (opts.dst_addr) {
		ret = ft_tx(ep, remote_fi_addr, 1, &tx_ctx);
		if (ret)
			return ret;

		ret = ft_get_rx_comp(rx_seq);
	} else {
		ret = ft_get_rx_comp(rx_seq);
		if (ret)
			return ret;

		ret = ft_tx(ep, remote_fi_addr, 1, &tx_ctx);
	}

	return ret;
}

static int run_loop(void)
{
	int ret, i;

	/* Receive side delay is used in order to let the sender
 	   get ahead of the receiver and post multiple sends
	   before the receiver begins processing them. */
	if (!opts.dst_addr)
		sleep(sleep_time);

	ft_start();
	if (opts.dst_addr) {
		for (i = 0; i < opts.window_size; i++) {
			ret = post_one_tx(&tx_ctx_arr[i]);
			if (ret)
				return ret;
		}

		ret = ft_get_tx_comp(tx_seq);
		if (ret)
			return ret;
	} else {
		for (i = 0; i < opts.window_size; i++) {
			ret = ft_post_rx_buf(ep, opts.transfer_size,
					     &rx_ctx_arr[i].context,
					     rx_ctx_arr[i].buf,
					     rx_ctx_arr[i].desc, 0);
			if (ret)
				return ret;
		}

		ret = wait_check_rx_bufs();
		if (ret)
			return ret;
	}
	ft_stop();

	if (opts.options & FT_OPT_OOB_SYNC)
		ret = ft_sync();
	else
		ret = post_rx_sync();
	if (ret)
		return ret;

	if (opts.machr)
		show_perf_mr(opts.transfer_size, opts.window_size, &start, &end, 1,
				opts.argc, opts.argv);
	else
		show_perf(NULL, opts.transfer_size, opts.window_size, &start, &end, 1);

	return ret;
}

static int run(void)
{
	int ret, i;

	ret = hints->ep_attr->type == FI_EP_MSG ?
		ft_init_fabric_cm() : ft_init_fabric();
	if (ret)
		return ret;
	
	ret = ft_tx(ep, remote_fi_addr, 1, &tx_ctx);
	if (ret)
		return ret;

	ret = ft_get_tx_comp(tx_seq);
	if (ret)
		return ret;

	ret = ft_get_rx_comp(rx_seq);
	if (ret)
		return ret;

	if (!(opts.options & FT_OPT_SIZE)) {
		for (i = 0; i < TEST_CNT; i++) {
			if (!ft_use_size(i, opts.sizes_enabled))
				continue;
			opts.transfer_size = test_size[i].size;
			ret = run_loop();
			if (ret)
				goto out;
		}
	} else {
		ret = run_loop();
		if (ret)
			goto out;
	}

out:
	return ret;
}

int main(int argc, char **argv)
{
	int op, ret;

	opts = INIT_OPTS;

	hints = fi_allocinfo();
	if (!hints)
		return EXIT_FAILURE;

	hints->ep_attr->type = FI_EP_RDM;

	while ((op = getopt(argc, argv, "UW:vT:h" CS_OPTS ADDR_OPTS INFO_OPTS)) != -1) {
		switch (op) {
		default:
			ft_parse_addr_opts(op, optarg, &opts);
			ft_parseinfo(op, optarg, hints, &opts);
			ft_parsecsopts(op, optarg, &opts);
			break;
		case 'W':
			opts.window_size = atoi(optarg);
			break;
		case 'U':
			hints->tx_attr->op_flags |= FI_DELIVERY_COMPLETE;
			break;
		case 'v':
			opts.options |= FT_OPT_VERIFY_DATA;
			break;
		case 'T':
			sleep_time = atoi(optarg);
			break;
		case '?':
		case 'h':
			ft_usage(argv[0], "A bandwidth test with data verification.");
			FT_PRINT_OPTS_USAGE("-T sleep_time",
				"Receive side delay before starting");
			FT_PRINT_OPTS_USAGE("-v", "Enable data verification");
			FT_PRINT_OPTS_USAGE("-W window_size",
				"Set transmit window size before waiting for completion");
			return EXIT_FAILURE;
		}
	}

	if (optind < argc)
		opts.dst_addr = argv[optind];

	hints->caps = FI_MSG;
	hints->mode = FI_CONTEXT;
	hints->domain_attr->mr_mode = opts.mr_mode;
	hints->addr_format = opts.address_format;

	opts.options |= FT_OPT_ALLOC_MULT_MR;

	if (hints->ep_attr->type == FI_EP_DGRAM) {
		fprintf(stderr, "This test does not support DGRAM endpoints\n");
		return -FI_EINVAL;
	}

	if (opts.options & FT_OPT_VERIFY_DATA) {
		hints->tx_attr->msg_order |= FI_ORDER_SAS;
		hints->rx_attr->msg_order |= FI_ORDER_SAS;
	}

	ret = run();

	ft_free_res();

	return ft_exit_code(ret);
}