patches for DPDK stable branches
 help / color / mirror / Atom feed
* [PATCH] app/testpmd: fix link check condition on port start
@ 2023-01-27 22:45 Ferruh Yigit
  2023-02-03  9:56 ` Singh, Aman Deep
  0 siblings, 1 reply; 3+ messages in thread
From: Ferruh Yigit @ 2023-01-27 22:45 UTC (permalink / raw)
  To: Aman Singh, Yuying Zhang, Michael Qiu, Pablo de Lara
  Cc: dev, stable, michael.qiu

In testpmd port start function, 'need_check_link_status' variable is
used to detect if a link check is required after port is started.

Intention is if at least one port is started, link check should be
called, and initially 'need_check_link_status' used as following:
```
start_port
	need_check_link_status <- 0
	for each p in port
		ret <- config & start p
		if ret is failure
			break
		need_check_link_status <- 1
	if need_check_link_status
		check link
	else
		log failure message
```

Later above logic is modified [1] because when there is no port at all,
'need_check_link_status' remains zero and it causes and error message
although this is a valid use case.

For this code updated as following:

```
start_port
	need_check_link_status <- -1
	for each p in port
		need_check_link_status <- 0
		ret <- config & start p
		if ret is failure
			break
		need_check_link_status <- 1
	if need_check_link_status == 1
		check link
	else if need_check_link_status == 0
		log failure message
