Added resource cleaning before end of pingpong tests + ack to CQ events.

Signed-off-by: Dotan Barak <[EMAIL PROTECTED]>
---

Index: gen2_devel_user/src/userspace/libibverbs/examples/rc_pingpong.c
===================================================================
--- gen2_devel_user.orig/src/userspace/libibverbs/examples/rc_pingpong.c        
2007-01-17 10:58:02.000000000 +0200
+++ gen2_devel_user/src/userspace/libibverbs/examples/rc_pingpong.c     
2007-01-17 11:09:59.000000000 +0200
@@ -322,7 +322,7 @@ static struct pingpong_context *pp_init_
 
        ctx->mr = ibv_reg_mr(ctx->pd, ctx->buf, size, IBV_ACCESS_LOCAL_WRITE);
        if (!ctx->mr) {
-               fprintf(stderr, "Couldn't allocate MR\n");
+               fprintf(stderr, "Couldn't register MR\n");
                return NULL;
        }
 
@@ -374,6 +374,46 @@ static struct pingpong_context *pp_init_
        return ctx;
 }
 
+int pp_close_ctx(struct pingpong_context *ctx)
+{
+       if (ibv_destroy_qp(ctx->qp)) {
+               fprintf(stderr, "Couldn't destroy QP\n");
+               return 1;
+       }
+
+       if (ibv_destroy_cq(ctx->cq)) {
+               fprintf(stderr, "Couldn't destroy CQ\n");
+               return 1;
+       }
+
+       if (ibv_dereg_mr(ctx->mr)) {
+               fprintf(stderr, "Couldn't deregister MR\n");
+               return 1;
+       }
+
+       if (ibv_dealloc_pd(ctx->pd)) {
+               fprintf(stderr, "Couldn't deallocate PD\n");
+               return 1;
+       }
+
+       if (ctx->channel) {
+               if (ibv_destroy_comp_channel(ctx->channel)) {
+                       fprintf(stderr, "Couldn't destroy completion 
channel\n");
+                       return 1;
+               }
+       }
+
+       if (ibv_close_device(ctx->context)) {
+               fprintf(stderr, "Couldn't release context\n");
+               return 1;
+       }
+
+       free(ctx->buf);
+       free(ctx);
+
+       return 0;
+}
+
 static int pp_post_recv(struct pingpong_context *ctx, int n)
 {
        struct ibv_sge list = {
@@ -451,6 +491,7 @@ int main(int argc, char *argv[])
        int                      use_event = 0;
        int                      routs;
        int                      rcnt, scnt;
+       int                      num_of_events = 0;
 
        srand48(getpid() * time(NULL));
 
@@ -622,6 +663,8 @@ int main(int argc, char *argv[])
                                return 1;
                        }
 
+                       ++num_of_events;
+
                        if (ev_cq != ctx->cq) {
                                fprintf(stderr, "CQ event for unknown CQ %p\n", 
ev_cq);
                                return 1;
@@ -706,5 +749,13 @@ int main(int argc, char *argv[])
                       iters, usec / 1000000., usec / iters);
        }
 
+       ibv_ack_cq_events(ctx->cq, num_of_events);
+
+       if (pp_close_ctx(ctx))
+               return 1;
+
+       ibv_free_device_list(dev_list);
+       free(rem_dest);
+
        return 0;
 }
Index: gen2_devel_user/src/userspace/libibverbs/examples/srq_pingpong.c
===================================================================
--- gen2_devel_user.orig/src/userspace/libibverbs/examples/srq_pingpong.c       
2007-01-17 10:58:02.000000000 +0200
+++ gen2_devel_user/src/userspace/libibverbs/examples/srq_pingpong.c    
2007-01-17 11:10:31.000000000 +0200
@@ -358,7 +358,7 @@ static struct pingpong_context *pp_init_
 
        ctx->mr = ibv_reg_mr(ctx->pd, ctx->buf, size, IBV_ACCESS_LOCAL_WRITE);
        if (!ctx->mr) {
-               fprintf(stderr, "Couldn't allocate MR\n");
+               fprintf(stderr, "Couldn't register MR\n");
                return NULL;
        }
 
@@ -424,6 +424,55 @@ static struct pingpong_context *pp_init_
        return ctx;
 }
 
