diff mbox series

[2/2] examples/ethtool: add closing port operation

Message ID 1617876888-63458-3-git-send-email-humin29@huawei.com (mailing list archive)
State Superseded
Delegated to: Thomas Monjalon
Headers show
Series fix bugs for ethtool APP | expand

Checks

Context Check Description
ci/iol-testing success Testing PASS
ci/iol-abi-testing success Testing PASS
ci/intel-Testing success Testing PASS
ci/Intel-compilation success Compilation OK
ci/github-robot success github build: passed
ci/travis-robot success travis build: passed
ci/checkpatch success coding style OK

Commit Message

Min Hu (Connor) April 8, 2021, 10:14 a.m. UTC
From: Huisong Li <lihuisong@huawei.com>

Currently, ethtool directly ends the process after 'quit' cmd. In this
case, software resources are not released and hardware resources of the
device are not uninstalled.

This patch adds closing port operation to release resources.

Fixes: bda68ab9d1e7 ("examples/ethtool: add user-space ethtool sample application")
Cc: stable@dpdk.org

Signed-off-by: Huisong Li <lihuisong@huawei.com>
Signed-off-by: Min Hu (Connor) <humin29@huawei.com>
---
 examples/ethtool/ethtool-app/main.c | 23 +++++++++++++++++++++++
 1 file changed, 23 insertions(+)

Comments

