[openib-general] [PATCH] ib_mad: Use wait queue and wait_event rather than signals and semaphores

Hal Rosenstock halr at voltaire.com
Thu Sep 16 10:23:24 PDT 2004


ib_mad: Use wait queue and wait_event rather than signals and semaphores

Index: ib_mad_priv.h
===================================================================
--- ib_mad_priv.h	(revision 849)
+++ ib_mad_priv.h	(working copy)
@@ -120,9 +120,8 @@
 	struct ib_mad_mgmt_method_table *method_table[MAX_MGMT_CLASS];
 };
 
-struct ib_mad_thread_data {
-	struct semaphore sem;
-	int run;
+struct ib_mad_thread_private {
+	wait_queue_head_t	wait;
 };
 
 struct ib_mad_port_private {
@@ -147,7 +146,7 @@
 	struct list_head recv_posted_mad_list[IB_MAD_QPS_SUPPORTED];
 	int recv_posted_mad_count[IB_MAD_QPS_SUPPORTED];
 
-	struct ib_mad_thread_data thread_data;
+	struct ib_mad_thread_private mad_thread_private;
 };
 
 #endif	/* __IB_MAD_PRIV_H__ */
Index: TODO
===================================================================
--- TODO	(revision 847)
+++ TODO	(working copy)
@@ -1,9 +1,8 @@
-9/15/04
+9/16/04
 
 OpenIB MAD Layer
 
 Short Term
-Use wait queue and wait_event rather than signals and semaphores
 Send timeout support
 Treat send overruns as timeouts for now (once timeout support
implemented) ?
 
Index: ib_mad.c
===================================================================
--- ib_mad.c	(revision 852)
+++ ib_mad.c	(working copy)
@@ -879,21 +879,21 @@
 static int ib_mad_thread(void *param)
 {
 	struct ib_mad_port_private *port_priv = param;
-	struct ib_mad_thread_data *thread_data = &port_priv->thread_data;
+	struct ib_mad_thread_private *mad_thread_priv =
&port_priv->mad_thread_private;
+	int ret;
 
 	while (1) {
-		if (down_interruptible(&thread_data->sem)) {
-			printk(KERN_DEBUG "Exiting ib_mad thread\n");
-			break;
+		while (!signal_pending(current)) {
+			ret = wait_event_interruptible(mad_thread_priv->wait, 0);
+			if (ret) {
+				printk(KERN_ERR "ib_mad thread exiting\n");
+				return 0;
+			}
+
+			ib_mad_completion_handler(port_priv);
 		}
 
-		if (!thread_data->run)
-			break;
-
-		ib_mad_completion_handler(port_priv);
 	}
-
-	return 0;
 }
 
 /*
@@ -901,10 +901,10 @@
  */
 static int ib_mad_thread_init(struct ib_mad_port_private *port_priv)
 {
-	struct ib_mad_thread_data *thread_data = &port_priv->thread_data;
+	struct ib_mad_thread_private *mad_thread_priv =
&port_priv->mad_thread_private;
 
-	sema_init(&thread_data->sem, 0);
-	thread_data->run = 1;
+	init_waitqueue_head(&mad_thread_priv->wait);
+
 	port_priv->mad_thread = kthread_create(ib_mad_thread,
 					       port_priv,
 					       "ib_mad-%-6s-%-2d",
@@ -918,30 +918,19 @@
 }
 
 /*
- * Wake up the IB MAD thread
- */
-static void ib_mad_thread_signal(struct ib_mad_port_private *port_priv)
-{
-	struct ib_mad_thread_data *thread_data = &port_priv->thread_data;
-
-	up(&thread_data->sem);
-}
-
-/*
  * Stop the IB MAD thread
  */
 static void ib_mad_thread_stop(struct ib_mad_port_private *port_priv)
 {
-	struct ib_mad_thread_data *thread_data = &port_priv->thread_data;
-
-	thread_data->run = 0;
-	ib_mad_thread_signal(port_priv);
-	schedule();
+	kthread_stop(port_priv->mad_thread);
 }
 
 static void ib_mad_thread_completion_handler(struct ib_cq *cq)
 {
-	ib_mad_thread_signal(cq->cq_context);
+	struct ib_mad_port_private *port_priv = cq->cq_context;
+	struct ib_mad_thread_private *mad_thread_priv =
&port_priv->mad_thread_private;
+
+	wake_up_interruptible(&mad_thread_priv->wait);
 }
 
 static int ib_mad_post_receive_mad(struct ib_mad_port_private
*port_priv,





More information about the general mailing list