PERFORCE change 137346 for review

Steve Wise swise at FreeBSD.org
Mon Mar 10 20:25:03 UTC 2008


http://perforce.freebsd.org/chv.cgi?CH=137346

Change 137346 by swise at swise:vic10:iwarp on 2008/03/10 20:24:16

	Process all socket upcalls on a thread.

Affected files ...

.. //depot/projects/iwarp/sys/dev/cxgb/ulp/iw_cxgb/iw_cxgb_cm.c#8 edit
.. //depot/projects/iwarp/sys/dev/cxgb/ulp/iw_cxgb/iw_cxgb_cm.h#3 edit

Differences ...

==== //depot/projects/iwarp/sys/dev/cxgb/ulp/iw_cxgb/iw_cxgb_cm.c#8 (text+ko) ====

@@ -158,6 +158,15 @@
 static void connect_reply_upcall(struct iwch_ep *ep, int status);
 static void iwch_so_upcall(struct socket *so, void *arg, int waitflag);
 
+/*
+ * Cruft to offload socket upcalls onto thread.
+ */
+static struct mtx req_lock;
+static TAILQ_HEAD(iwch_ep_list, iwch_ep_common) req_list;
+static struct task iw_cxgb_task;
+static struct taskqueue *iw_cxgb_taskq;
+static void process_req(void *ctx, int pending);
+
 static void
 start_ep_timer(struct iwch_ep *ep)
 {
@@ -265,8 +274,8 @@
 void __free_ep(struct iwch_ep_common *epc)
 {
 	PDBG("%s ep %p state %s\n", __FUNCTION__, epc, states[state_read(epc)]);
-	if (epc->so)
-		printf("%s warning ep->so %p \n", __FUNCTION__, epc->so);
+	KASSERT(!epc->so, ("%s warning ep->so %p \n", __FUNCTION__, epc->so));
+	KASSERT(!epc->entry.tqe_prev, ("%s epc %p still on req list!\n", __FUNCTION__, epc));
 	free(epc, M_DEVBUF);
 }
 
@@ -1621,7 +1630,21 @@
 iwch_so_upcall(struct socket *so, void *arg, int waitflag)
 {
 	struct iwch_ep *ep = arg;
+
+	PDBG("%s so %p so state %x ep %p ep state(%d)=%s\n", __FUNCTION__, so, so->so_state, ep, ep->com.state, states[ep->com.state]);
+	mtx_lock(&req_lock);
+	if (ep && !ep->com.entry.tqe_prev) {
+		get_ep(&ep->com);
+		TAILQ_INSERT_TAIL(&req_list, &ep->com, entry);
+		taskqueue_enqueue(iw_cxgb_taskq, &iw_cxgb_task);
+	}
+	mtx_unlock(&req_lock);
+}
+
+static void process_socket_event(struct iwch_ep *ep)
+{
 	int state = state_read(&ep->com);
+	struct socket *so = ep->com.so;
 	
 	PDBG("%s so %p so state %x ep %p ep state(%d)=%s\n", __FUNCTION__, so, so->so_state, ep, ep->com.state, states[ep->com.state]);
 	if (state == CONNECTING) {
@@ -1641,7 +1664,7 @@
 	}
 
 	/* peer close */
-	if (so->so_state & SS_ISDISCONNECTING && state < CLOSING) {
+	if ((so->so_rcv.sb_state & SBS_CANTRCVMORE) && state < CLOSING) {
 		process_peer_close(ep);
 		return;
 	}
@@ -1657,9 +1680,37 @@
 	return;
 }
 
+static void process_req(void *ctx, int pending)
+{
+	struct iwch_ep_common *epc;
+
+	PDBG("%s enter\n", __FUNCTION__);
+	mtx_lock(&req_lock);
+	while (!TAILQ_EMPTY(&req_list)) {
+		epc = TAILQ_FIRST(&req_list);
+		TAILQ_REMOVE(&req_list, epc, entry);
+		epc->entry.tqe_prev = NULL;
+		mtx_unlock(&req_lock);
+		process_socket_event((struct iwch_ep *)epc);
+		put_ep(epc);
+		mtx_lock(&req_lock);
+	}
+	mtx_unlock(&req_lock);
+}
+
 int __init
 iwch_cm_init(void)
 {
+	TAILQ_INIT(&req_list);
+	mtx_init(&req_lock, "iw_cxgb req_list lock", NULL, MTX_DEF);
+	iw_cxgb_taskq = taskqueue_create("iw_cxgb_taskq", M_NOWAIT,
+		taskqueue_thread_enqueue, &iw_cxgb_taskq);
+        if (iw_cxgb_taskq == NULL) {
+                printf("failed to allocate iw_cxgb taskqueue\n");
+                return (ENOMEM);
+        }
+        taskqueue_start_threads(&iw_cxgb_taskq, 1, PI_NET, "iw_cxgb taskq");
+        TASK_INIT(&iw_cxgb_task, 0, process_req, NULL);
 	t3tom_register_cpl_handler(CPL_RDMA_TERMINATE, terminate);
 	t3tom_register_cpl_handler(CPL_RDMA_EC_STATUS, ec_status);
 	return 0;
@@ -1670,4 +1721,6 @@
 {
 	t3tom_register_cpl_handler(CPL_RDMA_TERMINATE, NULL);
 	t3tom_register_cpl_handler(CPL_RDMA_EC_STATUS, NULL);
+	taskqueue_drain(iw_cxgb_taskq, &iw_cxgb_task);
+	taskqueue_free(iw_cxgb_taskq);
 }

==== //depot/projects/iwarp/sys/dev/cxgb/ulp/iw_cxgb/iw_cxgb_cm.h#3 (text+ko) ====

@@ -115,6 +115,7 @@
 };
 
 struct iwch_ep_common {
+	TAILQ_ENTRY(iwch_ep_common) entry;
 	struct iw_cm_id *cm_id;
 	struct iwch_qp *qp;
 	struct t3cdev *tdev;


More information about the p4-projects mailing list