[ofa-general] [PATCH 11/10] libibmad:infiniband-diags: deprecate madrpc_set_[retries|timeout] WAS: [PATCH 1/10] libibmad: Clean up "new" interface

Sasha Khapyorsky sashak at voltaire.com
Wed Mar 11 03:29:41 PDT 2009


On 16:34 Tue 10 Mar     , Ira Weiny wrote:
> 
> I will look at documenting the above as technically it is possible to change
> the timeout on various ports by setting the parameters appropriately on each
> call.  I don't like this going forward but I guess it is doable without
> changing the interface.

And what do you say about the patch below? It doesn't change the current
diags behavior and provides per port timeout/retries setup. The global
parameters and rpc's fields remain to be same, and we don;t need to
deprecate madrpc_set_timeout/retires().

Sasha


>From 25060f5a7243a1bae6a7e7e9b2b79051ab0473d9 Mon Sep 17 00:00:00 2001
From: Sasha Khapyorsky <sashak at voltaire.com>
Date: Wed, 11 Mar 2009 12:15:54 +0200
Subject: [PATCH] libibmad: per port timeout and retires setup

This adds functions mad_rpc_set_timeout() and mad_rpc_set_retries()
which provides possibility to specify timeout and retries for mad rpc
processing per port. This doesn't change the default behavior.

Signed-off-by: Sasha Khapyorsky <sashak at voltaire.com>
---
 libibmad/include/infiniband/mad.h |    2 ++
 libibmad/src/libibmad.map         |    2 ++
 libibmad/src/mad_internal.h       |    1 +
 libibmad/src/rpc.c                |   37 +++++++++++++++++++++++++++----------
 4 files changed, 32 insertions(+), 10 deletions(-)