```

This modification works fine if 'start_port()' called for a single port,
but function support both single port and all ports with 'RTE_PORT_ALL'
parameter to the function.

When it is called for all ports, above logic is wrong because
'need_check_link_status' value reset on each iteration of the loop.

For multi port case, if last port fails to start,
'need_check_link_status' will be zero and no link check will be done and
it will log a wrong error message.

Overall there are three cases to cover:
* No port exist at all
* All ports are already started
* At least on port started successfully

To cover all three cases, one option is to use 'need_check_link_status'
have multiple values to reflect above cases.
But meaning of values are not obvious which can lead more issues in the
future.

Instead converting 'need_check_link_status' to multiple boolean
variables whose names are self explanatory.

This fixes issue and link check called if at least one port started
successfully as intended.
Also log message only printed when at least one port exists and all
ports are already in started state.

[1]
Fixes: 92d2703e2c43 ("app/testpmd: fix log with no bound device")
Cc: stable@dpdk.org

Signed-off-by: Ferruh Yigit <ferruh.yigit@amd.com>
---

Cc: michael.qiu@intel.com
---
 app/test-pmd/testpmd.c | 20 ++++++++++++--------
 1 file changed, 12 insertions(+), 8 deletions(-)

diff --git a/app/test-pmd/testpmd.c b/app/test-pmd/testpmd.c
index 134d79a55547..2a1125c9fe81 100644
--- a/app/test-pmd/testpmd.c
+++ b/app/test-pmd/testpmd.c
@@ -2880,7 +2880,7 @@ update_bonding_port_dev_conf(portid_t bond_pid)
 int
 start_port(portid_t pid)
 {
-	int diag, need_check_link_status = -1;
+	int diag;
 	portid_t pi;
 	portid_t p_pi = RTE_MAX_ETHPORTS;
 	portid_t pl[RTE_MAX_ETHPORTS];
@@ -2891,6 +2891,9 @@ start_port(portid_t pid)
 	queueid_t qi;
 	struct rte_port *port;
 	struct rte_eth_hairpin_cap cap;
+	bool at_least_one_port_exist = false;
+	bool all_ports_already_started = true;
+	bool at_least_one_port_successfully_started = false;
 
 	if (port_id_is_invalid(pid, ENABLED_WARN))
 		return 0;
@@ -2906,11 +2909,13 @@ start_port(portid_t pid)
 			continue;
 		}
 
-		need_check_link_status = 0;
+		at_least_one_port_exist = true;
+
 		port = &ports[pi];
-		if (port->port_status == RTE_PORT_STOPPED)
+		if (port->port_status == RTE_PORT_STOPPED) {
 			port->port_status = RTE_PORT_HANDLING;
-		else {
+			all_ports_already_started = false;
+		} else {
 			fprintf(stderr, "Port %d is now not stopped\n", pi);
 			continue;
 		}
@@ -3130,15 +3135,14 @@ start_port(portid_t pid)
 			printf("Port %d: " RTE_ETHER_ADDR_PRT_FMT "\n", pi,
 					RTE_ETHER_ADDR_BYTES(&port->eth_addr));
 
-		/* at least one port started, need checking link status */
-		need_check_link_status = 1;
+		at_least_one_port_successfully_started = true;
 
 		pl[cfg_pi++] = pi;
 	}
 
-	if (need_check_link_status == 1 && !no_link_check)
+	if (at_least_one_port_successfully_started && !no_link_check)
 		check_all_ports_link_status(RTE_PORT_ALL);
-	else if (need_check_link_status == 0)
+	else if (at_least_one_port_exist & all_ports_already_started)
 		fprintf(stderr, "Please stop the ports first\n");
 
 	if (hairpin_mode & 0xf) {
-- 
2.25.1


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] app/testpmd: fix link check condition on port start
  2023-01-27 22:45 [PATCH] app/testpmd: fix link check condition on port start Ferruh Yigit
@ 2023-02-03  9:56 ` Singh, Aman Deep
  2023-02-08 22:54   ` Ferruh Yigit
  0 siblings, 1 reply; 3+ messages in thread
From: Singh, Aman Deep @ 2023-02-03  9:56 UTC (permalink / raw)
  To: Ferruh Yigit, Yuying Zhang, Michael Qiu, Pablo de Lara
  Cc: dev, stable, michael.qiu

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


On 1/28/2023 4:15 AM, Ferruh Yigit wrote:
> In testpmd port start function, 'need_check_link_status' variable is
> used to detect if a link check is required after port is started.
>
> Intention is if at least one port is started, link check should be
> called, and initially 'need_check_link_status' used as following:
> ```
> start_port
> 	need_check_link_status <- 0
> 	for each p in port
> 		ret <- config & start p
> 		if ret is failure
> 			break
> 		need_check_link_status <- 1
> 	if need_check_link_status
> 		check link
> 	else
> 		log failure message
> ```
>
> Later above logic is modified [1] because when there is no port at all,
> 'need_check_link_status' remains zero and it causes and error message
> although this is a valid use case.
>
> For this code updated as following:
>
> ```
> start_port
> 	need_check_link_status <- -1
> 	for each p in port
> 		need_check_link_status <- 0
> 		ret <- config & start p
> 		if ret is failure
> 			break
> 		need_check_link_status <- 1
> 	if need_check_link_status == 1
> 		check link
> 	else if need_check_link_status == 0
> 		log failure message
> ```
>
> This modification works fine if 'start_port()' called for a single port,
> but function support both single port and all ports with 'RTE_PORT_ALL'
> parameter to the function.
>
> When it is called for all ports, above logic is wrong because
> 'need_check_link_status' value reset on each iteration of the loop.
>
> For multi port case, if last port fails to start,
> 'need_check_link_status' will be zero and no link check will be done and
> it will log a wrong error message.
>
> Overall there are three cases to cover:
> * No port exist at all
> * All ports are already started
> * At least on port started successfully

Minor typo, on => one

> To cover all three cases, one option is to use 'need_check_link_status'
> have multiple values to reflect above cases.
> But meaning of values are not obvious which can lead more issues in the
> future.
>
> Instead converting 'need_check_link_status' to multiple boolean
> variables whose names are self explanatory.
>
> This fixes issue and link check called if at least one port started
> successfully as intended.
> Also log message only printed when at least one port exists and all
> ports are already in started state.
>
> [1]
> Fixes: 92d2703e2c43 ("app/testpmd: fix log with no bound device")
> Cc:stable@dpdk.org
>
> Signed-off-by: Ferruh Yigit<ferruh.yigit@amd.com>

Acked-by: Aman Singh<aman.deep.singh@intel.com>

> ---
>
> Cc:michael.qiu@intel.com
> ---
>   app/test-pmd/testpmd.c | 20 ++++++++++++--------
>   1 file changed, 12 insertions(+), 8 deletions(-)
>
> diff --git a/app/test-pmd/testpmd.c b/app/test-pmd/testpmd.c
> index 134d79a55547..2a1125c9fe81 100644
> --- a/app/test-pmd/testpmd.c
> +++ b/app/test-pmd/testpmd.c
> @@ -2880,7 +2880,7 @@ update_bonding_port_dev_conf(portid_t bond_pid)
>   int
>   start_port(portid_t pid)
>   {
> -	int diag, need_check_link_status = -1;
> +	int diag;
>   	portid_t pi;
>   	portid_t p_pi = RTE_MAX_ETHPORTS;
>   	portid_t pl[RTE_MAX_ETHPORTS];
> @@ -2891,6 +2891,9 @@ start_port(portid_t pid)
>   	queueid_t qi;
>   	struct rte_port *port;
>   	struct rte_eth_hairpin_cap cap;
> +	bool at_least_one_port_exist = false;
> +	bool all_ports_already_started = true;
> +	bool at_least_one_port_successfully_started = false;
>   
>   	if (port_id_is_invalid(pid, ENABLED_WARN))
>   		return 0;
> @@ -2906,11 +2909,13 @@ start_port(portid_t pid)
>   			continue;
>   		}
>   
> -		need_check_link_status = 0;
> +		at_least_one_port_exist = true;
> +
>   		port = &ports[pi];
> -		if (port->port_status == RTE_PORT_STOPPED)
> +		if (port->port_status == RTE_PORT_STOPPED) {
>   			port->port_status = RTE_PORT_HANDLING;
> -		else {
> +			all_ports_already_started = false;
> +		} else {
>   			fprintf(stderr, "Port %d is now not stopped\n", pi);
>   			continue;
>   		}
> @@ -3130,15 +3135,14 @@ start_port(portid_t pid)
>   			printf("Port %d: " RTE_ETHER_ADDR_PRT_FMT "\n", pi,
>   					RTE_ETHER_ADDR_BYTES(&port->eth_addr));
>   
> -		/* at least one port started, need checking link status */
> -		need_check_link_status = 1;
> +		at_least_one_port_successfully_started = true;
>   
>   		pl[cfg_pi++] = pi;
>   	}
>   
> -	if (need_check_link_status == 1 && !no_link_check)
> +	if (at_least_one_port_successfully_started && !no_link_check)
>   		check_all_ports_link_status(RTE_PORT_ALL);
> -	else if (need_check_link_status == 0)
> +	else if (at_least_one_port_exist & all_ports_already_started)
>   		fprintf(stderr, "Please stop the ports first\n");
>   
>   	if (hairpin_mode & 0xf) {

[-- Attachment #2: Type: text/html, Size: 5433 bytes --]

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] app/testpmd: fix link check condition on port start
  2023-02-03  9:56 ` Singh, Aman Deep