Thomas Monjalon April 20, 2021, 12:59 a.m. UTC | #1
08/04/2021 12:14, Min Hu (Connor):
> From: Huisong Li <lihuisong@huawei.com>
> 
> Currently, ethtool directly ends the process after 'quit' cmd. In this
> case, software resources are not released and hardware resources of the
> device are not uninstalled.
> 
> This patch adds closing port operation to release resources.
> 
> Fixes: bda68ab9d1e7 ("examples/ethtool: add user-space ethtool sample application")
> Cc: stable@dpdk.org
> 
> Signed-off-by: Huisong Li <lihuisong@huawei.com>
> Signed-off-by: Min Hu (Connor) <humin29@huawei.com>
> ---
> --- a/examples/ethtool/ethtool-app/main.c
> +++ b/examples/ethtool/ethtool-app/main.c
> +static void close_ports(void)
> +{
> +	uint16_t portid;
> +	int ret;
> +
> +	for (portid = 0; portid < app_cfg.cnt_ports; portid++) {
> +		printf("Closing port %d...", portid);
> +		ret = rte_eth_dev_stop(portid);
> +		if (ret != 0)
> +			rte_exit(EXIT_FAILURE, "rte_eth_dev_stop: err=%s, port=%u\n",
> +				 strerror(-ret), portid);
> +		rte_eth_dev_close(portid);
> +		printf(" Done\n");
> +	}
> +
> +	ret = rte_eal_cleanup();
> +	if (ret != 0)
> +		rte_exit(EXIT_FAILURE, "EAL cleanup failed: %s\n",
> +			 strerror(-ret));

It would be better to add EAL cleanup in the main function.
Min Hu (Connor) April 20, 2021, 9:10 a.m. UTC | #2
在 2021/4/20 8:59, Thomas Monjalon 写道:
> 08/04/2021 12:14, Min Hu (Connor):
>> From: Huisong Li <lihuisong@huawei.com>
>>
>> Currently, ethtool directly ends the process after 'quit' cmd. In this
>> case, software resources are not released and hardware resources of the
>> device are not uninstalled.
>>
>> This patch adds closing port operation to release resources.
>>
>> Fixes: bda68ab9d1e7 ("examples/ethtool: add user-space ethtool sample application")
>> Cc: stable@dpdk.org
>>
>> Signed-off-by: Huisong Li <lihuisong@huawei.com>
>> Signed-off-by: Min Hu (Connor) <humin29@huawei.com>
>> ---
>> --- a/examples/ethtool/ethtool-app/main.c
>> +++ b/examples/ethtool/ethtool-app/main.c
>> +static void close_ports(void)
>> +{
>> +	uint16_t portid;
>> +	int ret;
>> +
>> +	for (portid = 0; portid < app_cfg.cnt_ports; portid++) {
>> +		printf("Closing port %d...", portid);
>> +		ret = rte_eth_dev_stop(portid);
>> +		if (ret != 0)
>> +			rte_exit(EXIT_FAILURE, "rte_eth_dev_stop: err=%s, port=%u\n",
>> +				 strerror(-ret), portid);
>> +		rte_eth_dev_close(portid);
>> +		printf(" Done\n");
>> +	}
>> +
>> +	ret = rte_eal_cleanup();
>> +	if (ret != 0)
>> +		rte_exit(EXIT_FAILURE, "EAL cleanup failed: %s\n",
>> +			 strerror(-ret));
> 
> It would be better to add EAL cleanup in the main function.
> 
Hi, Thomas,
	It has already been done in this patch: "examples: add eal
cleanup to examples", please check it out, thanks.
> 
> .
>
Thomas Monjalon April 20, 2021, 9:38 a.m. UTC | #3
20/04/2021 11:10, Min Hu (Connor):
> 
> 在 2021/4/20 8:59, Thomas Monjalon 写道:
> > 08/04/2021 12:14, Min Hu (Connor):
> >> From: Huisong Li <lihuisong@huawei.com>
> >>
> >> Currently, ethtool directly ends the process after 'quit' cmd. In this
> >> case, software resources are not released and hardware resources of the
> >> device are not uninstalled.
> >>
> >> This patch adds closing port operation to release resources.
> >>
> >> Fixes: bda68ab9d1e7 ("examples/ethtool: add user-space ethtool sample application")
> >> Cc: stable@dpdk.org
> >>
> >> Signed-off-by: Huisong Li <lihuisong@huawei.com>
> >> Signed-off-by: Min Hu (Connor) <humin29@huawei.com>
> >> ---
> >> --- a/examples/ethtool/ethtool-app/main.c
> >> +++ b/examples/ethtool/ethtool-app/main.c
> >> +static void close_ports(void)
> >> +{
> >> +	uint16_t portid;
> >> +	int ret;
> >> +
> >> +	for (portid = 0; portid < app_cfg.cnt_ports; portid++) {
> >> +		printf("Closing port %d...", portid);
> >> +		ret = rte_eth_dev_stop(portid);
> >> +		if (ret != 0)
> >> +			rte_exit(EXIT_FAILURE, "rte_eth_dev_stop: err=%s, port=%u\n",
> >> +				 strerror(-ret), portid);
> >> +		rte_eth_dev_close(portid);
> >> +		printf(" Done\n");
> >> +	}
> >> +
> >> +	ret = rte_eal_cleanup();
> >> +	if (ret != 0)
> >> +		rte_exit(EXIT_FAILURE, "EAL cleanup failed: %s\n",
> >> +			 strerror(-ret));
> > 
> > It would be better to add EAL cleanup in the main function.
> > 
> Hi, Thomas,
> 	It has already been done in this patch: "examples: add eal
> cleanup to examples", please check it out, thanks.

So why adding it in this patch about ethdev close?
diff mbox series

Patch

diff --git a/examples/ethtool/ethtool-app/main.c b/examples/ethtool/ethtool-app/main.c
index c6023a1..adabe6e 100644
--- a/examples/ethtool/ethtool-app/main.c
+++ b/examples/ethtool/ethtool-app/main.c
@@ -256,6 +256,27 @@  static int worker_main(__rte_unused void *ptr_data)
 	return 0;
 }
 
+static void close_ports(void)
+{
+	uint16_t portid;
+	int ret;
+
+	for (portid = 0; portid < app_cfg.cnt_ports; portid++) {
+		printf("Closing port %d...", portid);
+		ret = rte_eth_dev_stop(portid);
+		if (ret != 0)
+			rte_exit(EXIT_FAILURE, "rte_eth_dev_stop: err=%s, port=%u\n",
+				 strerror(-ret), portid);
+		rte_eth_dev_close(portid);
+		printf(" Done\n");
+	}
+
+	ret = rte_eal_cleanup();
+	if (ret != 0)
+		rte_exit(EXIT_FAILURE, "EAL cleanup failed: %s\n",
+			 strerror(-ret));
+}
+
 int main(int argc, char **argv)
 {
 	int cnt_args_parsed;
@@ -299,5 +320,7 @@  int main(int argc, char **argv)
 			return -1;
 	}
 
+	close_ports();
+
 	return 0;
 }