+int pp_close_ctx(struct pingpong_context *ctx, int num_qp)
+{
+       int i;
+
+       for (i = 0; i < num_qp; ++i) {
+               if (ibv_destroy_qp(ctx->qp[i])) {
+                       fprintf(stderr, "Couldn't destroy QP[%d]\n", i);
+                       return 1;
+               }
+       }
+
+       if (ibv_destroy_srq(ctx->srq)) {
+               fprintf(stderr, "Couldn't destroy SRQ\n");
+               return 1;
+       }
+
+       if (ibv_destroy_cq(ctx->cq)) {
+               fprintf(stderr, "Couldn't destroy CQ\n");
+               return 1;
+       }
+
+       if (ibv_dereg_mr(ctx->mr)) {
+               fprintf(stderr, "Couldn't deregister MR\n");
+               return 1;
+       }
+
+       if (ibv_dealloc_pd(ctx->pd)) {
+               fprintf(stderr, "Couldn't deallocate PD\n");
+               return 1;
+       }
+
+       if (ctx->channel) {
+               if (ibv_destroy_comp_channel(ctx->channel)) {
+                       fprintf(stderr, "Couldn't destroy completion 
channel\n");
+                       return 1;
+               }
+       }
+
+       if (ibv_close_device(ctx->context)) {
+               fprintf(stderr, "Couldn't release context\n");
+               return 1;
+       }
+
+       free(ctx->buf);
+       free(ctx);
+
+       return 0;
+}
+
 static int pp_post_recv(struct pingpong_context *ctx, int n)
 {
        struct ibv_sge list = {
@@ -517,6 +566,7 @@ int main(int argc, char *argv[])
        int                      rcnt, scnt;
        int                      num_wc;
        int                      i;
+       int                      num_of_events = 0;
 
        srand48(getpid() * time(NULL));
 
@@ -710,6 +760,8 @@ int main(int argc, char *argv[])
                                return 1;
                        }
 
+                       ++num_of_events;
+
                        if (ev_cq != ctx->cq) {
                                fprintf(stderr, "CQ event for unknown CQ %p\n", 
ev_cq);
                                return 1;
@@ -801,5 +853,13 @@ int main(int argc, char *argv[])
                       iters, usec / 1000000., usec / iters);
        }
 
+       ibv_ack_cq_events(ctx->cq, num_of_events);
+
+       if (pp_close_ctx(ctx, num_qp))
+               return 1;
+
+       ibv_free_device_list(dev_list);
+       free(rem_dest);
+
        return 0;
 }
Index: gen2_devel_user/src/userspace/libibverbs/examples/uc_pingpong.c
===================================================================
--- gen2_devel_user.orig/src/userspace/libibverbs/examples/uc_pingpong.c        
2007-01-17 10:58:02.000000000 +0200
+++ gen2_devel_user/src/userspace/libibverbs/examples/uc_pingpong.c     
2007-01-17 11:10:11.000000000 +0200
@@ -310,7 +310,7 @@ static struct pingpong_context *pp_init_
 
        ctx->mr = ibv_reg_mr(ctx->pd, ctx->buf, size, IBV_ACCESS_LOCAL_WRITE);
        if (!ctx->mr) {
-               fprintf(stderr, "Couldn't allocate MR\n");
+               fprintf(stderr, "Couldn't register MR\n");
                return NULL;
        }
 
@@ -362,6 +362,46 @@ static struct pingpong_context *pp_init_
        return ctx;
 }
 
+int pp_close_ctx(struct pingpong_context *ctx)
+{
+       if (ibv_destroy_qp(ctx->qp)) {
+               fprintf(stderr, "Couldn't destroy QP\n");
+               return 1;
+       }
+
+       if (ibv_destroy_cq(ctx->cq)) {
+               fprintf(stderr, "Couldn't destroy CQ\n");
+               return 1;
+       }
+
+       if (ibv_dereg_mr(ctx->mr)) {
+               fprintf(stderr, "Couldn't deregister MR\n");
+               return 1;
+       }
+
+       if (ibv_dealloc_pd(ctx->pd)) {
+               fprintf(stderr, "Couldn't deallocate PD\n");
+               return 1;
+       }
+
+       if (ctx->channel) {
+               if (ibv_destroy_comp_channel(ctx->channel)) {
+                       fprintf(stderr, "Couldn't destroy completion 
channel\n");
+                       return 1;
+               }
+       }
+
+       if (ibv_close_device(ctx->context)) {
+               fprintf(stderr, "Couldn't release context\n");
+               return 1;
+       }
+
+       free(ctx->buf);
+       free(ctx);
+
+       return 0;
+}
+
 static int pp_post_recv(struct pingpong_context *ctx, int n)
 {
        struct ibv_sge list = {
@@ -439,6 +479,7 @@ int main(int argc, char *argv[])
        int                      use_event = 0;
        int                      routs;
        int                      rcnt, scnt;
+       int                      num_of_events = 0;
 
        srand48(getpid() * time(NULL));
 
@@ -610,6 +651,8 @@ int main(int argc, char *argv[])
                                return 1;
                        }
 
+                       ++num_of_events;
+
                        if (ev_cq != ctx->cq) {
                                fprintf(stderr, "CQ event for unknown CQ %p\n", 
ev_cq);
                                return 1;
@@ -694,5 +737,13 @@ int main(int argc, char *argv[])
                       iters, usec / 1000000., usec / iters);
        }
 
+       ibv_ack_cq_events(ctx->cq, num_of_events);
+
+       if (pp_close_ctx(ctx))
+               return 1;
+
+       ibv_free_device_list(dev_list);
+       free(rem_dest);
+
        return 0;
 }
