From: Przemek Kitszel <przemyslaw.kitszel@intel.com>
To: Hangbin Liu <liuhangbin@gmail.com>, <netdev@vger.kernel.org>
Cc: Jay Vosburgh <j.vosburgh@gmail.com>,
"David S . Miller" <davem@davemloft.net>,
Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>,
Eric Dumazet <edumazet@google.com>, Liang Li <liali@redhat.com>
Subject: Re: [PATCH net-next 1/4] selftests/net/forwarding: add slowwait functions
Date: Wed, 24 Jan 2024 14:25:57 +0100 [thread overview]
Message-ID: <31c8afe0-86fe-4b39-ba7d-a26d157972c9@intel.com> (raw)
In-Reply-To: <20240124095814.1882509-2-liuhangbin@gmail.com>
On 1/24/24 10:58, Hangbin Liu wrote:
> Add slowwait functions to wait for some operations that may need a long time
> to finish. The busywait executes the cmd too fast, which is kind of wasting
> cpu in this scenario. At the same time, if shell debugging is enabled with
> `set -x`. the busywait will output too much logs.
>
> Signed-off-by: Hangbin Liu <liuhangbin@gmail.com>
> ---
> tools/testing/selftests/net/forwarding/lib.sh | 36 +++++++++++++++++++
> 1 file changed, 36 insertions(+)
>
> diff --git a/tools/testing/selftests/net/forwarding/lib.sh b/tools/testing/selftests/net/forwarding/lib.sh
> index 8a61464ab6eb..07faedc2071b 100644
> --- a/tools/testing/selftests/net/forwarding/lib.sh
> +++ b/tools/testing/selftests/net/forwarding/lib.sh
> @@ -41,6 +41,7 @@ fi
> # Kselftest framework requirement - SKIP code is 4.
> ksft_skip=4
>
> +# timeout in milliseconds
> busywait()
> {
> local timeout=$1; shift
> @@ -64,6 +65,32 @@ busywait()
> done
> }
>
> +# timeout in seconds
> +slowwait()
> +{
> + local timeout=$1; shift
> +
> + local start_time="$(date -u +%s)"
> + while true
> + do
> + local out
> + out=$("$@")
> + local ret=$?
> + if ((!ret)); then
it would be nice to have some exit code used (or just reserved) for
"operation failed, no need to wait, fail the test please"
similar to the xargs, eg:
126 if the command cannot be run
> + echo -n "$out"
> + return 0
> + fi
> +
> + local current_time="$(date -u +%s)"
> + if ((current_time - start_time > timeout)); then
> + echo -n "$out"
> + return 1
> + fi
> +
> + sleep 1
I see that `sleep 1` is simplest correct impl, but it's tempting to
suggest exponential back-off, perhaps with saturation at 15
(but then you will have to cap last sleep to don't exceed timeout by
more than 1).
> + done
> +}
> +
> ##############################################################################
> # Sanity checks
>
> @@ -505,6 +532,15 @@ busywait_for_counter()
> busywait "$timeout" until_counter_is ">= $((base + delta))" "$@"
> }
>
> +slowwait_for_counter()
> +{
> + local timeout=$1; shift
> + local delta=$1; shift
> +
> + local base=$("$@")
> + slowwait "$timeout" until_counter_is ">= $((base + delta))" "$@"
> +}
> +
> setup_wait_dev()
> {
> local dev=$1; shift
just nitpicks so I will provide my RB in case you want to ignore ;)
next prev parent reply other threads:[~2024-01-24 13:26 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-01-24 9:58 [PATCH net-next 0/4] selftests: bonding: use busy/slowwait when waiting Hangbin Liu
2024-01-24 9:58 ` [PATCH net-next 1/4] selftests/net/forwarding: add slowwait functions Hangbin Liu
2024-01-24 13:25 ` Przemek Kitszel [this message]
2024-01-26 9:22 ` Hangbin Liu
2024-01-26 9:53 ` Paolo Abeni
2024-01-24 9:58 ` [PATCH net-next 2/4] selftests: bonding: use tc filter to check if LACP was sent Hangbin Liu
2024-01-24 9:58 ` [PATCH net-next 3/4] selftests: bonding: reduce garp_test/arp_validate test time Hangbin Liu
2024-01-26 9:57 ` Paolo Abeni
2024-01-26 12:52 ` Hangbin Liu
2024-01-24 9:58 ` [PATCH net-next 4/4] selftests: bonding: use busy/slowwait instead of hard code sleep Hangbin Liu
2024-01-24 13:26 ` [PATCH net-next 0/4] selftests: bonding: use busy/slowwait when waiting Przemek Kitszel
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=31c8afe0-86fe-4b39-ba7d-a26d157972c9@intel.com \
--to=przemyslaw.kitszel@intel.com \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=j.vosburgh@gmail.com \
--cc=kuba@kernel.org \
--cc=liali@redhat.com \
--cc=liuhangbin@gmail.com \
--cc=netdev@vger.kernel.org \
--cc=pabeni@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.
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 NNTP newsgroup(s).