aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRoland Dreier <rolandd@cisco.com>2006-01-21 00:53:08 +0000
committerRoland Dreier <rolandd@cisco.com>2006-11-09 11:35:58 -0800
commitac4c1e7f7a959d379b422c7b3a6b405aca1b9a78 (patch)
tree128fd45b1db99b028dae5d2f2807914567427fc0
parent1af90a30d8be4dd338c2571fda96f22a6587c7c0 (diff)
downloadlibibverbs-ac4c1e7f7a959d379b422c7b3a6b405aca1b9a78.tar.gz
Factor out some common code in pingpong examples
- Create pingpong.c/pingpong.h to hold common code for pingpong examples. - Add option to set path MTU for connected transport pingpong examples. Signed-off-by: Roland Dreier <rolandd@cisco.com>
-rw-r--r--ChangeLog11
-rw-r--r--Makefile.am13
-rw-r--r--examples/pingpong.c47
-rw-r--r--examples/pingpong.h42
-rw-r--r--examples/rc_pingpong.c28
-rw-r--r--examples/srq_pingpong.c28
-rw-r--r--examples/uc_pingpong.c28
-rw-r--r--examples/ud_pingpong.c4
8 files changed, 162 insertions, 39 deletions
diff --git a/ChangeLog b/ChangeLog
index 9469156..c5423f5 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,14 @@
+2006-01-20 Roland Dreier <rdreier@cisco.com>
+
+ * examples/rc_pingpong.c, examples/uc_pingpong.c,
+ examples/srq_pingpong.c: Add "-m/--mtu=" option to set path MTU.
+ (Based on a patch from Ralph Campbell <ralphc@pathscale.com>)
+
+ * examples/pingpong.c, examples/pingpong.h: Create generic
+ pingpong files so that we can start factoring out common code from
+ the pingpong examples. Start with functions to convert MTU to an
+ IBV enum value.
+
2006-01-17 Ralph Campbell <ralphc@pathscale.com>
* examples/rc_pingpong.c (main), examples/srq_pingpong.c (main),
diff --git a/Makefile.am b/Makefile.am
index 0f8121f..e038d8d 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -27,13 +27,13 @@ examples_ibv_devices_SOURCES = examples/device_list.c
examples_ibv_devices_LDADD = $(top_builddir)/src/libibverbs.la
examples_ibv_devinfo_SOURCES = examples/devinfo.c
examples_ibv_devinfo_LDADD = $(top_builddir)/src/libibverbs.la
-examples_ibv_rc_pingpong_SOURCES = examples/rc_pingpong.c
+examples_ibv_rc_pingpong_SOURCES = examples/rc_pingpong.c examples/pingpong.c
examples_ibv_rc_pingpong_LDADD = $(top_builddir)/src/libibverbs.la
-examples_ibv_uc_pingpong_SOURCES = examples/uc_pingpong.c
+examples_ibv_uc_pingpong_SOURCES = examples/uc_pingpong.c examples/pingpong.c
examples_ibv_uc_pingpong_LDADD = $(top_builddir)/src/libibverbs.la
-examples_ibv_ud_pingpong_SOURCES = examples/ud_pingpong.c
+examples_ibv_ud_pingpong_SOURCES = examples/ud_pingpong.c examples/pingpong.c
examples_ibv_ud_pingpong_LDADD = $(top_builddir)/src/libibverbs.la
-examples_ibv_srq_pingpong_SOURCES = examples/srq_pingpong.c
+examples_ibv_srq_pingpong_SOURCES = examples/srq_pingpong.c examples/pingpong.c
examples_ibv_srq_pingpong_LDADD = $(top_builddir)/src/libibverbs.la
examples_ibv_asyncwatch_SOURCES = examples/asyncwatch.c
examples_ibv_asyncwatch_LDADD = $(top_builddir)/src/libibverbs.la
@@ -54,8 +54,9 @@ DEBIAN = debian/changelog debian/compat debian/control debian/copyright \
debian/rules
EXTRA_DIST = include/infiniband/driver.h include/infiniband/kern-abi.h \
- include/infiniband/opcode.h include/infiniband/verbs.h src/ibverbs.h \
- include/infiniband/marshall.h include/infiniband/sa-kern-abi.h include/infiniband/sa.h \
+ include/infiniband/opcode.h include/infiniband/verbs.h include/infiniband/marshall.h \
+ include/infiniband/sa-kern-abi.h include/infiniband/sa.h \
+ src/ibverbs.h examples/pingpong.h \
src/libibverbs.map libibverbs.spec.in $(man_MANS) $(DEBIAN)
dist-hook: libibverbs.spec
diff --git a/examples/pingpong.c b/examples/pingpong.c
new file mode 100644
index 0000000..b6d637d
--- /dev/null
+++ b/examples/pingpong.c
@@ -0,0 +1,47 @@
+/*
+ * Copyright (c) 2006 Cisco Systems. All rights reserved.
+ *
+ * This software is available to you under a choice of one of two
+ * licenses. You may choose to be licensed under the terms of the GNU
+ * General Public License (GPL) Version 2, available from the file
+ * COPYING in the main directory of this source tree, or the
+ * OpenIB.org BSD license below:
+ *
+ * Redistribution and use in source and binary forms, with or
+ * without modification, are permitted provided that the following
+ * conditions are met:
+ *
+ * - Redistributions of source code must retain the above
+ * copyright notice, this list of conditions and the following
+ * disclaimer.
+ *
+ * - Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following
+ * disclaimer in the documentation and/or other materials
+ * provided with the distribution.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
+ * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
+ * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ *
+ * $Id$
+ */
+
+#include "pingpong.h"
+
+enum ibv_mtu pp_mtu_to_enum(int mtu)
+{
+ switch (mtu) {
+ case 256: return IBV_MTU_256;
+ case 512: return IBV_MTU_512;
+ case 1024: return IBV_MTU_1024;
+ case 2048: return IBV_MTU_2048;
+ case 4096: return IBV_MTU_4096;
+ default: return -1;
+ }
+}
diff --git a/examples/pingpong.h b/examples/pingpong.h
new file mode 100644
index 0000000..67ec641
--- /dev/null
+++ b/examples/pingpong.h
@@ -0,0 +1,42 @@
+/*
+ * Copyright (c) 2006 Cisco Systems. All rights reserved.
+ *
+ * This software is available to you under a choice of one of two
+ * licenses. You may choose to be licensed under the terms of the GNU
+ * General Public License (GPL) Version 2, available from the file
+ * COPYING in the main directory of this source tree, or the
+ * OpenIB.org BSD license below:
+ *
+ * Redistribution and use in source and binary forms, with or
+ * without modification, are permitted provided that the following
+ * conditions are met:
+ *
+ * - Redistributions of source code must retain the above
+ * copyright notice, this list of conditions and the following
+ * disclaimer.
+ *
+ * - Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following
+ * disclaimer in the documentation and/or other materials
+ * provided with the distribution.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
+ * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
+ * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ *
+ * $Id$
+ */
+
+#ifndef IBV_PINGPONG_H
+#define IBV_PINGPONG_H
+
+#include <infiniband/verbs.h>
+
+enum ibv_mtu pp_mtu_to_enum(int mtu);
+
+#endif /* IBV_PINGPONG_H */
diff --git a/examples/rc_pingpong.c b/examples/rc_pingpong.c
index 6c4ef9d..41630c6 100644
--- a/examples/rc_pingpong.c
+++ b/examples/rc_pingpong.c
@@ -49,9 +49,7 @@
#include <arpa/inet.h>
#include <time.h>
-#include <sysfs/libsysfs.h>
-
-#include <infiniband/verbs.h>
+#include "pingpong.h"
enum {
PINGPONG_RECV_WRID = 1,
@@ -90,11 +88,11 @@ static uint16_t pp_get_local_lid(struct pingpong_context *ctx, int port)
}
static int pp_connect_ctx(struct pingpong_context *ctx, int port, int my_psn,
- struct pingpong_dest *dest)
+ enum ibv_mtu mtu, struct pingpong_dest *dest)
{
struct ibv_qp_attr attr = {
.qp_state = IBV_QPS_RTR,
- .path_mtu = IBV_MTU_1024,
+ .path_mtu = mtu,
.dest_qp_num = dest->qpn,
.rq_psn = dest->psn,
.max_dest_rd_atomic = 1,
@@ -204,7 +202,7 @@ out:
}
static struct pingpong_dest *pp_server_exch_dest(struct pingpong_context *ctx,
- int ib_port, int port,
+ int ib_port, enum ibv_mtu mtu, int port,
const struct pingpong_dest *my_dest)
{
struct addrinfo *res, *t;
@@ -269,7 +267,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, mtu, rem_dest)) {
fprintf(stderr, "Couldn't connect to remote QP\n");
free(rem_dest);
rem_dest = NULL;
@@ -440,6 +438,7 @@ static void usage(const char *argv0)
printf(" -d, --ib-dev=<dev> use IB device <dev> (default first device found)\n");
printf(" -i, --ib-port=<port> use port <port> of IB device (default 1)\n");
printf(" -s, --size=<size> size of message to exchange (default 4096)\n");
+ 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(" -e, --events sleep on CQ events (default poll)\n");
@@ -458,6 +457,7 @@ int main(int argc, char *argv[])
int port = 18515;
int ib_port = 1;
int size = 4096;
+ enum ibv_mtu mtu = IBV_MTU_1024;
int rx_depth = 500;
int iters = 1000;
int use_event = 0;
@@ -474,13 +474,14 @@ int main(int argc, char *argv[])
{ .name = "ib-dev", .has_arg = 1, .val = 'd' },
{ .name = "ib-port", .has_arg = 1, .val = 'i' },
{ .name = "size", .has_arg = 1, .val = 's' },
+ { .name = "mtu", .has_arg = 1, .val = 'm' },
{ .name = "rx-depth", .has_arg = 1, .val = 'r' },
{ .name = "iters", .has_arg = 1, .val = 'n' },
{ .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:m:r:n:e", long_options, NULL);
if (c == -1)
break;
@@ -509,6 +510,13 @@ int main(int argc, char *argv[])
size = strtol(optarg, NULL, 0);
break;
+ case 'm':
+ mtu = pp_mtu_to_enum(strtol(optarg, NULL, 0));
+ if (mtu < 0) {
+ usage(argv[0]);
+ return 1;
+ }
+
case 'r':
rx_depth = strtol(optarg, NULL, 0);
break;
@@ -588,7 +596,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, mtu, port, &my_dest);
if (!rem_dest)
return 1;
@@ -597,7 +605,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, mtu, rem_dest))
return 1;
ctx->pending = PINGPONG_RECV_WRID;
diff --git a/examples/srq_pingpong.c b/examples/srq_pingpong.c
index bc1d2e6..48e1ca9 100644
--- a/examples/srq_pingpong.c
+++ b/examples/srq_pingpong.c
@@ -49,9 +49,7 @@
#include <arpa/inet.h>
#include <time.h>
-#include <sysfs/libsysfs.h>
-
-#include <infiniband/verbs.h>
+#include "pingpong.h"
enum {
PINGPONG_RECV_WRID = 1,
@@ -93,7 +91,7 @@ static uint16_t pp_get_local_lid(struct pingpong_context *ctx, int port)
return attr.lid;
}
-static int pp_connect_ctx(struct pingpong_context *ctx, int port,
+static int pp_connect_ctx(struct pingpong_context *ctx, int port, enum ibv_mtu mtu,
const struct pingpong_dest *my_dest,
const struct pingpong_dest *dest)
{
@@ -102,7 +100,7 @@ static int pp_connect_ctx(struct pingpong_context *ctx, int port,
for (i = 0; i < ctx->num_qp; ++i) {
struct ibv_qp_attr attr = {
.qp_state = IBV_QPS_RTR,
- .path_mtu = IBV_MTU_1024,
+ .path_mtu = mtu,
.dest_qp_num = dest[i].qpn,
.rq_psn = dest[i].psn,
.max_dest_rd_atomic = 1,
@@ -226,7 +224,7 @@ out:
}
static struct pingpong_dest *pp_server_exch_dest(struct pingpong_context *ctx,
- int ib_port, int port,
+ int ib_port, enum ibv_mtu mtu, int port,
const struct pingpong_dest *my_dest)
{
struct addrinfo *res, *t;
@@ -301,7 +299,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, my_dest, rem_dest)) {
+ if (pp_connect_ctx(ctx, ib_port, mtu, my_dest, rem_dest)) {
fprintf(stderr, "Couldn't connect to remote QP\n");
free(rem_dest);
rem_dest = NULL;
@@ -501,6 +499,7 @@ static void usage(const char *argv0)
printf(" -d, --ib-dev=<dev> use IB device <dev> (default first device found)\n");
printf(" -i, --ib-port=<port> use port <port> of IB device (default 1)\n");
printf(" -s, --size=<size> size of message to exchange (default 4096)\n");
+ printf(" -m, --mtu=<size> path MTU (default 1024)\n");
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");
@@ -521,6 +520,7 @@ int main(int argc, char *argv[])
int port = 18515;
int ib_port = 1;
int size = 4096;
+ enum ibv_mtu mtu = IBV_MTU_1024;
int num_qp = 16;
int rx_depth = 500;
int iters = 1000;
@@ -540,6 +540,7 @@ int main(int argc, char *argv[])
{ .name = "ib-dev", .has_arg = 1, .val = 'd' },
{ .name = "ib-port", .has_arg = 1, .val = 'i' },
{ .name = "size", .has_arg = 1, .val = 's' },
+ { .name = "mtu", .has_arg = 1, .val = 'm' },
{ .name = "num-qp", .has_arg = 1, .val = 'q' },
{ .name = "rx-depth", .has_arg = 1, .val = 'r' },
{ .name = "iters", .has_arg = 1, .val = 'n' },
@@ -547,7 +548,7 @@ int main(int argc, char *argv[])
{ 0 }
};
- c = getopt_long(argc, argv, "p:d:i:s:q:r:n:e", long_options, NULL);
+ c = getopt_long(argc, argv, "p:d:i:s:m:q:r:n:e", long_options, NULL);
if (c == -1)
break;
@@ -576,6 +577,13 @@ int main(int argc, char *argv[])
size = strtol(optarg, NULL, 0);
break;
+ case 'm':
+ mtu = pp_mtu_to_enum(strtol(optarg, NULL, 0));
+ if (mtu < 0) {
+ usage(argv[0]);
+ return 1;
+ }
+
case 'q':
num_qp = strtol(optarg, NULL, 0);
break;
@@ -673,7 +681,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, mtu, port, my_dest);
if (!rem_dest)
return 1;
@@ -683,7 +691,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, my_dest, rem_dest))
+ if (pp_connect_ctx(ctx, ib_port, mtu, my_dest, rem_dest))
return 1;
if (servername)
diff --git a/examples/uc_pingpong.c b/examples/uc_pingpong.c
index 08266d4..aeeb871 100644
--- a/examples/uc_pingpong.c
+++ b/examples/uc_pingpong.c
@@ -49,9 +49,7 @@
#include <arpa/inet.h>
#include <time.h>
-#include <sysfs/libsysfs.h>
-
-#include <infiniband/verbs.h>
+#include "pingpong.h"
enum {
PINGPONG_RECV_WRID = 1,
@@ -90,11 +88,11 @@ static uint16_t pp_get_local_lid(struct pingpong_context *ctx, int port)
}
static int pp_connect_ctx(struct pingpong_context *ctx, int port, int my_psn,
- struct pingpong_dest *dest)
+ enum ibv_mtu mtu, struct pingpong_dest *dest)
{
struct ibv_qp_attr attr = {
.qp_state = IBV_QPS_RTR,
- .path_mtu = IBV_MTU_1024,
+ .path_mtu = mtu,
.dest_qp_num = dest->qpn,
.rq_psn = dest->psn,
.ah_attr = {
@@ -192,7 +190,7 @@ out:
}
static struct pingpong_dest *pp_server_exch_dest(struct pingpong_context *ctx,
- int ib_port, int port,
+ int ib_port, enum ibv_mtu mtu, int port,
const struct pingpong_dest *my_dest)
{
struct addrinfo *res, *t;
@@ -257,7 +255,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, mtu, rem_dest)) {
fprintf(stderr, "Couldn't connect to remote QP\n");
free(rem_dest);
rem_dest = NULL;
@@ -428,6 +426,7 @@ static void usage(const char *argv0)
printf(" -d, --ib-dev=<dev> use IB device <dev> (default first device found)\n");
printf(" -i, --ib-port=<port> use port <port> of IB device (default 1)\n");
printf(" -s, --size=<size> size of message to exchange (default 4096)\n");
+ 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(" -e, --events sleep on CQ events (default poll)\n");
@@ -446,6 +445,7 @@ int main(int argc, char *argv[])
int port = 18515;
int ib_port = 1;
int size = 4096;
+ enum ibv_mtu mtu = IBV_MTU_1024;
int rx_depth = 500;
int iters = 1000;
int use_event = 0;
@@ -462,13 +462,14 @@ int main(int argc, char *argv[])
{ .name = "ib-dev", .has_arg = 1, .val = 'd' },
{ .name = "ib-port", .has_arg = 1, .val = 'i' },
{ .name = "size", .has_arg = 1, .val = 's' },
+ { .name = "mtu", .has_arg = 1, .val = 'm' },
{ .name = "rx-depth", .has_arg = 1, .val = 'r' },
{ .name = "iters", .has_arg = 1, .val = 'n' },
{ .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:m:r:n:e", long_options, NULL);
if (c == -1)
break;
@@ -497,6 +498,13 @@ int main(int argc, char *argv[])
size = strtol(optarg, NULL, 0);
break;
+ case 'm':
+ mtu = pp_mtu_to_enum(strtol(optarg, NULL, 0));
+ if (mtu < 0) {
+ usage(argv[0]);
+ return 1;
+ }
+
case 'r':
rx_depth = strtol(optarg, NULL, 0);
break;
@@ -576,7 +584,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, mtu, port, &my_dest);
if (!rem_dest)
return 1;
@@ -585,7 +593,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, mtu, rem_dest))
return 1;
ctx->pending = PINGPONG_RECV_WRID;
diff --git a/examples/ud_pingpong.c b/examples/ud_pingpong.c
index fd9bd42..fbaa3f1 100644
--- a/examples/ud_pingpong.c
+++ b/examples/ud_pingpong.c
@@ -49,9 +49,7 @@
#include <arpa/inet.h>
#include <time.h>
-#include <sysfs/libsysfs.h>
-
-#include <infiniband/verbs.h>
+#include "pingpong.h"
enum {
PINGPONG_RECV_WRID = 1,