From 91f6faf31920e0823aa6cb98f22ec39dbe661891 Mon Sep 17 00:00:00 2001 From: Roland Dreier Date: Sat, 7 Jan 2006 01:06:03 +0000 Subject: [PATCH] Fix ibv_srq_pingpong bug with many QPs when using CQ events Fix SRQ example to avoid problems with many QPs and events. Based on a patch from Dotan Barak (who also found the problem). Signed-off-by: Roland Dreier --- ChangeLog | 6 ++++++ examples/srq_pingpong.c | 17 ++++++++++++++--- 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/ChangeLog b/ChangeLog index 692f55d..fc1c03f 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2006-01-06 Roland Dreier + + * examples/srq_pingpong.c (main): Fix SRQ example to avoid + problems with many QPs and events. Based on a patch from Dotan + Barak (who also found the problem). + 2006-01-06 Ralph Campbell * examples/rc_pingpong.c (main), examples/srq_pingpong.c (main), diff --git a/examples/srq_pingpong.c b/examples/srq_pingpong.c index 70c59ab..836ddc9 100644 --- a/examples/srq_pingpong.c +++ b/examples/srq_pingpong.c @@ -511,6 +511,7 @@ int main(int argc, char *argv[]) { struct ibv_device **dev_list; struct ibv_device *ib_dev; + struct ibv_wc *wc; struct pingpong_context *ctx; struct pingpong_dest my_dest[MAX_QP]; struct pingpong_dest *rem_dest; @@ -526,6 +527,7 @@ int main(int argc, char *argv[]) int use_event = 0; int routs; int rcnt, scnt; + int num_wc; int i; srand48(getpid() * time(NULL)); @@ -603,6 +605,16 @@ int main(int argc, char *argv[]) return 1; } + if (num_qp > rx_depth) { + fprintf(stderr, "rx_depth %d is too small for %d QPs -- " + "must have at least one receive per QP.\n", + rx_depth, num_qp); + return 1; + } + + num_wc = num_qp + rx_depth; + wc = alloca(num_wc * sizeof *wc); + page_size = sysconf(_SC_PAGESIZE); dev_list = ibv_get_device_list(NULL); @@ -714,11 +726,10 @@ int main(int argc, char *argv[]) } { - struct ibv_wc wc[2]; int ne, qp_ind; do { - ne = ibv_poll_cq(ctx->cq, 2, wc); + ne = ibv_poll_cq(ctx->cq, num_wc, wc); if (ne < 0) { fprintf(stderr, "poll CQ failed %d\n", ne); return 1; @@ -745,7 +756,7 @@ int main(int argc, char *argv[]) break; case PINGPONG_RECV_WRID: - if (--routs <= 1) { + if (--routs <= num_qp) { routs += pp_post_recv(ctx, ctx->rx_depth - routs); if (routs < ctx->rx_depth) { fprintf(stderr, -- 2.41.0