[openib-general] [PATCH] OpenSM: Properly encode response time value in SA ClassPortInfo

Hal Rosenstock halr at voltaire.com
Thu Mar 9 18:15:18 PST 2006


OpenSM: Properly encode response time value in SA ClassPortInfo

Rather than use log function, use a precalculated table to help in
calculation of the encoding (4.096 usec * 2 ** n)

Signed-off-by: Hal Rosenstock <halr at voltaire.com>

Index: opensm/osm_sa_class_port_info.c
===================================================================
--- opensm/osm_sa_class_port_info.c	(revision 5733)
+++ opensm/osm_sa_class_port_info.c	(working copy)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2004, 2005 Voltaire, Inc. All rights reserved.
+ * Copyright (c) 2004-2006 Voltaire, Inc. All rights reserved.
  * Copyright (c) 2002-2005 Mellanox Technologies LTD. All rights reserved.
  * Copyright (c) 1996-2003 Intel Corporation. All rights reserved.
  *
@@ -66,6 +66,17 @@
 #include <vendor/osm_vendor_api.h>
 #include <opensm/osm_helper.h>
 
+#define MAX_MSECS_TO_RTV 24
+/* Precalculated table in msec (index is related to encoded value) */
+/* 4.096 usec * 2 ** n (where n = 8 - 31) */
+static int __msecs_to_rtv_table[MAX_MSECS_TO_RTV] =
+					{ 1, 2, 4, 8,
+					  16, 33, 67, 134, 
+					  268, 536, 1073, 2147,
+					  4294, 8589, 17179, 34359,
+					  68719, 137438, 274877, 549755,
+					  1099511, 2199023, 4398046, 8796093 };
+
 /**********************************************************************
  **********************************************************************/
 void
@@ -125,6 +136,7 @@ __osm_cpi_rcv_respond(
   ib_class_port_info_t    *p_resp_cpi;
   ib_api_status_t       status;
   ib_gid_t                zero_gid;
+  int                   rtv;
 
   OSM_LOG_ENTER( p_rcv->p_log, __osm_cpi_rcv_respond );
 
@@ -159,7 +171,18 @@ __osm_cpi_rcv_respond(
   /* finally do it (the job) man ! */
   p_resp_cpi->base_ver = 1;
   p_resp_cpi->class_ver = 2;
-  p_resp_cpi->resp_time_val = p_rcv->p_subn->opt.transaction_timeout;
+  /* Calculate encoded response time value */
+  /* transaction timeout is in msec */
+  if (p_rcv->p_subn->opt.transaction_timeout > __msecs_to_rtv_table[MAX_MSECS_TO_RTV])
+    rtv = MAX_MSECS_TO_RTV - 1;
+  else {
+    for (rtv = 0; rtv < MAX_MSECS_TO_RTV; rtv++) {
+      if (p_rcv->p_subn->opt.transaction_timeout <= __msecs_to_rtv_table[rtv])
+         break;
+    }
+  }
+  rtv += 8;
+  p_resp_cpi->resp_time_val = rtv;
   p_resp_cpi->redir_gid = zero_gid;
   p_resp_cpi->redir_tc_sl_fl = 0;
   p_resp_cpi->redir_lid = 0;






More information about the general mailing list