* [PATCH v1 1/1] app/testpmd: add sleep command
@ 2025-05-02 12:27 Anatoly Burakov
2025-05-02 12:37 ` Bruce Richardson
2025-05-02 15:42 ` Stephen Hemminger
0 siblings, 2 replies; 6+ messages in thread
From: Anatoly Burakov @ 2025-05-02 12:27 UTC (permalink / raw)
To: dev, Aman Singh
Test-pmd already has a way to run a list of commands from file, but there
is no way to pause execution for a specified amount of time between two
commands. This may be necessary for simple automation, particularly for
waiting on some asynchronous operation such as link status update.
Add a simple sleep command to wait until certain number of milliseconds has
passed.
Signed-off-by: Anatoly Burakov <anatoly.burakov@intel.com>
---
app/test-pmd/cmdline.c | 35 +++++++++++++++++++++++++++++++++++
1 file changed, 35 insertions(+)
diff --git a/app/test-pmd/cmdline.c b/app/test-pmd/cmdline.c
index d4bb3ec998..1e429e6d0a 100644
--- a/app/test-pmd/cmdline.c
+++ b/app/test-pmd/cmdline.c
@@ -151,6 +151,9 @@ static void cmd_help_long_parsed(void *parsed_result,
"quit\n"
" Quit to prompt.\n\n"
+
+ "sleep ms\n"
+ " Sleep for ms milliseconds.\n\n"
);
}
@@ -7768,6 +7771,37 @@ static cmdline_parse_inst_t cmd_quit = {
},
};
+/* *** SLEEP *** */
+struct cmd_sleep_result {
+ cmdline_fixed_string_t sleep;
+ uint32_t ms;
+};
+
+static void cmd_sleep_parsed(void *parsed_result,
+ __rte_unused struct cmdline *cl,
+ __rte_unused void *data)
+{
+ struct cmd_sleep_result *res = parsed_result;
+
+ rte_delay_us_sleep(res->ms * 1000);
+}
+
+static cmdline_parse_token_string_t cmd_sleep_sleep =
+ TOKEN_STRING_INITIALIZER(struct cmd_sleep_result, sleep, "sleep");
+static cmdline_parse_token_num_t cmd_sleep_seconds =
+ TOKEN_NUM_INITIALIZER(struct cmd_sleep_result, ms, RTE_UINT32);
+
+static cmdline_parse_inst_t cmd_sleep = {
+ .f = cmd_sleep_parsed,
+ .data = NULL,
+ .help_str = "sleep <ms>: Sleep for a specified number of milliseconds",
+ .tokens = {
+ (void *)&cmd_sleep_sleep,
+ (void *)&cmd_sleep_seconds,
+ NULL,
+ },
+};
+
/* *** ADD/REMOVE MAC ADDRESS FROM A PORT *** */
struct cmd_mac_addr_result {
cmdline_fixed_string_t mac_addr_cmd;
@@ -13701,6 +13735,7 @@ static cmdline_parse_ctx_t builtin_ctx[] = {
&cmd_help_brief,
&cmd_help_long,
&cmd_quit,
+ &cmd_sleep,
&cmd_load_from_file,
&cmd_showport,
&cmd_showqueue,
--
2.47.1
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH v1 1/1] app/testpmd: add sleep command
2025-05-02 12:27 [PATCH v1 1/1] app/testpmd: add sleep command Anatoly Burakov
@ 2025-05-02 12:37 ` Bruce Richardson
2025-05-02 14:35 ` Burakov, Anatoly
2025-05-02 15:42 ` Stephen Hemminger
1 sibling, 1 reply; 6+ messages in thread
From: Bruce Richardson @ 2025-05-02 12:37 UTC (permalink / raw)
To: Anatoly Burakov; +Cc: dev, Aman Singh
On Fri, May 02, 2025 at 01:27:29PM +0100, Anatoly Burakov wrote:
> Test-pmd already has a way to run a list of commands from file, but there
> is no way to pause execution for a specified amount of time between two
> commands. This may be necessary for simple automation, particularly for
> waiting on some asynchronous operation such as link status update.
>
> Add a simple sleep command to wait until certain number of milliseconds has
> passed.
>
> Signed-off-by: Anatoly Burakov <anatoly.burakov@intel.com>
> ---
> app/test-pmd/cmdline.c | 35 +++++++++++++++++++++++++++++++++++
> 1 file changed, 35 insertions(+)
>
> diff --git a/app/test-pmd/cmdline.c b/app/test-pmd/cmdline.c
> index d4bb3ec998..1e429e6d0a 100644
> --- a/app/test-pmd/cmdline.c
> +++ b/app/test-pmd/cmdline.c
> @@ -151,6 +151,9 @@ static void cmd_help_long_parsed(void *parsed_result,
>
> "quit\n"
> " Quit to prompt.\n\n"
> +
> + "sleep ms\n"
> + " Sleep for ms milliseconds.\n\n"
> );
> }
>
A "sleep" command, I would expect to sleep for a certain number of seconds,
for compatibility e.g. with terminal "sleep" command.
To keep this as "ms" granularity, how about making it explicit as a
"sleep_ms" command. Alternatively, how about adding a usleep command? [Not
sure "msleep" works, which is why I suggested sleep_ms instead]
/Bruce
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH v1 1/1] app/testpmd: add sleep command
2025-05-02 12:37 ` Bruce Richardson
@ 2025-05-02 14:35 ` Burakov, Anatoly
2025-05-02 14:43 ` Bruce Richardson
0 siblings, 1 reply; 6+ messages in thread
From: Burakov, Anatoly @ 2025-05-02 14:35 UTC (permalink / raw)
To: Bruce Richardson; +Cc: dev, Aman Singh
On 5/2/2025 2:37 PM, Bruce Richardson wrote:
> On Fri, May 02, 2025 at 01:27:29PM +0100, Anatoly Burakov wrote:
>> Test-pmd already has a way to run a list of commands from file, but there
>> is no way to pause execution for a specified amount of time between two
>> commands. This may be necessary for simple automation, particularly for
>> waiting on some asynchronous operation such as link status update.
>>
>> Add a simple sleep command to wait until certain number of milliseconds has
>> passed.
>>
>> Signed-off-by: Anatoly Burakov <anatoly.burakov@intel.com>
>> ---
>> app/test-pmd/cmdline.c | 35 +++++++++++++++++++++++++++++++++++
>> 1 file changed, 35 insertions(+)
>>
>> diff --git a/app/test-pmd/cmdline.c b/app/test-pmd/cmdline.c
>> index d4bb3ec998..1e429e6d0a 100644
>> --- a/app/test-pmd/cmdline.c
>> +++ b/app/test-pmd/cmdline.c
>> @@ -151,6 +151,9 @@ static void cmd_help_long_parsed(void *parsed_result,
>>
>> "quit\n"
>> " Quit to prompt.\n\n"
>> +
>> + "sleep ms\n"
>> + " Sleep for ms milliseconds.\n\n"
>> );
>> }
>>
>
> A "sleep" command, I would expect to sleep for a certain number of seconds,
> for compatibility e.g. with terminal "sleep" command.
> To keep this as "ms" granularity, how about making it explicit as a
> "sleep_ms" command. Alternatively, how about adding a usleep command? [Not
> sure "msleep" works, which is why I suggested sleep_ms instead]
>
> /Bruce
I have no strong opinions on what it should do. My initial version *was*
a "sleep in seconds" command, I just thought that maybe someone would
want it more flexible. I suspect that actually "sleep" and second
granularity is just fine.
--
Thanks,
Anatoly
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH v1 1/1] app/testpmd: add sleep command
2025-05-02 14:35 ` Burakov, Anatoly
@ 2025-05-02 14:43 ` Bruce Richardson
2025-05-02 15:33 ` Morten Brørup
0 siblings, 1 reply; 6+ messages in thread
From: Bruce Richardson @ 2025-05-02 14:43 UTC (permalink / raw)
To: Burakov, Anatoly; +Cc: dev, Aman Singh
On Fri, May 02, 2025 at 04:35:08PM +0200, Burakov, Anatoly wrote:
> On 5/2/2025 2:37 PM, Bruce Richardson wrote:
> > On Fri, May 02, 2025 at 01:27:29PM +0100, Anatoly Burakov wrote:
> > > Test-pmd already has a way to run a list of commands from file, but there
> > > is no way to pause execution for a specified amount of time between two
> > > commands. This may be necessary for simple automation, particularly for
> > > waiting on some asynchronous operation such as link status update.
> > >
> > > Add a simple sleep command to wait until certain number of milliseconds has
> > > passed.
> > >
> > > Signed-off-by: Anatoly Burakov <anatoly.burakov@intel.com>
> > > ---
> > > app/test-pmd/cmdline.c | 35 +++++++++++++++++++++++++++++++++++
> > > 1 file changed, 35 insertions(+)
> > >
> > > diff --git a/app/test-pmd/cmdline.c b/app/test-pmd/cmdline.c
> > > index d4bb3ec998..1e429e6d0a 100644
> > > --- a/app/test-pmd/cmdline.c
> > > +++ b/app/test-pmd/cmdline.c
> > > @@ -151,6 +151,9 @@ static void cmd_help_long_parsed(void *parsed_result,
> > > "quit\n"
> > > " Quit to prompt.\n\n"
> > > +
> > > + "sleep ms\n"
> > > + " Sleep for ms milliseconds.\n\n"
> > > );
> > > }
> >
> > A "sleep" command, I would expect to sleep for a certain number of seconds,
> > for compatibility e.g. with terminal "sleep" command.
> > To keep this as "ms" granularity, how about making it explicit as a
> > "sleep_ms" command. Alternatively, how about adding a usleep command? [Not
> > sure "msleep" works, which is why I suggested sleep_ms instead]
> >
> > /Bruce
>
> I have no strong opinions on what it should do. My initial version *was* a
> "sleep in seconds" command, I just thought that maybe someone would want it
> more flexible. I suspect that actually "sleep" and second granularity is
> just fine.
>
I think we do need to support sub-second sleep granularity, though. If we
only add "sleep" with time specified in seconds, I think we'd also need to
add in usleep with micro-sec granularity too.
Other alternatives:
- have sleep take an option 3rd parameter of time in
minisecond. So "sleep 1" is to sleep for one second, but "sleep 0 500" is
to sleep for 1/2 sec, and "sleep 2 750" is to sleep for 2.75 seconds.
- add floating point support to the cmdline library, and then allow sleep time
specified in seconds using that.
/Bruce
^ permalink raw reply [flat|nested] 6+ messages in thread
* RE: [PATCH v1 1/1] app/testpmd: add sleep command
2025-05-02 14:43 ` Bruce Richardson
@ 2025-05-02 15:33 ` Morten Brørup
0 siblings, 0 replies; 6+ messages in thread
From: Morten Brørup @ 2025-05-02 15:33 UTC (permalink / raw)
To: Bruce Richardson, Burakov, Anatoly; +Cc: dev, Aman Singh
> From: Bruce Richardson [mailto:bruce.richardson@intel.com]
> Sent: Friday, 2 May 2025 16.44
>
> On Fri, May 02, 2025 at 04:35:08PM +0200, Burakov, Anatoly wrote:
> > On 5/2/2025 2:37 PM, Bruce Richardson wrote:
> > > On Fri, May 02, 2025 at 01:27:29PM +0100, Anatoly Burakov wrote:
> > > > Test-pmd already has a way to run a list of commands from file,
> but there
> > > > is no way to pause execution for a specified amount of time
> between two
> > > > commands. This may be necessary for simple automation,
> particularly for
> > > > waiting on some asynchronous operation such as link status
> update.
> > > >
> > > > Add a simple sleep command to wait until certain number of
> milliseconds has
> > > > passed.
> > > >
> > > > Signed-off-by: Anatoly Burakov <anatoly.burakov@intel.com>
> > > > ---
> > > > app/test-pmd/cmdline.c | 35 +++++++++++++++++++++++++++++++++++
> > > > 1 file changed, 35 insertions(+)
> > > >
> > > > diff --git a/app/test-pmd/cmdline.c b/app/test-pmd/cmdline.c
> > > > index d4bb3ec998..1e429e6d0a 100644
> > > > --- a/app/test-pmd/cmdline.c
> > > > +++ b/app/test-pmd/cmdline.c
> > > > @@ -151,6 +151,9 @@ static void cmd_help_long_parsed(void
> *parsed_result,
> > > > "quit\n"
> > > > " Quit to prompt.\n\n"
> > > > +
> > > > + "sleep ms\n"
> > > > + " Sleep for ms milliseconds.\n\n"
> > > > );
> > > > }
> > >
> > > A "sleep" command, I would expect to sleep for a certain number of
> seconds,
> > > for compatibility e.g. with terminal "sleep" command.
> > > To keep this as "ms" granularity, how about making it explicit as a
> > > "sleep_ms" command. Alternatively, how about adding a usleep
> command? [Not
> > > sure "msleep" works, which is why I suggested sleep_ms instead]
> > >
> > > /Bruce
> >
> > I have no strong opinions on what it should do. My initial version
> *was* a
> > "sleep in seconds" command, I just thought that maybe someone would
> want it
> > more flexible. I suspect that actually "sleep" and second granularity
> is
> > just fine.
> >
>
> I think we do need to support sub-second sleep granularity, though. If
> we
> only add "sleep" with time specified in seconds, I think we'd also need
> to
> add in usleep with micro-sec granularity too.
>
> Other alternatives:
> - have sleep take an option 3rd parameter of time in
> minisecond. So "sleep 1" is to sleep for one second, but "sleep 0
> 500" is
> to sleep for 1/2 sec, and "sleep 2 750" is to sleep for 2.75 seconds.
> - add floating point support to the cmdline library, and then allow
> sleep time
> specified in seconds using that.
>
> /Bruce
"sleep" should take one parameter: seconds.
It can be float, or a separate "usleep" command taking a microseconds parameter can be added. This change (using float instead of int) or addition (usleep command) can be added later, if you like.
Initially, I would lean towards a float parameter, but maybe it's easier for scripts to use "usleep" with an integer.
In real life, the duration will probably be either "N" (i.e. a natural number) or "0.N" (i.e. less than one second), so an "usleep" might be just as good.
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH v1 1/1] app/testpmd: add sleep command
2025-05-02 12:27 [PATCH v1 1/1] app/testpmd: add sleep command Anatoly Burakov
2025-05-02 12:37 ` Bruce Richardson
@ 2025-05-02 15:42 ` Stephen Hemminger
1 sibling, 0 replies; 6+ messages in thread
From: Stephen Hemminger @ 2025-05-02 15:42 UTC (permalink / raw)
To: Anatoly Burakov; +Cc: dev, Aman Singh
On Fri, 2 May 2025 13:27:29 +0100
Anatoly Burakov <anatoly.burakov@intel.com> wrote:
> @@ -13701,6 +13735,7 @@ static cmdline_parse_ctx_t builtin_ctx[] = {
> &cmd_help_brief,
> &cmd_help_long,
> &cmd_quit,
> + &cmd_sleep,
> &cmd_load_from_file,
> &cmd_showport,
> &cmd_showqueue,
> --
Looks like original list was in alphabetic order.
Please preserve that
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2025-05-02 20:26 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-05-02 12:27 [PATCH v1 1/1] app/testpmd: add sleep command Anatoly Burakov
2025-05-02 12:37 ` Bruce Richardson
2025-05-02 14:35 ` Burakov, Anatoly
2025-05-02 14:43 ` Bruce Richardson
2025-05-02 15:33 ` Morten Brørup
2025-05-02 15:42 ` Stephen Hemminger
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).