xref: /freebsd/contrib/ofed/opensm/include/opensm/osm_perfmgr_db.h (revision 87181516ef48be852d5e5fee53c6e0dbfc62f21e)
1 /*
2  * Copyright (c) 2008 Voltaire, Inc. All rights reserved.
3  * Copyright (c) 2007 The Regents of the University of California.
4  * Copyright (c) 2009 HNR Consulting. All rights reserved.
5  *
6  * This software is available to you under a choice of one of two
7  * licenses.  You may choose to be licensed under the terms of the GNU
8  * General Public License (GPL) Version 2, available from the file
9  * COPYING in the main directory of this source tree, or the
10  * OpenIB.org BSD license below:
11  *
12  *     Redistribution and use in source and binary forms, with or
13  *     without modification, are permitted provided that the following
14  *     conditions are met:
15  *
16  *      - Redistributions of source code must retain the above
17  *        copyright notice, this list of conditions and the following
18  *        disclaimer.
19  *
20  *      - Redistributions in binary form must reproduce the above
21  *        copyright notice, this list of conditions and the following
22  *        disclaimer in the documentation and/or other materials
23  *        provided with the distribution.
24  *
25  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
26  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
27  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
28  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
29  * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
30  * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
31  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
32  * SOFTWARE.
33  *
34  */
35 
36 #ifndef _PERFMGR_EVENT_DB_H_
37 #define _PERFMGR_EVENT_DB_H_
38 
39 #ifdef ENABLE_OSM_PERF_MGR
40 
41 #include <stdio.h>
42 #include <time.h>
43 #include <iba/ib_types.h>
44 #include <complib/cl_qmap.h>
45 #include <complib/cl_passivelock.h>
46 
47 #ifdef __cplusplus
48 #  define BEGIN_C_DECLS extern "C" {
49 #  define END_C_DECLS   }
50 #else				/* !__cplusplus */
51 #  define BEGIN_C_DECLS
52 #  define END_C_DECLS
53 #endif				/* __cplusplus */
54 
55 BEGIN_C_DECLS
56 
57 struct osm_perfmgr;
58 /****h* OpenSM/PerfMgr Event Database
59 * DESCRIPTION
60 *       Database interface to record subnet events
61 *
62 *       Implementations of this object _MUST_ be thread safe.
63 *
64 * AUTHOR
65 *	Ira Weiny, LLNL
66 *
67 *********/
68 typedef enum {
69 	PERFMGR_EVENT_DB_SUCCESS = 0,
70 	PERFMGR_EVENT_DB_FAIL,
71 	PERFMGR_EVENT_DB_NOMEM,
72 	PERFMGR_EVENT_DB_GUIDNOTFOUND,
73 	PERFMGR_EVENT_DB_PORTNOTFOUND,
74 	PERFMGR_EVENT_DB_NOT_IMPL
75 } perfmgr_db_err_t;
76 
77 /** =========================================================================
78  * Port error reading
79  */
80 typedef struct {
81 	uint64_t symbol_err_cnt;
82 	uint64_t link_err_recover;
83 	uint64_t link_downed;
84 	uint64_t rcv_err;
85 	uint64_t rcv_rem_phys_err;
86 	uint64_t rcv_switch_relay_err;
87 	uint64_t xmit_discards;
88 	uint64_t xmit_constraint_err;
89 	uint64_t rcv_constraint_err;
90 	uint64_t link_integrity;
91 	uint64_t buffer_overrun;
92 	uint64_t vl15_dropped;
93 	uint64_t xmit_wait;
94 	time_t time;
95 } perfmgr_db_err_reading_t;
96 
97 /** =========================================================================
98  * Port data count reading
99  */
100 typedef struct {
101 	uint64_t xmit_data;	/* can be used for std or extended */
102 	uint64_t rcv_data;	/* can be used for std or extended */
103 	uint64_t xmit_pkts;	/* can be used for std or extended */
104 	uint64_t rcv_pkts;	/* can be used for std or extended */
105 	uint64_t unicast_xmit_pkts;
106 	uint64_t unicast_rcv_pkts;
107 	uint64_t multicast_xmit_pkts;
108 	uint64_t multicast_rcv_pkts;
109 	time_t time;
110 } perfmgr_db_data_cnt_reading_t;
111 
112 /** =========================================================================
113  * Dump output options
114  */
115 typedef enum {
116 	PERFMGR_EVENT_DB_DUMP_HR = 0,	/* Human readable */
117 	PERFMGR_EVENT_DB_DUMP_MR	/* Machine readable */
118 } perfmgr_db_dump_t;
119 
120 /** =========================================================================
121  * Port counter object.
122  * Store all the port counters for a single port.
123  */
124 typedef struct db_port {
125 	perfmgr_db_err_reading_t err_total;
126 	perfmgr_db_err_reading_t err_previous;
127 	perfmgr_db_data_cnt_reading_t dc_total;
128 	perfmgr_db_data_cnt_reading_t dc_previous;
129 	time_t last_reset;
130 	boolean_t valid;
131 } db_port_t;
132 
133 /** =========================================================================
134  * group port counters for ports into the nodes
135  */
136 #define NODE_NAME_SIZE (IB_NODE_DESCRIPTION_SIZE + 1)
137 typedef struct db_node {
138 	cl_map_item_t map_item;	/* must be first */
139 	uint64_t node_guid;
140 	boolean_t active;       /* activly being monitored */
141 	boolean_t esp0;
142 	db_port_t *ports;
143 	uint8_t num_ports;
144 	char node_name[NODE_NAME_SIZE];
145 } db_node_t;
146 
147 /** =========================================================================
148  * all nodes in the subnet.
149  */
150 typedef struct perfmgr_db {
151 	cl_qmap_t pc_data;	/* stores type (db_node_t *) */
152 	cl_plock_t lock;
153 	struct osm_perfmgr *perfmgr;
154 } perfmgr_db_t;
155 
156 /**
157  * functions
158  */
159 perfmgr_db_t *perfmgr_db_construct(struct osm_perfmgr *perfmgr);
160 void perfmgr_db_destroy(perfmgr_db_t * db);
161 
162 perfmgr_db_err_t perfmgr_db_create_entry(perfmgr_db_t * db, uint64_t guid,
163 					 boolean_t esp0, uint8_t num_ports,
164 					 char *node_name);
165 perfmgr_db_err_t perfmgr_db_delete_entry(perfmgr_db_t * db, uint64_t guid);
166 perfmgr_db_err_t perfmgr_db_delete_inactive(perfmgr_db_t * db, unsigned *cnt);
167 
168 perfmgr_db_err_t perfmgr_db_update_name(perfmgr_db_t * db, uint64_t node_guid,
169 					char *name);
170 
171 perfmgr_db_err_t perfmgr_db_add_err_reading(perfmgr_db_t * db, uint64_t guid,
172 					    uint8_t port,
173 					    perfmgr_db_err_reading_t * reading);
174 perfmgr_db_err_t perfmgr_db_get_prev_err(perfmgr_db_t * db, uint64_t guid,
175 					 uint8_t port,
176 					 perfmgr_db_err_reading_t * reading);
177 perfmgr_db_err_t perfmgr_db_clear_prev_err(perfmgr_db_t * db, uint64_t guid,
178 					   uint8_t port);
179 
180 perfmgr_db_err_t perfmgr_db_add_dc_reading(perfmgr_db_t * db, uint64_t guid,
181 					   uint8_t port,
182 					   perfmgr_db_data_cnt_reading_t *
183 					   reading,
184 					   int ietf_sup);
185 perfmgr_db_err_t perfmgr_db_get_prev_dc(perfmgr_db_t * db, uint64_t guid,
186 					uint8_t port,
187 					perfmgr_db_data_cnt_reading_t *
188 					reading);
189 perfmgr_db_err_t perfmgr_db_clear_prev_dc(perfmgr_db_t * db, uint64_t guid,
190 					  uint8_t port);
191 
192 perfmgr_db_err_t perfmgr_db_mark_active(perfmgr_db_t *db, uint64_t guid,
193 					boolean_t active);
194 
195 void perfmgr_db_clear_counters(perfmgr_db_t * db);
196 perfmgr_db_err_t perfmgr_db_dump(perfmgr_db_t * db, char *file,
197 				 perfmgr_db_dump_t dump_type);
198 void perfmgr_db_print_all(perfmgr_db_t * db, FILE *fp, int err_only);
199 void perfmgr_db_print_by_name(perfmgr_db_t * db, char *nodename, FILE *fp,
200 			      char *port, int err_only);
201 void perfmgr_db_print_by_guid(perfmgr_db_t * db, uint64_t guid, FILE *fp,
202 			      char *port, int err_only);
203 
204 /** =========================================================================
205  * helper functions to fill in the various db objects from wire objects
206  */
207 
208 void perfmgr_db_fill_err_read(ib_port_counters_t * wire_read,
209 			      perfmgr_db_err_reading_t * reading,
210 			      boolean_t xmit_wait_sup);
211 void perfmgr_db_fill_data_cnt_read_pc(ib_port_counters_t * wire_read,
212 				      perfmgr_db_data_cnt_reading_t * reading);
213 void perfmgr_db_fill_data_cnt_read_pce(ib_port_counters_ext_t * wire_read,
214 				       perfmgr_db_data_cnt_reading_t * reading,
215 				       int ietf_sup);
216 
217 END_C_DECLS
218 
219 #endif				/* ENABLE_OSM_PERF_MGR */
220 
221 #endif				/* _PERFMGR_PM_DB_H_ */
222