From patchwork Tue Nov 14 15:11:31 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lucas Karpinski X-Patchwork-Id: 164988 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:6358:a59:b0:164:83eb:24d7 with SMTP id 25csp1988808rwb; Tue, 14 Nov 2023 07:12:17 -0800 (PST) X-Google-Smtp-Source: AGHT+IEqpDgiDa52M9SZqn7g6ru8E9SMyy7OBk/KW3bvO7LiYqSHWHE2gubHRJG6tLjd2vseMDct X-Received: by 2002:a17:902:bd95:b0:1cc:36fb:22ae with SMTP id q21-20020a170902bd9500b001cc36fb22aemr3132951pls.2.1699974737205; Tue, 14 Nov 2023 07:12:17 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1699974737; cv=none; d=google.com; s=arc-20160816; b=YxIoLNFFc7aPLB6EcQCuUSDxcBOvfoO71M+aw6tTc6J/T3kx0Ro+0Pys7JITVUt9jA gmsP4AUMo1euT69Dz29X+XHS3SA0nZPgvXcZnxOhhyAyVZmymt5NUWbLdE6DuejJ8xob V9/tUEs28SI6sR0uVmgsnQqx278SP7daz9Dc7b5h6BUPtAfPH/Ks6Qvw6t9K+wpJdg8Y GzdpJHaISo71yQ2qa/r82iLprGlIRV2TFsBxsww5okk3pltFuCSefXLSvnfY47TlLW68 0hSwT7ex3fzgQ/Dw3emR/6Ys8uafqZVelT+VShnNZGUCN/mZn9GK59xtKj2kNjIMyuqv clUQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:user-agent:content-disposition:mime-version :message-id:subject:cc:to:from:date:dkim-signature; bh=m/doj/T8nqtKHRc2PP5ZmgpfbSgB0XHlZpghgNdMkI4=; fh=Vlhq0d/Io7RuK4h5uT1aEVRWteSg0QIhqitL6VtnXtw=; b=SWT4GL+vWrm5uUM8tV7OdN0mWqdnCmoxKvXkxvYJBVwWbnxKG1KZ3Cd/8Dts+CNr6z NDM+5LP8qZAETm59R0IX9iuCiftZJeLojFaDHAZ65lXJRl9TautU/2EQI4yaUuMz++0I XhX+rysGmmYARlU7YZzIjXZZmRVTCVKXNLH2FX602N8xBfnCWut5TXq0HYwFdPm+W3EM h+diMuBbUydy9Okfh98lJvg5WJ8gjFJphBgtWpZtSQll1PgtKykmeGE94LrUrYUk8pMO kn8ogfkYtbddOQVmrQmzVRYtHbXGQfa4HuWhe3367BLGK4J0CraLmKT/TGmepyxlKxQo J1/A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b="V6/jzaqe"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from snail.vger.email (snail.vger.email. [2620:137:e000::3:7]) by mx.google.com with ESMTPS id b16-20020a170903229000b001ca4ad86363si8467025plh.390.2023.11.14.07.12.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 14 Nov 2023 07:12:17 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) client-ip=2620:137:e000::3:7; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b="V6/jzaqe"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by snail.vger.email (Postfix) with ESMTP id 13872805F099; Tue, 14 Nov 2023 07:11:54 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232211AbjKNPLk (ORCPT + 29 others); Tue, 14 Nov 2023 10:11:40 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36896 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229456AbjKNPLj (ORCPT ); Tue, 14 Nov 2023 10:11:39 -0500 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C6B7BE3 for ; Tue, 14 Nov 2023 07:11:35 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1699974695; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type; bh=m/doj/T8nqtKHRc2PP5ZmgpfbSgB0XHlZpghgNdMkI4=; b=V6/jzaqeGA0KVZTTy+OiBNzPOO7lRV1qFqMf+K7/mcIgJU8THMtIrJdBNvB1XbPw9yH3B+ Dx1q/Cgkg7RrR5i1O5+S1vDKvyjA/MQ36y/Tpl7ft+TJdLZK/MaplikanOc5UdN5Lv+J4X kMcNNtiuW0+iekVULs/VWDl1jdRqf7o= Received: from mail-qv1-f69.google.com (mail-qv1-f69.google.com [209.85.219.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-247-xyUMiUYkNWSqUArVx0MXBg-1; Tue, 14 Nov 2023 10:11:33 -0500 X-MC-Unique: xyUMiUYkNWSqUArVx0MXBg-1 Received: by mail-qv1-f69.google.com with SMTP id 6a1803df08f44-66d4aa946ceso98350636d6.1 for ; Tue, 14 Nov 2023 07:11:33 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1699974693; x=1700579493; h=user-agent:content-disposition:mime-version:message-id:subject:cc :to:from:date:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=m/doj/T8nqtKHRc2PP5ZmgpfbSgB0XHlZpghgNdMkI4=; b=SeEZexdrGuWyIhcO27qmU8Csz9hKmlUweEUj1ov5400m+V0EUltDvS450ZxJrZ/OtE nG64mY2n2vnxh2taS4Q/fhvE5g8n8NIj2ECVctgqTFIsVh9tUwnBlhsYyhoXIfgAZTXd SJJer0evRWkHYEKJw5ZGL4qZoPriia6kwsZvkfT5mjRZTzyktxDw/QAjhpp7XS4nxzo6 TELuOaAD5/J3nWVVdsmTW8aj1yZ/jPYQ2SR3XrQHBrAozeKH/FqTup9SLI8bWX4pYxcm FpYFUz3SUDF80GGsLumyo9nwDIqO8CKqZ1euBsjpo4jr0TJ/KNeYeuuRKUrbU1PaKF+k b98w== X-Gm-Message-State: AOJu0YwzbSVmbvkNAU0Wp83i5LA7/WVRqbJMEQaiHf8mnPf0bapE/a/5 YbwfCsKWVDQ5AC82E0IKD9npzNPe431JHYDF3Ie9ENFedlP5RktqTq2gmjng+SunkV02zDkLCtM +3rDUaYxWDUVzhmkggCWXwm35 X-Received: by 2002:a05:6214:a6b:b0:671:560f:3306 with SMTP id ef11-20020a0562140a6b00b00671560f3306mr4222477qvb.4.1699974693059; Tue, 14 Nov 2023 07:11:33 -0800 (PST) X-Received: by 2002:a05:6214:a6b:b0:671:560f:3306 with SMTP id ef11-20020a0562140a6b00b00671560f3306mr4222433qvb.4.1699974692710; Tue, 14 Nov 2023 07:11:32 -0800 (PST) Received: from fedora ([142.181.225.135]) by smtp.gmail.com with ESMTPSA id u12-20020a0cea4c000000b00655d711180dsm2988835qvp.17.2023.11.14.07.11.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 14 Nov 2023 07:11:32 -0800 (PST) Date: Tue, 14 Nov 2023 10:11:31 -0500 From: Lucas Karpinski To: "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Shuah Khan Cc: linux-kernel@vger.kernel.org, netdev@vger.kernel.org, linux-kselftest@vger.kernel.org Subject: [PATCH net-next v3] selftests/net: synchronize udpgro tests' tx and rx connection Message-ID: MIME-Version: 1.0 Content-Disposition: inline User-Agent: NeoMutt/20231023 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H4,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_NONE, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (snail.vger.email [0.0.0.0]); Tue, 14 Nov 2023 07:11:54 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1782552710010901137 X-GMAIL-MSGID: 1782552710010901137 The sockets used by udpgso_bench_tx aren't always ready when udpgso_bench_tx transmits packets. This issue is more prevalent in -rt kernels, but can occur in both. Replace the hacky sleep calls with a function that checks whether the ports in the namespace are ready for use. Suggested-by: Paolo Abeni Signed-off-by: Lucas Karpinski Reviewed-by: Willem de Bruijn --- https://lore.kernel.org/all/6ceki76bcv7qz6de5rxc26ot6aezdmeoz2g4ubtve7qwozmyyw@zibbg64wsdjp/ v3: - moved redundant code to net_helper.sh - replaced awk with grep - changed commit message to specify udpgro - added target tree v2: - applied synchronization method suggested by Paolo - changed commit message to code tools/testing/selftests/net/net_helper.sh | 22 +++++++++++++++++++ tools/testing/selftests/net/udpgro.sh | 13 +++++------ tools/testing/selftests/net/udpgro_bench.sh | 5 +++-- tools/testing/selftests/net/udpgro_frglist.sh | 5 +++-- 4 files changed, 34 insertions(+), 11 deletions(-) create mode 100755 tools/testing/selftests/net/net_helper.sh diff --git a/tools/testing/selftests/net/net_helper.sh b/tools/testing/selftests/net/net_helper.sh new file mode 100755 index 000000000000..4fe0befa13fb --- /dev/null +++ b/tools/testing/selftests/net/net_helper.sh @@ -0,0 +1,22 @@ +#!/bin/bash +# SPDX-License-Identifier: GPL-2.0 +# +# Helper functions + +wait_local_port_listen() +{ + local listener_ns="${1}" + local port="${2}" + local protocol="${3}" + local port_hex + local i + + port_hex="$(printf "%04X" "${port}")" + for i in $(seq 10); do + if ip netns exec "${listener_ns}" cat /proc/net/"${protocol}"* | \ + grep -q "${port_hex}"; then + break + fi + sleep 0.1 + done +} diff --git a/tools/testing/selftests/net/udpgro.sh b/tools/testing/selftests/net/udpgro.sh index 0c743752669a..af5dc57c8ce9 100755 --- a/tools/testing/selftests/net/udpgro.sh +++ b/tools/testing/selftests/net/udpgro.sh @@ -3,6 +3,8 @@ # # Run a series of udpgro functional tests. +source net_helper.sh + readonly PEER_NS="ns-peer-$(mktemp -u XXXXXX)" BPF_FILE="../bpf/xdp_dummy.bpf.o" @@ -51,8 +53,7 @@ run_one() { echo "ok" || \ echo "failed" & - # Hack: let bg programs complete the startup - sleep 0.2 + wait_local_port_listen ${PEER_NS} 8000 udp ./udpgso_bench_tx ${tx_args} ret=$? wait $(jobs -p) @@ -97,7 +98,7 @@ run_one_nat() { echo "ok" || \ echo "failed"& - sleep 0.1 + wait_local_port_listen "${PEER_NS}" 8000 udp ./udpgso_bench_tx ${tx_args} ret=$? kill -INT $pid @@ -118,11 +119,9 @@ run_one_2sock() { echo "ok" || \ echo "failed" & - # Hack: let bg programs complete the startup - sleep 0.2 + wait_local_port_listen "${PEER_NS}" 12345 udp ./udpgso_bench_tx ${tx_args} -p 12345 - sleep 0.1 - # first UDP GSO socket should be closed at this point + wait_local_port_listen "${PEER_NS}" 8000 udp ./udpgso_bench_tx ${tx_args} ret=$? wait $(jobs -p) diff --git a/tools/testing/selftests/net/udpgro_bench.sh b/tools/testing/selftests/net/udpgro_bench.sh index 894972877e8b..cb664679b434 100755 --- a/tools/testing/selftests/net/udpgro_bench.sh +++ b/tools/testing/selftests/net/udpgro_bench.sh @@ -3,6 +3,8 @@ # # Run a series of udpgro benchmarks +source net_helper.sh + readonly PEER_NS="ns-peer-$(mktemp -u XXXXXX)" BPF_FILE="../bpf/xdp_dummy.bpf.o" @@ -40,8 +42,7 @@ run_one() { ip netns exec "${PEER_NS}" ./udpgso_bench_rx ${rx_args} -r & ip netns exec "${PEER_NS}" ./udpgso_bench_rx -t ${rx_args} -r & - # Hack: let bg programs complete the startup - sleep 0.2 + wait_local_port_listen "${PEER_NS}" 8000 udp ./udpgso_bench_tx ${tx_args} } diff --git a/tools/testing/selftests/net/udpgro_frglist.sh b/tools/testing/selftests/net/udpgro_frglist.sh index 0a6359bed0b9..dd47fa96f6b3 100755 --- a/tools/testing/selftests/net/udpgro_frglist.sh +++ b/tools/testing/selftests/net/udpgro_frglist.sh @@ -3,6 +3,8 @@ # # Run a series of udpgro benchmarks +source net_helper.sh + readonly PEER_NS="ns-peer-$(mktemp -u XXXXXX)" BPF_FILE="../bpf/xdp_dummy.bpf.o" @@ -45,8 +47,7 @@ run_one() { echo ${rx_args} ip netns exec "${PEER_NS}" ./udpgso_bench_rx ${rx_args} -r & - # Hack: let bg programs complete the startup - sleep 0.2 + wait_local_port_listen "${PEER_NS}" 8000 udp ./udpgso_bench_tx ${tx_args} }