ehca: fix mismatched sync between completion handler and destroy cq
PATCH 1/1 ehca: fix mismatched sync between completion handler and destroy cq
This patch fixes two issues reported by Roland and Christoph H.:
- Mismatched sync/locking between completion handler and destroy cq We introduced a counter nr_events per cq to track number of irq events seen. This counter is incremented when an event queue entry is seen and decremented after completion handler has been called regardless if scaling code is active or not. Note that nr_callbacks tracks number of events assigned to a cpu and both counters can potentially diverge.
The sync between running completion handler and destroy cq is done by using the global spin lock ehca_cq_idr_lock.
- Replace yield by wait_event on the counter above to become zero
---
ehca_classes.h | 6 ++++- ehca_cq.c | 16 +++++++++++++-- ehca_irq.c | 59 +++++++++++++++++++++++++++++++++++++-------------------- ehca_main.c | 4 +-- 4 files changed, 60 insertions(+), 25 deletions(-)
drivers/infiniband/hw/ehca/ehca_classes.h +5 -1
@@ -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>
@@ -153,7 +155,9 @@ struct ehca_cq {spinlock_t cb_lock;struct hlist_head qp_hashtab[QP_HASHTAB_LEN ];struct list_head entry; -u32 nr_callbacks; +u32 nr_callbacks;/* #events assigned to cpu by scaling code */ +u32 nr_events;/* #events seen */ +wait_queue_head_t wait_completion;spinlock_t task_lock;u32 ownpid;/* mmap counter for resources mapped into user space */
drivers/infiniband/hw/ehca/ehca_cq.c +14 -2
@@ -146,6 +146,7 @@ struct ib_cq *ehca_create_cq(struct ib_dspin_lock_init (&my_cq->spinlock);spin_lock_init (&my_cq->cb_lock);spin_lock_init (&my_cq->task_lock); +init_waitqueue_head (&my_cq->wait_completion); my_cq->ownpid = current->tgid; cq = &my_cq->ib_cq;
@@ -302,6 +303,16 @@ create_cq_exit1:return cq; } +static int get_cq_nr_events (struct ehca_cq *my_cq) +{ +int ret; +unsigned long flags; +spin_lock_irqsave (&ehca_cq_idr_lock, flags); + ret = my_cq->nr_events; +spin_unlock_irqrestore (&ehca_cq_idr_lock, flags); +return ret; +} +int ehca_destroy_cq (struct ib_cq *cq) {u64 h_ret;
@@ -329,10 +340,11 @@ int ehca_destroy_cq(struct ib_cq *cq) }spin_lock_irqsave (&ehca_cq_idr_lock, flags); -while (my_cq->nr_callbacks) { +while (my_cq->nr_events) {spin_unlock_irqrestore (&ehca_cq_idr_lock, flags); -yield (); +wait_event (my_cq->wait_completion, !get_cq_nr_events (my_cq));spin_lock_irqsave (&ehca_cq_idr_lock, flags); +/* recheck nr_events to assure no cqe has just arrived */ }idr_remove (&ehca_cq_idr, my_cq->token);
drivers/infiniband/hw/ehca/ehca_irq.c +39 -20
127 lines not on this page · raw message
drivers/infiniband/hw/ehca/ehca_main.c +2 -2
@@ -52,7 +52,7 @@ #include "hcp_if.h"MODULE_LICENSE ("Dual BSD/GPL" );MODULE_AUTHOR ("Christoph Raisch <[email protected]>" );MODULE_DESCRIPTION ("IBM eServer HCA InfiniBand Device Driver" ); -MODULE_VERSION ("SVNEHCA_0021" ); +MODULE_VERSION ("SVNEHCA_0022" );int ehca_open_aqp1 =0 ;int ehca_debug_level =0 ;
@@ -810,7 +809,7 @@ int __init ehca_module_init(void)int ret;printk (KERN_INFO "eHCA Infiniband Device Driver " -"(Rel.: SVNEHCA_0021)\n" ); +"(Rel.: SVNEHCA_0022)\n" );idr_init (&ehca_qp_idr);idr_init (&ehca_cq_idr);spin_lock_init (&ehca_qp_idr_lock);
Looks OK to me, queued for 2.6.21, except:
Quoted 1 line
+#include <
linux/completion.h>
This can just be <linux/wait.h>, because you're only using wait_queue_head_t and not struct completion, right?
I fixed this up before merging.
Quoted 4 lines
Quoted 1 line
+#include <
linux/completion.h>This can just be <
linux/wait.h>, because you're only usingwait_queue_head_tand not struct completion, right? I fixed this up before merging.
Yes, right. Thanks for your help!
Regards
Nam