[ofa-general] [PATCH] opensm configure: add perf-mgr-profile option and clean up "#if 0" debug code
Ira Weiny
weiny2 at llnl.gov
Wed Aug 22 17:09:47 PDT 2007
>From 5b22095ed47d62355c14441c3aaf7e9db7829f95 Mon Sep 17 00:00:00 2001
From: Ira K. Weiny <weiny2 at llnl.gov>
Date: Fri, 17 Aug 2007 14:47:58 -0700
Subject: [PATCH] opensm configure: add perf-mgr-profile option and clean up "#if 0" debug code
This option does some time stamping on the perfmgr data colection and
reports it under OSM_LOG_INFO level.
Signed-off-by: Ira K. Weiny <weiny2 at llnl.gov>
---
opensm/config/osmvsel.m4 | 16 ++++++-
opensm/include/opensm/osm_madw.h | 2 +-
opensm/opensm/osm_perfmgr.c | 97 ++++++++++++++++++++++++++++++--------
3 files changed, 92 insertions(+), 23 deletions(-)
diff --git a/opensm/config/osmvsel.m4 b/opensm/config/osmvsel.m4
index 3cdccc6..47ad36f 100644
--- a/opensm/config/osmvsel.m4
+++ b/opensm/config/osmvsel.m4
@@ -215,10 +215,22 @@ AC_ARG_ENABLE(perf-mgr,
no) perf_mgr=no ;;
esac],
perf_mgr=no)
+AC_ARG_ENABLE(perf-mgr-profile,
+[ --enable-perf-mgr-profile Enable the performance manager profiling (default no)],
+ [case $enableval in
+ yes) perf_mgr_profile=yes ;;
+ no) perf_mgr_profile=no ;;
+ esac],
+ perf_mgr_profile=no)
if test $perf_mgr = yes; then
AC_DEFINE(ENABLE_OSM_PERF_MGR,
- 1,
- [Define as 1 if you want to enable the performance manager])
+ 1,
+ [Define as 1 if you want to enable the performance manager])
+ if test $perf_mgr_profile = yes; then
+ AC_DEFINE(ENABLE_OSM_PERF_MGR_PROFILE,
+ 1,
+ [Define as 1 if you want to enable the performance manager profiling code])
+ fi
fi
# --- END OPENIB_OSM_PERF_MGR_SEL ---
]) dnl OPENIB_OSM_PERF_MGR_SEL
diff --git a/opensm/include/opensm/osm_madw.h b/opensm/include/opensm/osm_madw.h
index b996037..bdaa7bc 100644
--- a/opensm/include/opensm/osm_madw.h
+++ b/opensm/include/opensm/osm_madw.h
@@ -314,7 +314,7 @@ typedef struct _osm_perfmgr_context {
uint64_t node_guid;
uint16_t port;
uint8_t mad_method; /* was this a get or a set */
-#if 0
+#if ENABLE_OSM_PERF_MGR_PROFILE
struct timeval query_start;
#endif
} osm_perfmgr_context_t;
diff --git a/opensm/opensm/osm_perfmgr.c b/opensm/opensm/osm_perfmgr.c
index f1c6ca0..37baf7c 100644
--- a/opensm/opensm/osm_perfmgr.c
+++ b/opensm/opensm/osm_perfmgr.c
@@ -61,9 +61,62 @@
#include <opensm/osm_node.h>
#include <complib/cl_thread.h>
#include <vendor/osm_vendor_api.h>
+#include <float.h>
#define OSM_PERFMGR_INITIAL_TID_VALUE 0xcafe
+#if ENABLE_OSM_PERF_MGR_PROFILE
+struct {
+ double fastest_us;
+ double slowest_us;
+ double avg_us;
+ uint64_t num;
+} perfmgr_mad_stats =
+{
+ fastest_us: DBL_MAX,
+ slowest_us: DBL_MIN,
+ avg_us: 0,
+ num: 0
+};
+
+/* diff must be something which can fit in a susecond_t */
+static inline void update_mad_stats(struct timeval *diff)
+{
+ double new = (diff->tv_sec * 1000000) + diff->tv_usec;
+ if (new < perfmgr_mad_stats.fastest_us)
+ perfmgr_mad_stats.fastest_us = new;
+ if (new > perfmgr_mad_stats.slowest_us)
+ perfmgr_mad_stats.slowest_us = new;
+
+ perfmgr_mad_stats.avg_us = ((perfmgr_mad_stats.avg_us * perfmgr_mad_stats.num) + new)
+ /(perfmgr_mad_stats.num+1);
+ perfmgr_mad_stats.num++;
+}
+
+static inline void perfmgr_clear_mad_stats(void)
+{
+ perfmgr_mad_stats.fastest_us = DBL_MAX;
+ perfmgr_mad_stats.slowest_us = DBL_MIN;
+ perfmgr_mad_stats.avg_us = 0;
+ perfmgr_mad_stats.num = 0;
+}
+
+/* after and diff can be the same struct */
+static inline void diff_time(struct timeval *before,
+ struct timeval *after,
+ struct timeval *diff)
+{
+ struct timeval tmp = *after;
+ if (tmp.tv_usec < before->tv_usec) {
+ tmp.tv_sec--;
+ tmp.tv_usec += 1000000;
+ }
+ diff->tv_sec = tmp.tv_sec - before->tv_sec;
+ diff->tv_usec = tmp.tv_usec - before->tv_usec;
+}
+
+#endif
+
/**********************************************************************
* Internal helper functions.
**********************************************************************/
@@ -130,16 +183,6 @@ osm_perfmgr_mad_recv_callback(osm_madw_t * p_madw, void *bind_context,
"PerfMgr Dispatcher post failed\n");
osm_mad_pool_put(pm->mad_pool, p_madw);
}
-#if 0
- do {
- struct timeval rcv_time;
- gettimeofday(&rcv_time, NULL);
- osm_log(pm->log, OSM_LOG_INFO,
- "perfmgr rcv time %ld\n",
- rcv_time.tv_usec -
- p_madw->context.perfmgr_context.query_start.tv_usec);
- } while (0);
-#endif
OSM_LOG_EXIT(pm->log);
}
@@ -506,7 +549,7 @@ __osm_perfmgr_query_counters(cl_map_item_t * const p_map_item, void *context)
mad_context.perfmgr_context.node_guid = node_guid;
mad_context.perfmgr_context.port = port;
mad_context.perfmgr_context.mad_method = IB_MAD_METHOD_GET;
-#if 0
+#if ENABLE_OSM_PERF_MGR_PROFILE
gettimeofday(&(mad_context.perfmgr_context.query_start), NULL);
#endif
osm_log(pm->log, OSM_LOG_VERBOSE,
@@ -554,7 +597,7 @@ void __osm_perfmgr_sweeper(void *p_ptr)
*/
if (pm->subn->sm_state == IB_SMINFO_STATE_MASTER &&
pm->state == PERFMGR_STATE_ENABLED) {
-#if 0
+#if ENABLE_OSM_PERF_MGR_PROFILE
struct timeval before, after;
gettimeofday(&before, NULL);
#endif
@@ -579,11 +622,25 @@ void __osm_perfmgr_sweeper(void *p_ptr)
* sweep
*/
__remove_marked_nodes(pm);
-#if 0
+
+#if ENABLE_OSM_PERF_MGR_PROFILE
+ /* spin on outstanding queries */
+ while (pm->outstanding_queries > 0)
+ cl_event_wait_on(&pm->sig_sweep, 1000, TRUE);
+
gettimeofday(&after, NULL);
+ diff_time(&before, &after, &after);
osm_log(pm->log, OSM_LOG_INFO,
- "PerfMgr total sweep time : %ld us\n",
- after.tv_usec - before.tv_usec);
+ "PerfMgr total sweep time : %ld.%06ld s\n"
+ " fastest mad : %g us\n"
+ " slowest mad : %g us\n"
+ " average mad : %g us\n"
+ ,
+ after.tv_sec, after.tv_usec,
+ perfmgr_mad_stats.fastest_us,
+ perfmgr_mad_stats.slowest_us,
+ perfmgr_mad_stats.avg_us);
+ perfmgr_clear_mad_stats();
#endif
}
@@ -950,14 +1007,14 @@ static void osm_pc_rcv_process(void *context, void *data)
osm_perfmgr_check_overflow(pm, node_guid, port, wire_read);
-#if 0
+#if ENABLE_OSM_PERF_MGR_PROFILE
do {
struct timeval proc_time;
gettimeofday(&proc_time, NULL);
- osm_log(pm->log, OSM_LOG_INFO,
- "PerfMgr done: processing time %ld\n",
- proc_time.tv_usec -
- p_madw->context.perfmgr_context.query_start.tv_usec);
+ diff_time(&(p_madw->context.perfmgr_context.query_start),
+ &proc_time,
+ &proc_time);
+ update_mad_stats(&proc_time);
} while (0);
#endif
--
1.5.2
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0001-opensm-configure-add-perf-mgr-profile-option-and-cl.patch
Type: application/octet-stream
Size: 6431 bytes
Desc: not available
URL: <http://lists.openfabrics.org/pipermail/general/attachments/20070822/649fc674/attachment.obj>
More information about the general
mailing list