[DAPL2] DAPL Counters & 2.0.3 extensions to support counter retrieval.
[mirror/winof/.git] / ulp / dapl2 / dapl / common / dapl_debug.c
1 /*\r
2  * Copyright (c) 2002-2003, Network Appliance, Inc. All rights reserved.\r
3  *\r
4  * This Software is licensed under one of the following licenses:\r
5  *\r
6  * 1) under the terms of the "Common Public License 1.0" a copy of which is\r
7  *    available from the Open Source Initiative, see\r
8  *    http://www.opensource.org/licenses/cpl.php.\r
9  *\r
10  * 2) under the terms of the "The BSD License" a copy of which is\r
11  *    available from the Open Source Initiative, see\r
12  *    http://www.opensource.org/licenses/bsd-license.php.\r
13  *\r
14  * 3) under the terms of the "GNU General Public License (GPL) Version 2" a\r
15  *    copy of which is available from the Open Source Initiative, see\r
16  *    http://www.opensource.org/licenses/gpl-license.php.\r
17  *\r
18  * Licensee has the right to choose one of the above licenses.\r
19  *\r
20  * Redistributions of source code must retain the above copyright\r
21  * notice and one of the license notices.\r
22  *\r
23  * Redistributions in binary form must reproduce both the above copyright\r
24  * notice, one of the license notices in the documentation\r
25  * and/or other materials provided with the distribution.\r
26  */\r
27 \r
28 #include "dapl.h"\r
29 #if !defined(__KDAPL__)\r
30 #include <stdarg.h>\r
31 #include <stdlib.h>\r
32 #endif /* __KDAPL__ */\r
33 \r
34 DAPL_DBG_TYPE g_dapl_dbg_type;          /* initialized in dapl_init.c */\r
35 DAPL_DBG_DEST g_dapl_dbg_dest;          /* initialized in dapl_init.c */\r
36 \r
37 static char *_ptr_host_ = NULL;\r
38 static char _hostname_[128];\r
39 \r
40 void dapl_internal_dbg_log ( DAPL_DBG_TYPE type, const char *fmt, ...)\r
41 {\r
42     va_list args;\r
43 \r
44     if ( _ptr_host_ == NULL )\r
45     {\r
46        gethostname(_hostname_, sizeof(_hostname_));\r
47        _ptr_host_ = _hostname_;\r
48     }\r
49 \r
50     if ( type & g_dapl_dbg_type )\r
51     {\r
52         if ( DAPL_DBG_DEST_STDOUT & g_dapl_dbg_dest )\r
53         {\r
54             va_start (args, fmt);\r
55             fprintf(stdout, "%s:%d: ", _ptr_host_, dapl_os_getpid());\r
56             dapl_os_vprintf (fmt, args);\r
57             va_end (args);\r
58         }\r
59 \r
60         if ( DAPL_DBG_DEST_SYSLOG & g_dapl_dbg_dest )\r
61         {\r
62             va_start (args, fmt);\r
63             dapl_os_syslog(fmt, args);\r
64             va_end (args);\r
65         }\r
66     }\r
67 }\r
68 \r
69 #ifdef DAPL_COUNTERS\r
70 \r
71 /*\r
72  * The order of this list must match the DAT counter definitions \r
73  */\r
74 static char *ia_cntr_names[] = {\r
75         "DCNT_IA_PZ_CREATE",\r
76         "DCNT_IA_PZ_FREE",\r
77         "DCNT_IA_LMR_CREATE",\r
78         "DCNT_IA_LMR_FREE",\r
79         "DCNT_IA_RMR_CREATE",\r
80         "DCNT_IA_RMR_FREE",\r
81         "DCNT_IA_PSP_CREATE",\r
82         "DCNT_IA_PSP_CREATE_ANY",\r
83         "DCNT_IA_PSP_FREE",\r
84         "DCNT_IA_RSP_CREATE",\r
85         "DCNT_IA_RSP_FREE",\r
86         "DCNT_IA_EVD_CREATE",\r
87         "DCNT_IA_EVD_FREE",\r
88         "DCNT_IA_EP_CREATE",\r
89         "DCNT_IA_EP_FREE",\r
90         "DCNT_IA_SRQ_CREATE",\r
91         "DCNT_IA_SRQ_FREE",\r
92         "DCNT_IA_SP_CR",\r
93         "DCNT_IA_SP_CR_ACCEPTED",\r
94         "DCNT_IA_SP_CR_REJECTED",\r
95         "DCNT_IA_MEM_ALLOC",\r
96         "DCNT_IA_MEM_ALLOC_DATA",\r
97         "DCNT_IA_MEM_FREE",\r
98         "DCNT_IA_ASYNC_ERROR",\r
99         "DCNT_IA_ASYNC_QP_ERROR",\r
100         "DCNT_IA_ASYNC_CQ_ERROR"\r
101 };\r
102 \r
103 static char *ep_cntr_names[] = {\r
104         "DCNT_EP_CONNECT",\r
105         "DCNT_EP_DISCONNECT",\r
106         "DCNT_EP_POST_SEND",\r
107         "DCNT_EP_POST_SEND_DATA",\r
108         "DCNT_EP_POST_SEND_UD",\r
109         "DCNT_EP_POST_SEND_UD_DATA",\r
110         "DCNT_EP_POST_RECV",\r
111         "DCNT_EP_POST_RECV_DATA",\r
112         "DCNT_EP_POST_WRITE",\r
113         "DCNT_EP_POST_WRITE_DATA",\r
114         "DCNT_EP_POST_WRITE_IMM",\r
115         "DCNT_EP_POST_WRITE_IMM_DATA",\r
116         "DCNT_EP_POST_READ",\r
117         "DCNT_EP_POST_READ_DATA",\r
118         "DCNT_EP_POST_CMP_SWAP",\r
119         "DCNT_EP_POST_FETCH_ADD",\r
120         "DCNT_EP_RECV",\r
121         "DCNT_EP_RECV_DATA",\r
122         "DCNT_EP_RECV_UD",\r
123         "DCNT_EP_RECV_UD_DATA",\r
124         "DCNT_EP_RECV_IMM",\r
125         "DCNT_EP_RECV_IMM_DATA",\r
126         "DCNT_EP_RECV_RDMA_IMM",\r
127         "DCNT_EP_RECV_RDMA_IMM_DATA",\r
128 };\r
129 \r
130 static char *evd_cntr_names[] = {\r
131         "DCNT_EVD_WAIT",\r
132         "DCNT_EVD_WAIT_BLOCKED",\r
133         "DCNT_EVD_WAIT_NOTIFY",\r
134         "DCNT_EVD_DEQUEUE",\r
135         "DCNT_EVD_DEQUEUE_FOUND",\r
136         "DCNT_EVD_DEQUEUE_NOT_FOUND",\r
137         "DCNT_EVD_DEQUEUE_POLL",\r
138         "DCNT_EVD_DEQUEUE_POLL_FOUND",\r
139         "DCNT_EVD_CONN_CALLBACK",\r
140         "DCNT_EVD_DTO_CALLBACK",\r
141 };\r
142 \r
143 DAT_RETURN dapl_query_counter(DAT_HANDLE dh, \r
144                               int counter, \r
145                               void *p_cntrs_out,\r
146                               int reset) \r
147 {\r
148         int i, max;\r
149         DAT_UINT64 *p_cntrs;\r
150         DAT_HANDLE_TYPE type = 0;\r
151                 \r
152         dat_get_handle_type(dh, &type);\r
153 \r
154         switch(type) {\r
155                 case DAT_HANDLE_TYPE_IA:\r
156                         max = DCNT_IA_ALL_COUNTERS;\r
157                         p_cntrs = ((DAPL_IA*)dh)->cntrs;\r
158                         break;\r
159                 case DAT_HANDLE_TYPE_EP:\r
160                         max = DCNT_EP_ALL_COUNTERS;\r
161                         p_cntrs = ((DAPL_EP*)dh)->cntrs;\r
162                         break;\r
163                 case DAT_HANDLE_TYPE_EVD:\r
164                         max = DCNT_EVD_ALL_COUNTERS;\r
165                         p_cntrs = ((DAPL_EVD*)dh)->cntrs;\r
166                         break;\r
167                 default:\r
168                         return DAT_INVALID_HANDLE;\r
169         }\r
170                               \r
171         for (i=0; i < max; i++) {\r
172                 if ((counter == i) || (counter == max)) {\r
173                         ((DAT_UINT64*)p_cntrs_out)[i] = p_cntrs[i];\r
174                         if (reset) p_cntrs[i]=0;\r
175                 }\r
176         }\r
177         return DAT_SUCCESS;\r
178 }\r
179 \r
180 char *dapl_query_counter_name(DAT_HANDLE dh, int counter) \r
181 {\r
182         DAT_HANDLE_TYPE type = 0;\r
183                 \r
184         dat_get_handle_type(dh, &type);\r
185 \r
186         switch(type) {\r
187                 case DAT_HANDLE_TYPE_IA:\r
188                         if (counter < DCNT_IA_ALL_COUNTERS)\r
189                                 return ia_cntr_names[counter];\r
190                         break;\r
191                 case DAT_HANDLE_TYPE_EP:\r
192                         if (counter < DCNT_EP_ALL_COUNTERS)\r
193                                 return ep_cntr_names[counter];\r
194                         break;\r
195                 case DAT_HANDLE_TYPE_EVD:\r
196                         if (counter < DCNT_EVD_ALL_COUNTERS)\r
197                                 return evd_cntr_names[counter];\r
198                         break;\r
199                 default:\r
200                         return NULL;\r
201         }\r
202         return NULL;\r
203 }\r
204 \r
205 #include <inttypes.h>\r
206 void dapl_print_counter(DAT_HANDLE dh, int counter, int reset)\r
207 {\r
208         int i, max;\r
209         DAT_UINT64 *p_cntrs;\r
210         DAT_HANDLE_TYPE type = 0;\r
211                 \r
212         dat_get_handle_type(dh, &type);\r
213 \r
214         switch(type) {\r
215                 case DAT_HANDLE_TYPE_IA:\r
216                         max = DCNT_IA_ALL_COUNTERS;\r
217                         p_cntrs = ((DAPL_IA*)dh)->cntrs;\r
218                         break;\r
219                 case DAT_HANDLE_TYPE_EP:\r
220                         max = DCNT_EP_ALL_COUNTERS;\r
221                         p_cntrs = ((DAPL_EP*)dh)->cntrs;\r
222                         break;\r
223                 case DAT_HANDLE_TYPE_EVD:\r
224                         max = DCNT_EVD_ALL_COUNTERS;\r
225                         p_cntrs = ((DAPL_EVD*)dh)->cntrs;\r
226                         break;\r
227                 default:\r
228                         return;\r
229         }\r
230                               \r
231         for (i=0; i < max; i++) {\r
232                 if ((counter == i) || (counter == max)) {\r
233                         printf( " %s = " F64u " \n",\r
234                                 dapl_query_counter_name(dh, i),\r
235                                 p_cntrs[i] );\r
236                         if (reset) p_cntrs[i]=0;\r
237                 }\r
238         }\r
239         return;\r
240 }\r
241 \r
242 #endif /* DAPL_COUNTERS */\r
243 \r