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] Fix definitions of SOCKET_MAX, TCP_MAX_CONNS
Date: Mon, 27 Feb 2023 21:53:45 +1100	[thread overview]
Message-ID: <Y/yLuf2OzMHT8uku@yekko> (raw)
In-Reply-To: <20230227100003.225833-1-sbrivio@redhat.com>

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

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().
> 
> Signed-off-by: Stefano Brivio <sbrivio@redhat.com>

Reviewed-by: David Gibson <david@gibson.dropbear.id.au>

> ---
>  passt.h    | 4 ++--
>  tcp.h      | 4 ++--
>  tcp_conn.h | 2 +-
>  util.h     | 2 ++
>  4 files changed, 7 insertions(+), 5 deletions(-)
> 
> 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 @@
>  
>  #define TCP_TIMER_INTERVAL		1000	/* ms */
>  
> -#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)
>  
>  struct ctx;
>  
> 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 {
>  
>  #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)
>  
>  #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))
>  
> +#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))

-- 
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 --]

      reply	other threads:[~2023-02-27 13:29 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-02-27 10:00 [PATCH] Fix definitions of SOCKET_MAX, TCP_MAX_CONNS Stefano Brivio
2023-02-27 10:53 ` 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=Y/yLuf2OzMHT8uku@yekko \
    --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).