]> git.openfabrics.org - ~shefty/libibverbs.git/commitdiff
Fix ibv_srq_pingpong bug with many QPs when using CQ events
authorRoland Dreier <rolandd@cisco.com>
Sat, 7 Jan 2006 01:06:03 +0000 (01:06 +0000)
committerRoland Dreier <rolandd@cisco.com>
Thu, 9 Nov 2006 19:35:58 +0000 (11:35 -0800)
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 <rolandd@cisco.com>
ChangeLog
examples/srq_pingpong.c

index 692f55d4c5c139157cfbcf6bf235b7fb751feb5a..fc1c03fb25e404349b090b4d5801afaeddf3653b 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2006-01-06  Roland Dreier  <rdreier@cisco.com>
+
+       * 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  <ralphc@pathscale.com>
 
        * examples/rc_pingpong.c (main), examples/srq_pingpong.c (main),
index 70c59ab1e8e214e1d34e74ac697b784e58f51905..836ddc98cdfcc9c7629f088a021e1dc7bccefd4f 100644 (file)
@@ -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,