[ofa-general] [PATCH] libibmad: make accessors function for timeout values used in libibmad

Ira Weiny weiny2 at llnl.gov
Thu Aug 6 16:01:06 PDT 2009


Sasha,

In using mad_send_via and mad_receive_via I have found getting the timeout and retry values from the mad layer to be beneficial.

This and the patch that follows export functions to get those values as well as standardize the use of them internally.

Ira


From: Ira Weiny <weiny2 at llnl.gov>
Date: Mon, 27 Jul 2009 13:48:17 -0700
Subject: [PATCH] libibmad: make accessors function for timeout values used in libibmad

	In addition use this function to determine the timeout to be used throughout the library.

Signed-off-by: Ira Weiny <weiny2 at llnl.gov>
---
 libibmad/include/infiniband/mad.h |    3 +++
 libibmad/src/libibmad.map         |    1 +
 libibmad/src/mad.c                |    8 ++++++++
 libibmad/src/mad_internal.h       |    1 +
 libibmad/src/rpc.c                |   17 ++++++++---------
 libibmad/src/serv.c               |    8 +++++---
 6 files changed, 26 insertions(+), 12 deletions(-)

diff --git a/libibmad/include/infiniband/mad.h b/libibmad/include/infiniband/mad.h
index ee004a9..c5d73d5 100644
--- a/libibmad/include/infiniband/mad.h
+++ b/libibmad/include/infiniband/mad.h
@@ -803,6 +803,9 @@ MAD_EXPORT void mad_rpc_set_retries(struct ibmad_port *port, int retries);
 MAD_EXPORT void mad_rpc_set_timeout(struct ibmad_port *port, int timeout);
 MAD_EXPORT int mad_rpc_class_agent(struct ibmad_port *srcport, int cls);
 
+MAD_EXPORT int mad_get_timeout(struct ibmad_port *srcport, int override_ms);
+
+
 /* register.c */
 MAD_EXPORT int mad_register_port_client(int port_id, int mgmt,
 					uint8_t rmpp_version);
diff --git a/libibmad/src/libibmad.map b/libibmad/src/libibmad.map
index 1462064..a8605b5 100644
--- a/libibmad/src/libibmad.map
+++ b/libibmad/src/libibmad.map
@@ -70,6 +70,7 @@ IBMAD_1.3 {
 		mad_rpc_class_agent;
 		mad_rpc_set_retries;
 		mad_rpc_set_timeout;
+		mad_get_timeout;
 		madrpc;
 		madrpc_def_timeout;
 		madrpc_init;
diff --git a/libibmad/src/mad.c b/libibmad/src/mad.c
index 8defabd..bc64a0f 100644
--- a/libibmad/src/mad.c
+++ b/libibmad/src/mad.c
@@ -44,6 +44,8 @@
 #include <infiniband/umad.h>
 #include <infiniband/mad.h>
 
+#include "mad_internal.h"
+
 #undef DEBUG
 #define DEBUG	if (ibdebug)	IBWARN
 
@@ -62,6 +64,12 @@ uint64_t mad_trid(void)
 	return next;
 }
 
