* $Id$\r
*/\r
\r
-\r
#include <iba/ib_types.h>\r
#include <iba/ib_al.h>\r
#include <complib/cl_memory.h>\r
+#include <complib/cl_timer.h>\r
#include <alts_debug.h>\r
#include <alts_common.h>\r
\r
/*\r
* Test Case RegisterMemRegion\r
*/\r
-\r
ib_api_status_t\r
al_test_register_mem(\r
void\r
return ib_status;\r
}\r
\r
+\r
+\r
+/*\r
+ * Test Case RegisterVarMemRegions\r
+ */\r
+\r
+#define MIN_MEM_SIZE 1 // size of the first region\r
+#define N_SIZES 27 // number of regions, each next one is twice the size of the previous one\r
+#define ITER_NUM 3 // each region will be re-/deregistered ITER_NUM times\r
+\r
+ib_api_status_t\r
+al_test_register_var_mem(\r
+ void\r
+ )\r
+{\r
+ ib_api_status_t ib_status = IB_SUCCESS;\r
+ ib_al_handle_t h_al = NULL;\r
+ ib_ca_handle_t h_ca = NULL;\r
+ ib_pd_handle_t h_pd = NULL;\r
+\r
+ ib_mr_create_t virt_mem;\r
+ char *ptr = NULL;\r
+ uint32_t lkey;\r
+ uint32_t rkey;\r
+ ib_mr_handle_t h_mr = NULL;\r
+ ib_mr_attr_t alts_mr_attr;\r
+\r
+ ALTS_ENTER( ALTS_DBG_VERBOSE );\r
+\r
+ /* Open AL */\r
+ ib_status = alts_open_al(&h_al);\r
+\r
+ if(ib_status != IB_SUCCESS)\r
+ goto done;\r
+\r
+ CL_ASSERT(h_al);\r
+\r
+ /* Open CA */\r
+ ib_status = alts_open_ca(h_al,&h_ca);\r
+ if(ib_status != IB_SUCCESS)\r
+ goto err_open_ca;\r
+\r
+ CL_ASSERT(h_ca);\r
+\r
+ /*\r
+ * Allocate a PD here\r
+ */\r
+ ib_status = ib_alloc_pd(h_ca, IB_PDT_NORMAL, NULL, &h_pd); //passing null context\r
+\r
+ if(ib_status != IB_SUCCESS) \r
+ {\r
+ ALTS_PRINT( ALTS_DBG_ERROR,\r
+ ("ib_alloc_pd failed status = %s\n", ib_get_err_str(ib_status)) );\r
+ goto err_alloc_pd;;\r
+ }\r
+\r
+ /*\r
+ * Register the memory region\r
+ */\r
+ {\r
+ #define MAX_MEM_SIZE (MIN_MEM_SIZE << N_SIZES) // 1GB\r
+ #define MEM_OFFSET 1\r
+ #define PAGE_SIZE 4096\r
+ #define PAGE_MASK (PAGE_SIZE - 1)\r
+ unsigned i, j, offset;\r
+ unsigned __int64 size;\r
+ unsigned __int64 sizea;\r
+ int reg_time[N_SIZES], dereg_time[N_SIZES];\r
+ int reg_tries[N_SIZES], dereg_tries[N_SIZES];\r
+ unsigned __int64 Start, End;\r
+\r
+ ALTS_PRINT( ALTS_DBG_ERROR, ("***** min_size %#x, max_size %#x, n_sizes %d \n",\r
+ MIN_MEM_SIZE, MAX_MEM_SIZE, N_SIZES ));\r
+ \r
+\r
+ for (size = MIN_MEM_SIZE, j=0; size < MAX_MEM_SIZE; size <<= 1, ++j) \r
+ {\r
+\r
+ /* Allocate the virtual memory which needs to be registered */\r
+ sizea = size + MEM_OFFSET - 1;\r
+ ptr = cl_malloc((size_t)sizea);\r
+ if (!ptr) {\r
+ ALTS_PRINT( ALTS_DBG_ERROR,\r
+ ("cl_malloc failed on %#x bytes\n", sizea) );\r
+ continue;\r
+ }\r
+ offset = (int)((ULONG_PTR)ptr & PAGE_MASK);\r
+ virt_mem.vaddr = ptr - offset;\r
+ virt_mem.length = sizea + offset;\r
+ virt_mem.access_ctrl = IB_AC_LOCAL_WRITE;\r
+ \r
+ reg_time[j] =dereg_time[j] =reg_tries[j] =dereg_tries[j] =0;\r
+ for (i=0; i<ITER_NUM; ++i) {\r
+\r
+ /* Register the memory region */\r
+ Start = cl_get_time_stamp();\r
+ ib_status = ib_reg_mem(h_pd, &virt_mem, &lkey, &rkey, &h_mr);\r
+ End = cl_get_time_stamp();\r
+ if(ib_status != IB_SUCCESS) {\r
+ ALTS_PRINT( ALTS_DBG_ERROR,\r
+ ("ib_reg_mem failed status = %s on size %#x\n", \r
+ ib_get_err_str(ib_status), virt_mem.length) );\r
+ break;\r
+ }\r
+ else {\r
+ #if 0\r
+ ALTS_PRINT( ALTS_DBG_ERROR, ("ib_reg_mr: sz %#x in %d usec \n",\r
+ virt_mem.length, (int) (End - Start)));\r
+ #endif\r
+ reg_time[j] += (int) (End - Start);\r
+ ++reg_tries[j];\r
+ }\r
+\r
+ /* De-register the memory region */\r
+ Start = cl_get_time_stamp();\r
+ ib_status = ib_dereg_mr(h_mr);\r
+ End = cl_get_time_stamp();\r
+ if(ib_status != IB_SUCCESS) {\r
+ ALTS_PRINT( ALTS_DBG_ERROR,\r
+ ("ib_dereg_mr failed status = %s\n", \r
+ ib_get_err_str(ib_status)) );\r
+ }\r
+ else {\r
+ #if 0\r
+ ALTS_PRINT( ALTS_DBG_ERROR, ("ib_dereg_mr: sz %#x in %d usec \n",\r
+ virt_mem.length, (int) (End - Start)));\r
+ #endif\r
+ dereg_time[j] += (int) (End - Start);\r
+ ++dereg_tries[j];\r
+ }\r
+ }\r
+\r
+ if ( ptr )\r
+ cl_free ( ptr );\r
+ }\r
+\r
+ /* results */\r
+ for (size = MIN_MEM_SIZE, j=0; j<N_SIZES; size <<= 1, ++j) \r
+ {\r
+ ALTS_PRINT( ALTS_DBG_ERROR, ("sz %#x \treg %d \tdereg %d \t \n",\r
+ size, \r
+ (reg_tries[j]) ? reg_time[j]/reg_tries[j] : 0,\r
+ (dereg_tries[j]) ? dereg_time[j]/dereg_tries[j] : 0\r
+ ));\r
+ }\r
+ \r
+ }\r
+\r
+ /*\r
+ * Deallocate the PD\r
+ */\r
+\r
+ ib_status = ib_dealloc_pd(h_pd,alts_pd_destroy_cb);\r
+ if(ib_status != IB_SUCCESS) \r
+ {\r
+ ALTS_PRINT( ALTS_DBG_ERROR,\r
+ ("ib_dealloc_pd failed status = %s\n",ib_get_err_str(ib_status)) );\r
+ }\r
+\r
+err_alloc_pd:\r
+ alts_close_ca(h_ca);\r
+err_open_ca:\r
+ /* Close AL */\r
+ if(h_al)\r
+ alts_close_al(h_al);\r
+done:\r
+ ALTS_EXIT( ALTS_DBG_VERBOSE);\r
+ return ib_status;\r
+}\r
+\r
+\r
/*\r
* Test Case RegisterPhyMemRegion\r
*/\r
--- /dev/null
+
+/*
+ * Copyright (c) 2005 SilverStorm Technologies. All rights reserved.
+ * Copyright (c) 1996-2003 Intel Corporation. All rights reserved.
+ *
+ * This software is available to you under the OpenIB.org 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.
+ *
+ * $Id: registermemregion.c 689 2005-10-31 07:23:08Z sleybo $
+ */
+
+#include <iba/ib_types.h>
+#include <iba/ib_al.h>
+#include <complib/cl_memory.h>
+#include <complib/cl_timer.h>
+#include <alts_debug.h>
+#include <alts_common.h>
+#include <mthca/mthca_vc.h>
+
+
+/*
+ * Function prototypes
+ */
+
+
+/*
+ * Test Case RegisterMemRegion
+ */
+ib_api_status_t
+al_test_reregister_hca(
+ void
+ )
+{
+ ib_api_status_t ib_status = IB_SUCCESS;
+ ib_al_handle_t h_al = NULL;
+ ib_ca_handle_t h_ca = NULL;
+ ib_ci_op_t ci_op;
+
+ ALTS_ENTER( ALTS_DBG_VERBOSE );
+
+ while(1)
+ {
+ /* Open AL */
+ ib_status = alts_open_al(&h_al);
+
+ if(ib_status != IB_SUCCESS)
+ break;
+
+ CL_ASSERT(h_al);
+
+ /* Open CA */
+ ib_status = alts_open_ca(h_al,&h_ca);
+ if(ib_status != IB_SUCCESS)
+ break;
+
+ CL_ASSERT(h_ca);
+
+ /* send ioctl */
+ memset( &ci_op, 0, sizeof(ci_op) );
+ ci_op.command = FW_REREGISTER_HCA;
+
+ ib_status = ib_ci_call (h_ca, NULL, 0, &ci_op);
+ if(ib_status != IB_SUCCESS)
+ ALTS_PRINT( ALTS_DBG_ERROR,
+ ("ib_ci_call failed status = %s\n",
+ ib_get_err_str(ib_status)) );
+ else
+ ALTS_PRINT( ALTS_DBG_INFO,
+ ("ib_ci_call PASSED.\n") );
+ break;
+ }
+
+ if(h_ca)
+ alts_close_ca(h_ca);
+
+ if(h_al)
+ alts_close_al(h_al);
+
+ ALTS_EXIT( ALTS_DBG_VERBOSE);
+ return ib_status;
+}
+