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