@ 2023-02-08 22:54   ` Ferruh Yigit
  0 siblings, 0 replies; 3+ messages in thread
From: Ferruh Yigit @ 2023-02-08 22:54 UTC (permalink / raw)
  To: Singh, Aman Deep, Yuying Zhang, Michael Qiu, Pablo de Lara
  Cc: dev, stable, michael.qiu

On 2/3/2023 9:56 AM, Singh, Aman Deep wrote:
> 
> On 1/28/2023 4:15 AM, Ferruh Yigit wrote:
>> In testpmd port start function, 'need_check_link_status' variable is
>> used to detect if a link check is required after port is started.
>>
>> Intention is if at least one port is started, link check should be
>> called, and initially 'need_check_link_status' used as following:
>> ```
>> start_port
>> 	need_check_link_status <- 0
>> 	for each p in port
>> 		ret <- config & start p
>> 		if ret is failure
>> 			break
>> 		need_check_link_status <- 1
>> 	if need_check_link_status
>> 		check link
>> 	else
>> 		log failure message
>> ```
>>
>> Later above logic is modified [1] because when there is no port at all,
>> 'need_check_link_status' remains zero and it causes and error message
>> although this is a valid use case.
>>
>> For this code updated as following:
>>
>> ```
>> start_port
>> 	need_check_link_status <- -1
>> 	for each p in port
>> 		need_check_link_status <- 0
>> 		ret <- config & start p
>> 		if ret is failure
>> 			break
>> 		need_check_link_status <- 1
>> 	if need_check_link_status == 1
>> 		check link
>> 	else if need_check_link_status == 0
>> 		log failure message
>> ```
>>
>> This modification works fine if 'start_port()' called for a single port,
>> but function support both single port and all ports with 'RTE_PORT_ALL'
>> parameter to the function.
>>
>> When it is called for all ports, above logic is wrong because
>> 'need_check_link_status' value reset on each iteration of the loop.
>>
>> For multi port case, if last port fails to start,
>> 'need_check_link_status' will be zero and no link check will be done and
>> it will log a wrong error message.
>>
>> Overall there are three cases to cover:
>> * No port exist at all
>> * All ports are already started
>> * At least on port started successfully
> 
> Minor typo, on => one
> 

Fixed while merging.

>> To cover all three cases, one option is to use 'need_check_link_status'
>> have multiple values to reflect above cases.
>> But meaning of values are not obvious which can lead more issues in the
>> future.
>>
>> Instead converting 'need_check_link_status' to multiple boolean
>> variables whose names are self explanatory.
>>
>> This fixes issue and link check called if at least one port started
>> successfully as intended.
>> Also log message only printed when at least one port exists and all
>> ports are already in started state.
>>
>> [1]
>> Fixes: 92d2703e2c43 ("app/testpmd: fix log with no bound device")
>> Cc: stable@dpdk.org
>>
>> Signed-off-by: Ferruh Yigit <ferruh.yigit@amd.com>
> 
> Acked-by: Aman Singh <aman.deep.singh@intel.com>
> 

Applied to dpdk-next-net/main, thanks.


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2023-02-08 22:55 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-01-27 22:45 [PATCH] app/testpmd: fix link check condition on port start Ferruh Yigit
2023-02-03  9:56 ` Singh, Aman Deep
2023-02-08 22:54   ` Ferruh Yigit

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).