[openib-general] [PATCH] change MAD completion processing to use workqueue

Sean Hefty mshefty at ichips.intel.com
Wed Oct 27 11:59:22 PDT 2004


Index: access/ib_mad_priv.h
===================================================================
--- access/ib_mad_priv.h	(revision 1078)
+++ access/ib_mad_priv.h	(working copy)
@@ -153,6 +153,7 @@
 	struct ib_mad_mgmt_class_table *version[MAX_MGMT_VERSION];
 	struct list_head agent_list;
 	struct workqueue_struct *wq;
+	struct work_struct work;
 
 	spinlock_t send_list_lock;
 	struct list_head send_posted_mad_list;
@@ -162,9 +163,6 @@
 	struct list_head recv_posted_mad_list[IB_MAD_QPS_CORE];
 	int recv_posted_mad_count[IB_MAD_QPS_CORE];
 	u32 recv_wr_index[IB_MAD_QPS_CORE];
-
-	struct task_struct *mad_thread;
-	int thread_wake;
 };
 
 #endif	/* __IB_MAD_PRIV_H__ */
Index: access/ib_mad.c
===================================================================
--- access/ib_mad.c	(revision 1078)
+++ access/ib_mad.c	(working copy)
@@ -1158,10 +1158,12 @@
 /*
  * IB MAD completion callback
  */
-static void ib_mad_completion_handler(struct ib_mad_port_private *port_priv)
+static void ib_mad_completion_handler(void *data)
 {
+	struct ib_mad_port_private *port_priv;
 	struct ib_wc wc;
 
+	port_priv = (struct ib_mad_port_private*)data;
 	ib_req_notify_cq(port_priv->cq, IB_CQ_NEXT_COMP);
 	
 	while (ib_poll_cq(port_priv->cq, 1, &wc) == 1) {
@@ -1333,57 +1335,10 @@
 	spin_unlock_irqrestore(&mad_agent_priv->lock, flags);
 }
 
-/*
- * IB MAD thread
- */
-static int ib_mad_thread(void *param)
-{
-	struct ib_mad_port_private *port_priv = param;
-
-	__set_current_state(TASK_RUNNING);
-
-	do {
-		port_priv->thread_wake = 0;
-		wmb();
-
-		ib_mad_completion_handler(port_priv);
-
-		set_current_state(TASK_INTERRUPTIBLE);
-		if (!port_priv->thread_wake)
-			schedule();
-		__set_current_state(TASK_RUNNING);
-	} while (!kthread_should_stop());
-
-	return 0;
-}
-
-/*
- * Initialize the IB MAD thread
- */
-static int ib_mad_thread_init(struct ib_mad_port_private *port_priv)
-{
-	port_priv->thread_wake = 0;
-
-	port_priv->mad_thread = kthread_create(ib_mad_thread,
-					       port_priv,
-					       "ib_mad(%6s-%-2d)",
-					       port_priv->device->name,
-					       port_priv->port_num);
-	if (IS_ERR(port_priv->mad_thread)) {
-		printk(KERN_ERR PFX "Couldn't start ib_mad thread for %s port %d\n",
-		       port_priv->device->name, port_priv->port_num);
-		return PTR_ERR(port_priv->mad_thread);
-	}	
-	return 0;
-}
-
 static void ib_mad_thread_completion_handler(struct ib_cq *cq)
 {
 	struct ib_mad_port_private *port_priv = cq->cq_context;
-
-	port_priv->thread_wake = 1;
-	wmb();
-	wake_up_process(port_priv->mad_thread);
+	queue_work(port_priv->wq, &port_priv->work);
 }
 
 static int ib_mad_post_receive_mad(struct ib_mad_port_private *port_priv,
@@ -1845,15 +1800,12 @@
 		ret = -ENOMEM;
 		goto error8;
 	}
-
-	ret = ib_mad_thread_init(port_priv);
-	if (ret)
-		goto error9;
+	INIT_WORK(&port_priv->work, ib_mad_completion_handler, port_priv);
 
 	ret = ib_mad_port_start(port_priv);
 	if (ret) {
 		printk(KERN_ERR PFX "Couldn't start port\n");
-		goto error10;
+		goto error9;
 	}
 
 	spin_lock_irqsave(&ib_mad_port_list_lock, flags);
@@ -1862,8 +1814,6 @@
 
 	return 0;
 
-error10:
-	kthread_stop(port_priv->mad_thread);
 error9:
 	destroy_workqueue(port_priv->wq);
 error8:
@@ -1903,7 +1853,7 @@
 	spin_unlock_irqrestore(&ib_mad_port_list_lock, flags);
 
 	ib_mad_port_stop(port_priv);
-	kthread_stop(port_priv->mad_thread);
+	flush_workqueue(port_priv->wq);
 	destroy_workqueue(port_priv->wq);
 	ib_destroy_qp(port_priv->qp[1]);
 	ib_destroy_qp(port_priv->qp[0]);

-- 



More information about the general mailing list