greybus: get rid of pending operations list
authorAlex Elder <elder@linaro.org>
Wed, 3 Dec 2014 14:35:07 +0000 (08:35 -0600)
committerGreg Kroah-Hartman <greg@kroah.com>
Wed, 3 Dec 2014 23:05:58 +0000 (15:05 -0800)
A connection has two lists of operations, and an operation is always
on one or the other of them.  One of them contains the operations
that are currently "in flight".

We really don't expect to have very many in-flight operations on any
given connection (in fact, at the moment it's always exactly one).
So there's no significant performance benefit to keeping these in a
separate list.  An in-flight operation can also be distinguished by
its errno field holding -EINPROGRESS.

Get rid of the pending list, and search all operations rather than
the pending list when looking up a response message's operation.
Rename gb_pending_operation_find() accordingly.

There's no longer any need to remove operations from the pending
list, and the insertion function no longer has anything to do with a
pending list.  Just open code what was the insertion function (it
now has only to do with assigning the operation id).

Signed-off-by: Alex Elder <elder@linaro.org>
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
drivers/staging/greybus/connection.c
drivers/staging/greybus/connection.h
drivers/staging/greybus/operation.c
drivers/staging/greybus/operation.h

index 6503546ccc018f2dd18b48ee578c52a0e0304622..7fbfcdc22307fe458fee950bfcad1f2191b9065b 100644 (file)
@@ -192,7 +192,6 @@ struct gb_connection *gb_connection_create(struct gb_interface *interface,
        spin_unlock_irq(&gb_connections_lock);
 
        INIT_LIST_HEAD(&connection->operations);
-       INIT_LIST_HEAD(&connection->pending);
 
        return connection;
 }
index 8cde114f5ac2160e7296a6f7bbb0233d6b190b7f..035fced12edc3e6edc68bfa2aa9d8f7078074b3f 100644 (file)
@@ -37,7 +37,6 @@ struct gb_connection {
 
        u16                             op_cycle;
        struct list_head                operations;
-       struct list_head                pending;        /* awaiting response */
 
        void                            *private;
 };
index c0e206db9ed738e884adf6bb5dd70a1fc9362cff..6ed1d479b11720678217cc3537f44e7503709551 100644 (file)
@@ -144,44 +144,14 @@ int gb_operation_result(struct gb_operation *operation)
        return result;
 }
 
-static void gb_pending_operation_insert(struct gb_operation *operation)
-{
-       struct gb_connection *connection = operation->connection;
-       struct gb_operation_msg_hdr *header;
-
-       /*
-        * Assign the operation's id and move it into its
-        * connection's pending list.  Zero is a reserved operation
-        * id.
-        */
-       spin_lock_irq(&gb_operations_lock);
-       operation->id = ++connection->op_cycle % U16_MAX + 1;
-       list_move_tail(&operation->links, &connection->pending);
-       spin_unlock_irq(&gb_operations_lock);
-
-       /* Store the operation id in the request header */
-       header = operation->request->header;
-       header->operation_id = cpu_to_le16(operation->id);
-}
-
-static void gb_pending_operation_remove(struct gb_operation *operation)
-{
-       struct gb_connection *connection = operation->connection;
-
-       /* Take us off of the list of pending operations */
-       spin_lock_irq(&gb_operations_lock);
-       list_move_tail(&operation->links, &connection->operations);
-       spin_unlock_irq(&gb_operations_lock);
-}
-
 static struct gb_operation *
-gb_pending_operation_find(struct gb_connection *connection, u16 operation_id)
+gb_operation_find(struct gb_connection *connection, u16 operation_id)
 {
        struct gb_operation *operation;
        bool found = false;
 
        spin_lock_irq(&gb_operations_lock);
-       list_for_each_entry(operation, &connection->pending, links)
+       list_for_each_entry(operation, &connection->operations, links)
                if (operation->id == operation_id) {
                        found = true;
                        break;
@@ -667,10 +637,12 @@ static void gb_operation_sync_callback(struct gb_operation *operation)
 int gb_operation_request_send(struct gb_operation *operation,
                                gb_operation_callback callback)
 {
+       struct gb_connection *connection = operation->connection;
+       struct gb_operation_msg_hdr *header;
        unsigned long timeout;
        int ret;
 
-       if (operation->connection->state != GB_CONNECTION_STATE_ENABLED)
+       if (connection->state != GB_CONNECTION_STATE_ENABLED)
                return -ENOTCONN;
 
        /*
@@ -684,7 +656,16 @@ int gb_operation_request_send(struct gb_operation *operation,
                operation->callback = callback;
        else
                operation->callback = gb_operation_sync_callback;
-       gb_pending_operation_insert(operation);
+
+       /*
+        * Assign the operation's id, and store it in the request header.
+        * Zero is a reserved operation id.
+        */
+       spin_lock_irq(&gb_operations_lock);
+       operation->id = ++connection->op_cycle % U16_MAX + 1;
+       spin_unlock_irq(&gb_operations_lock);
+       header = operation->request->header;
+       header->operation_id = cpu_to_le16(operation->id);
 
        /*
         * We impose a time limit for requests to complete.  We need
@@ -826,14 +807,13 @@ static void gb_connection_recv_response(struct gb_connection *connection,
        struct gb_message *message;
        int errno = gb_operation_status_map(result);
 
-       operation = gb_pending_operation_find(connection, operation_id);
+       operation = gb_operation_find(connection, operation_id);
        if (!operation) {
                gb_connection_err(connection, "operation not found");
                return;
        }
 
        cancel_delayed_work(&operation->timeout_work);
-       gb_pending_operation_remove(operation);
 
        message = operation->response;
        if (!errno && size != message->size) {
index 40b2e7d68b877d5b09ae670002b5f674935854ba..c73d9b92b5c57f9eaa05753de3ccada86d528679 100644 (file)
@@ -92,7 +92,7 @@ struct gb_operation {
        struct delayed_work     timeout_work;
 
        struct kref             kref;
-       struct list_head        links;  /* connection->{operations,pending} */
+       struct list_head        links;          /* connection->operations */
 };
 
 void gb_connection_recv(struct gb_connection *connection,