diff --git a/libibmad/include/infiniband/mad.h b/libibmad/include/infiniband/mad.h
index 064cbb7..9b398fa 100644
--- a/libibmad/include/infiniband/mad.h
+++ b/libibmad/include/infiniband/mad.h
@@ -742,6 +742,8 @@ MAD_EXPORT void *mad_rpc(const struct ibmad_port *srcport, ib_rpc_t * rpc, ib_po
 MAD_EXPORT void *mad_rpc_rmpp(const struct ibmad_port *srcport, ib_rpc_t * rpc, ib_portid_t * dport,
 			ib_rmpp_hdr_t * rmpp, void *data);
 MAD_EXPORT int mad_rpc_portid(struct ibmad_port *srcport);
+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);
 
 /* register.c */
 MAD_EXPORT int mad_register_port_client(int port_id, int mgmt,
diff --git a/libibmad/src/libibmad.map b/libibmad/src/libibmad.map
index 0be7a92..10c7cd0 100644
--- a/libibmad/src/libibmad.map
+++ b/libibmad/src/libibmad.map
@@ -68,6 +68,8 @@ IBMAD_1.3 {
 		mad_rpc;
 		mad_rpc_rmpp;
 		mad_rpc_portid;
+		mad_rpc_set_retries;
+		mad_rpc_set_timeout;
 		madrpc;
 		madrpc_def_timeout;
 		madrpc_init;
diff --git a/libibmad/src/mad_internal.h b/libibmad/src/mad_internal.h
index e948540..24418cc 100644
--- a/libibmad/src/mad_internal.h
+++ b/libibmad/src/mad_internal.h
@@ -39,6 +39,7 @@
 struct ibmad_port {
 	int port_id;		/* file descriptor returned by umad_open() */
 	int class_agents[MAX_CLASS];	/* class2agent mapper */
+	int timeout, retries;
 };
 
 extern struct ibmad_port *ibmp;
diff --git a/libibmad/src/rpc.c b/libibmad/src/rpc.c
index 8c68cf9..3f3b7a2 100644
--- a/libibmad/src/rpc.c
+++ b/libibmad/src/rpc.c
@@ -53,7 +53,7 @@ struct ibmad_port *ibmp = &mad_port;
 static int iberrs;
 
 static int madrpc_retries = MAD_DEF_RETRIES;
-static int def_madrpc_timeout = MAD_DEF_TIMEOUT_MS;
+static int madrpc_timeout = MAD_DEF_TIMEOUT_MS;
 static void *save_mad;
 static int save_mad_len = 256;
 
@@ -83,13 +83,23 @@ int madrpc_set_retries(int retries)
 
 int madrpc_set_timeout(int timeout)
 {
-	def_madrpc_timeout = timeout;
+	madrpc_timeout = timeout;
 	return 0;
 }
 
+void mad_rpc_set_retries(struct ibmad_port *port, int retries)
+{
+	port->retries = retries;
+}
+
+void mad_rpc_set_timeout(struct ibmad_port *port, int timeout)
+{
+	port->timeout = timeout;
+}
+
 int madrpc_def_timeout(void)
 {
-	return def_madrpc_timeout;
+	return madrpc_timeout;
 }
 
 int madrpc_portid(void)
@@ -104,15 +114,12 @@ int mad_rpc_portid(struct ibmad_port *srcport)
 
 static int
 _do_madrpc(int port_id, void *sndbuf, void *rcvbuf, int agentid, int len,
-	   int timeout)
+	   int timeout, int max_retries)
 {
 	uint32_t trid;		/* only low 32 bits */
 	int retries;
 	int length, status;
 
-	if (!timeout)
-		timeout = def_madrpc_timeout;
-
 	if (ibdebug > 1) {
 		IBWARN(">>> sending: len %d pktsz %zu", len, umad_size() + len);
 		xdump(stderr, "send buf\n", sndbuf, umad_size() + len);
@@ -127,7 +134,7 @@ _do_madrpc(int port_id, void *sndbuf, void *rcvbuf, int agentid, int len,
 	trid =
 	    (uint32_t) mad_get_field64(umad_get_mad(sndbuf), 0, IB_MAD_TRID_F);
 
-	for (retries = 0; retries < madrpc_retries; retries++) {
+	for (retries = 0; retries < max_retries; retries++) {
 		if (retries) {
 			ERRS("retry %d (timeout %d ms)", retries, timeout);
 		}
@@ -171,6 +178,7 @@ void *mad_rpc(const struct ibmad_port *port, ib_rpc_t * rpc, ib_portid_t * dport
 {
 	int status, len;
 	uint8_t sndbuf[1024], rcvbuf[1024], *mad;
+	int timeout, retries;
 
 	len = 0;
 	memset(sndbuf, 0, umad_size() + IB_MAD_SIZE);
@@ -178,9 +186,13 @@ void *mad_rpc(const struct ibmad_port *port, ib_rpc_t * rpc, ib_portid_t * dport
 	if ((len = mad_build_pkt(sndbuf, rpc, dport, 0, payload)) < 0)
 		return 0;
 
+	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, rpc->timeout)) < 0) {
+			      len, timeout, retries)) < 0) {
 		IBWARN("_do_madrpc failed; dport (%s)", portid2str(dport));
 		return 0;
 	}
@@ -209,6 +221,7 @@ void *mad_rpc_rmpp(const struct ibmad_port *port, ib_rpc_t * rpc, ib_portid_t *
 {
 	int status, len;
 	uint8_t sndbuf[1024], rcvbuf[1024], *mad;
+	int timeout, retries;
 
 	memset(sndbuf, 0, umad_size() + IB_MAD_SIZE);
 
@@ -217,9 +230,13 @@ void *mad_rpc_rmpp(const struct ibmad_port *port, ib_rpc_t * rpc, ib_portid_t *
 	if ((len = mad_build_pkt(sndbuf, rpc, dport, rmpp, data)) < 0)
 		return 0;
 
+	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, rpc->timeout)) < 0) {
+			      len, rpc->timeout, retries)) < 0) {
 		IBWARN("_do_madrpc failed; dport (%s)", portid2str(dport));
 		return 0;
 	}
-- 
1.6.1.2.319.gbd9e




More information about the general mailing list