From: David Gibson <david@gibson.dropbear.id.au>
To: Stefano Brivio <sbrivio@redhat.com>
Cc: passt-dev@passt.top
Subject: Re: [PATCH 2/2] tcp: Use runtime tests for TCP_INFO fields
Date: Thu, 24 Oct 2024 13:02:45 +1100 [thread overview]
Message-ID: <ZxmqxTmTHM9z3_Vz@zatzit> (raw)
In-Reply-To: <20241023094139.4e94b322@elisabeth>
[-- Attachment #1: Type: text/plain, Size: 5470 bytes --]
On Wed, Oct 23, 2024 at 09:41:39AM +0200, Stefano Brivio wrote:
> On Wed, 23 Oct 2024 11:42:53 +1100
> David Gibson <david@gibson.dropbear.id.au> wrote:
>
> > In order to use particular fields from the TCP_INFO getsockopt() we
> > need them to be in the version of the structure we have defined. We
> > test this in the Makefile, setting HAS_BYTES_ACKED and HAS_MIN_RTT
> > accordingly.
> >
> > However, we also need the fields to be present in the runtime kernel
> > we're using, which we don't currently check for those fields. Add
> > logic similar to that for tcpi_snd_wnd to check for these fields too
> > instead of just using the compile time check.
> >
> > Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
> > ---
> > tcp.c | 65 +++++++++++++++++++++++++++++++++++------------------------
> > 1 file changed, 39 insertions(+), 26 deletions(-)
> >
> > diff --git a/tcp.c b/tcp.c
> > index 3cca5c6..b5ef1f1 100644
> > --- a/tcp.c
> > +++ b/tcp.c
> > @@ -380,6 +380,19 @@ socklen_t tcp_info_size;
> > #else
> > #define snd_wnd_cap (false)
> > #endif
> > +#ifdef HAS_BYTES_ACKED
> > +/* Does the kernel report bytes acked in TCP_INFO (kernel commit 0df48c26d84) */
> > +#define bytes_acked_cap tcp_info_cap(bytes_acked)
> > +#else
> > +#define bytes_acked_cap (false)
> > +#endif
> > +#ifdef HAS_MIN_RTT
> > +/* Does the kernel report minimum RTT TCP_INFO (kernel commit cd9b266095f4) */
>
> Nit: "in TCP_INFO". This becomes too long, but perhaps:
>
> /* Kernel reports minimum RTT in TCP_INFO (kernel commit cd9b266095f4) */
>
> (and similar above) is just as informative.
Good idea, adjusted.
>
> > +#define min_rtt_cap tcp_info_cap(min_rtt)
> > +#else
> > +#define min_rtt_cap (false)
> > +#endif
> > +
> >
> > /* sendmsg() to socket */
> > static struct iovec tcp_iov [UIO_MAXIOV];
> > @@ -687,11 +700,10 @@ static int tcp_rtt_dst_low(const struct tcp_tap_conn *conn)
> > static void tcp_rtt_dst_check(const struct tcp_tap_conn *conn,
> > const struct tcp_info *tinfo)
> > {
> > -#ifdef HAS_MIN_RTT
>
> I think we should keep those conditionals as well, because if
> tcpi_min_rtt is not defined in the headers:
>
> > const struct flowside *tapside = TAPFLOW(conn);
> > int i, hole = -1;
> >
> > - if (!tinfo->tcpi_min_rtt ||
> > + if (!min_rtt_cap ||
> > (int)tinfo->tcpi_min_rtt > LOW_RTT_THRESHOLD)
>
> ...this won't build.
Ah, bother. Earlier drafts had a field-getter macro which removed the
need for ifdefs outside its definition. Then I removed it to simplify
things, but forgot that needed the ifdefs to come back.
> > return;
> >
> > @@ -712,10 +724,6 @@ static void tcp_rtt_dst_check(const struct tcp_tap_conn *conn,
> > if (hole == LOW_RTT_TABLE_SIZE)
> > hole = 0;
> > inany_from_af(low_rtt_dst + hole, AF_INET6, &in6addr_any);
> > -#else
> > - (void)conn;
> > - (void)tinfo;
> > -#endif /* HAS_MIN_RTT */
> > }
> >
> > /**
> > @@ -1131,30 +1139,29 @@ int tcp_update_seqack_wnd(const struct ctx *c, struct tcp_tap_conn *conn,
> > uint32_t new_wnd_to_tap = prev_wnd_to_tap;
> > int s = conn->sock;
> >
> > -#ifndef HAS_BYTES_ACKED
>
> Same here:
>
> > - (void)force_seq;
> > -
> > - conn->seq_ack_to_tap = conn->seq_from_tap;
> > - if (SEQ_LT(conn->seq_ack_to_tap, prev_ack_to_tap))
> > - conn->seq_ack_to_tap = prev_ack_to_tap;
> > -#else
> > - if ((unsigned)SNDBUF_GET(conn) < SNDBUF_SMALL || tcp_rtt_dst_low(conn)
> > - || CONN_IS_CLOSING(conn) || (conn->flags & LOCAL) || force_seq) {
> > + if (!bytes_acked_cap) {
> > conn->seq_ack_to_tap = conn->seq_from_tap;
> > - } else if (conn->seq_ack_to_tap != conn->seq_from_tap) {
> > - if (!tinfo) {
> > - tinfo = &tinfo_new;
> > - if (getsockopt(s, SOL_TCP, TCP_INFO, tinfo, &sl))
> > - return 0;
> > - }
> > -
> > - conn->seq_ack_to_tap = tinfo->tcpi_bytes_acked +
> > - conn->seq_init_from_tap;
> > -
> > if (SEQ_LT(conn->seq_ack_to_tap, prev_ack_to_tap))
> > conn->seq_ack_to_tap = prev_ack_to_tap;
> > + } else {
> > + if ((unsigned)SNDBUF_GET(conn) < SNDBUF_SMALL ||
> > + tcp_rtt_dst_low(conn) || CONN_IS_CLOSING(conn) ||
> > + (conn->flags & LOCAL) || force_seq) {
> > + conn->seq_ack_to_tap = conn->seq_from_tap;
> > + } else if (conn->seq_ack_to_tap != conn->seq_from_tap) {
> > + if (!tinfo) {
> > + tinfo = &tinfo_new;
> > + if (getsockopt(s, SOL_TCP, TCP_INFO, tinfo, &sl))
> > + return 0;
> > + }
> > +
> > + conn->seq_ack_to_tap = tinfo->tcpi_bytes_acked +
>
> ...this won't build.
>
> > + conn->seq_init_from_tap;
> > +
> > + if (SEQ_LT(conn->seq_ack_to_tap, prev_ack_to_tap))
> > + conn->seq_ack_to_tap = prev_ack_to_tap;
> > + }
> > }
> > -#endif /* !HAS_BYTES_ACKED */
> >
> > if (!snd_wnd_cap) {
> > tcp_get_sndbuf(conn);
> > @@ -2653,6 +2660,12 @@ int tcp_init(struct ctx *c)
> > #ifdef HAS_SND_WND
> > dbg_tcpi(snd_wnd);
> > #endif
> > +#ifdef HAS_BYTES_ACKED
> > + dbg_tcpi(bytes_acked);
> > +#endif
> > +#ifdef HAS_MIN_RTT
> > + dbg_tcpi(min_rtt);
> > +#endif
> > #undef dbg_tcpi
> >
> > return 0;
>
> Everything else looks good to me.
>
--
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 --]
prev parent reply other threads:[~2024-10-24 3:38 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-10-23 0:42 [PATCH 0/2] tcp: Runtime checks for availability of TCP_INFO fields David Gibson
2024-10-23 0:42 ` [PATCH 1/2] tcp: Generalise probing for tcpi_snd_wnd field David Gibson
2024-10-23 0:42 ` [PATCH 2/2] tcp: Use runtime tests for TCP_INFO fields David Gibson
2024-10-23 7:41 ` Stefano Brivio
2024-10-24 2: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=ZxmqxTmTHM9z3_Vz@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).