examples/vm_power: replace list foreach with while loop

Message ID 20220301145313.560577-1-shibin.koikkara.reeny@intel.com (mailing list archive)
State Superseded, archived
Delegated to: Thomas Monjalon
Headers
Series examples/vm_power: replace list foreach with while loop |

Checks

Context Check Description
ci/checkpatch success coding style OK
ci/Intel-compilation success Compilation OK
ci/intel-Testing success Testing PASS
ci/github-robot: build success github build: passed
ci/iol-intel-Performance success Performance Testing PASS
ci/iol-intel-Functional success Functional Testing PASS
ci/iol-aarch64-unit-testing success Testing PASS
ci/iol-x86_64-compile-testing success Testing PASS
ci/iol-x86_64-unit-testing success Testing PASS
ci/iol-aarch64-compile-testing success Testing PASS
ci/iol-abi-testing success Testing PASS

Commit Message

Koikkara Reeny, Shibin March 1, 2022, 2:53 p.m. UTC
  Linux header files don't support LIST_FOREACH_SAFE so replacing
LIST_FOREACH with while loop.

Fixes: e8ae9b662506 ("examples/vm_power: channel manager and monitor in host")
Cc: alan.carew@intel.com
Cc: stable@dpdk.org

Signed-off-by: Shibin Koikkara Reeny <shibin.koikkara.reeny@intel.com>
---
 examples/vm_power_manager/channel_manager.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)
  

Comments

Thomas Monjalon March 8, 2022, 1:26 p.m. UTC | #1
01/03/2022 15:53, Shibin Koikkara Reeny:
> Linux header files don't support LIST_FOREACH_SAFE so replacing
> LIST_FOREACH with while loop.

What is the original issue you are trying to solve?

> -	struct virtual_machine_info *vm_info;
> -
> -	LIST_FOREACH(vm_info, &vm_list_head, vms_info) {
> +	struct virtual_machine_info *vm_info = LIST_FIRST(&vm_list_head);
>  
> +	/* No LIST_FOREACH_SAFE, using while instead. */
> +	while (vm_info) {
>  		rte_spinlock_lock(&(vm_info->config_spinlock));
>  
>  		memcpy(mask, (char *)vm_info->channel_mask, RTE_MAX_LCORE);
> @@ -1024,6 +1024,8 @@ channel_manager_exit(void)
>  
>  		LIST_REMOVE(vm_info, vms_info);
>  		rte_free(vm_info);
> +
> +		vm_info = LIST_NEXT((vm_info), vms_info);
>  	}
  
Koikkara Reeny, Shibin March 10, 2022, 9:32 a.m. UTC | #2
> -----Original Message-----
> From: Thomas Monjalon <thomas@monjalon.net>
> 01/03/2022 15:53, Shibin Koikkara Reeny:
> > Linux header files don't support LIST_FOREACH_SAFE so replacing
> > LIST_FOREACH with while loop.
> 
> What is the original issue you are trying to solve?
Asan tool reported LIST_FOREACH should be replaced with LIST_FOREACH_SAFE but 
Linux don't have LIST_FOREACH_SAFE API. So replacing it with while loop.

Regards,
Shibin
  
Thomas Monjalon March 10, 2022, 9:39 a.m. UTC | #3
10/03/2022 10:32, Koikkara Reeny, Shibin:
> > -----Original Message-----
> > From: Thomas Monjalon <thomas@monjalon.net>
> > 01/03/2022 15:53, Shibin Koikkara Reeny:
> > > Linux header files don't support LIST_FOREACH_SAFE so replacing
> > > LIST_FOREACH with while loop.
> > 
> > What is the original issue you are trying to solve?
> Asan tool reported LIST_FOREACH should be replaced with LIST_FOREACH_SAFE but 
> Linux don't have LIST_FOREACH_SAFE API. So replacing it with while loop.

This explanation should be in the commit log please.
  
Stephen Hemminger March 10, 2022, 5:21 p.m. UTC | #4
On Thu, 10 Mar 2022 09:32:08 +0000
"Koikkara Reeny, Shibin" <shibin.koikkara.reeny@intel.com> wrote:

> > -----Original Message-----
> > From: Thomas Monjalon <thomas@monjalon.net>
> > 01/03/2022 15:53, Shibin Koikkara Reeny:  
> > > Linux header files don't support LIST_FOREACH_SAFE so replacing
> > > LIST_FOREACH with while loop.  
> > 
> > What is the original issue you are trying to solve?  
> Asan tool reported LIST_FOREACH should be replaced with LIST_FOREACH_SAFE but 
> Linux don't have LIST_FOREACH_SAFE API. So replacing it with while loop.
> 
> Regards,
> Shibin

Why not just clone LIST_FOREACH_SAFE from BSD?
That is what RTE_TAILQ does.

It might be generally useful.
  

Patch

diff --git a/examples/vm_power_manager/channel_manager.c b/examples/vm_power_manager/channel_manager.c
index 838465ab4b..b4dea4b275 100644
--- a/examples/vm_power_manager/channel_manager.c
+++ b/examples/vm_power_manager/channel_manager.c
@@ -1005,10 +1005,10 @@  channel_manager_exit(void)
 {
 	unsigned i;
 	char mask[RTE_MAX_LCORE];
-	struct virtual_machine_info *vm_info;
-
-	LIST_FOREACH(vm_info, &vm_list_head, vms_info) {
+	struct virtual_machine_info *vm_info = LIST_FIRST(&vm_list_head);
 
+	/* No LIST_FOREACH_SAFE, using while instead. */
+	while (vm_info) {
 		rte_spinlock_lock(&(vm_info->config_spinlock));
 
 		memcpy(mask, (char *)vm_info->channel_mask, RTE_MAX_LCORE);
@@ -1024,6 +1024,8 @@  channel_manager_exit(void)
 
 		LIST_REMOVE(vm_info, vms_info);
 		rte_free(vm_info);
+
+		vm_info = LIST_NEXT((vm_info), vms_info);
 	}
 
 	if (global_hypervisor_available) {