All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jakub Kicinski <kuba@kernel.org>
To: Gal Pressman <gal@nvidia.com>
Cc: "David S. Miller" <davem@davemloft.net>, <netdev@vger.kernel.org>,
	Eric Dumazet <edumazet@google.com>,
	Paolo Abeni <pabeni@redhat.com>, Simon Horman <horms@kernel.org>,
	Jonathan Corbet <corbet@lwn.net>,
	Tony Nguyen <anthony.l.nguyen@intel.com>,
	Przemek Kitszel <przemyslaw.kitszel@intel.com>,
	Andrew Lunn <andrew+netdev@lunn.ch>,
	"Tariq Toukan" <tariqt@nvidia.com>,
	Edward Cree <ecree.xilinx@gmail.com>,
	Ahmed Zaki <ahmed.zaki@intel.com>, <linux-doc@vger.kernel.org>,
	Nimrod Oren <noren@nvidia.com>
Subject: Re: [PATCH net-next v4 5/5] selftests: drv-net-hw: Add a test for symmetric RSS hash
Date: Thu, 20 Feb 2025 18:03:51 -0800	[thread overview]
Message-ID: <20250220180351.7e278ec9@kernel.org> (raw)
In-Reply-To: <20250220113435.417487-6-gal@nvidia.com>

On Thu, 20 Feb 2025 13:34:35 +0200 Gal Pressman wrote:
> +def _get_rand_port(remote):
> +    for _ in range(1000):
> +        port = rand_port()
> +        try:
> +            check_port_available_remote(port, remote)
> +            return port
> +        except:
> +            continue
> +
> +    raise Exception("Can't find any free unprivileged port")

TCP and UDP port spaces are separate, I think your checking if the
ports are available on TCP here, and then use them for UDP below.

We don't really care about the 100% success, I don't think we should 
be checking the ports. Pick two ports, send a A<>B packet, send a B<>A
packet, if either fails to connect or doesn't arrive just ignore.
As long as we can get ~10? successful pairs in 100? ties it's good.

> +def traffic(cfg, local_port, remote_port, ipver):
> +    af_inet = socket.AF_INET if ipver == "4" else socket.AF_INET6
> +    sock = socket.socket(af_inet, socket.SOCK_DGRAM)
> +    sock.bind(('', local_port))
> +    sock.connect((cfg.remote_addr_v[ipver], remote_port))
> +    tgt = f"{ipver}:[{cfg.addr_v[ipver]}]:{local_port},sourceport={remote_port}"
> +    cmd("echo a | socat - UDP" + tgt, host=cfg.remote)
> +    sock.recvmsg(100)

Could you use fd_read_timeout():
https://git.kernel.org/pub/scm/linux/kernel/git/netdev/net-next.git/tree/tools/testing/selftests/net/lib/py/utils.py#n20

In case the packet got lost?

> +    return sock.getsockopt(socket.SOL_SOCKET, socket.SO_INCOMING_CPU)
> +
> +
> +def test_rss_input_xfrm(cfg, ipver):
> +    """
> +    Test symmetric input_xfrm.
> +    If symmetric RSS hash is configured, send traffic twice, swapping the
> +    src/dst UDP ports, and verify that the same queue is receiving the traffic
> +    in both cases (IPs are constant).
> +    """
> +
> +    input_xfrm = cfg.ethnl.rss_get(
> +        {'header': {'dev-name': cfg.ifname}}).get('input_xfrm')
> +
> +    # Check for symmetric xor/or-xor
> +    if input_xfrm and (input_xfrm == 1 or input_xfrm == 2):
> +        cpus = set()
> +        for _ in range(8):
> +            port1 = _get_rand_port(cfg.remote)
> +            port2 = _get_rand_port(cfg.remote)
> +            cpu1 = traffic(cfg, port1, port2, ipver)
> +            cpu2 = traffic(cfg, port2, port1, ipver)
> +            cpus.update([cpu1, cpu2])
> +
> +            ksft_eq(
> +                cpu1, cpu2, comment=f"Received traffic on different cpus ({cpu1} != {cpu2}) with ports ({port1 = }, {port2 = }) while symmetric hash is configured")

the cpu1 cpu2 values will already be printed by the helper, no need 
to format them in

> +
> +        ksft_ge(len(cpus), 2, comment=f"Received traffic on less than two cpus")
> +    else:
> +        raise KsftSkipEx("Symmetric RSS hash not requested")

Flip the condition, raise the exception right after the if, then the
rest of the code doesn't have to be indented?

I'd also add a:

	if len(cpus) == 1:
		raise KsftSkipEx(f"Only one CPU seen traffic: {cpus}")
-- 
pw-bot: cr

  reply	other threads:[~2025-02-21  2:03 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-02-20 11:34 [PATCH net-next v4 0/5] Symmetric OR-XOR RSS hash Gal Pressman
2025-02-20 11:34 ` [PATCH net-next v4 1/5] ethtool: " Gal Pressman
2025-02-21 10:51   ` Bagas Sanjaya
2025-02-23 12:41     ` Gal Pressman
2025-02-20 11:34 ` [PATCH net-next v4 2/5] net/mlx5e: Symmetric OR-XOR RSS hash control Gal Pressman
2025-02-20 11:34 ` [PATCH net-next v4 3/5] selftests: drv-net: Make rand_port() get a port more reliably Gal Pressman
2025-02-20 11:34 ` [PATCH net-next v4 4/5] selftests: drv-net: Introduce a function that checks whether a port is available on remote host Gal Pressman
2025-02-20 11:34 ` [PATCH net-next v4 5/5] selftests: drv-net-hw: Add a test for symmetric RSS hash Gal Pressman
2025-02-21  2:03   ` Jakub Kicinski [this message]
2025-02-23 12:43     ` Gal Pressman

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=20250220180351.7e278ec9@kernel.org \
    --to=kuba@kernel.org \
    --cc=ahmed.zaki@intel.com \
    --cc=andrew+netdev@lunn.ch \
    --cc=anthony.l.nguyen@intel.com \
    --cc=corbet@lwn.net \
    --cc=davem@davemloft.net \
    --cc=ecree.xilinx@gmail.com \
    --cc=edumazet@google.com \
    --cc=gal@nvidia.com \
    --cc=horms@kernel.org \
    --cc=linux-doc@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=noren@nvidia.com \
    --cc=pabeni@redhat.com \
    --cc=przemyslaw.kitszel@intel.com \
    --cc=tariqt@nvidia.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.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.