Commit afb2e134 authored by Alex Elder's avatar Alex Elder Committed by Greg Kroah-Hartman

greybus: get rid of pending operations list

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: default avatarAlex Elder <elder@linaro.org>
Signed-off-by: default avatarGreg Kroah-Hartman <greg@kroah.com>
parent 0ba02c4d
...@@ -192,7 +192,6 @@ struct gb_connection *gb_connection_create(struct gb_interface *interface, ...@@ -192,7 +192,6 @@ struct gb_connection *gb_connection_create(struct gb_interface *interface,
spin_unlock_irq(&gb_connections_lock); spin_unlock_irq(&gb_connections_lock);
INIT_LIST_HEAD(&connection->operations); INIT_LIST_HEAD(&connection->operations);
INIT_LIST_HEAD(&connection->pending);
return connection; return connection;
} }
......
...@@ -37,7 +37,6 @@ struct gb_connection { ...@@ -37,7 +37,6 @@ struct gb_connection {
u16 op_cycle; u16 op_cycle;
struct list_head operations; struct list_head operations;
struct list_head pending; /* awaiting response */
void *private; void *private;
}; };
......
...@@ -144,44 +144,14 @@ int gb_operation_result(struct gb_operation *operation) ...@@ -144,44 +144,14 @@ int gb_operation_result(struct gb_operation *operation)
return result; 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 * 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; struct gb_operation *operation;
bool found = false; bool found = false;
spin_lock_irq(&gb_operations_lock); 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) { if (operation->id == operation_id) {
found = true; found = true;
break; break;
...@@ -667,10 +637,12 @@ static void gb_operation_sync_callback(struct gb_operation *operation) ...@@ -667,10 +637,12 @@ static void gb_operation_sync_callback(struct gb_operation *operation)
int gb_operation_request_send(struct gb_operation *operation, int gb_operation_request_send(struct gb_operation *operation,
gb_operation_callback callback) gb_operation_callback callback)
{ {
struct gb_connection *connection = operation->connection;
struct gb_operation_msg_hdr *header;
unsigned long timeout; unsigned long timeout;
int ret; int ret;
if (operation->connection->state != GB_CONNECTION_STATE_ENABLED) if (connection->state != GB_CONNECTION_STATE_ENABLED)
return -ENOTCONN; return -ENOTCONN;
/* /*
...@@ -684,7 +656,16 @@ int gb_operation_request_send(struct gb_operation *operation, ...@@ -684,7 +656,16 @@ int gb_operation_request_send(struct gb_operation *operation,
operation->callback = callback; operation->callback = callback;
else else
operation->callback = gb_operation_sync_callback; 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 * 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, ...@@ -826,14 +807,13 @@ static void gb_connection_recv_response(struct gb_connection *connection,
struct gb_message *message; struct gb_message *message;
int errno = gb_operation_status_map(result); int errno = gb_operation_status_map(result);
operation = gb_pending_operation_find(connection, operation_id); operation = gb_operation_find(connection, operation_id);
if (!operation) { if (!operation) {
gb_connection_err(connection, "operation not found"); gb_connection_err(connection, "operation not found");
return; return;
} }
cancel_delayed_work(&operation->timeout_work); cancel_delayed_work(&operation->timeout_work);
gb_pending_operation_remove(operation);
message = operation->response; message = operation->response;
if (!errno && size != message->size) { if (!errno && size != message->size) {
......
...@@ -92,7 +92,7 @@ struct gb_operation { ...@@ -92,7 +92,7 @@ struct gb_operation {
struct delayed_work timeout_work; struct delayed_work timeout_work;
struct kref kref; struct kref kref;
struct list_head links; /* connection->{operations,pending} */ struct list_head links; /* connection->operations */
}; };
void gb_connection_recv(struct gb_connection *connection, void gb_connection_recv(struct gb_connection *connection,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment