]> git.karo-electronics.de Git - mv-sheeva.git/blobdiff - net/rds/send.c
rds: Fix reference counting on the for xmit_atomic and xmit_rdma
[mv-sheeva.git] / net / rds / send.c
index 8a0647af5d95a4557644a190c767fce60a3c6a2b..437f1e72609c612c7c140e95724556bd3edf8bde 100644 (file)
@@ -60,15 +60,22 @@ void rds_send_reset(struct rds_connection *conn)
        struct rds_message *rm, *tmp;
        unsigned long flags;
 
+       spin_lock_irqsave(&conn->c_send_lock, flags);
        if (conn->c_xmit_rm) {
+               rm = conn->c_xmit_rm;
+               conn->c_xmit_rm = NULL;
                /* Tell the user the RDMA op is no longer mapped by the
                 * transport. This isn't entirely true (it's flushed out
                 * independently) but as the connection is down, there's
                 * no ongoing RDMA to/from that memory */
-               rds_message_unmapped(conn->c_xmit_rm);
-               rds_message_put(conn->c_xmit_rm);
-               conn->c_xmit_rm = NULL;
+               rds_message_unmapped(rm);
+               spin_unlock_irqrestore(&conn->c_send_lock, flags);
+
+               rds_message_put(rm);
+       } else {
+               spin_unlock_irqrestore(&conn->c_send_lock, flags);
        }
+
        conn->c_xmit_sg = 0;
        conn->c_xmit_hdr_off = 0;
        conn->c_xmit_data_off = 0;
@@ -110,37 +117,39 @@ int rds_send_xmit(struct rds_connection *conn)
        struct rds_message *rm;
        unsigned long flags;
        unsigned int tmp;
-       unsigned int send_quota = send_batch_count;
        struct scatterlist *sg;
        int ret = 0;
-       int was_empty = 0;
+       int gen = 0;
        LIST_HEAD(to_be_dropped);
 
+restart:
+       if (!rds_conn_up(conn))
+               goto out;
+
        /*
         * sendmsg calls here after having queued its message on the send
         * queue.  We only have one task feeding the connection at a time.  If
         * another thread is already feeding the queue then we back off.  This
         * avoids blocking the caller and trading per-connection data between
         * caches per message.
-        *
-        * The sem holder will issue a retry if they notice that someone queued
-        * a message after they stopped walking the send queue but before they
-        * dropped the sem.
         */
