From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from gandalf.ozlabs.org (mail.ozlabs.org [IPv6:2404:9400:2221:ea00::3]) by passt.top (Postfix) with ESMTPS id 750645A026B for ; Mon, 27 Feb 2023 14:29:55 +0100 (CET) Received: by gandalf.ozlabs.org (Postfix, from userid 1007) id 4PQLvg5PvFz4xDl; Tue, 28 Feb 2023 00:29:51 +1100 (AEDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gibson.dropbear.id.au; s=201602; t=1677504591; bh=TICqtp6ZgEWpA3Odht+kSOeBjRn+pv5l8KE8famVwMQ=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=HxoPav/V0IY59QiMsPudBwm/Q2ht98KVVZMIV7HeSyhtKtpJlCtCh382V3ShGxgg5 VtRlfLjwt07AvBoixNInPUdWi3517Jqc8gDyfO1N0+tTiw2amsw8fknG/9jlT7B0ub g8mQPUxYQsUCbpDQWTgFYPG5l62VKpc/uVEmIWZo= Date: Mon, 27 Feb 2023 21:53:45 +1100 From: David Gibson To: Stefano Brivio Subject: Re: [PATCH] Fix definitions of SOCKET_MAX, TCP_MAX_CONNS Message-ID: References: <20230227100003.225833-1-sbrivio@redhat.com> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="8hOCwIN/SFi+8LD2" Content-Disposition: inline In-Reply-To: <20230227100003.225833-1-sbrivio@redhat.com> Message-ID-Hash: QDMJ77RH2UBW7VZTF4YMKAO6BBKXK3NS X-Message-ID-Hash: QDMJ77RH2UBW7VZTF4YMKAO6BBKXK3NS 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: --8hOCwIN/SFi+8LD2 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Mon, Feb 27, 2023 at 11:00:03AM +0100, Stefano Brivio wrote: > ...and, given that I keep getting this wrong, add a convenience > macro, MAX_FROM_BITS(). >=20 > Signed-off-by: Stefano Brivio Reviewed-by: David Gibson > --- > passt.h | 4 ++-- > tcp.h | 4 ++-- > tcp_conn.h | 2 +- > util.h | 2 ++ > 4 files changed, 7 insertions(+), 5 deletions(-) >=20 > diff --git a/passt.h b/passt.h > index 3d7e567..e0383eb 100644 > --- a/passt.h > +++ b/passt.h > @@ -42,7 +42,7 @@ union epoll_ref; > /** > * union epoll_ref - Breakdown of reference for epoll socket bookkeeping > * @proto: IP protocol number > - * @s: Socket number (implies 2^24 limit on number of descriptors) > + * @s: Socket number (implies 2^24-1 limit on number of descriptors) > * @tcp: TCP-specific reference part > * @udp: UDP-specific reference part > * @icmp: ICMP-specific reference part > @@ -53,7 +53,7 @@ union epoll_ref { > struct { > int32_t proto:8, > #define SOCKET_REF_BITS 24 > -#define SOCKET_MAX (1 << SOCKET_REF_BITS) > +#define SOCKET_MAX MAX_FROM_BITS(SOCKET_REF_BITS) > s:SOCKET_REF_BITS; > union { > union tcp_epoll_ref tcp; > diff --git a/tcp.h b/tcp.h > index 5527c5b..36e5391 100644 > --- a/tcp.h > +++ b/tcp.h > @@ -8,8 +8,8 @@ > =20 > #define TCP_TIMER_INTERVAL 1000 /* ms */ > =20 > -#define TCP_CONN_INDEX_BITS 17 /* 128k */ > -#define TCP_MAX_CONNS (1 << TCP_CONN_INDEX_BITS) > +#define TCP_CONN_INDEX_BITS 17 /* 128k - 1 */ > +#define TCP_MAX_CONNS MAX_FROM_BITS(TCP_CONN_INDEX_BITS) > =20 > struct ctx; > =20 > diff --git a/tcp_conn.h b/tcp_conn.h > index a499f34..c22632b 100644 > --- a/tcp_conn.h > +++ b/tcp_conn.h > @@ -54,7 +54,7 @@ struct tcp_tap_conn { > =20 > #define TCP_RETRANS_BITS 3 > unsigned int retrans :TCP_RETRANS_BITS; > -#define TCP_MAX_RETRANS ((1U << TCP_RETRANS_BITS) - 1) > +#define TCP_MAX_RETRANS MAX_FROM_BITS(TCP_RETRANS_BITS) > =20 > #define TCP_WS_BITS 4 /* RFC 7323 */ > #define TCP_WS_MAX 14 > diff --git a/util.h b/util.h > index 6303c17..570094c 100644 > --- a/util.h > +++ b/util.h > @@ -40,6 +40,8 @@ > #define ROUND_DOWN(x, y) ((x) & ~((y) - 1)) > #define ROUND_UP(x, y) (((x) + (y) - 1) & ~((y) - 1)) > =20 > +#define MAX_FROM_BITS(n) ((int)((1U << (n)) - 1)) > + > #define BIT(n) (1UL << (n)) > #define BITMAP_BIT(n) (BIT((n) % (sizeof(long) * 8))) > #define BITMAP_WORD(n) (n / (sizeof(long) * 8)) --=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 --8hOCwIN/SFi+8LD2 Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAEBCAAdFiEEO+dNsU4E3yXUXRK2zQJF27ox2GcFAmP8i7MACgkQzQJF27ox 2GdjwA//R5zMfanwlFGMslUspAUebAWLiS648WN3xYZ2S7bsKNyba88ReJEIj2bW Lv4hSg/5bYSx2dlcPhaHvuMreQLiAxtm7aradyzlXEpv+FPWO6ikmXHiD4uwVALA Uh2S1r+s9hs3qyUrB5AmP7hdctffxxZy6JfGoMmMAnQFozlckaTQmy8qKKwvsA5b BNj5bvQpP4WdLS9oEJ+/kfdlhAqK2KvY7XSpa27MKZK6l+PcMTpN1K1WU1YIjHcp 3VXhabF+i/vLkL89HDEw2cINsMg9q8xJ55Xffprp4AWONZFsJS7w5r7TKyf1CM+1 LXi6x2o8XRZ3gHv26yx4YQFztItEo3n3pMSIvl+/t3xAq17B2RqBxIjB+/OSbU8k cqulqxg3OTM3SWLWHnWHIxYjncAp128C2711se5bghITUvYDUf63v8wGzj3RrWCF qSdlbXYX9GufuQliW5CK5Q1rB4ywVQ0Ml+irOqXhrNiVcuMnDQ8jQxyQkBGUUx6e SSxr/5dK3KIp6GY8FYx74CsXWUeUadc5bO/xgvXk6zKbFp/lhxMxs6AnLKRlrpTL XPDbfeXjjjpBdX65rA9O/jvUKzc+di9b+TB80RVUZ/FPtie+NB8/cIaHuE/Y9k3p Jgxb4w8SxoAvOp9I78lpF6GGRaorq4jRmB4NwnbtYnb1MAhU5A4= =u9ZU -----END PGP SIGNATURE----- --8hOCwIN/SFi+8LD2--