1219820Sjeff/* 2219820Sjeff * Copyright (c) 2004-2008 Voltaire, Inc. All rights reserved. 3219820Sjeff * Copyright (c) 2002-2005 Mellanox Technologies LTD. All rights reserved. 4219820Sjeff * Copyright (c) 1996-2003 Intel Corporation. All rights reserved. 5219820Sjeff * 6219820Sjeff * This software is available to you under a choice of one of two 7219820Sjeff * licenses. You may choose to be licensed under the terms of the GNU 8219820Sjeff * General Public License (GPL) Version 2, available from the file 9219820Sjeff * COPYING in the main directory of this source tree, or the 10219820Sjeff * OpenIB.org BSD license below: 11219820Sjeff * 12219820Sjeff * Redistribution and use in source and binary forms, with or 13219820Sjeff * without modification, are permitted provided that the following 14219820Sjeff * conditions are met: 15219820Sjeff * 16219820Sjeff * - Redistributions of source code must retain the above 17219820Sjeff * copyright notice, this list of conditions and the following 18219820Sjeff * disclaimer. 19219820Sjeff * 20219820Sjeff * - Redistributions in binary form must reproduce the above 21219820Sjeff * copyright notice, this list of conditions and the following 22219820Sjeff * disclaimer in the documentation and/or other materials 23219820Sjeff * provided with the distribution. 24219820Sjeff * 25219820Sjeff * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 26219820Sjeff * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 27219820Sjeff * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 28219820Sjeff * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS 29219820Sjeff * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 30219820Sjeff * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 31219820Sjeff * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 32219820Sjeff * SOFTWARE. 33219820Sjeff * 34219820Sjeff */ 35219820Sjeff 36219820Sjeff/* 37219820Sjeff * Abstract: 38219820Sjeff * Declaration of osm_stats_t. 39219820Sjeff * This object represents the OpenSM statistics object. 40219820Sjeff * This object is part of the OpenSM family of objects. 41219820Sjeff */ 42219820Sjeff 43219820Sjeff#ifndef _OSM_STATS_H_ 44219820Sjeff#define _OSM_STATS_H_ 45219820Sjeff 46219820Sjeff#ifdef HAVE_LIBPTHREAD 47219820Sjeff#include <pthread.h> 48219820Sjeff#else 49219820Sjeff#include <complib/cl_event.h> 50219820Sjeff#endif 51219820Sjeff#include <complib/cl_atomic.h> 52219820Sjeff#include <opensm/osm_base.h> 53219820Sjeff 54219820Sjeff#ifdef __cplusplus 55219820Sjeff# define BEGIN_C_DECLS extern "C" { 56219820Sjeff# define END_C_DECLS } 57219820Sjeff#else /* !__cplusplus */ 58219820Sjeff# define BEGIN_C_DECLS 59219820Sjeff# define END_C_DECLS 60219820Sjeff#endif /* __cplusplus */ 61219820Sjeff 62219820SjeffBEGIN_C_DECLS 63219820Sjeff/****h* OpenSM/Statistics 64219820Sjeff* NAME 65219820Sjeff* OpenSM 66219820Sjeff* 67219820Sjeff* DESCRIPTION 68219820Sjeff* The OpenSM object encapsulates the information needed by the 69219820Sjeff* OpenSM to track interesting traffic and internal statistics. 70219820Sjeff* 71219820Sjeff* AUTHOR 72219820Sjeff* Steve King, Intel 73219820Sjeff* 74219820Sjeff*********/ 75219820Sjeff/****s* OpenSM: Statistics/osm_stats_t 76219820Sjeff* NAME 77219820Sjeff* osm_stats_t 78219820Sjeff* 79219820Sjeff* DESCRIPTION 80219820Sjeff* OpenSM statistics block. 81219820Sjeff* 82219820Sjeff* SYNOPSIS 83219820Sjeff*/ 84219820Sjefftypedef struct osm_stats { 85219820Sjeff atomic32_t qp0_mads_outstanding; 86219820Sjeff atomic32_t qp0_mads_outstanding_on_wire; 87219820Sjeff atomic32_t qp0_mads_rcvd; 88219820Sjeff atomic32_t qp0_mads_sent; 89219820Sjeff atomic32_t qp0_unicasts_sent; 90219820Sjeff atomic32_t qp0_mads_rcvd_unknown; 91219820Sjeff atomic32_t sa_mads_outstanding; 92219820Sjeff atomic32_t sa_mads_rcvd; 93219820Sjeff atomic32_t sa_mads_sent; 94219820Sjeff atomic32_t sa_mads_rcvd_unknown; 95219820Sjeff atomic32_t sa_mads_ignored; 96219820Sjeff#ifdef HAVE_LIBPTHREAD 97219820Sjeff pthread_mutex_t mutex; 98219820Sjeff pthread_cond_t cond; 99219820Sjeff#else 100219820Sjeff cl_event_t event; 101219820Sjeff#endif 102219820Sjeff} osm_stats_t; 103219820Sjeff/* 104219820Sjeff* FIELDS 105219820Sjeff* qp0_mads_outstanding 106219820Sjeff* Contains the number of MADs outstanding on QP0. 107219820Sjeff* When this value reaches zero, OpenSM has discovered all 108219820Sjeff* nodes on the subnet, and finished retrieving attributes. 109219820Sjeff* At that time, subnet configuration may begin. 110219820Sjeff* This variable must be manipulated using atomic instructions. 111219820Sjeff* 112219820Sjeff* qp0_mads_outstanding_on_wire 113219820Sjeff* The number of MADs outstanding on the wire at any moment. 114219820Sjeff* 115219820Sjeff* qp0_mads_rcvd 116219820Sjeff* Total number of QP0 MADs received. 117219820Sjeff* 118219820Sjeff* qp0_mads_sent 119219820Sjeff* Total number of QP0 MADs sent. 120219820Sjeff* 121219820Sjeff* qp0_unicasts_sent 122219820Sjeff* Total number of response-less MADs sent on the wire. This count 123219820Sjeff* includes getresp(), send() and trap() methods. 124219820Sjeff* 125219820Sjeff* qp0_mads_rcvd_unknown 126219820Sjeff* Total number of unknown QP0 MADs received. This includes 127219820Sjeff* unrecognized attribute IDs and methods. 128219820Sjeff* 129219820Sjeff* sa_mads_outstanding 130219820Sjeff* Contains the number of SA MADs outstanding on QP1. 131219820Sjeff* 132219820Sjeff* sa_mads_rcvd 133219820Sjeff* Total number of SA MADs received. 134219820Sjeff* 135219820Sjeff* sa_mads_sent 136219820Sjeff* Total number of SA MADs sent. 137219820Sjeff* 138219820Sjeff* sa_mads_rcvd_unknown 139219820Sjeff* Total number of unknown SA MADs received. This includes 140219820Sjeff* unrecognized attribute IDs and methods. 141219820Sjeff* 142219820Sjeff* sa_mads_ignored 143219820Sjeff* Total number of SA MADs received because SM is not 144219820Sjeff* master or SM is in first time sweep. 145219820Sjeff* 146219820Sjeff* SEE ALSO 147219820Sjeff***************/ 148219820Sjeff 149219820Sjeffstatic inline uint32_t osm_stats_inc_qp0_outstanding(osm_stats_t *stats) 150219820Sjeff{ 151219820Sjeff uint32_t outstanding; 152219820Sjeff 153219820Sjeff#ifdef HAVE_LIBPTHREAD 154219820Sjeff pthread_mutex_lock(&stats->mutex); 155219820Sjeff outstanding = ++stats->qp0_mads_outstanding; 156219820Sjeff pthread_mutex_unlock(&stats->mutex); 157219820Sjeff#else 158219820Sjeff outstanding = cl_atomic_inc(&stats->qp0_mads_outstanding); 159219820Sjeff#endif 160219820Sjeff 161219820Sjeff return outstanding; 162219820Sjeff} 163219820Sjeff 164219820Sjeffstatic inline uint32_t osm_stats_dec_qp0_outstanding(osm_stats_t *stats) 165219820Sjeff{ 166219820Sjeff uint32_t outstanding; 167219820Sjeff 168219820Sjeff#ifdef HAVE_LIBPTHREAD 169219820Sjeff pthread_mutex_lock(&stats->mutex); 170219820Sjeff outstanding = --stats->qp0_mads_outstanding; 171219820Sjeff if (!outstanding) 172219820Sjeff pthread_cond_signal(&stats->cond); 173219820Sjeff pthread_mutex_unlock(&stats->mutex); 174219820Sjeff#else 175219820Sjeff outstanding = cl_atomic_dec(&stats->qp0_mads_outstanding); 176219820Sjeff if (!outstanding) 177219820Sjeff cl_event_signal(&stats->event); 178219820Sjeff#endif 179219820Sjeff 180219820Sjeff return outstanding; 181219820Sjeff} 182219820Sjeff 183219820SjeffEND_C_DECLS 184219820Sjeff#endif /* _OSM_STATS_H_ */ 185