-       if (!mutex_trylock(&conn->c_send_lock)) {
-               rds_stats_inc(s_send_sem_contention);
+       if (!spin_trylock_irqsave(&conn->c_send_lock, flags)) {
+               rds_stats_inc(s_send_lock_contention);
                ret = -ENOMEM;
                goto out;
        }
+       atomic_inc(&conn->c_senders);
 
        if (conn->c_trans->xmit_prepare)
                conn->c_trans->xmit_prepare(conn);
 
+       gen = atomic_inc_return(&conn->c_send_generation);
+
        /*
         * spin trying to push headers and data down the connection until
         * the connection doesn't make forward progress.
         */
-       while (--send_quota) {
+       while (1) {
 
                rm = conn->c_xmit_rm;
 
@@ -169,7 +178,7 @@ int rds_send_xmit(struct rds_connection *conn)
                if (!rm) {
                        unsigned int len;
 
-                       spin_lock_irqsave(&conn->c_lock, flags);
+                       spin_lock(&conn->c_lock);
 
                        if (!list_empty(&conn->c_send_queue)) {
                                rm = list_entry(conn->c_send_queue.next,
@@ -184,12 +193,10 @@ int rds_send_xmit(struct rds_connection *conn)
                                list_move_tail(&rm->m_conn_item, &conn->c_retrans);
                        }
 
-                       spin_unlock_irqrestore(&conn->c_lock, flags);
+                       spin_unlock(&conn->c_lock);
 
-                       if (!rm) {
-                               was_empty = 1;
+                       if (!rm)
                                break;
-                       }
 
                        /* Unfortunately, the way Infiniband deals with
                         * RDMA to a bad MR key is by moving the entire
@@ -200,11 +207,10 @@ int rds_send_xmit(struct rds_connection *conn)
                         */
                        if (rm->rdma.op_active &&
                            test_bit(RDS_MSG_RETRANSMITTED, &rm->m_flags)) {
-                               spin_lock_irqsave(&conn->c_lock, flags);
+                               spin_lock(&conn->c_lock);
                                if (test_and_clear_bit(RDS_MSG_ON_CONN, &rm->m_flags))
                                        list_move(&rm->m_conn_item, &to_be_dropped);
-                               spin_unlock_irqrestore(&conn->c_lock, flags);
-                               rds_message_put(rm);
+                               spin_unlock(&conn->c_lock);
                                continue;
                        }
 
@@ -327,10 +333,6 @@ int rds_send_xmit(struct rds_connection *conn)
                }
        }
 
-       /* Nuke any messages we decided not to retransmit. */
-       if (!list_empty(&to_be_dropped))
-               rds_send_remove_from_sock(&to_be_dropped, RDS_RDMA_DROPPED);
-
        if (conn->c_trans->xmit_complete)
                conn->c_trans->xmit_complete(conn);
 
@@ -346,24 +348,36 @@ int rds_send_xmit(struct rds_connection *conn)
         * stop processing the loop when the transport hasn't taken
         * responsibility for forward progress.
         */
-       mutex_unlock(&conn->c_send_lock);
+       spin_unlock_irqrestore(&conn->c_send_lock, flags);
 
-       if (send_quota == 0 && !was_empty) {
-               /* We exhausted the send quota, but there's work left to
-                * do. Return and (re-)schedule the send worker.
-                */
-               ret = -EAGAIN;
+       /* Nuke any messages we decided not to retransmit. */
+       if (!list_empty(&to_be_dropped)) {
+               /* irqs on here, so we can put(), unlike above */
+               list_for_each_entry(rm, &to_be_dropped, m_conn_item)
+                       rds_message_put(rm);
+               rds_send_remove_from_sock(&to_be_dropped, RDS_RDMA_DROPPED);
        }
 
-       if (ret == 0 && was_empty) {
-               /* A simple bit test would be way faster than taking the
-                * spin lock */
-               spin_lock_irqsave(&conn->c_lock, flags);
+       atomic_dec(&conn->c_senders);
+
+       /*
+        * Other senders will see we have c_send_lock and exit. We
+        * need to recheck the send queue and race again for c_send_lock
+        * to make sure messages don't just sit on the send queue, if
+        * somebody hasn't already beat us into the loop.
+        *
+        * If the transport cannot continue (i.e ret != 0), then it must
+        * call us when more room is available, such as from the tx
+        * completion handler.
+        */
+       if (ret == 0) {
+               smp_mb();
                if (!list_empty(&conn->c_send_queue)) {
-                       rds_stats_inc(s_send_sem_queue_raced);
-                       ret = -EAGAIN;
+                       rds_stats_inc(s_send_lock_queue_raced);
+                       if (gen == atomic_read(&conn->c_send_generation)) {
+                               goto restart;
+                       }
                }
-               spin_unlock_irqrestore(&conn->c_lock, flags);
        }
 out:
        return ret;
@@ -466,8 +480,9 @@ void rds_atomic_send_complete(struct rds_message *rm, int status)
        struct rds_sock *rs = NULL;
        struct rm_atomic_op *ao;
        struct rds_notifier *notifier;
+       unsigned long flags;
 
-       spin_lock(&rm->m_rs_lock);
+       spin_lock_irqsave(&rm->m_rs_lock, flags);
 
        ao = &rm->atomic;
        if (test_bit(RDS_MSG_ON_SOCK, &rm->m_flags)
@@ -484,7 +499,7 @@ void rds_atomic_send_complete(struct rds_message *rm, int status)
                ao->op_notifier = NULL;
        }
 
-       spin_unlock(&rm->m_rs_lock);
+       spin_unlock_irqrestore(&rm->m_rs_lock, flags);
 
        if (rs) {
                rds_wake_sk_sleep(rs);
@@ -1071,7 +1086,7 @@ int rds_sendmsg(struct kiocb *iocb, struct socket *sock, struct msghdr *msg,
        rds_stats_inc(s_send_queued);
 
        if (!test_bit(RDS_LL_SEND_FULL, &conn->c_flags))
-               rds_send_worker(&conn->c_send_w.work);
+               rds_send_xmit(conn);
 
        rds_message_put(rm);
        return payload_len;
@@ -1105,6 +1120,7 @@ rds_send_pong(struct rds_connection *conn, __be16 dport)
        }
 
        rm->m_daddr = conn->c_faddr;
+       rm->data.op_active = 1;
 
        /* If the connection is down, trigger a connect. We may
         * have scheduled a delayed reconnect however - in this case
@@ -1132,7 +1148,9 @@ rds_send_pong(struct rds_connection *conn, __be16 dport)
        rds_stats_inc(s_send_queued);
        rds_stats_inc(s_send_pong);
 
-       queue_delayed_work(rds_wq, &conn->c_send_w, 0);
+       if (!test_bit(RDS_LL_SEND_FULL, &conn->c_flags))
+               rds_send_xmit(conn);
+
        rds_message_put(rm);
        return 0;