Skip to contentSkip to conversation

ehca: replace yield() by wait_for_completion()

PATCH In review Hoang-Nam Nguyen 3 participants 3 messages Feb 14, 2007 – Feb 15, 2007 InfiniBand

lore
Share & tools
lore
#0 lore raw

PATCH 4/5 ehca: replace yield() by wait_for_completion()

Hi,
this patch removes yield() and uses wait_for_completion() in order to wait for running completion handlers finished before destroying associated completion queue.
Thanks
Nam

---

 ehca_classes.h |    3 +++
 ehca_cq.c      |    3 ++-
 ehca_irq.c     |    6 +++++-
 3 files changed, 10 insertions(+), 2 deletions(-)
drivers/infiniband/hw/ehca/ehca_classes.h 2007-02-14 13:52:06.000000000 +0100 renamed from drivers/infiniband/hw/ehca/ehca_classes.h 2007-02-14 13:52:49.000000000 +0100 +3 -0
diff -Nurp infiniband_orig/drivers/infiniband/hw/ehca/ehca_classes.h infiniband_work/drivers/infiniband/hw/ehca/ehca_classes.h
@@ -52,6 +52,8 @@ struct ehca_mw;
 struct ehca_pd;
 struct ehca_av;
 
+#include <linux/completion.h>
+
 #include <rdma/ib_verbs.h>
 #include <rdma/ib_user_verbs.h>
 
@@ -154,6 +156,7 @@ struct ehca_cq {
        struct hlist_head qp_hashtab[QP_HASHTAB_LEN];
        struct list_head entry;
        u32 nr_callbacks;
+       struct completion zero_callbacks;
        spinlock_t task_lock;
        u32 ownpid;
        /* mmap counter for resources mapped into user space */
drivers/infiniband/hw/ehca/ehca_cq.c 2007-02-14 13:52:06.000000000 +0100 renamed from drivers/infiniband/hw/ehca/ehca_cq.c 2007-02-14 13:52:49.000000000 +0100 +2 -1
diff -Nurp infiniband_orig/drivers/infiniband/hw/ehca/ehca_cq.c infiniband_work/drivers/infiniband/hw/ehca/ehca_cq.c
@@ -147,6 +147,7 @@ struct ib_cq *ehca_create_cq(struct ib_d
        spin_lock_init(&my_cq->spinlock);
        spin_lock_init(&my_cq->cb_lock);
        spin_lock_init(&my_cq->task_lock);
+       init_completion(&my_cq->zero_callbacks);
        my_cq->ownpid = current->tgid;
 
        cq = &my_cq->ib_cq;
@@ -332,7 +333,7 @@ int ehca_destroy_cq(struct ib_cq *cq)
        spin_lock_irqsave(&ehca_cq_idr_lock, flags);
        while (my_cq->nr_callbacks) {
                spin_unlock_irqrestore(&ehca_cq_idr_lock, flags);
-               yield();
+               wait_for_completion(&my_cq->zero_callbacks);
                spin_lock_irqsave(&ehca_cq_idr_lock, flags);
        }
 
drivers/infiniband/hw/ehca/ehca_irq.c 2007-02-14 13:52:06.000000000 +0100 renamed from drivers/infiniband/hw/ehca/ehca_irq.c 2007-02-14 13:52:49.000000000 +0100 +5 -1
diff -Nurp infiniband_orig/drivers/infiniband/hw/ehca/ehca_irq.c infiniband_work/drivers/infiniband/hw/ehca/ehca_irq.c
@@ -605,6 +605,7 @@ static void run_comp_task(struct ehca_cp
        spin_lock_irqsave(&cct->task_lock, flags);
 
        while (!list_empty(&cct->cq_list)) {
+               int is_complete = 0;
                cq = list_entry(cct->cq_list.next, struct ehca_cq, entry);
                spin_unlock_irqrestore(&cct->task_lock, flags);
                comp_event_callback(cq);
@@ -612,11 +613,14 @@ static void run_comp_task(struct ehca_cp
 
                spin_lock(&cq->task_lock);
                cq->nr_callbacks--;
-               if (cq->nr_callbacks == 0) {
+               is_complete = (cq->nr_callbacks == 0);
+               if (is_complete) {
                        list_del_init(cct->cq_list.next);
                        cct->cq_jobs--;
                }
                spin_unlock(&cq->task_lock);
+               if (is_complete) /* wake up waiting destroy_cq() */
+                       complete(&cq->zero_callbacks);
        }
 
        spin_unlock_irqrestore(&cct->task_lock, flags);
#1 lore raw

drivers/infiniband/hw/ehca/ehca_cq.c 2007-02-14 13:52:06.000000000 +0100 int ehca_destroy_cq(struct ib_cq *cq) · line 338

Quoted 8 lines
drivers/infiniband/hw/ehca/ehca_cq.c 2007-02-14 13:52:06.000000000 +0100 renamed from drivers/infiniband/hw/ehca/ehca_cq.c 2007-02-14 13:52:49.000000000 +0100 +1 -1
@@ -332,7 +333,7 @@ int ehca_destroy_cq(struct ib_cq *cq)
        spin_lock_irqsave(&ehca_cq_idr_lock, flags);
        while (my_cq->nr_callbacks) {
                spin_unlock_irqrestore(&ehca_cq_idr_lock, flags);
-               yield();
+               wait_for_completion(&my_cq->zero_callbacks);
                spin_lock_irqsave(&ehca_cq_idr_lock, flags);
        }

A while loop around wait_for_completion doesn't make all that much sense. I suspect a simple

	if (my_cq->nr_callbacks)
		wait_for_completion(&my_cq->zero_callbacks);

Is what you need.

#2 lore raw
In reply to Hoang-Nam Nguyen

I agree with Christoph -- the use of wait_for_completion() in a loop makes no sense. When you send a new copy of this patch without whitespace damage, please fix that up too...