1/* 2 * Copyright (c) 2004-2008 Voltaire, Inc. All rights reserved. 3 * Copyright (c) 2002-2005 Mellanox Technologies LTD. All rights reserved. 4 * Copyright (c) 1996-2003 Intel Corporation. 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/* 37 * Abstract: 38 * Declaration of osm_stats_t. 39 * This object represents the OpenSM statistics object. 40 * This object is part of the OpenSM family of objects. 41 */ 42 43#ifndef _OSM_STATS_H_ 44#define _OSM_STATS_H_ 45 46#ifdef HAVE_LIBPTHREAD 47#include <pthread.h> 48#else 49#include <complib/cl_event.h> 50#endif 51#include <complib/cl_atomic.h> 52#include <opensm/osm_base.h> 53 54#ifdef __cplusplus 55# define BEGIN_C_DECLS extern "C" { 56# define END_C_DECLS } 57#else /* !__cplusplus */ 58# define BEGIN_C_DECLS 59# define END_C_DECLS 60#endif /* __cplusplus */ 61 62BEGIN_C_DECLS 63/****h* OpenSM/Statistics 64* NAME 65* OpenSM 66* 67* DESCRIPTION 68* The OpenSM object encapsulates the information needed by the 69* OpenSM to track interesting traffic and internal statistics. 70* 71* AUTHOR 72* Steve King, Intel 73* 74*********/ 75/****s* OpenSM: Statistics/osm_stats_t 76* NAME 77* osm_stats_t 78* 79* DESCRIPTION 80* OpenSM statistics block. 81* 82* SYNOPSIS 83*/ 84typedef struct osm_stats { 85 atomic32_t qp0_mads_outstanding; 86 atomic32_t qp0_mads_outstanding_on_wire; 87 atomic32_t qp0_mads_rcvd; 88 atomic32_t qp0_mads_sent; 89 atomic32_t qp0_unicasts_sent; 90 atomic32_t qp0_mads_rcvd_unknown; 91 atomic32_t sa_mads_outstanding; 92 atomic32_t sa_mads_rcvd; 93 atomic32_t sa_mads_sent; 94 atomic32_t sa_mads_rcvd_unknown; 95 atomic32_t sa_mads_ignored; 96#ifdef HAVE_LIBPTHREAD 97 pthread_mutex_t mutex; 98 pthread_cond_t cond; 99#else 100 cl_event_t event; 101#endif 102} osm_stats_t; 103/* 104* FIELDS 105* qp0_mads_outstanding 106* Contains the number of MADs outstanding on QP0. 107* When this value reaches zero, OpenSM has discovered all 108* nodes on the subnet, and finished retrieving attributes. 109* At that time, subnet configuration may begin. 110* This variable must be manipulated using atomic instructions. 111* 112* qp0_mads_outstanding_on_wire 113* The number of MADs outstanding on the wire at any moment. 114* 115* qp0_mads_rcvd 116* Total number of QP0 MADs received. 117* 118* qp0_mads_sent 119* Total number of QP0 MADs sent. 120* 121* qp0_unicasts_sent 122* Total number of response-less MADs sent on the wire. This count 123* includes getresp(), send() and trap() methods. 124* 125* qp0_mads_rcvd_unknown 126* Total number of unknown QP0 MADs received. This includes 127* unrecognized attribute IDs and methods. 128* 129* sa_mads_outstanding 130* Contains the number of SA MADs outstanding on QP1. 131* 132* sa_mads_rcvd 133* Total number of SA MADs received. 134* 135* sa_mads_sent 136* Total number of SA MADs sent. 137* 138* sa_mads_rcvd_unknown 139* Total number of unknown SA MADs received. This includes 140* unrecognized attribute IDs and methods. 141* 142* sa_mads_ignored 143* Total number of SA MADs received because SM is not 144* master or SM is in first time sweep. 145* 146* SEE ALSO 147***************/ 148 149static inline uint32_t osm_stats_inc_qp0_outstanding(osm_stats_t *stats) 150{ 151 uint32_t outstanding; 152 153#ifdef HAVE_LIBPTHREAD 154 pthread_mutex_lock(&stats->mutex); 155 outstanding = ++stats->qp0_mads_outstanding; 156 pthread_mutex_unlock(&stats->mutex); 157#else 158 outstanding = cl_atomic_inc(&stats->qp0_mads_outstanding); 159#endif 160 161 return outstanding; 162} 163 164static inline uint32_t osm_stats_dec_qp0_outstanding(osm_stats_t *stats) 165{ 166 uint32_t outstanding; 167 168#ifdef HAVE_LIBPTHREAD 169 pthread_mutex_lock(&stats->mutex); 170 outstanding = --stats->qp0_mads_outstanding; 171 if (!outstanding) 172 pthread_cond_signal(&stats->cond); 173 pthread_mutex_unlock(&stats->mutex); 174#else 175 outstanding = cl_atomic_dec(&stats->qp0_mads_outstanding); 176 if (!outstanding) 177 cl_event_signal(&stats->event); 178#endif 179 180 return outstanding; 181} 182 183END_C_DECLS 184#endif /* _OSM_STATS_H_ */ 185