[DAPL2] DAPL Counters & 2.0.3 extensions to support counter retrieval.
[mirror/winof/.git] / ulp / dapl2 / dapl / common / dapl_debug.c
index 59d1253..c34fa3f 100644 (file)
@@ -25,7 +25,6 @@
  * and/or other materials provided with the distribution.\r
  */\r
 \r
-#include "dapl_debug.h"\r
 #include "dapl.h"\r
 #if !defined(__KDAPL__)\r
 #include <stdarg.h>\r
@@ -67,52 +66,177 @@ void dapl_internal_dbg_log ( DAPL_DBG_TYPE type, const char *fmt, ...)
     }\r
 }\r
 \r
-#if defined(DAPL_COUNTERS)\r
-int dapl_dbg_counters[DCNT_NUM_COUNTERS] = { 0 };\r
+#ifdef DAPL_COUNTERS\r
 \r
 /*\r
- * The order of this list must match exactly with the #defines\r
- * in dapl_debug.h\r
+ * The order of this list must match the DAT counter definitions \r
  */\r
-char  *dapl_dbg_counter_names[] = {\r
-       "dapl_ep_create",\r
-       "dapl_ep_free",\r
-       "dapl_ep_connect",\r
-       "dapl_ep_disconnect",\r
-       "dapl_ep_post_send",\r
-       "dapl_ep_post_recv",\r
-       "dapl_ep_post_rdma_write",\r
-       "dapl_ep_post_rdma_read",\r
-       "dapl_evd_create",\r
-       "dapl_evd_free",\r
-       "dapl_evd_wait",\r
-       "dapl_evd_blocked",\r
-       "dapl_evd_completion_notify",\r
-       "dapl_evd_dto_callback",\r
-       "dapl_evd_connection_callback",\r
-       "dapl_evd_dequeue",\r
-       "dapl_evd_poll",\r
-       "dapl_evd_found",\r
-       "dapl_evd_not_found",\r
-       "dapls_timer_set",\r
-       "dapls_timer_cancel",\r
-       "dapl_extensions"\r
+static char *ia_cntr_names[] = {\r
+       "DCNT_IA_PZ_CREATE",\r
+       "DCNT_IA_PZ_FREE",\r
+       "DCNT_IA_LMR_CREATE",\r
+       "DCNT_IA_LMR_FREE",\r
+       "DCNT_IA_RMR_CREATE",\r
+       "DCNT_IA_RMR_FREE",\r
+       "DCNT_IA_PSP_CREATE",\r
+       "DCNT_IA_PSP_CREATE_ANY",\r
+       "DCNT_IA_PSP_FREE",\r
+       "DCNT_IA_RSP_CREATE",\r
+       "DCNT_IA_RSP_FREE",\r
+       "DCNT_IA_EVD_CREATE",\r
+       "DCNT_IA_EVD_FREE",\r
+       "DCNT_IA_EP_CREATE",\r
+       "DCNT_IA_EP_FREE",\r
+       "DCNT_IA_SRQ_CREATE",\r
+       "DCNT_IA_SRQ_FREE",\r
+       "DCNT_IA_SP_CR",\r
+       "DCNT_IA_SP_CR_ACCEPTED",\r
+       "DCNT_IA_SP_CR_REJECTED",\r
+       "DCNT_IA_MEM_ALLOC",\r
+       "DCNT_IA_MEM_ALLOC_DATA",\r
+       "DCNT_IA_MEM_FREE",\r
+       "DCNT_IA_ASYNC_ERROR",\r
+       "DCNT_IA_ASYNC_QP_ERROR",\r
+       "DCNT_IA_ASYNC_CQ_ERROR"\r
 };\r
 \r
-void dapl_dump_cntr( int cntr )\r
+static char *ep_cntr_names[] = {\r
+       "DCNT_EP_CONNECT",\r
+       "DCNT_EP_DISCONNECT",\r
+       "DCNT_EP_POST_SEND",\r
+       "DCNT_EP_POST_SEND_DATA",\r
+       "DCNT_EP_POST_SEND_UD",\r
+       "DCNT_EP_POST_SEND_UD_DATA",\r
+       "DCNT_EP_POST_RECV",\r
+       "DCNT_EP_POST_RECV_DATA",\r
+       "DCNT_EP_POST_WRITE",\r
+       "DCNT_EP_POST_WRITE_DATA",\r
+       "DCNT_EP_POST_WRITE_IMM",\r
+       "DCNT_EP_POST_WRITE_IMM_DATA",\r
+       "DCNT_EP_POST_READ",\r
+       "DCNT_EP_POST_READ_DATA",\r
+       "DCNT_EP_POST_CMP_SWAP",\r
+       "DCNT_EP_POST_FETCH_ADD",\r
+       "DCNT_EP_RECV",\r
+       "DCNT_EP_RECV_DATA",\r
+       "DCNT_EP_RECV_UD",\r
+       "DCNT_EP_RECV_UD_DATA",\r
+       "DCNT_EP_RECV_IMM",\r
+       "DCNT_EP_RECV_IMM_DATA",\r
+       "DCNT_EP_RECV_RDMA_IMM",\r
+       "DCNT_EP_RECV_RDMA_IMM_DATA",\r
+};\r
+\r
+static char *evd_cntr_names[] = {\r
+       "DCNT_EVD_WAIT",\r
+       "DCNT_EVD_WAIT_BLOCKED",\r
+       "DCNT_EVD_WAIT_NOTIFY",\r
+       "DCNT_EVD_DEQUEUE",\r
+       "DCNT_EVD_DEQUEUE_FOUND",\r
+       "DCNT_EVD_DEQUEUE_NOT_FOUND",\r
+       "DCNT_EVD_DEQUEUE_POLL",\r
+       "DCNT_EVD_DEQUEUE_POLL_FOUND",\r
+       "DCNT_EVD_CONN_CALLBACK",\r
+       "DCNT_EVD_DTO_CALLBACK",\r
+};\r
+\r
+DAT_RETURN dapl_query_counter(DAT_HANDLE dh, \r
+                             int counter, \r
+                             void *p_cntrs_out,\r
+                             int reset) \r
 {\r
-    int i;\r
+       int i, max;\r
+       DAT_UINT64 *p_cntrs;\r
+       DAT_HANDLE_TYPE type = 0;\r
+               \r
+       dat_get_handle_type(dh, &type);\r
 \r
-    for ( i = 0; i < DCNT_NUM_COUNTERS; i++ )\r
-    {\r
-        if (( cntr == i ) || ( cntr == DCNT_ALL_COUNTERS ))\r
-        {\r
-            dapl_dbg_log (  DAPL_DBG_TYPE_CNTR,\r
-                            "DAPL Counter: %s = %lu \n",\r
-                            dapl_dbg_counter_names[i],\r
-                            dapl_dbg_counters[i] );\r
+       switch(type) {\r
+               case DAT_HANDLE_TYPE_IA:\r
+                       max = DCNT_IA_ALL_COUNTERS;\r
+                       p_cntrs = ((DAPL_IA*)dh)->cntrs;\r
+                       break;\r
+               case DAT_HANDLE_TYPE_EP:\r
+                       max = DCNT_EP_ALL_COUNTERS;\r
+                       p_cntrs = ((DAPL_EP*)dh)->cntrs;\r
+                       break;\r
+               case DAT_HANDLE_TYPE_EVD:\r
+                       max = DCNT_EVD_ALL_COUNTERS;\r
+                       p_cntrs = ((DAPL_EVD*)dh)->cntrs;\r
+                       break;\r
+               default:\r
+                       return DAT_INVALID_HANDLE;\r
+       }\r
+                              \r
+       for (i=0; i < max; i++) {\r
+               if ((counter == i) || (counter == max)) {\r
+                       ((DAT_UINT64*)p_cntrs_out)[i] = p_cntrs[i];\r
+                       if (reset) p_cntrs[i]=0;\r
+               }\r
+       }\r
+       return DAT_SUCCESS;\r
+}\r
+\r
+char *dapl_query_counter_name(DAT_HANDLE dh, int counter) \r
+{\r
+       DAT_HANDLE_TYPE type = 0;\r
+               \r
+       dat_get_handle_type(dh, &type);\r
+\r
+       switch(type) {\r
+               case DAT_HANDLE_TYPE_IA:\r
+                       if (counter < DCNT_IA_ALL_COUNTERS)\r
+                               return ia_cntr_names[counter];\r
+                       break;\r
+               case DAT_HANDLE_TYPE_EP:\r
+                       if (counter < DCNT_EP_ALL_COUNTERS)\r
+                               return ep_cntr_names[counter];\r
+                       break;\r
+               case DAT_HANDLE_TYPE_EVD:\r
+                       if (counter < DCNT_EVD_ALL_COUNTERS)\r
+                               return evd_cntr_names[counter];\r
+                       break;\r
+               default:\r
+                       return NULL;\r
+       }\r
+       return NULL;\r
+}\r
+\r
+#include <inttypes.h>\r
+void dapl_print_counter(DAT_HANDLE dh, int counter, int reset)\r
+{\r
+       int i, max;\r
+       DAT_UINT64 *p_cntrs;\r
+       DAT_HANDLE_TYPE type = 0;\r
+               \r
+       dat_get_handle_type(dh, &type);\r
+\r
+       switch(type) {\r
+               case DAT_HANDLE_TYPE_IA:\r
+                       max = DCNT_IA_ALL_COUNTERS;\r
+                       p_cntrs = ((DAPL_IA*)dh)->cntrs;\r
+                       break;\r
+               case DAT_HANDLE_TYPE_EP:\r
+                       max = DCNT_EP_ALL_COUNTERS;\r
+                       p_cntrs = ((DAPL_EP*)dh)->cntrs;\r
+                       break;\r
+               case DAT_HANDLE_TYPE_EVD:\r
+                       max = DCNT_EVD_ALL_COUNTERS;\r
+                       p_cntrs = ((DAPL_EVD*)dh)->cntrs;\r
+                       break;\r
+               default:\r
+                       return;\r
+       }\r
+                              \r
+       for (i=0; i < max; i++) {\r
+               if ((counter == i) || (counter == max)) {\r
+                       printf( " %s = " F64u " \n",\r
+                               dapl_query_counter_name(dh, i),\r
+                               p_cntrs[i] );\r
+                       if (reset) p_cntrs[i]=0;\r
+               }\r
         }\r
-    }\r
+       return;\r
 }\r
 \r
 #endif /* DAPL_COUNTERS */\r