From 02e092b4feb8abf9f9beb77a9155ad75b0e4e3d5 Mon Sep 17 00:00:00 2001 From: David Gibson Date: Tue, 16 Jan 2024 11:50:38 +1100 Subject: tcp, tcp_splice: Avoid double layered dispatch for connected TCP sockets Currently connected TCP sockets have the same epoll type, whether they're for a "tap" connection or a spliced connection. This means that tcp_sock_handler() has to do a secondary check on the type of the connection to call the right function. We can avoid this by adding a new epoll type and dispatching directly to the right thing. Signed-off-by: David Gibson Signed-off-by: Stefano Brivio --- tcp_splice.c | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) (limited to 'tcp_splice.c') diff --git a/tcp_splice.c b/tcp_splice.c index a7d577a..33bbef1 100644 --- a/tcp_splice.c +++ b/tcp_splice.c @@ -127,9 +127,9 @@ static int tcp_splice_epoll_ctl(const struct ctx *c, { int m = conn->in_epoll ? EPOLL_CTL_MOD : EPOLL_CTL_ADD; const union epoll_ref ref[SIDES] = { - { .type = EPOLL_TYPE_TCP, .fd = conn->s[0], + { .type = EPOLL_TYPE_TCP_SPLICE, .fd = conn->s[0], .flowside = FLOW_SIDX(conn, 0) }, - { .type = EPOLL_TYPE_TCP, .fd = conn->s[1], + { .type = EPOLL_TYPE_TCP_SPLICE, .fd = conn->s[1], .flowside = FLOW_SIDX(conn, 1) } }; struct epoll_event ev[SIDES] = { { .data.u64 = ref[0].u64 }, @@ -484,18 +484,20 @@ bool tcp_splice_conn_from_sock(const struct ctx *c, /** * tcp_splice_sock_handler() - Handler for socket mapped to spliced connection * @c: Execution context - * @conn: Connection state - * @side: Side of the connection on which an event has occurred + * @ref: epoll reference * @events: epoll events bitmap * * #syscalls:pasta splice */ -void tcp_splice_sock_handler(struct ctx *c, struct tcp_splice_conn *conn, - int side, uint32_t events) +void tcp_splice_sock_handler(struct ctx *c, union epoll_ref ref, + uint32_t events) { + struct tcp_splice_conn *conn = CONN(ref.flowside.flow); + unsigned side = ref.flowside.side, fromside; uint8_t lowat_set_flag, lowat_act_flag; int eof, never_read; - unsigned fromside; + + ASSERT(conn->f.type == FLOW_TCP_SPLICE); if (conn->events == SPLICE_CLOSED) return; -- cgit v1.2.3