public inbox for passt-dev@passt.top
 help / color / mirror / code / Atom feed
From: David Gibson <david@gibson.dropbear.id.au>
To: Stefano Brivio <sbrivio@redhat.com>
Cc: passt-dev@passt.top
Subject: Re: [PATCH v2 03/10] tcp: Simplify ifdef logic in tcp_update_seqack_wnd()
Date: Wed, 18 Sep 2024 11:31:24 +1000	[thread overview]
Message-ID: <ZuotbALGSHSY16R-@zatzit.fritz.box> (raw)
In-Reply-To: <20240917235434.22e09fef@elisabeth>

[-- Attachment #1: Type: text/plain, Size: 3066 bytes --]

On Tue, Sep 17, 2024 at 11:54:34PM +0200, Stefano Brivio wrote:
> On Fri, 13 Sep 2024 14:32:07 +1000
> David Gibson <david@gibson.dropbear.id.au> wrote:
> 
> > This function has a block conditional on !snd_wnd_cap shortly before an
> > #ifdef HAS_SND_WND.  But snd_wnd_cap implies HAS_SND_WND (if !HAS_SND_WND,
> > snd_wnd_cap is statically false).
> > 
> > Therefore, simplify this down to a single conditional with an else branch.
> > While we're there, fix some improperly indented closing braces.
> > 
> > Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
> > ---
> >  tcp.c | 36 +++++++++++++++++-------------------
> >  1 file changed, 17 insertions(+), 19 deletions(-)
> > 
> > diff --git a/tcp.c b/tcp.c
> > index cba3f3bd..6733e7e3 100644
> > --- a/tcp.c
> > +++ b/tcp.c
> > @@ -1061,27 +1061,25 @@ int tcp_update_seqack_wnd(const struct ctx *c, struct tcp_tap_conn *conn,
> >  		conn->wnd_to_tap = MIN(new_wnd_to_tap >> conn->ws_to_tap,
> >  				       USHRT_MAX);
> >  		goto out;
> > -	}
> > -
> > -	if (!tinfo) {
> > -		if (prev_wnd_to_tap > WINDOW_DEFAULT) {
> > -			goto out;
> > -}
> > -		tinfo = &tinfo_new;
> > -		if (getsockopt(s, SOL_TCP, TCP_INFO, tinfo, &sl)) {
> > -			goto out;
> > -}
> > -	}
> > -
> > -#ifdef HAS_SND_WND
> > -	if ((conn->flags & LOCAL) || tcp_rtt_dst_low(conn)) {
> > -		new_wnd_to_tap = tinfo->tcpi_snd_wnd;
> >  	} else {
> 
> I thought cppcheck would report else-after-goto, but it doesn't, just
> else-after-return. In any case, we could simplify further by avoid that
> else clause (and one level of indentation) in the whole block below.

Good idea, done.

> It would also look more natural to me: we deal with if (!snd_wnd_cap)
> as a special case and go to 'out' in that special case, then we resume
> with the regular path.
> 
> I guess this is better than the original anyway and it's not a strong
> preference, so I can also apply this up to 4/10 as it is (or fix up on
> merge). The rest of the patches up to 4/10 look good to me.

Well, I've made the change now, so I might as well repost :).

> 
> > -		tcp_get_sndbuf(conn);
> > -		new_wnd_to_tap = MIN((int)tinfo->tcpi_snd_wnd,
> > -				     SNDBUF_GET(conn));
> > +		if (!tinfo) {
> > +			if (prev_wnd_to_tap > WINDOW_DEFAULT) {
> > +				goto out;
> > +			}
> > +			tinfo = &tinfo_new;
> > +			if (getsockopt(s, SOL_TCP, TCP_INFO, tinfo, &sl)) {
> > +				goto out;
> > +			}
> > +		}
> > +
> > +		if ((conn->flags & LOCAL) || tcp_rtt_dst_low(conn)) {
> > +			new_wnd_to_tap = tinfo->tcpi_snd_wnd;
> > +		} else {
> > +			tcp_get_sndbuf(conn);
> > +			new_wnd_to_tap = MIN((int)tinfo->tcpi_snd_wnd,
> > +					     SNDBUF_GET(conn));
> > +		}
> >  	}
> > -#endif
> >  
> >  	new_wnd_to_tap = MIN(new_wnd_to_tap, MAX_WINDOW);
> >  	if (!(conn->events & ESTABLISHED))
> 

-- 
David Gibson (he or they)	| 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 --]

  reply	other threads:[~2024-09-18  1:52 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-09-13  4:32 [PATCH v2 00/10] RFC: Clean up TCP epoll mask handling David Gibson
2024-09-13  4:32 ` [PATCH v2 01/10] tcp: Make some extra functions private David Gibson
2024-09-13  4:32 ` [PATCH v2 02/10] tcp: Clean up tcpi_snd_wnd probing David Gibson
2024-09-17 21:54   ` Stefano Brivio
2024-09-18  1:27     ` David Gibson
2024-09-13  4:32 ` [PATCH v2 03/10] tcp: Simplify ifdef logic in tcp_update_seqack_wnd() David Gibson
2024-09-17 21:54   ` Stefano Brivio
2024-09-18  1:31     ` David Gibson [this message]
2024-09-13  4:32 ` [PATCH v2 04/10] tcp: Make tcp_update_seqack_wnd()s force_seq parameter explicitly boolean David Gibson
2024-09-13  4:32 ` [PATCH v2 05/10] tcp: On socket EPOLLOUT, send new ACK to tap immediately David Gibson
2024-09-13  4:32 ` [PATCH v2 06/10] tap: Re-introduce EPOLLET for tap connections David Gibson
2024-09-13  4:32 ` [PATCH v2 07/10] tap: Keep track of whether there might be space in the tap buffers David Gibson
2024-09-13  4:32 ` [PATCH v2 08/10] tcp: Keep track of connections blocked due to a full tap interface David Gibson
2024-09-13  4:32 ` [PATCH v2 09/10] tcp: Move deferred handling functions later in tcp.c David Gibson
2024-09-13  4:32 ` [PATCH v2 10/10] tcp: Simplify epoll event mask management David Gibson

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=ZuotbALGSHSY16R-@zatzit.fritz.box \
    --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).