[ofa-general] [PATCH] libibverbs/examples: add command line parameter for SL

Dotan Barak dotanb at dev.mellanox.co.il
Tue Oct 23 05:39:25 PDT 2007


Added command line parameter to support changing the SL of the QP/AH.
(This is being used mainly in order to check the QoS feature)

Signed-off-by: Dotan Barak <dotanb at dev.mellanox.co.il>

---

diff --git a/examples/rc_pingpong.c b/examples/rc_pingpong.c
index 258eb8f..4a90498 100644
--- a/examples/rc_pingpong.c
+++ b/examples/rc_pingpong.c
@@ -76,7 +76,8 @@ struct pingpong_dest {
 };
 
 static int pp_connect_ctx(struct pingpong_context *ctx, int port, int my_psn,
-			  enum ibv_mtu mtu, struct pingpong_dest *dest)
+			  enum ibv_mtu mtu, int sl,
+			  struct pingpong_dest *dest)
 {
 	struct ibv_qp_attr attr = {
 		.qp_state		= IBV_QPS_RTR,
@@ -88,7 +89,7 @@ static int pp_connect_ctx(struct pingpong_context *ctx, int port, int my_psn,
 		.ah_attr		= {
 			.is_global	= 0,
 			.dlid		= dest->lid,
-			.sl		= 0,
+			.sl		= sl,
 			.src_path_bits	= 0,
 			.port_num	= port
 		}
@@ -192,7 +193,8 @@ out:
 }
 
 static struct pingpong_dest *pp_server_exch_dest(struct pingpong_context *ctx,
-						 int ib_port, enum ibv_mtu mtu, int port,
+						 int ib_port, enum ibv_mtu mtu,
+						 int port, int sl,
 						 const struct pingpong_dest *my_dest)
 {
 	struct addrinfo *res, *t;
@@ -259,7 +261,7 @@ static struct pingpong_dest *pp_server_exch_dest(struct pingpong_context *ctx,
 
 	sscanf(msg, "%x:%x:%x", &rem_dest->lid, &rem_dest->qpn, &rem_dest->psn);
 
-	if (pp_connect_ctx(ctx, ib_port, my_dest->psn, mtu, rem_dest)) {
+	if (pp_connect_ctx(ctx, ib_port, my_dest->psn, mtu, sl, rem_dest)) {
 		fprintf(stderr, "Couldn't connect to remote QP\n");
 		free(rem_dest);
 		rem_dest = NULL;
@@ -473,6 +475,7 @@ static void usage(const char *argv0)
 	printf("  -m, --mtu=<size>       path MTU (default 1024)\n");
 	printf("  -r, --rx-depth=<dep>   number of receives to post at a time (default 500)\n");
 	printf("  -n, --iters=<iters>    number of exchanges (default 1000)\n");
+	printf("  -l, --sl=<sl>          service level value\n");
 	printf("  -e, --events           sleep on CQ events (default poll)\n");
 }
 
@@ -496,6 +499,7 @@ int main(int argc, char *argv[])
 	int                      routs;
 	int                      rcnt, scnt;
 	int                      num_cq_events = 0;
+	int                      sl = 0;
 
 	srand48(getpid() * time(NULL));
 
@@ -510,11 +514,12 @@ int main(int argc, char *argv[])
 			{ .name = "mtu",      .has_arg = 1, .val = 'm' },
 			{ .name = "rx-depth", .has_arg = 1, .val = 'r' },
 			{ .name = "iters",    .has_arg = 1, .val = 'n' },
+			{ .name = "sl",       .has_arg = 1, .val = 'l' },
 			{ .name = "events",   .has_arg = 0, .val = 'e' },
 			{ 0 }
 		};
 
-		c = getopt_long(argc, argv, "p:d:i:s:m:r:n:e", long_options, NULL);
+		c = getopt_long(argc, argv, "p:d:i:s:m:r:n:l:e", long_options, NULL);
 		if (c == -1)
 			break;
 
@@ -558,6 +563,10 @@ int main(int argc, char *argv[])
 			iters = strtol(optarg, NULL, 0);
 			break;
 
+		case 'l':
+			sl = strtol(optarg, NULL, 0);
+			break;
+
 		case 'e':
 			++use_event;
 			break;
@@ -631,7 +640,7 @@ int main(int argc, char *argv[])
 	if (servername)
 		rem_dest = pp_client_exch_dest(servername, port, &my_dest);
 	else
-		rem_dest = pp_server_exch_dest(ctx, ib_port, mtu, port, &my_dest);
+		rem_dest = pp_server_exch_dest(ctx, ib_port, mtu, port, sl, &my_dest);
 
 	if (!rem_dest)
 		return 1;
@@ -640,7 +649,7 @@ int main(int argc, char *argv[])
 	       rem_dest->lid, rem_dest->qpn, rem_dest->psn);
 
 	if (servername)
-		if (pp_connect_ctx(ctx, ib_port, my_dest.psn, mtu, rem_dest))
+		if (pp_connect_ctx(ctx, ib_port, my_dest.psn, mtu, sl, rem_dest))
 			return 1;
 
 	ctx->pending = PINGPONG_RECV_WRID;
diff --git a/examples/srq_pingpong.c b/examples/srq_pingpong.c
index 490ad0a..1ff4668 100644
--- a/examples/srq_pingpong.c
+++ b/examples/srq_pingpong.c
@@ -80,7 +80,7 @@ struct pingpong_dest {
 };
 
 static int pp_connect_ctx(struct pingpong_context *ctx, int port, enum ibv_mtu mtu,
-			  const struct pingpong_dest *my_dest,
+			  int sl, const struct pingpong_dest *my_dest,
 			  const struct pingpong_dest *dest)
 {
 	int i;
@@ -96,7 +96,7 @@ static int pp_connect_ctx(struct pingpong_context *ctx, int port, enum ibv_mtu m
 			.ah_attr		= {
 				.is_global	= 0,
 				.dlid		= dest[i].lid,
-				.sl		= 0,
+				.sl		= sl,
 				.src_path_bits	= 0,
 				.port_num	= port
 			}
@@ -214,7 +214,8 @@ out:
 }
 
 static struct pingpong_dest *pp_server_exch_dest(struct pingpong_context *ctx,
-						 int ib_port, enum ibv_mtu mtu, int port,
+						 int ib_port, enum ibv_mtu mtu,
+						 int port, int sl,
 						 const struct pingpong_dest *my_dest)
 {
 	struct addrinfo *res, *t;
@@ -291,7 +292,7 @@ static struct pingpong_dest *pp_server_exch_dest(struct pingpong_context *ctx,
 		       &rem_dest[i].lid, &rem_dest[i].qpn, &rem_dest[i].psn);
 	}
 
-	if (pp_connect_ctx(ctx, ib_port, mtu, my_dest, rem_dest)) {
+	if (pp_connect_ctx(ctx, ib_port, mtu, sl, my_dest, rem_dest)) {
 		fprintf(stderr, "Couldn't connect to remote QP\n");
 		free(rem_dest);
 		rem_dest = NULL;
@@ -544,6 +545,7 @@ static void usage(const char *argv0)
 	printf("  -q, --num-qp=<num>     number of QPs to use (default 16)\n");
 	printf("  -r, --rx-depth=<dep>   number of receives to post at a time (default 500)\n");
 	printf("  -n, --iters=<iters>    number of exchanges per QP(default 1000)\n");
+	printf("  -l, --sl=<sl>          service level value\n");
 	printf("  -e, --events           sleep on CQ events (default poll)\n");
 }
 
@@ -571,6 +573,7 @@ int main(int argc, char *argv[])
 	int			 num_wc;
 	int                      i;
 	int                      num_cq_events = 0;
+	int                      sl = 0;
 
 	srand48(getpid() * time(NULL));
 
@@ -586,11 +589,12 @@ int main(int argc, char *argv[])
 			{ .name = "num-qp",   .has_arg = 1, .val = 'q' },
 			{ .name = "rx-depth", .has_arg = 1, .val = 'r' },
 			{ .name = "iters",    .has_arg = 1, .val = 'n' },
+			{ .name = "sl",       .has_arg = 1, .val = 'l' },
 			{ .name = "events",   .has_arg = 0, .val = 'e' },
 			{ 0 }
 		};
 
-		c = getopt_long(argc, argv, "p:d:i:s:m:q:r:n:e", long_options, NULL);
+		c = getopt_long(argc, argv, "p:d:i:s:m:q:r:n:l:e", long_options, NULL);
 		if (c == -1)
 			break;
 
@@ -639,6 +643,10 @@ int main(int argc, char *argv[])
 			iters = strtol(optarg, NULL, 0);
 			break;
 
+		case 'l':
+			sl = strtol(optarg, NULL, 0);
+			break;
+
 		case 'e':
 			++use_event;
 			break;
@@ -726,7 +734,7 @@ int main(int argc, char *argv[])
 	if (servername)
 		rem_dest = pp_client_exch_dest(servername, port, my_dest);
 	else
-		rem_dest = pp_server_exch_dest(ctx, ib_port, mtu, port, my_dest);
+		rem_dest = pp_server_exch_dest(ctx, ib_port, mtu, port, sl, my_dest);
 
 	if (!rem_dest)
 		return 1;
@@ -736,7 +744,7 @@ int main(int argc, char *argv[])
 		       rem_dest[i].lid, rem_dest[i].qpn, rem_dest[i].psn);
 
 	if (servername)
-		if (pp_connect_ctx(ctx, ib_port, mtu, my_dest, rem_dest))
+		if (pp_connect_ctx(ctx, ib_port, mtu, sl, my_dest, rem_dest))
 			return 1;
 
 	if (servername)
diff --git a/examples/uc_pingpong.c b/examples/uc_pingpong.c
index b6051c8..45be804 100644
--- a/examples/uc_pingpong.c
+++ b/examples/uc_pingpong.c
@@ -76,7 +76,8 @@ struct pingpong_dest {
 };
 
 static int pp_connect_ctx(struct pingpong_context *ctx, int port, int my_psn,
-			  enum ibv_mtu mtu, struct pingpong_dest *dest)
+			  enum ibv_mtu mtu, int sl,
+			  struct pingpong_dest *dest)
 {
 	struct ibv_qp_attr attr = {
 		.qp_state		= IBV_QPS_RTR,
@@ -86,7 +87,7 @@ static int pp_connect_ctx(struct pingpong_context *ctx, int port, int my_psn,
 		.ah_attr		= {
 			.is_global	= 0,
 			.dlid		= dest->lid,
-			.sl		= 0,
+			.sl		= sl,
 			.src_path_bits	= 0,
 			.port_num	= port
 		}
@@ -180,7 +181,8 @@ out:
 }
 
 static struct pingpong_dest *pp_server_exch_dest(struct pingpong_context *ctx,
-						 int ib_port, enum ibv_mtu mtu, int port,
+						 int ib_port, enum ibv_mtu mtu,
+						 int port, int sl,
 						 const struct pingpong_dest *my_dest)
 {
 	struct addrinfo *res, *t;
@@ -247,7 +249,7 @@ static struct pingpong_dest *pp_server_exch_dest(struct pingpong_context *ctx,
 
 	sscanf(msg, "%x:%x:%x", &rem_dest->lid, &rem_dest->qpn, &rem_dest->psn);
 
-	if (pp_connect_ctx(ctx, ib_port, my_dest->psn, mtu, rem_dest)) {
+	if (pp_connect_ctx(ctx, ib_port, my_dest->psn, mtu, sl, rem_dest)) {
 		fprintf(stderr, "Couldn't connect to remote QP\n");
 		free(rem_dest);
 		rem_dest = NULL;
@@ -461,6 +463,7 @@ static void usage(const char *argv0)
 	printf("  -m, --mtu=<size>       path MTU (default 1024)\n");
 	printf("  -r, --rx-depth=<dep>   number of receives to post at a time (default 500)\n");
 	printf("  -n, --iters=<iters>    number of exchanges (default 1000)\n");
+	printf("  -l, --sl=<sl>          service level value\n");
 	printf("  -e, --events           sleep on CQ events (default poll)\n");
 }
 
@@ -484,6 +487,7 @@ int main(int argc, char *argv[])
 	int                      routs;
 	int                      rcnt, scnt;
 	int                      num_cq_events = 0;
+	int                      sl = 0;
 
 	srand48(getpid() * time(NULL));
 
@@ -498,11 +502,12 @@ int main(int argc, char *argv[])
 			{ .name = "mtu",      .has_arg = 1, .val = 'm' },
 			{ .name = "rx-depth", .has_arg = 1, .val = 'r' },
 			{ .name = "iters",    .has_arg = 1, .val = 'n' },
+			{ .name = "sl",       .has_arg = 1, .val = 'l' },
 			{ .name = "events",   .has_arg = 0, .val = 'e' },
 			{ 0 }
 		};
 
-		c = getopt_long(argc, argv, "p:d:i:s:m:r:n:e", long_options, NULL);
+		c = getopt_long(argc, argv, "p:d:i:s:m:r:n:l:e", long_options, NULL);
 		if (c == -1)
 			break;
 
@@ -546,6 +551,10 @@ int main(int argc, char *argv[])
 			iters = strtol(optarg, NULL, 0);
 			break;
 
+		case 'l':
+			sl = strtol(optarg, NULL, 0);
+			break;
+
 		case 'e':
 			++use_event;
 			break;
@@ -619,7 +628,7 @@ int main(int argc, char *argv[])
 	if (servername)
 		rem_dest = pp_client_exch_dest(servername, port, &my_dest);
 	else
-		rem_dest = pp_server_exch_dest(ctx, ib_port, mtu, port, &my_dest);
+		rem_dest = pp_server_exch_dest(ctx, ib_port, mtu, port, sl, &my_dest);
 
 	if (!rem_dest)
 		return 1;
@@ -628,7 +637,7 @@ int main(int argc, char *argv[])
 	       rem_dest->lid, rem_dest->qpn, rem_dest->psn);
 
 	if (servername)
-		if (pp_connect_ctx(ctx, ib_port, my_dest.psn, mtu, rem_dest))
+		if (pp_connect_ctx(ctx, ib_port, my_dest.psn, mtu, sl, rem_dest))
 			return 1;
 
 	ctx->pending = PINGPONG_RECV_WRID;
diff --git a/examples/ud_pingpong.c b/examples/ud_pingpong.c
index c631e25..981c503 100644
--- a/examples/ud_pingpong.c
+++ b/examples/ud_pingpong.c
@@ -77,13 +77,13 @@ struct pingpong_dest {
 };
 
 static int pp_connect_ctx(struct pingpong_context *ctx, int port, int my_psn,
-			  struct pingpong_dest *dest)
+			  int sl, struct pingpong_dest *dest)
 {
 	struct ibv_qp_attr attr;
 	struct ibv_ah_attr ah_attr = {
 		.is_global     = 0,
 		.dlid          = dest->lid,
-		.sl            = 0,
+		.sl            = sl,
 		.src_path_bits = 0,
 		.port_num      = port
 	};
@@ -181,7 +181,7 @@ out:
 }
 
 static struct pingpong_dest *pp_server_exch_dest(struct pingpong_context *ctx,
-						 int ib_port, int port,
+						 int ib_port, int port, int sl,
 						 const struct pingpong_dest *my_dest)
 {
 	struct addrinfo *res, *t;
@@ -248,7 +248,7 @@ static struct pingpong_dest *pp_server_exch_dest(struct pingpong_context *ctx,
 
 	sscanf(msg, "%x:%x:%x", &rem_dest->lid, &rem_dest->qpn, &rem_dest->psn);
 
-	if (pp_connect_ctx(ctx, ib_port, my_dest->psn, rem_dest)) {
+	if (pp_connect_ctx(ctx, ib_port, my_dest->psn, sl, rem_dest)) {
 		fprintf(stderr, "Couldn't connect to remote QP\n");
 		free(rem_dest);
 		rem_dest = NULL;
@@ -495,6 +495,7 @@ int main(int argc, char *argv[])
 	int                      routs;
 	int                      rcnt, scnt;
 	int                      num_cq_events = 0;
+	int                      sl = 0;
 
 	srand48(getpid() * time(NULL));
 
@@ -508,11 +509,12 @@ int main(int argc, char *argv[])
 			{ .name = "size",     .has_arg = 1, .val = 's' },
 			{ .name = "rx-depth", .has_arg = 1, .val = 'r' },
 			{ .name = "iters",    .has_arg = 1, .val = 'n' },
+			{ .name = "sl",       .has_arg = 1, .val = 'l' },
 			{ .name = "events",   .has_arg = 0, .val = 'e' },
 			{ 0 }
 		};
 
-		c = getopt_long(argc, argv, "p:d:i:s:r:n:e", long_options, NULL);
+		c = getopt_long(argc, argv, "p:d:i:s:r:n:l:e", long_options, NULL);
 		if (c == -1)
 			break;
 
@@ -549,6 +551,10 @@ int main(int argc, char *argv[])
 			iters = strtol(optarg, NULL, 0);
 			break;
 
+		case 'l':
+			sl = strtol(optarg, NULL, 0);
+			break;
+
 		case 'e':
 			++use_event;
 			break;
@@ -622,7 +628,7 @@ int main(int argc, char *argv[])
 	if (servername)
 		rem_dest = pp_client_exch_dest(servername, port, &my_dest);
 	else
-		rem_dest = pp_server_exch_dest(ctx, ib_port, port, &my_dest);
+		rem_dest = pp_server_exch_dest(ctx, ib_port, port, sl, &my_dest);
 
 	if (!rem_dest)
 		return 1;
@@ -631,7 +637,7 @@ int main(int argc, char *argv[])
 	       rem_dest->lid, rem_dest->qpn, rem_dest->psn);
 
 	if (servername)
-		if (pp_connect_ctx(ctx, ib_port, my_dest.psn, rem_dest))
+		if (pp_connect_ctx(ctx, ib_port, my_dest.psn, sl, rem_dest))
 			return 1;
 
 	ctx->pending = PINGPONG_RECV_WRID;



More information about the general mailing list