2 * Copyright (c) 2005 SilverStorm Technologies. All rights reserved.
\r
3 * Portions Copyright (c) 2008 Microsoft Corporation. All rights reserved.
\r
5 * This software is available to you under the OpenIB.org BSD license
\r
8 * Redistribution and use in source and binary forms, with or
\r
9 * without modification, are permitted provided that the following
\r
10 * conditions are met:
\r
12 * - Redistributions of source code must retain the above
\r
13 * copyright notice, this list of conditions and the following
\r
16 * - Redistributions in binary form must reproduce the above
\r
17 * copyright notice, this list of conditions and the following
\r
18 * disclaimer in the documentation and/or other materials
\r
19 * provided with the distribution.
\r
21 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
\r
22 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
\r
23 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
\r
24 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
\r
25 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
\r
26 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
\r
27 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
\r
37 * - memory registration
\r
50 #include <complib/cl_atomic.h>
\r
51 #include <complib/cl_debug.h>
\r
52 #include <complib/cl_event.h>
\r
53 #include <complib/cl_math.h>
\r
54 #include <complib/cl_mutex.h>
\r
55 #include <complib/cl_qlist.h>
\r
56 #include <complib/cl_thread.h>
\r
57 #include <complib/cl_timer.h>
\r
58 #include <iba/ib_types.h>
\r
59 #include <iba/ib_al.h>
\r
63 #define CMT_DBG_VERBOSE 1
\r
66 uint32_t cmt_dbg_lvl = 0x80000000;
\r
69 /**********************************************************************
\r
70 **********************************************************************/
\r
74 printf( "\n------- ib_limits - Usage and options ----------------------\n" );
\r
75 printf( "Usage: ib_limits [options]\n");
\r
76 printf( "Options:\n" );
\r
79 "\tThis option directs ib_limits to test memory registration\n" );
\r
82 "\tThis option directs ib_limits to test CQ creation\n" );
\r
85 "\tThis option directs ib_limits to test CQ resize\n" );
\r
88 "\tThis option directs ib_limits to test QP creation\n" );
\r
91 " This option enables verbosity level to debug console.\n" );
\r
94 " Display this usage info then exit.\n\n" );
\r
98 /* Windows support. */
\r
101 const char *long_name;
\r
102 unsigned long flag;
\r
107 static char *optarg;
\r
109 #define strtoull strtoul
\r
112 boolean_t test_mr, test_cq, test_resize, test_qp;
\r
119 const char *short_option,
\r
120 const struct option *long_option,
\r
127 UNUSED_PARAM( unused );
\r
132 if( argv[i][0] != '-' )
\r
135 /* find the first character of the value. */
\r
136 for( j = 1; isalpha( argv[i][j] ); j++ )
\r
138 optarg = &argv[i][j];
\r
140 if( argv[i][1] == '-' )
\r
143 for( j = 0; long_option[j].long_name; j++ )
\r
145 if( strncmp( &argv[i][2], long_option[j].long_name,
\r
146 optarg - argv[i] - 2 ) )
\r
151 switch( long_option[j].flag )
\r
154 if( *optarg == '\0' )
\r
159 ret = long_option[j].short_name;
\r
165 for( j = 0; short_option[j] != '\0'; j++ )
\r
167 if( !isalpha( short_option[j] ) )
\r
170 if( short_option[j] == argv[i][1] )
\r
172 ret = short_option[j];
\r
176 if( short_option[j+1] == ':' )
\r
178 if( *optarg == '\0' )
\r
194 uint32_t next_option;
\r
195 const char* const short_option = "mcrq:vh";
\r
198 In the array below, the 2nd parameter specified the number
\r
199 of arguments as follows:
\r
204 const struct option long_option[] =
\r
206 { "memory", 2, NULL, 'm'},
\r
207 { "cq", 2, NULL, 'c'},
\r
208 { "resize_cq",2, NULL, 'r'},
\r
209 { "qp", 2, NULL, 'q'},
\r
210 { "verbose", 0, NULL, 'v'},
\r
211 { "help", 0, NULL, 'h'},
\r
212 { NULL, 0, NULL, 0 } /* Required at end of array */
\r
217 test_resize = FALSE;
\r
220 /* parse cmd line arguments as input params */
\r
223 next_option = getopt_long( argc, argv, short_option,
\r
224 long_option, NULL );
\r
226 switch( next_option )
\r
230 printf( "\tTest Memory Registration\n" );
\r
235 printf( "\tTest CQ\n" );
\r
239 test_resize = TRUE;
\r
240 printf( "\tTest CQ Resize\n" );
\r
245 printf( "\tTest QP\n" );
\r
249 cmt_dbg_lvl = 0xFFFFFFFF;
\r
250 printf( "\tverbose\n" );
\r
260 default: /* something wrong */
\r
264 } while( next_option != -1 );
\r
272 cl_list_item_t list_item;
\r
273 ib_mr_handle_t h_mr;
\r
274 char buf[8192 - sizeof(ib_mr_handle_t) - sizeof(cl_list_item_t)];
\r
279 ib_pd_handle_t h_pd )
\r
281 ib_api_status_t status = IB_SUCCESS;
\r
282 struct __mr_buf *p_mr;
\r
284 ib_mr_create_t mr_create;
\r
285 cl_qlist_t mr_list;
\r
286 net32_t lkey, rkey;
\r
287 int64_t reg_time, dereg_time, tmp_time, cnt;
\r
289 printf( "MR testing [\n" );
\r
291 cl_qlist_init( &mr_list );
\r
298 p_mr = cl_malloc( sizeof(struct __mr_buf) );
\r
302 printf( "Failed to allocate memory.\n" );
\r
306 mr_create.vaddr = p_mr->buf;
\r
307 mr_create.length = sizeof(p_mr->buf);
\r
308 mr_create.access_ctrl =
\r
309 IB_AC_LOCAL_WRITE | IB_AC_RDMA_READ | IB_AC_RDMA_WRITE;
\r
311 tmp_time = cl_get_time_stamp();
\r
312 status = ib_reg_mem( h_pd, &mr_create, &lkey, &rkey, &p_mr->h_mr );
\r
313 if( status != IB_SUCCESS )
\r
316 printf( "ib_reg_mem returned %s\n", ib_get_err_str( status ) );
\r
320 reg_time += cl_get_time_stamp() - tmp_time;
\r
323 cl_qlist_insert_tail( &mr_list, &p_mr->list_item );
\r
325 } while( status == IB_SUCCESS || i < 1000 );
\r
327 while( cl_qlist_count( &mr_list ) )
\r
329 p_mr = PARENT_STRUCT( cl_qlist_remove_head( &mr_list ),
\r
330 struct __mr_buf, list_item );
\r
332 tmp_time = cl_get_time_stamp();
\r
333 status = ib_dereg_mr( p_mr->h_mr );
\r
334 if( status != IB_SUCCESS )
\r
335 printf( "ib_dereg_mr returned %s\n", ib_get_err_str( status ) );
\r
336 dereg_time += cl_get_time_stamp() - tmp_time;
\r
341 printf( "reg time %f, dereg time %f\n", (double)reg_time/(double)cnt,
\r
342 (double)dereg_time/(double)cnt );
\r
343 printf( "MR testing ]\n" );
\r
349 cl_list_item_t list_item;
\r
350 ib_cq_handle_t h_cq;
\r
355 ib_ca_handle_t h_ca,
\r
358 ib_api_status_t status = IB_SUCCESS;
\r
361 ib_cq_create_t cq_create;
\r
362 cl_qlist_t cq_list;
\r
363 cl_waitobj_handle_t h_waitobj;
\r
366 printf( "CQ %stesting [\n", resize?"resize ":"" );
\r
368 cl_qlist_init( &cq_list );
\r
370 if( cl_waitobj_create( FALSE, &h_waitobj ) != CL_SUCCESS )
\r
372 printf( "Failed to allocate CQ wait object.\n" );
\r
378 p_cq = cl_malloc( sizeof(*p_cq) );
\r
382 printf( "Failed to allocate memory.\n" );
\r
386 cq_create.h_wait_obj = h_waitobj;
\r
387 cq_create.pfn_comp_cb = NULL;
\r
389 cq_create.size = 32;
\r
391 cq_create.size = 4096;
\r
393 status = ib_create_cq( h_ca, &cq_create, NULL, NULL, &p_cq->h_cq );
\r
394 if( status != IB_SUCCESS )
\r
397 printf( "ib_create_cq returned %s\n", ib_get_err_str( status ) );
\r
409 status = ib_modify_cq( p_cq->h_cq, &size );
\r
410 if( status == IB_SUCCESS )
\r
417 printf( "ib_modify_cq returned %s\n",
\r
418 ib_get_err_str( status ) );
\r
421 } while( status == IB_SUCCESS || j < 100 );
\r
424 cl_qlist_insert_tail( &cq_list, &p_cq->list_item );
\r
426 } while( status == IB_SUCCESS || i < 1000 );
\r
428 while( cl_qlist_count( &cq_list ) )
\r
430 p_cq = PARENT_STRUCT( cl_qlist_remove_head( &cq_list ),
\r
431 struct __cq, list_item );
\r
433 status = ib_destroy_cq( p_cq->h_cq, NULL );
\r
434 if( status != IB_SUCCESS )
\r
435 printf( "ib_destroy_cq returned %s\n", ib_get_err_str( status ) );
\r
440 printf( "CQ %stesting ]\n", resize?"resize ":"" );
\r
443 /**********************************************************************
\r
444 **********************************************************************/
\r
450 ib_api_status_t status;
\r
451 ib_al_handle_t h_al;
\r
452 ib_ca_handle_t h_ca;
\r
453 ib_pd_handle_t h_pd;
\r
457 /* Set defaults. */
\r
458 if( !__parse_options( argc, argv ) )
\r
461 status = ib_open_al( &h_al );
\r
462 if( status != IB_SUCCESS )
\r
464 printf( "ib_open_al returned %s\n", ib_get_err_str( status ) );
\r
469 status = ib_get_ca_guids( h_al, NULL, &size );
\r
470 if( status != IB_INSUFFICIENT_MEMORY )
\r
472 printf( "ib_get_ca_guids for array size returned %s",
\r
473 ib_get_err_str( status ) );
\r
479 printf( "No CAs installed.\n" );
\r
483 ca_guids = malloc( sizeof(net64_t) * size );
\r
486 printf( "Failed to allocate CA GUID array.\n" );
\r
490 status = ib_get_ca_guids( h_al, ca_guids, &size );
\r
491 if( status != IB_SUCCESS )
\r
493 printf( "ib_get_ca_guids for CA guids returned %s",
\r
494 ib_get_err_str( status ) );
\r
499 status = ib_open_ca( h_al, ca_guids[0], NULL, NULL, &h_ca );
\r
501 if( status != IB_SUCCESS )
\r
503 printf( "ib_open_ca returned %s", ib_get_err_str( status ) );
\r
507 status = ib_alloc_pd( h_ca, IB_PDT_NORMAL, NULL, &h_pd );
\r
508 if( status != IB_SUCCESS )
\r
510 printf( "ib_alloc_pd returned %s", ib_get_err_str( status ) );
\r
518 __test_cq( h_ca, FALSE );
\r
521 __test_cq( h_ca, TRUE );
\r
524 // __test_qp( h_ca, h_pd );
\r
527 ib_close_al( h_al );
\r