Commit 6d6959e9 authored by Ben Walker's avatar Ben Walker Committed by Tomasz Zawadzki
Browse files

sock/posix: Rename pending_recv to pending_events



This list will hold any socket that has some event pending and needs to
be part of the set returned during polling of the group.

Signed-off-by: default avatarBen Walker <benjamin.walker@intel.com>
Change-Id: I5acf01677e59c1026f93671c7b7b3dc458075bf7
Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/6748


Tested-by: default avatarSPDK CI Jenkins <sys_sgci@intel.com>
Reviewed-by: default avatarJim Harris <james.r.harris@intel.com>
Reviewed-by: default avatarAleksey Marchuk <alexeymar@mellanox.com>
Community-CI: Mellanox Build Bot
parent fc551b3a
Loading
Loading
Loading
Loading
+40 −42
Original line number Diff line number Diff line
@@ -67,7 +67,7 @@ struct spdk_posix_sock {
	struct spdk_pipe	*recv_pipe;
	void			*recv_buf;
	int			recv_buf_sz;
	bool			pending_recv;
	bool			pending_events;
	bool			zcopy;

	int			placement_id;
@@ -75,12 +75,12 @@ struct spdk_posix_sock {
	TAILQ_ENTRY(spdk_posix_sock)	link;
};

TAILQ_HEAD(spdk_pending_recv_list, spdk_posix_sock);
TAILQ_HEAD(spdk_pending_events_list, spdk_posix_sock);

struct spdk_posix_sock_group_impl {
	struct spdk_sock_group_impl	base;
	int				fd;
	struct spdk_pending_recv_list	pending_recv;
	struct spdk_pending_events_list	pending_events;
};

static struct spdk_sock_impl_opts g_spdk_posix_sock_impl_opts = {
@@ -727,11 +727,11 @@ _sock_check_zcopy(struct spdk_sock *sock)
				}
			}

			/* If we reaped buffer reclaim notification and sock is not in pending_recv list yet,
			/* If we reaped buffer reclaim notification and sock is not in pending_events list yet,
			 * add it now. It allows to call socket callback and process completions */
			if (found && !psock->pending_recv && group) {
				psock->pending_recv = true;
				TAILQ_INSERT_TAIL(&group->pending_recv, psock, link);
			if (found && !psock->pending_events && group) {
				psock->pending_events = true;
				TAILQ_INSERT_TAIL(&group->pending_events, psock, link);
			}
		}
	}
@@ -887,13 +887,13 @@ posix_sock_recv_from_pipe(struct spdk_posix_sock *sock, struct iovec *diov, int

	spdk_pipe_reader_advance(sock->recv_pipe, bytes);

	/* If we drained the pipe, take it off the pending_recv list. The socket may still have data buffered
	/* If we drained the pipe, take it off the pending_events list. The socket may still have data buffered
	 * in the kernel to receive, but this will be handled on the next poll call when we get the same EPOLLIN
	 * event again. */
	if (sock->base.group_impl && spdk_pipe_reader_bytes_available(sock->recv_pipe) == 0) {
		group = __posix_group_impl(sock->base.group_impl);
		TAILQ_REMOVE(&group->pending_recv, sock, link);
		sock->pending_recv = false;
		TAILQ_REMOVE(&group->pending_events, sock, link);
		sock->pending_events = false;
	}

	return bytes;
@@ -914,20 +914,18 @@ posix_sock_read(struct spdk_posix_sock *sock)
			spdk_pipe_writer_advance(sock->recv_pipe, bytes);

			/* For normal operation, this function is called in response to an EPOLLIN
			 * event, which already placed the socket onto the pending_recv list.
			 * event, which already placed the socket onto the pending_events list.
			 * But between polls the user may repeatedly call posix_sock_read
			 * and if they clear the pipe on one of those earlier calls, the
			 * socket will be removed from the pending_recv list. In that case,
			 * socket will be removed from the pending_events list. In that case,
			 * if we now found more data, put it back on.
			 * This essentially never happens in practice because the application
			 * will stop trying to receive and wait for the next EPOLLIN event, but
			 * for correctness let's handle it. */
			if (!sock->pending_recv && sock->base.group_impl) {
			if (!sock->pending_events && sock->base.group_impl) {
				group = __posix_group_impl(sock->base.group_impl);
				if (!sock->pending_recv) {
					TAILQ_INSERT_TAIL(&group->pending_recv, sock, link);
					sock->pending_recv = true;
				}
				TAILQ_INSERT_TAIL(&group->pending_events, sock, link);
				sock->pending_events = true;
			}
		}
	}
