Debian Codegraph @

test/dapltest/cmd/dapl_performance_cmd.c

raw
1 /*
2 * Copyright (c) 2002-2005, Network Appliance, Inc. All rights reserved.
3 *
4 * This Software is licensed under one of the following licenses:
5 *
6 * 1) under the terms of the "Common Public License 1.0" a copy of which is
7 * in the file LICENSE.txt in the root directory. The license is also
8 * available from the Open Source Initiative, see
9 * http://www.opensource.org/licenses/cpl.php.
10 *
11 * 2) under the terms of the "The BSD License" a copy of which is in the file
12 * LICENSE2.txt in the root directory. The license is also available from
13 * the Open Source Initiative, see
14 * http://www.opensource.org/licenses/bsd-license.php.
15 *
16 * 3) under the terms of the "GNU General Public License (GPL) Version 2" a
17 * copy of which is in the file LICENSE3.txt in the root directory. The
18 * license is also available from the Open Source Initiative, see
19 * http://www.opensource.org/licenses/gpl-license.php.
20 *
21 * Licensee has the right to choose one of the above licenses.
22 *
23 * Redistributions of source code must retain the above copyright
24 * notice and one of the license notices.
25 *
26 * Redistributions in binary form must reproduce both the above copyright
27 * notice, one of the license notices in the documentation
28 * and/or other materials provided with the distribution.
29 */
30
31 #include "dapl_proto.h"
32
33 static void DT_Performance_Cmd_Usage(void)
34 {
35 DT_Mdep_printf("USAGE: ---- PERFORMANCE TEST ----\n");
36 DT_Mdep_printf("USAGE: dapltest -T P\n");
37 DT_Mdep_printf("USAGE: -s <server Name>\n");
38 DT_Mdep_printf("USAGE: -n <server port number>\n");
39 DT_Mdep_printf("USAGE: [-m b|p]\n");
40 DT_Mdep_printf("USAGE: [-D <device Name>]\n");
41 DT_Mdep_printf("USAGE: [-d] : debug (zero)\n");
42 DT_Mdep_printf("USAGE: [-i <num iterations>] : (1, 000)\n");
43 DT_Mdep_printf("USAGE: [-p <pipline>]\n");
44 DT_Mdep_printf("USAGE: [-R <service reliability>]\n");
45 DT_Mdep_printf("USAGE: (BE == QOS_BEST_EFFORT - Default)\n");
46 DT_Mdep_printf("USAGE: (HT == QOS_HIGH_THROUGHPUT)\n");
47 DT_Mdep_printf("USAGE: (LL == QOS_LOW_LATENCY)\n");
48 DT_Mdep_printf("USAGE: (EC == QOS_ECONOMY)\n");
49 DT_Mdep_printf("USAGE: (PM == QOS_PREMIUM)\n");
50 DT_Mdep_printf("USAGE: <OP>\n");
51 DT_Mdep_printf("USAGE:\n");
52 DT_Mdep_printf("USAGE: Each OP consists of:\n");
53 DT_Mdep_printf("USAGE: <transfer_type> : \"RR\" (RDMA READ)\n");
54 DT_Mdep_printf("USAGE: : \"RW\" (RDMA WRITE)\n");
55 DT_Mdep_printf("USAGE: [seg_size [num_segs] ] : (4096, 1)\n");
56 }
57
58 static bool
59 DT_Performance_Cmd_Parse_Op(Performance_Cmd_t * cmd,
60 int index, int my_argc, char **my_argv)
61 {
62 int i;
63
64 /*
65 * Op Format: <RR/RW> [seg_size] [num_segs]
66 */
67
68 if (index == my_argc) {
69 DT_Mdep_printf("Operation Missing Transfer Type\n");
70 return (false);
71 }
72
73 for (i = 0; index < my_argc; i++, index++) {
74 switch (i) {
75 case 0:
76 {
77 if (0 ==
78 strncmp(my_argv[index], "RR",
79 strlen("RR"))) {
80 cmd->op.transfer_type = RDMA_READ;
81 } else if (0 ==
82 strncmp(my_argv[index], "RW",
83 strlen("RW"))) {
84 cmd->op.transfer_type = RDMA_WRITE;
85 } else {
86 DT_Mdep_printf
87 ("OP type must be <RR/RW/SR>\n");
88 return (false);
89 }
90 break;
91 }
92 case 1:
93 {
94 cmd->op.seg_size = atoi(my_argv[index]);
95 break;
96 }
97 case 2:
98 {
99 cmd->op.num_segs = atoi(my_argv[index]);
100 break;
101 }
102 default:
103 {
104 DT_Mdep_printf("Too many OP args\n");
105 return (false);
106 }
107 }
108 }
109
110 return (true);
111 }
112
113 static bool DT_Performance_Cmd_Validate(Performance_Cmd_t * cmd)
114 {
115 if ('\0' == cmd->server_name[0]) {
116 DT_Mdep_printf
117 ("Must specify server_name in command line or scriptfile\n");
118 return (false);
119 }
120
121 if ('\0' == cmd->dapl_name[0]) {
122 DT_Mdep_printf
123 ("Must specify device_name in command line or scriptfile\n");
124 return (false);
125 }
126
127 if (0 == cmd->pipeline_len) {
128 DT_Mdep_printf("Pipeline size must not be 0\n");
129 return (false);
130 }
131
132 if (cmd->debug) {
133 DT_Performance_Cmd_Print(cmd);
134 }
135
136 return true;
137 }
138
139 bool
140 DT_Performance_Cmd_Parse(Performance_Cmd_t * cmd,
141 int my_argc, char **my_argv, mygetopt_t * opts)
142 {
143 int c;
144 unsigned int len;
145
146 for (;;) {
147 c = DT_mygetopt_r(my_argc, my_argv, "D:dm:i:p:R:s:n:", opts);
148
149 if (EOF == c) {
150 break;
151 }
152
153 switch (c) {
154 case 'D': /* device name */
155 {
156 strncpy(cmd->dapl_name, opts->optarg, NAME_SZ);
157 break;
158 }
159 case 'd': /* print debug messages */
160 {
161 DT_dapltest_debug++;
162 cmd->debug = true;
163 break;
164 }
165 case 'm': /* mode */
166 {
167 if (!strncmp(opts->optarg, "b", strlen("b"))) {
168 cmd->mode = BLOCKING_MODE;
169 } else
170 if (!strncmp
171 (opts->optarg, "p", strlen("p"))) {
172 cmd->mode = POLLING_MODE;
173 } else {
174 DT_Mdep_printf
175 ("Syntax Error -m <mode> option\n");
176 DT_Performance_Cmd_Usage();
177 return (false);
178 }
179
180 break;
181 }
182 case 'i': /* num iterations */
183 {
184 len = strspn(opts->optarg, "0123456789");
185 if (len == 0 || len != strlen(opts->optarg)) {
186 DT_Mdep_printf
187 ("Syntax Error -i <iterations> option\n");
188 DT_Performance_Cmd_Usage();
189 return (false);
190 }
191 cmd->num_iterations = atol(opts->optarg);
192 break;
193 }
194 case 'p': /* pipline size */
195 {
196 len = strspn(opts->optarg, "0123456789");
197 if (len == 0 || len != strlen(opts->optarg)) {
198 DT_Mdep_printf
199 ("Syntax Error -p <piplein> option\n");
200 DT_Performance_Cmd_Usage();
201 return (false);
202 }
203 cmd->pipeline_len = atol(opts->optarg);
204 break;
205 }
206 case 'R': /* Service Reliability Level */
207 {
208 cmd->qos = DT_ParseQoS(opts->optarg);
209 break;
210 }
211 case 's': /* server name */
212 {
213 if ((opts->optarg == 0) ||
214 strlen(opts->optarg) == 0 ||
215 *opts->optarg == '-') {
216 DT_Mdep_printf
217 ("must specify server name\n");
218 DT_Performance_Cmd_Usage();
219 return (false);
220 }
221
222 strncpy(cmd->server_name, opts->optarg,
223 NAME_SZ);
224 break;
225 }
226 case 'n':
227 {
228 cmd->port = atoi(opts->optarg);
229 break;
230 }
231 default:
232 {
233 DT_Mdep_printf
234 ("Invalid Performance Test Parameter: %c\n",
235 c);
236 DT_Performance_Cmd_Usage();
237 return (false);
238 }
239 }
240 }
241
242 /*
243 * now parse the op
244 */
245 if (!DT_Performance_Cmd_Parse_Op(cmd, opts->optind, my_argc, my_argv)) {
246 DT_Performance_Cmd_Usage();
247 return (false);
248 }
249
250 if (!DT_Performance_Cmd_Validate(cmd)) {
251 DT_Performance_Cmd_Usage();
252 return (false);
253 }
254
255 return (true);
256 }
257
258 bool DT_Performance_Cmd_Init(Performance_Cmd_t * cmd)
259 {
260 memset(cmd, 0, sizeof(Performance_Cmd_t));
261 cmd->dapltest_version = DAPLTEST_VERSION;
262 cmd->client_is_little_endian = DT_local_is_little_endian;
263 cmd->qos = DAT_QOS_BEST_EFFORT;
264 cmd->debug = false;
265 cmd->num_iterations = 1000;
266 cmd->pipeline_len = ~0;
267 cmd->port = SERVER_PORT_NUMBER;
268 cmd->op.transfer_type = RDMA_WRITE;
269 cmd->op.seg_size = 4096;
270 cmd->op.num_segs = 1;
271
272 if (!DT_Mdep_GetDefaultDeviceName(cmd->dapl_name)) {
273 DT_Mdep_printf("can't get default device name\n");
274 return (false);
275 }
276
277 return (true);
278 }
279
280 void DT_Performance_Cmd_Print(Performance_Cmd_t * cmd)
281 {
282 DT_Mdep_printf("-------------------------------------\n");
283 DT_Mdep_printf("PerfCmd.server_name : %s\n",
284 cmd->server_name);
285 DT_Mdep_printf("PerfCmd.server_port_number : %lu\n",
286 cmd->port);
287 DT_Mdep_printf("PerfCmd.dapl_name : %s\n",
288 cmd->dapl_name);
289 DT_Mdep_printf("PerfCmd.mode : %s\n",
290 (cmd->mode == BLOCKING_MODE) ? "BLOCKING" : "POLLING");
291 DT_Mdep_printf("PerfCmd.num_iterations : %d\n",
292 cmd->num_iterations);
293 DT_Mdep_printf("PerfCmd.pipeline_len : %d\n",
294 cmd->pipeline_len);
295 DT_Mdep_printf("PerfCmd.op.transfer_type : %s\n",
296 cmd->op.transfer_type == RDMA_READ ? "RDMA_READ" :
297 cmd->op.transfer_type == RDMA_WRITE ? "RDMA_WRITE" :
298 "SEND_RECV");
299 DT_Mdep_printf("PerfCmd.op.num_segs : %d\n",
300 cmd->op.num_segs);
301 DT_Mdep_printf("PerfCmd.op.seg_size : %d\n",
302 cmd->op.seg_size);
303 }