+int mad_get_timeout(struct ibmad_port *srcport, int override_ms)
+{
+	return (override_ms ? override_ms :
+	    srcport->timeout ? srcport->timeout : madrpc_timeout);
+}
+
 void *mad_encode(void *buf, ib_rpc_t * rpc, ib_dr_path_t * drpath, void *data)
 {
 	int is_resp = rpc->method & IB_MAD_RESPONSE;
diff --git a/libibmad/src/mad_internal.h b/libibmad/src/mad_internal.h
index 24418cc..7a16a46 100644
--- a/libibmad/src/mad_internal.h
+++ b/libibmad/src/mad_internal.h
@@ -43,5 +43,6 @@ struct ibmad_port {
 };
 
 extern struct ibmad_port *ibmp;
+extern int madrpc_timeout;
 
 #endif /* _MAD_INTERNAL_H_ */
diff --git a/libibmad/src/rpc.c b/libibmad/src/rpc.c
index c6fd392..bb83114 100644
--- a/libibmad/src/rpc.c
+++ b/libibmad/src/rpc.c
@@ -53,8 +53,9 @@ struct ibmad_port *ibmp = &mad_port;
 
 static int iberrs;
 
+int madrpc_timeout = MAD_DEF_TIMEOUT_MS;
+
 static int madrpc_retries = MAD_DEF_RETRIES;
-static int madrpc_timeout = MAD_DEF_TIMEOUT_MS;
 static void *save_mad;
 static int save_mad_len = 256;
 
@@ -210,7 +211,7 @@ void *mad_rpc(const struct ibmad_port *port, ib_rpc_t * rpc,
 {
 	int status, len;
 	uint8_t sndbuf[1024], rcvbuf[1024], *mad;
-	int timeout, retries;
+	int retries;
 	int redirect = 1;
 
 	while (redirect) {
@@ -220,13 +221,12 @@ void *mad_rpc(const struct ibmad_port *port, ib_rpc_t * rpc,
 		if ((len = mad_build_pkt(sndbuf, rpc, dport, 0, payload)) < 0)
 			return NULL;
 
-		timeout = rpc->timeout ? rpc->timeout :
-			port->timeout ? port->timeout : madrpc_timeout;
 		retries = port->retries ? port->retries : madrpc_retries;
 
 		if ((len = _do_madrpc(port->port_id, sndbuf, rcvbuf,
 				      port->class_agents[rpc->mgtclass],
-				      len, timeout, retries)) < 0) {
+				      len, mad_get_timeout(port, rpc->timeout),
+				      retries)) < 0) {
 			IBWARN("_do_madrpc failed; dport (%s)", portid2str(dport));
 			return NULL;
 		}
@@ -267,7 +267,7 @@ void *mad_rpc_rmpp(const struct ibmad_port *port, ib_rpc_t * rpc,
 {
 	int status, len;
 	uint8_t sndbuf[1024], rcvbuf[1024], *mad;
-	int timeout, retries;
+	int retries;
 
 	memset(sndbuf, 0, umad_size() + IB_MAD_SIZE);
 
@@ -276,13 +276,12 @@ void *mad_rpc_rmpp(const struct ibmad_port *port, ib_rpc_t * rpc,
 	if ((len = mad_build_pkt(sndbuf, rpc, dport, rmpp, data)) < 0)
 		return NULL;
 
-	timeout = rpc->timeout ? rpc->timeout :
-	    port->timeout ? port->timeout : madrpc_timeout;
 	retries = port->retries ? port->retries : madrpc_retries;
 
 	if ((len = _do_madrpc(port->port_id, sndbuf, rcvbuf,
 			      port->class_agents[rpc->mgtclass],
-			      len, timeout, retries)) < 0) {
+			      len, mad_get_timeout(port, rpc->timeout),
+			      retries)) < 0) {
 		IBWARN("_do_madrpc failed; dport (%s)", portid2str(dport));
 		return NULL;
 	}
diff --git a/libibmad/src/serv.c b/libibmad/src/serv.c
index c9a093a..fad1e5b 100644
--- a/libibmad/src/serv.c
+++ b/libibmad/src/serv.c
@@ -73,7 +73,8 @@ int mad_send_via(ib_rpc_t * rpc, ib_portid_t * dport, ib_rmpp_hdr_t * rmpp,
 	}
 
 	if (umad_send(srcport->port_id, srcport->class_agents[rpc->mgtclass],
-		      umad, IB_MAD_SIZE, rpc->timeout, 0) < 0) {
+		      umad, IB_MAD_SIZE, mad_get_timeout(srcport, rpc->timeout),
+			0) < 0) {
 		IBWARN("send failed; %m");
 		return -1;
 	}
@@ -155,7 +156,7 @@ int mad_respond_via(void *umad, ib_portid_t * portid, uint32_t rstatus,
 
 	if (umad_send
 	    (srcport->port_id, srcport->class_agents[rpc.mgtclass], umad,
-	     IB_MAD_SIZE, rpc.timeout, 0) < 0) {
+	     IB_MAD_SIZE, mad_get_timeout(srcport, rpc.timeout), 0) < 0) {
 		DEBUG("send failed; %m");
 		return -1;
 	}
@@ -174,7 +175,8 @@ void *mad_receive_via(void *umad, int timeout, struct ibmad_port *srcport)
 	int agent;
 	int length = IB_MAD_SIZE;
 
-	if ((agent = umad_recv(srcport->port_id, mad, &length, timeout)) < 0) {
+	if ((agent = umad_recv(srcport->port_id, mad, &length,
+			mad_get_timeout(srcport, timeout))) < 0) {
 		if (!umad)
 			umad_free(mad);
 		DEBUG("recv failed: %m");
-- 
1.5.4.5




More information about the general mailing list