socket: break receive loop if there are no more outstanding PDUs
If the length of iscsi->waitpdu and iscsi->inqueue are the same then except for any target initiated NOPs or async messages we should have received any and all possible pdus from this socket and can abort early. This avoids running the loop one more time just to fail with EAGAIN at the recs/readv. Just avoiding that recv/readv syscall will shave at least 10us off this function and thus the latency. Suggested-by: Ronnie Sahlberg <ronniesahlberg@gmail.com> Signed-off-by: Peter Lieven <pl@kamp.de>
This commit is contained in:
@@ -567,6 +567,9 @@ iscsi_read_from_socket(struct iscsi_context *iscsi)
|
||||
{
|
||||
struct iscsi_in_pdu *in;
|
||||
ssize_t data_size, count, padding_size;
|
||||
int waitpdu_len, inqueue_len = 0;
|
||||
|
||||
ISCSI_LIST_LENGTH(&iscsi->waitpdu, waitpdu_len);
|
||||
|
||||
do {
|
||||
if (iscsi->incoming == NULL) {
|
||||
@@ -638,7 +641,6 @@ iscsi_read_from_socket(struct iscsi_context *iscsi)
|
||||
}
|
||||
count = recv(iscsi->fd, buf, count, 0);
|
||||
}
|
||||
|
||||
if (count == 0) {
|
||||
/* remote side has closed the socket. */
|
||||
return -1;
|
||||
@@ -652,7 +654,6 @@ iscsi_read_from_socket(struct iscsi_context *iscsi)
|
||||
iscsi_get_error(iscsi));
|
||||
return -1;
|
||||
}
|
||||
|
||||
in->data_pos += count;
|
||||
}
|
||||
|
||||
@@ -661,8 +662,9 @@ iscsi_read_from_socket(struct iscsi_context *iscsi)
|
||||
}
|
||||
|
||||
ISCSI_LIST_ADD_END(&iscsi->inqueue, in);
|
||||
inqueue_len++;
|
||||
iscsi->incoming = NULL;
|
||||
} while (iscsi->is_loggedin && iscsi->tcp_nonblocking);
|
||||
} while (iscsi->tcp_nonblocking && inqueue_len < waitpdu_len && iscsi->is_loggedin);
|
||||
|
||||
while (iscsi->inqueue != NULL) {
|
||||
struct iscsi_in_pdu *current = iscsi->inqueue;
|
||||
|
||||
Reference in New Issue
Block a user