1 /*
2 * Copyright (c) 2007 The Regents of the University of California.
3 * Copyright (c) 2007-2008 Voltaire, Inc. All rights reserved.
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 _OSM_PERFMGR_H_
36 #define _OSM_PERFMGR_H_
37
38 #if HAVE_CONFIG_H
39 # include <config.h>
40 #endif /* HAVE_CONFIG_H */
41
42 #ifdef ENABLE_OSM_PERF_MGR
43
44 #include <iba/ib_types.h>
45 #include <complib/cl_passivelock.h>
46 #include <complib/cl_event.h>
47 #include <complib/cl_timer.h>
48 #include <opensm/osm_subnet.h>
49 #include <opensm/osm_log.h>
50 #include <opensm/osm_perfmgr_db.h>
51 #include <opensm/osm_sm.h>
52 #include <opensm/osm_base.h>
53 #include <opensm/osm_event_plugin.h>
54
55 #ifdef __cplusplus
56 extern "C" {
57 #endif /* __cplusplus */
58
59 /****h* OpenSM/PerfMgr
60 * NAME
61 * PerfMgr
62 *
63 * DESCRIPTION
64 * Performance manager thread which takes care of polling the fabric for
65 * Port counters values.
66 *
67 * The PerfMgr object is thread safe.
68 *
69 * AUTHOR
70 * Ira Weiny, LLNL
71 *
72 *********/
73
74 #define OSM_PERFMGR_DEFAULT_SWEEP_TIME_S 180
75 #define OSM_PERFMGR_DEFAULT_DUMP_FILE "opensm_port_counters.log"
76 #define OSM_PERFMGR_DEFAULT_MAX_OUTSTANDING_QUERIES 500
77
78 /****s* OpenSM: PerfMgr/osm_perfmgr_state_t */
79 typedef enum {
80 PERFMGR_STATE_DISABLE,
81 PERFMGR_STATE_ENABLED,
82 PERFMGR_STATE_NO_DB
83 } osm_perfmgr_state_t;
84
85 /****s* OpenSM: PerfMgr/osm_perfmgr_sweep_state_t */
86 typedef enum {
87 PERFMGR_SWEEP_SLEEP,
88 PERFMGR_SWEEP_ACTIVE,
89 PERFMGR_SWEEP_SUSPENDED
90 } osm_perfmgr_sweep_state_t;
91
92 /* Redirection information */
93 typedef struct redir {
94 ib_net16_t redir_lid;
95 ib_net32_t redir_qp;
96 } redir_t;
97
98 /* Node to store information about which nodes we are monitoring */
99 typedef struct _monitored_node {
100 cl_map_item_t map_item;
101 struct _monitored_node *next;
102 uint64_t guid;
103 char *name;
104 uint32_t redir_tbl_size;
105 redir_t redir_port[1]; /* redirection on a per port basis */
106 } __monitored_node_t;
107
108 struct osm_opensm;
109 /****s* OpenSM: PerfMgr/osm_perfmgr_t
110 * This object should be treated as opaque and should
111 * be manipulated only through the provided functions.
112 */
113 typedef struct osm_perfmgr {
114 cl_event_t sig_sweep;
115 cl_timer_t sweep_timer;
116 struct osm_opensm *osm;
117 osm_subn_t *subn;
118 osm_sm_t *sm;
119 cl_plock_t *lock;
120 osm_log_t *log;
121 osm_mad_pool_t *mad_pool;
122 atomic32_t trans_id;
123 osm_vendor_t *vendor;
124 osm_bind_handle_t bind_handle;
125 cl_disp_reg_handle_t pc_disp_h;
126 osm_perfmgr_state_t state;
127 osm_perfmgr_sweep_state_t sweep_state;
128 uint16_t sweep_time_s;
129 perfmgr_db_t *db;
130 atomic32_t outstanding_queries; /* this along with sig_query */
131 cl_event_t sig_query; /* will throttle our querys */
132 uint32_t max_outstanding_queries;
133 cl_qmap_t monitored_map; /* map the nodes we are tracking */
134 __monitored_node_t *remove_list;
135 } osm_perfmgr_t;
136 /*
137 * FIELDS
138 * subn
139 * Subnet object for this subnet.
140 *
141 * log
142 * Pointer to the log object.
143 *
144 * mad_pool
145 * Pointer to the MAD pool.
146 *
147 * mad_ctrl
148 * Mad Controller
149 *********/
150
151 /****f* OpenSM: Creation Functions */
152 void osm_perfmgr_shutdown(osm_perfmgr_t * const p_perfmgr);
153 void osm_perfmgr_destroy(osm_perfmgr_t * const p_perfmgr);
154
155 /****f* OpenSM: Inline accessor functions */
osm_perfmgr_set_state(osm_perfmgr_t * p_perfmgr,osm_perfmgr_state_t state)156 inline static void osm_perfmgr_set_state(osm_perfmgr_t * p_perfmgr,
157 osm_perfmgr_state_t state)
158 {
159 p_perfmgr->state = state;
160 if (state == PERFMGR_STATE_ENABLED)
161 osm_sm_signal(p_perfmgr->sm, OSM_SIGNAL_PERFMGR_SWEEP);
162 }
163
osm_perfmgr_get_state(osm_perfmgr_t * p_perfmgr)164 inline static osm_perfmgr_state_t osm_perfmgr_get_state(osm_perfmgr_t
165 * p_perfmgr)
166 {
167 return (p_perfmgr->state);
168 }
169
osm_perfmgr_get_state_str(osm_perfmgr_t * p_perfmgr)170 inline static char *osm_perfmgr_get_state_str(osm_perfmgr_t * p_perfmgr)
171 {
172 switch (p_perfmgr->state) {
173 case PERFMGR_STATE_DISABLE:
174 return ("Disabled");
175 break;
176 case PERFMGR_STATE_ENABLED:
177 return ("Enabled");
178 break;
179 case PERFMGR_STATE_NO_DB:
180 return ("No Database");
181 break;
182 }
183 return ("UNKNOWN");
184 }
185
osm_perfmgr_get_sweep_state_str(osm_perfmgr_t * perfmgr)186 inline static char *osm_perfmgr_get_sweep_state_str(osm_perfmgr_t * perfmgr)
187 {
188 switch (perfmgr->sweep_state) {
189 case PERFMGR_SWEEP_SLEEP:
190 return ("Sleeping");
191 break;
192 case PERFMGR_SWEEP_ACTIVE:
193 return ("Active");
194 break;
195 case PERFMGR_SWEEP_SUSPENDED:
196 return ("Suspended");
197 break;
198 }
199 return ("UNKNOWN");
200 }
201
osm_perfmgr_set_sweep_time_s(osm_perfmgr_t * p_perfmgr,uint16_t time_s)202 inline static void osm_perfmgr_set_sweep_time_s(osm_perfmgr_t * p_perfmgr,
203 uint16_t time_s)
204 {
205 p_perfmgr->sweep_time_s = time_s;
206 osm_sm_signal(p_perfmgr->sm, OSM_SIGNAL_PERFMGR_SWEEP);
207 }
208
osm_perfmgr_get_sweep_time_s(osm_perfmgr_t * p_perfmgr)209 inline static uint16_t osm_perfmgr_get_sweep_time_s(osm_perfmgr_t * p_perfmgr)
210 {
211 return (p_perfmgr->sweep_time_s);
212 }
213
214 void osm_perfmgr_clear_counters(osm_perfmgr_t * p_perfmgr);
215 void osm_perfmgr_dump_counters(osm_perfmgr_t * p_perfmgr,
216 perfmgr_db_dump_t dump_type);
217 void osm_perfmgr_print_counters(osm_perfmgr_t *pm, char *nodename,
218 FILE *fp);
219
220 ib_api_status_t osm_perfmgr_bind(osm_perfmgr_t * const p_perfmgr,
221 const ib_net64_t port_guid);
222
223 void osm_perfmgr_process(osm_perfmgr_t * pm);
224
225 /****f* OpenSM: PerfMgr/osm_perfmgr_init */
226 ib_api_status_t osm_perfmgr_init(osm_perfmgr_t * const perfmgr,
227 struct osm_opensm *osm,
228 const osm_subn_opt_t * const p_opt);
229 /*
230 * PARAMETERS
231 * perfmgr
232 * [in] Pointer to an osm_perfmgr_t object to initialize.
233 *
234 * osm
235 * [in] Pointer to the OpenSM object.
236 *
237 * p_opt
238 * [in] Starting options
239 *
240 * RETURN VALUES
241 * IB_SUCCESS if the PerfMgr object was initialized successfully.
242 *********/
243
244 #ifdef __cplusplus
245 }
246 #endif /* __cplusplus */
247
248 #endif /* ENABLE_OSM_PERF_MGR */
249
250 #endif /* _OSM_PERFMGR_H_ */
251