From: David Gibson <david@gibson.dropbear.id.au>
To: Stefano Brivio <sbrivio@redhat.com>
Cc: passt-dev@passt.top
Subject: Re: [PATCH 11/11] tcp_splice: Simplify selection of socket and pipe sides in socket handler
Date: Sat, 4 Nov 2023 17:02:18 +1100 [thread overview]
Message-ID: <ZUXeaikLYIWJzC7A@zatzit> (raw)
In-Reply-To: <20231103172112.3b19eda7@elisabeth>
[-- Attachment #1: Type: text/plain, Size: 5644 bytes --]
On Fri, Nov 03, 2023 at 05:21:12PM +0100, Stefano Brivio wrote:
> On Thu, 12 Oct 2023 12:51:14 +1100
> David Gibson <david@gibson.dropbear.id.au> wrote:
>
> > tcp_splice_sock_handler() uses the tcp_splice_dir() helper to select
> > which of the socket, pipe and counter fields to use depending on which
> > side of the connection the socket event is coming from.
> >
> > Now that we are using arrays for the two sides, rather than separate named
> > fields, we can instead just use a variable indicating the side and use
> > that to index the arrays whever we need a particular side's field.
> >
> > Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
> > ---
> > tcp_splice.c | 81 ++++++++++++++--------------------------------------
> > 1 file changed, 22 insertions(+), 59 deletions(-)
> >
> > diff --git a/tcp_splice.c b/tcp_splice.c
> > index 239f6d2..822d15a 100644
> > --- a/tcp_splice.c
> > +++ b/tcp_splice.c
> > @@ -438,29 +438,6 @@ static int tcp_splice_new(const struct ctx *c, struct tcp_splice_conn *conn,
> > return tcp_splice_connect(c, conn, s, port);
> > }
> >
> > -/**
> > - * tcp_splice_dir() - Set sockets/pipe pointers reflecting flow direction
> > - * @conn: Connection pointers
> > - * @ref_sock: Socket returned as reference from epoll
> > - * @reverse: Reverse direction: @ref_sock is used as destination
> > - * @from: Destination socket pointer to set
> > - * @to: Source socket pointer to set
> > - * @pipes: Pipe set, assigned on return
> > - */
> > -static void tcp_splice_dir(struct tcp_splice_conn *conn, int ref_sock,
> > - int reverse, int *from, int *to, int **pipes)
> > -{
> > - if (!reverse) {
> > - *from = ref_sock;
> > - *to = (*from == conn->s[0]) ? conn->s[1] : conn->s[0];
> > - } else {
> > - *to = ref_sock;
> > - *from = (*to == conn->s[0]) ? conn->s[1] : conn->s[0];
> > - }
> > -
> > - *pipes = *from == conn->s[0] ? conn->pipe[0] : conn->pipe[1];
> > -}
> > -
> > /**
> > * tcp_splice_conn_from_sock() - Attempt to init state for a spliced connection
> > * @c: Execution context
> > @@ -521,8 +498,7 @@ void tcp_splice_sock_handler(struct ctx *c, struct tcp_splice_conn *conn,
> > int s, uint32_t events)
> > {
> > uint8_t lowat_set_flag, lowat_act_flag;
> > - int from, to, *pipes, eof, never_read;
> > - uint32_t *seq_read, *seq_write;
> > + int fromside, eof, never_read;
> >
> > if (conn->events == SPLICE_CLOSED)
> > return;
> > @@ -538,14 +514,15 @@ void tcp_splice_sock_handler(struct ctx *c, struct tcp_splice_conn *conn,
> > }
> >
> > if (events & EPOLLOUT) {
> > - if (s == conn->s[0])
> > + if (s == conn->s[0]) {
> > conn_event(c, conn, ~OUT_WAIT_0);
> > - else
> > + fromside = 1;
> > + } else {
> > conn_event(c, conn, ~OUT_WAIT_1);
> > -
> > - tcp_splice_dir(conn, s, 1, &from, &to, &pipes);
> > + fromside = 0;
> > + }
> > } else {
> > - tcp_splice_dir(conn, s, 0, &from, &to, &pipes);
> > + fromside = s == conn->s[0] ? 0 : 1;
> > }
> >
> > if (events & EPOLLRDHUP) {
> > @@ -566,24 +543,16 @@ swap:
> > eof = 0;
> > never_read = 1;
> >
> > - if (from == conn->s[0]) {
> > - seq_read = &conn->read[0];
> > - seq_write = &conn->written[0];
> > - lowat_set_flag = RCVLOWAT_SET_0;
> > - lowat_act_flag = RCVLOWAT_ACT_0;
> > - } else {
> > - seq_read = &conn->read[1];
> > - seq_write = &conn->written[1];
> > - lowat_set_flag = RCVLOWAT_SET_1;
> > - lowat_act_flag = RCVLOWAT_ACT_1;
> > - }
> > + lowat_set_flag = fromside == 0 ? RCVLOWAT_SET_0 : RCVLOWAT_SET_1;
> > + lowat_act_flag = fromside == 0 ? RCVLOWAT_ACT_0 : RCVLOWAT_ACT_1;
> >
> > while (1) {
> > ssize_t readlen, to_write = 0, written;
> > int more = 0;
> >
> > retry:
> > - readlen = splice(from, NULL, pipes[1], NULL, c->tcp.pipe_size,
> > + readlen = splice(conn->s[fromside], NULL,
> > + conn->pipe[fromside][1], NULL, c->tcp.pipe_size,
> > SPLICE_F_MOVE | SPLICE_F_NONBLOCK);
> > trace("TCP (spliced): %li from read-side call", readlen);
> > if (readlen < 0) {
> > @@ -608,7 +577,8 @@ retry:
> > }
> >
> > eintr:
> > - written = splice(pipes[0], NULL, to, NULL, to_write,
> > + written = splice(conn->pipe[fromside][0], NULL,
> > + conn->s[!fromside], NULL, to_write,
> > SPLICE_F_MOVE | more | SPLICE_F_NONBLOCK);
> > trace("TCP (spliced): %li from write-side call (passed %lu)",
> > written, to_write);
> > @@ -622,8 +592,8 @@ eintr:
> > readlen > (long)c->tcp.pipe_size / 10) {
> > int lowat = c->tcp.pipe_size / 4;
> >
> > - setsockopt(from, SOL_SOCKET, SO_RCVLOWAT,
> > - &lowat, sizeof(lowat));
> > + setsockopt(conn->s[fromside], SOL_SOCKET,
> > + SO_RCVLOWAT, &lowat, sizeof(lowat));
> >
> > conn_flag(c, conn, lowat_set_flag);
> > conn_flag(c, conn, lowat_act_flag);
> > @@ -632,8 +602,8 @@ eintr:
> > break;
> > }
> >
> > - *seq_read += readlen > 0 ? readlen : 0;
> > - *seq_write += written > 0 ? written : 0;
> > + conn->read[fromside] += readlen > 0 ? readlen : 0;
> > + conn->written[fromside] += written > 0 ? written : 0;
>
> The extra whitespace had the function of making this look more
> "tabular", now you should add a further one (or drop it altogether
> depending on taste).
Ah, yes. I've restored the alignment.
--
David Gibson | I'll have my music baroque, and my code
david AT gibson.dropbear.id.au | minimalist, thank you. NOT _the_ _other_
| _way_ _around_!
http://www.ozlabs.org/~dgibson
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]
prev parent reply other threads:[~2023-11-04 6:11 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-10-12 1:51 [PATCH 00/11] tcp_splice: Better exploit symmetry between sides of connection David Gibson
2023-10-12 1:51 ` [PATCH 01/11] tcp_splice: Remove redundant tcp_splice_epoll_ctl() David Gibson
2023-10-12 1:51 ` [PATCH 02/11] tcp_splice: Correct error handling in tcp_splice_epoll_ctl() David Gibson
2023-10-12 1:51 ` [PATCH 03/11] tcp_splice: Don't handle EPOLL_CTL_DEL as part of tcp_splice_epoll_ctl() David Gibson
2023-11-03 16:20 ` Stefano Brivio
2023-11-04 5:56 ` David Gibson
2023-10-12 1:51 ` [PATCH 04/11] tcp_splice: Remove unnecessary forward declaration David Gibson
2023-10-12 1:51 ` [PATCH 05/11] tcp_splice: Avoid awkward temporaries in tcp_splice_epoll_ctl() David Gibson
2023-11-03 16:21 ` Stefano Brivio
2023-11-04 5:58 ` David Gibson
2023-10-12 1:51 ` [PATCH 06/11] tcp_splice: Don't pool pipes in pairs David Gibson
2023-10-12 1:51 ` [PATCH 07/11] tcp_splice: Rename sides of connection from a/b to 0/1 David Gibson
2023-10-12 1:51 ` [PATCH 08/11] tcp_splice: Exploit side symmetry in tcp_splice_timer() David Gibson
2023-11-03 16:21 ` Stefano Brivio
2023-11-04 5:59 ` David Gibson
2023-10-12 1:51 ` [PATCH 09/11] tcp_splice: Exploit side symmetry in tcp_splice_connect_finish() David Gibson
2023-10-12 1:51 ` [PATCH 10/11] tcp_splice: Exploit side symmetry in tcp_splice_destroy() David Gibson
2023-11-03 16:22 ` Stefano Brivio
2023-11-06 2:39 ` David Gibson
2023-11-06 13:21 ` Stefano Brivio
2023-10-12 1:51 ` [PATCH 11/11] tcp_splice: Simplify selection of socket and pipe sides in socket handler David Gibson
2023-11-03 16:21 ` Stefano Brivio
2023-11-04 6:02 ` David Gibson [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=ZUXeaikLYIWJzC7A@zatzit \
--to=david@gibson.dropbear.id.au \
--cc=passt-dev@passt.top \
--cc=sbrivio@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://passt.top/passt
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for IMAP folder(s).