2 * Copyright (c) 2007 The Regents of the University of California.
3 * Copyright (c) 2007-2008 Voltaire, Inc. All rights reserved.
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:
11 * Redistribution and use in source and binary forms, with or
12 * without modification, are permitted provided that the following
15 * - Redistributions of source code must retain the above
16 * copyright notice, this list of conditions and the following
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.
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
35 #ifndef _OSM_PERFMGR_H_
36 #define _OSM_PERFMGR_H_
40 #endif /* HAVE_CONFIG_H */
42 #ifdef ENABLE_OSM_PERF_MGR
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>
57 #endif /* __cplusplus */
59 /****h* OpenSM/PerfMgr
64 * Performance manager thread which takes care of polling the fabric for
65 * Port counters values.
67 * The PerfMgr object is thread safe.
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
78 /****s* OpenSM: PerfMgr/osm_perfmgr_state_t */
80 PERFMGR_STATE_DISABLE,
81 PERFMGR_STATE_ENABLED,
83 } osm_perfmgr_state_t;
85 /****s* OpenSM: PerfMgr/osm_perfmgr_sweep_state_t */
89 PERFMGR_SWEEP_SUSPENDED
90 } osm_perfmgr_sweep_state_t;
92 /* Redirection information */
93 typedef struct redir {
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;
104 uint32_t redir_tbl_size;
105 redir_t redir_port[1]; /* redirection on a per port basis */
106 } __monitored_node_t;
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.
113 typedef struct osm_perfmgr {
114 cl_event_t sig_sweep;
115 cl_timer_t sweep_timer;
116 struct osm_opensm *osm;
121 osm_mad_pool_t *mad_pool;
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;
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;
139 * Subnet object for this subnet.
142 * Pointer to the log object.
145 * Pointer to the MAD pool.
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);
155 /****f* OpenSM: Inline accessor functions */
156 inline static void osm_perfmgr_set_state(osm_perfmgr_t * p_perfmgr,
157 osm_perfmgr_state_t state)
159 p_perfmgr->state = state;
160 if (state == PERFMGR_STATE_ENABLED)
161 osm_sm_signal(p_perfmgr->sm, OSM_SIGNAL_PERFMGR_SWEEP);
164 inline static osm_perfmgr_state_t osm_perfmgr_get_state(osm_perfmgr_t
167 return (p_perfmgr->state);
170 inline static char *osm_perfmgr_get_state_str(osm_perfmgr_t * p_perfmgr)
172 switch (p_perfmgr->state) {
173 case PERFMGR_STATE_DISABLE:
176 case PERFMGR_STATE_ENABLED:
179 case PERFMGR_STATE_NO_DB:
180 return ("No Database");
186 inline static char *osm_perfmgr_get_sweep_state_str(osm_perfmgr_t * perfmgr)
188 switch (perfmgr->sweep_state) {
189 case PERFMGR_SWEEP_SLEEP:
192 case PERFMGR_SWEEP_ACTIVE:
195 case PERFMGR_SWEEP_SUSPENDED:
196 return ("Suspended");
202 inline static void osm_perfmgr_set_sweep_time_s(osm_perfmgr_t * p_perfmgr,
205 p_perfmgr->sweep_time_s = time_s;
206 osm_sm_signal(p_perfmgr->sm, OSM_SIGNAL_PERFMGR_SWEEP);
209 inline static uint16_t osm_perfmgr_get_sweep_time_s(osm_perfmgr_t * p_perfmgr)
211 return (p_perfmgr->sweep_time_s);
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,
220 ib_api_status_t osm_perfmgr_bind(osm_perfmgr_t * const p_perfmgr,
221 const ib_net64_t port_guid);
223 void osm_perfmgr_process(osm_perfmgr_t * pm);
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);
232 * [in] Pointer to an osm_perfmgr_t object to initialize.
235 * [in] Pointer to the OpenSM object.
238 * [in] Starting options
241 * IB_SUCCESS if the PerfMgr object was initialized successfully.
246 #endif /* __cplusplus */
248 #endif /* ENABLE_OSM_PERF_MGR */
250 #endif /* _OSM_PERFMGR_H_ */