From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from gandalf.ozlabs.org (gandalf.ozlabs.org [150.107.74.76]) by passt.top (Postfix) with ESMTPS id 665585A0272 for ; Sat, 4 Nov 2023 07:11:27 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gibson.dropbear.id.au; s=201602; t=1699078279; bh=ljcMohAmzv/Ud0LK5yv8rU6JdQm4Rsnw5Qfa2zb7BII=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=lJQVyoXAfMez10AAWmaIoUcLRlvO+2LSItm/kHcmQUNAXHcJCZ/8nxbPhNRVGuhPq NYN64U97kzXakszz++H+uhFvVMqQimWArC5b+Z1kkAstBxn6bJPpakT4nyODQ9AnqN nTIGj6kAaWp9DzNT9LY8zWGf56a3w4S5GYIwnNVQ= Received: by gandalf.ozlabs.org (Postfix, from userid 1007) id 4SMnLH54tWz4xc4; Sat, 4 Nov 2023 17:11:19 +1100 (AEDT) Date: Sat, 4 Nov 2023 17:02:18 +1100 From: David Gibson To: Stefano Brivio Subject: Re: [PATCH 11/11] tcp_splice: Simplify selection of socket and pipe sides in socket handler Message-ID: References: <20231012015114.2612066-1-david@gibson.dropbear.id.au> <20231012015114.2612066-12-david@gibson.dropbear.id.au> <20231103172112.3b19eda7@elisabeth> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="l1BNeQLgsQeqx54i" Content-Disposition: inline In-Reply-To: <20231103172112.3b19eda7@elisabeth> Message-ID-Hash: 5OEJPGUWO7VT5HFJW4XUTOOSEPQB44J2 X-Message-ID-Hash: 5OEJPGUWO7VT5HFJW4XUTOOSEPQB44J2 X-MailFrom: dgibson@gandalf.ozlabs.org X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header CC: passt-dev@passt.top X-Mailman-Version: 3.3.8 Precedence: list List-Id: Development discussion and patches for passt Archived-At: Archived-At: List-Archive: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: --l1BNeQLgsQeqx54i Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Fri, Nov 03, 2023 at 05:21:12PM +0100, Stefano Brivio wrote: > On Thu, 12 Oct 2023 12:51:14 +1100 > David Gibson wrote: >=20 > > 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. > >=20 > > Now that we are using arrays for the two sides, rather than separate na= med > > 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. > >=20 > > Signed-off-by: David Gibson > > --- > > tcp_splice.c | 81 ++++++++++++++-------------------------------------- > > 1 file changed, 22 insertions(+), 59 deletions(-) > >=20 > > 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, str= uct tcp_splice_conn *conn, > > return tcp_splice_connect(c, conn, s, port); > > } > > =20 > > -/** > > - * tcp_splice_dir() - Set sockets/pipe pointers reflecting flow direct= ion > > - * @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 =3D ref_sock; > > - *to =3D (*from =3D=3D conn->s[0]) ? conn->s[1] : conn->s[0]; > > - } else { > > - *to =3D ref_sock; > > - *from =3D (*to =3D=3D conn->s[0]) ? conn->s[1] : conn->s[0]; > > - } > > - > > - *pipes =3D *from =3D=3D conn->s[0] ? conn->pipe[0] : conn->pipe[1]; > > -} > > - > > /** > > * tcp_splice_conn_from_sock() - Attempt to init state for a spliced c= onnection > > * @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; > > =20 > > if (conn->events =3D=3D SPLICE_CLOSED) > > return; > > @@ -538,14 +514,15 @@ void tcp_splice_sock_handler(struct ctx *c, struc= t tcp_splice_conn *conn, > > } > > =20 > > if (events & EPOLLOUT) { > > - if (s =3D=3D conn->s[0]) > > + if (s =3D=3D conn->s[0]) { > > conn_event(c, conn, ~OUT_WAIT_0); > > - else > > + fromside =3D 1; > > + } else { > > conn_event(c, conn, ~OUT_WAIT_1); > > - > > - tcp_splice_dir(conn, s, 1, &from, &to, &pipes); > > + fromside =3D 0; > > + } > > } else { > > - tcp_splice_dir(conn, s, 0, &from, &to, &pipes); > > + fromside =3D s =3D=3D conn->s[0] ? 0 : 1; > > } > > =20 > > if (events & EPOLLRDHUP) { > > @@ -566,24 +543,16 @@ swap: > > eof =3D 0; > > never_read =3D 1; > > =20 > > - if (from =3D=3D conn->s[0]) { > > - seq_read =3D &conn->read[0]; > > - seq_write =3D &conn->written[0]; > > - lowat_set_flag =3D RCVLOWAT_SET_0; > > - lowat_act_flag =3D RCVLOWAT_ACT_0; > > - } else { > > - seq_read =3D &conn->read[1]; > > - seq_write =3D &conn->written[1]; > > - lowat_set_flag =3D RCVLOWAT_SET_1; > > - lowat_act_flag =3D RCVLOWAT_ACT_1; > > - } > > + lowat_set_flag =3D fromside =3D=3D 0 ? RCVLOWAT_SET_0 : RCVLOWAT_SET_= 1; > > + lowat_act_flag =3D fromside =3D=3D 0 ? RCVLOWAT_ACT_0 : RCVLOWAT_ACT_= 1; > > =20 > > while (1) { > > ssize_t readlen, to_write =3D 0, written; > > int more =3D 0; > > =20 > > retry: > > - readlen =3D splice(from, NULL, pipes[1], NULL, c->tcp.pipe_size, > > + readlen =3D 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: > > } > > =20 > > eintr: > > - written =3D splice(pipes[0], NULL, to, NULL, to_write, > > + written =3D 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 =3D c->tcp.pipe_size / 4; > > =20 > > - setsockopt(from, SOL_SOCKET, SO_RCVLOWAT, > > - &lowat, sizeof(lowat)); > > + setsockopt(conn->s[fromside], SOL_SOCKET, > > + SO_RCVLOWAT, &lowat, sizeof(lowat)); > > =20 > > conn_flag(c, conn, lowat_set_flag); > > conn_flag(c, conn, lowat_act_flag); > > @@ -632,8 +602,8 @@ eintr: > > break; > > } > > =20 > > - *seq_read +=3D readlen > 0 ? readlen : 0; > > - *seq_write +=3D written > 0 ? written : 0; > > + conn->read[fromside] +=3D readlen > 0 ? readlen : 0; > > + conn->written[fromside] +=3D written > 0 ? written : 0; >=20 > 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. --=20 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 --l1BNeQLgsQeqx54i Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAEBCAAdFiEEO+dNsU4E3yXUXRK2zQJF27ox2GcFAmVF3mMACgkQzQJF27ox 2Gfudg//UN0UpUK/l0ADWzrJBCvwbTEBi88utVv5kZNx9aba5dxNYJUy76gc4yxS EllwJiibohmmceiwKNB7SsGmGbYVgDFh3/6Z7BNKY3a4SeZu1ddsOUac/gCMyEsi IFtrN4EnKacwV29CXkTilbn6A+SfCXV6GC/g149h3V6gJBBxXc4Oml2VoADBuE73 miKJmTmgMekfj30lK9PuyzGoWKZq92aGlXZeEyOf2TgwmY3FumytMHlwetTiPvbG trsxr4757WobBVgWdcW7N3tKl/6FCuxWzpj51Drfyiyyrmgt7Lq0SscqGCkret/s w607R8n4FXyOTXLVkyS+EBs83lBC3ROVZMUWcH0V33Js9IKImxCoNkzp66A6lM1/ Tq1WlHMdkU+ed8VQq7+dRNaISH+yPfOHkB9/eUuKR5CH0mpKIIcdIdzliPt58ULa CoVowZMO7ZfsolXQHanKCOi7Q+Yc9ywbJ5bJzVYOhLLxhwmHtAaCt9mfK3crM6+9 0HYAraJ38jeorqwacujAe1Ssi8Mf7VV+TCk6L6Pa0cL6We2cMcnLQY37XPl+/KYc w8GaVgJOxWlV7DatuAsFSWKbIGgV7TyXm4YFu67cgFkYopz+xZgVHAne9R11xYa6 otUsBAPL+vsym/AGxo8lBRvee+Z14DgdAiI/SzrF1spZfc7QowA= =RTj3 -----END PGP SIGNATURE----- --l1BNeQLgsQeqx54i--