@@ -944,9 +942,9 @@ posix_sock_readv(struct spdk_sock *_sock, struct iovec *iov, int iovcnt)
	size_t len;

	if (sock->recv_pipe == NULL) {
		if (group && sock->pending_recv) {
			sock->pending_recv = false;
			TAILQ_REMOVE(&group->pending_recv, sock, link);
		if (group && sock->pending_events) {
			sock->pending_events = false;
			TAILQ_REMOVE(&group->pending_events, sock, link);
		}
		return readv(sock->fd, iov, iovcnt);
	}
@@ -960,9 +958,9 @@ posix_sock_readv(struct spdk_sock *_sock, struct iovec *iov, int iovcnt)
		/* If the user is receiving a sufficiently large amount of data,
		 * receive directly to their buffers. */
		if (len >= MIN_SOCK_PIPE_SIZE) {
			if (group && sock->pending_recv) {
				sock->pending_recv = false;
				TAILQ_REMOVE(&group->pending_recv, sock, link);
			if (group && sock->pending_events) {
				sock->pending_events = false;
				TAILQ_REMOVE(&group->pending_events, sock, link);
			}
			return readv(sock->fd, iov, iovcnt);
		}
@@ -1143,7 +1141,7 @@ posix_sock_group_impl_create(void)
	}

	group_impl->fd = fd;
	TAILQ_INIT(&group_impl->pending_recv);
	TAILQ_INIT(&group_impl->pending_events);

	return &group_impl->base;
}
@@ -1176,9 +1174,9 @@ posix_sock_group_impl_add_sock(struct spdk_sock_group_impl *_group, struct spdk_
	/* switched from another polling group due to scheduling */
	if (spdk_unlikely(sock->recv_pipe != NULL  &&
			  (spdk_pipe_reader_bytes_available(sock->recv_pipe) > 0))) {
		assert(sock->pending_recv == false);
		sock->pending_recv = true;
		TAILQ_INSERT_TAIL(&group->pending_recv, sock, link);
		assert(sock->pending_events == false);
		sock->pending_events = true;
		TAILQ_INSERT_TAIL(&group->pending_events, sock, link);
	}

	return rc;
@@ -1191,9 +1189,9 @@ posix_sock_group_impl_remove_sock(struct spdk_sock_group_impl *_group, struct sp
	struct spdk_posix_sock *sock = __posix_sock(_sock);
	int rc;

	if (sock->pending_recv) {
		TAILQ_REMOVE(&group->pending_recv, sock, link);
		sock->pending_recv = false;
	if (sock->pending_events) {
		TAILQ_REMOVE(&group->pending_events, sock, link);
		sock->pending_events = false;
	}

#if defined(SPDK_EPOLL)
@@ -1293,15 +1291,15 @@ posix_sock_group_impl_poll(struct spdk_sock_group_impl *_group, int max_events,
#endif

		/* If the socket does not already have recv pending, add it now */
		if (!psock->pending_recv) {
			psock->pending_recv = true;
			TAILQ_INSERT_TAIL(&group->pending_recv, psock, link);
		if (!psock->pending_events) {
			psock->pending_events = true;
			TAILQ_INSERT_TAIL(&group->pending_events, psock, link);
		}
	}

	num_events = 0;

	TAILQ_FOREACH_SAFE(psock, &group->pending_recv, link, ptmp) {
	TAILQ_FOREACH_SAFE(psock, &group->pending_events, link, ptmp) {
		if (num_events == max_events) {
			break;
		}
@@ -1309,15 +1307,15 @@ posix_sock_group_impl_poll(struct spdk_sock_group_impl *_group, int max_events,
		/* If the socket's cb_fn is NULL, just remove it from the
		 * list and do not add it to socks array */
		if (spdk_unlikely(psock->base.cb_fn == NULL)) {
			psock->pending_recv = false;
			TAILQ_REMOVE(&group->pending_recv, psock, link);
			psock->pending_events = false;
			TAILQ_REMOVE(&group->pending_events, psock, link);
			continue;
		}

		socks[num_events++] = &psock->base;
	}

	/* Cycle the pending_recv list so that each time we poll things aren't
	/* Cycle the pending_events list so that each time we poll things aren't
	 * in the same order. Say we have 6 sockets in the list, named as follows:
	 * A B C D E F
	 * And all 6 sockets had epoll events, but max_events is only 3. That means
@@ -1332,9 +1330,9 @@ posix_sock_group_impl_poll(struct spdk_sock_group_impl *_group, int max_events,

		/* Capture pointers to the elements we need */
		pd = psock;
		pc = TAILQ_PREV(pd, spdk_pending_recv_list, link);
		pa = TAILQ_FIRST(&group->pending_recv);
		pf = TAILQ_LAST(&group->pending_recv, spdk_pending_recv_list);
		pc = TAILQ_PREV(pd, spdk_pending_events_list, link);
		pa = TAILQ_FIRST(&group->pending_events);
		pf = TAILQ_LAST(&group->pending_events, spdk_pending_events_list);

		/* Break the link between C and D */
		pc->link.tqe_next = NULL;
@@ -1345,8 +1343,8 @@ posix_sock_group_impl_poll(struct spdk_sock_group_impl *_group, int max_events,
		pa->link.tqe_prev = &pf->link.tqe_next;

		/* Fix up the list first/last pointers */
		group->pending_recv.tqh_first = pd;
		group->pending_recv.tqh_last = &pc->link.tqe_next;
		group->pending_events.tqh_first = pd;
		group->pending_events.tqh_last = &pc->link.tqe_next;
	}

	return num_events;