Index: gen2_devel_user/src/userspace/libibverbs/examples/ud_pingpong.c
===================================================================
--- gen2_devel_user.orig/src/userspace/libibverbs/examples/ud_pingpong.c        
2007-01-17 10:58:02.000000000 +0200
+++ gen2_devel_user/src/userspace/libibverbs/examples/ud_pingpong.c     
2007-01-17 11:10:20.000000000 +0200
@@ -311,7 +311,7 @@ static struct pingpong_context *pp_init_
 
        ctx->mr = ibv_reg_mr(ctx->pd, ctx->buf, size + 40, 
IBV_ACCESS_LOCAL_WRITE);
        if (!ctx->mr) {
-               fprintf(stderr, "Couldn't allocate MR\n");
+               fprintf(stderr, "Couldn't register MR\n");
                return NULL;
        }
 
@@ -363,6 +363,51 @@ static struct pingpong_context *pp_init_
        return ctx;
 }
 
+int pp_close_ctx(struct pingpong_context *ctx)
+{
+       if (ibv_destroy_qp(ctx->qp)) {
+               fprintf(stderr, "Couldn't destroy QP\n");
+               return 1;
+       }
+
+       if (ibv_destroy_cq(ctx->cq)) {
+               fprintf(stderr, "Couldn't destroy CQ\n");
+               return 1;
+       }
+
+       if (ibv_dereg_mr(ctx->mr)) {
+               fprintf(stderr, "Couldn't deregister MR\n");
+               return 1;
+       }
+
+       if (ibv_destroy_ah(ctx->ah)) {
+               fprintf(stderr, "Couldn't destroy AH\n");
+               return 1;
+       }
+
+       if (ibv_dealloc_pd(ctx->pd)) {
+               fprintf(stderr, "Couldn't deallocate PD\n");
+               return 1;
+       }
+
+       if (ctx->channel) {
+               if (ibv_destroy_comp_channel(ctx->channel)) {
+                       fprintf(stderr, "Couldn't destroy completion 
channel\n");
+                       return 1;
+               }
+       }
+
+       if (ibv_close_device(ctx->context)) {
+               fprintf(stderr, "Couldn't release context\n");
+               return 1;
+       }
+
+       free(ctx->buf);
+       free(ctx);
+
+       return 0;
+}
+
 static int pp_post_recv(struct pingpong_context *ctx, int n)
 {
        struct ibv_sge list = {
@@ -445,6 +490,7 @@ int main(int argc, char *argv[])
        int                      use_event = 0;
        int                      routs;
        int                      rcnt, scnt;
+       int                      num_of_events = 0;
 
        srand48(getpid() * time(NULL));
 
@@ -608,6 +654,8 @@ int main(int argc, char *argv[])
                                return 1;
                        }
 
+                       ++num_of_events;
+
                        if (ev_cq != ctx->cq) {
                                fprintf(stderr, "CQ event for unknown CQ %p\n", 
ev_cq);
                                return 1;
@@ -692,5 +740,13 @@ int main(int argc, char *argv[])
                       iters, usec / 1000000., usec / iters);
        }
 
+       ibv_ack_cq_events(ctx->cq, num_of_events);
+
+       if (pp_close_ctx(ctx))
+               return 1;
+
+       ibv_free_device_list(dev_list);
+       free(rem_dest);
+
        return 0;
 }



_______________________________________________
openib-general mailing list
[email protected]
http://openib.org/mailman/listinfo/openib-general

To unsubscribe, please visit http://openib.org/mailman/listinfo/openib-general

Reply via email to