* [PATCH] examples/vm_power: replace list foreach with while loop
@ 2022-03-01 14:53 Shibin Koikkara Reeny
2022-03-08 13:26 ` Thomas Monjalon
2022-03-21 9:33 ` [PATCH v2] examples/vm_power: add support for list_foreach_safe Shibin Koikkara Reeny
0 siblings, 2 replies; 9+ messages in thread
From: Shibin Koikkara Reeny @ 2022-03-01 14:53 UTC (permalink / raw)
To: david.hunt; +Cc: dev, Shibin Koikkara Reeny, alan.carew, stable
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(-)
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) {
--
2.25.1
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH] examples/vm_power: replace list foreach with while loop
2022-03-01 14:53 [PATCH] examples/vm_power: replace list foreach with while loop Shibin Koikkara Reeny
@ 2022-03-08 13:26 ` Thomas Monjalon
2022-03-10 9:32 ` Koikkara Reeny, Shibin
2022-03-21 9:33 ` [PATCH v2] examples/vm_power: add support for list_foreach_safe Shibin Koikkara Reeny
1 sibling, 1 reply; 9+ messages in thread
From: Thomas Monjalon @ 2022-03-08 13:26 UTC (permalink / raw)
To: Shibin Koikkara Reeny; +Cc: david.hunt, dev, stable
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);
> }
^ permalink raw reply [flat|nested] 9+ messages in thread
* RE: [PATCH] examples/vm_power: replace list foreach with while loop
2022-03-08 13:26 ` Thomas Monjalon
@ 2022-03-10 9:32 ` Koikkara Reeny, Shibin
2022-03-10 9:39 ` Thomas Monjalon
2022-03-10 17:21 ` Stephen Hemminger
0 siblings, 2 replies; 9+ messages in thread
From: Koikkara Reeny, Shibin @ 2022-03-10 9:32 UTC (permalink / raw)
To: Thomas Monjalon; +Cc: Hunt, David, dev, stable
> -----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
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH] examples/vm_power: replace list foreach with while loop
2022-03-10 9:32 ` Koikkara Reeny, Shibin
@ 2022-03-10 9:39 ` Thomas Monjalon
2022-03-10 17:21 ` Stephen Hemminger
1 sibling, 0 replies; 9+ messages in thread
From: Thomas Monjalon @ 2022-03-10 9:39 UTC (permalink / raw)
To: Koikkara Reeny, Shibin; +Cc: Hunt, David, dev, stable
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.
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH] examples/vm_power: replace list foreach with while loop
2022-03-10 9:32 ` Koikkara Reeny, Shibin
2022-03-10 9:39 ` Thomas Monjalon
@ 2022-03-10 17:21 ` Stephen Hemminger
1 sibling, 0 replies; 9+ messages in thread
From: Stephen Hemminger @ 2022-03-10 17:21 UTC (permalink / raw)
To: Koikkara Reeny, Shibin; +Cc: Thomas Monjalon, Hunt, David, dev, stable
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.
^ permalink raw reply [flat|nested] 9+ messages in thread
* [PATCH v2] examples/vm_power: add support for list_foreach_safe
2022-03-01 14:53 [PATCH] examples/vm_power: replace list foreach with while loop Shibin Koikkara Reeny
2022-03-08 13:26 ` Thomas Monjalon
@ 2022-03-21 9:33 ` Shibin Koikkara Reeny
2022-03-21 16:16 ` Stephen Hemminger
2022-03-22 14:43 ` [PATCH v3] " Shibin Koikkara Reeny
1 sibling, 2 replies; 9+ messages in thread
From: Shibin Koikkara Reeny @ 2022-03-21 9:33 UTC (permalink / raw)
To: david.hunt; +Cc: dev, Shibin Koikkara Reeny, alan.carew, stable
Asan tool reported LIST_FOREACH should be replaced with
LIST_FOREACH_SAFE. Added support for LIST_FOREACH_SAFE
macro in rte_os.h file as Linux header file sys/queue.h
don't support LIST_FOREACH_SAFE macro.
RTE_LIST_FOREACH_SAFE is alias for LIST_FOREACH_SAFE.
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 | 9 +++++----
lib/eal/linux/include/rte_os.h | 11 +++++++++++
2 files changed, 16 insertions(+), 4 deletions(-)
diff --git a/examples/vm_power_manager/channel_manager.c b/examples/vm_power_manager/channel_manager.c
index 838465ab4b..d297b28114 100644
--- a/examples/vm_power_manager/channel_manager.c
+++ b/examples/vm_power_manager/channel_manager.c
@@ -66,8 +66,8 @@ LIST_HEAD(, virtual_machine_info) vm_list_head;
static struct virtual_machine_info *
find_domain_by_name(const char *name)
{
- struct virtual_machine_info *info;
- LIST_FOREACH(info, &vm_list_head, vms_info) {
+ struct virtual_machine_info *info, *t_info;
+ RTE_LIST_FOREACH_SAFE(info, &vm_list_head, vms_info, t_info) {
if (!strncmp(info->name, name, CHANNEL_MGR_MAX_NAME_LEN-1))
return info;
}
@@ -1005,9 +1005,9 @@ channel_manager_exit(void)
{
unsigned i;
char mask[RTE_MAX_LCORE];
- struct virtual_machine_info *vm_info;
+ struct virtual_machine_info *vm_info, *t_info;
- LIST_FOREACH(vm_info, &vm_list_head, vms_info) {
+ RTE_LIST_FOREACH_SAFE(vm_info, &vm_list_head, vms_info, t_info) {
rte_spinlock_lock(&(vm_info->config_spinlock));
@@ -1024,6 +1024,7 @@ channel_manager_exit(void)
LIST_REMOVE(vm_info, vms_info);
rte_free(vm_info);
+
}
if (global_hypervisor_available) {
diff --git a/lib/eal/linux/include/rte_os.h b/lib/eal/linux/include/rte_os.h
index c72bf5b7e6..3acff49360 100644
--- a/lib/eal/linux/include/rte_os.h
+++ b/lib/eal/linux/include/rte_os.h
@@ -25,6 +25,8 @@ extern "C" {
#define RTE_TAILQ_NEXT(elem, field) TAILQ_NEXT(elem, field)
#define RTE_STAILQ_HEAD(name, type) STAILQ_HEAD(name, type)
#define RTE_STAILQ_ENTRY(type) STAILQ_ENTRY(type)
+#define RTE_LIST_FIRST(head) LIST_FIRST(head)
+#define RTE_LIST_NEXT(elem, field) LIST_NEXT(elem, field)
#ifdef CPU_SETSIZE /* may require _GNU_SOURCE */
typedef cpu_set_t rte_cpuset_t;
@@ -46,6 +48,15 @@ typedef cpu_set_t rte_cpuset_t;
} while (0)
#endif
+#ifndef LIST_FOREACH_SAFE
+#define LIST_FOREACH_SAFE(var, head, field, tvar) \
+ for ((var) = RTE_LIST_FIRST(head); \
+ (var) && ((tvar) = RTE_LIST_NEXT((var), field), 1); \
+ (var) = (tvar))
+#endif
+#define RTE_LIST_FOREACH_SAFE(var, head, field, tvar) \
+ LIST_FOREACH_SAFE(var, head, field, tvar)
+
#ifdef __cplusplus
}
#endif
--
2.25.1
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH v2] examples/vm_power: add support for list_foreach_safe
2022-03-21 9:33 ` [PATCH v2] examples/vm_power: add support for list_foreach_safe Shibin Koikkara Reeny
@ 2022-03-21 16:16 ` Stephen Hemminger
2022-03-22 14:43 ` [PATCH v3] " Shibin Koikkara Reeny
1 sibling, 0 replies; 9+ messages in thread
From: Stephen Hemminger @ 2022-03-21 16:16 UTC (permalink / raw)
To: Shibin Koikkara Reeny; +Cc: david.hunt, dev, alan.carew, stable
On Mon, 21 Mar 2022 09:33:42 +0000
Shibin Koikkara Reeny <shibin.koikkara.reeny@intel.com> wrote:
> diff --git a/examples/vm_power_manager/channel_manager.c b/examples/vm_power_manager/channel_manager.c
> index 838465ab4b..d297b28114 100644
> --- a/examples/vm_power_manager/channel_manager.c
> +++ b/examples/vm_power_manager/channel_manager.c
> @@ -66,8 +66,8 @@ LIST_HEAD(, virtual_machine_info) vm_list_head;
> static struct virtual_machine_info *
> find_domain_by_name(const char *name)
> {
> - struct virtual_machine_info *info;
> - LIST_FOREACH(info, &vm_list_head, vms_info) {
> + struct virtual_machine_info *info, *t_info;
> + RTE_LIST_FOREACH_SAFE(info, &vm_list_head, vms_info, t_info) {
> if (!strncmp(info->name, name, CHANNEL_MGR_MAX_NAME_LEN-1))
Please add blank line after declarations. It didn't have it before but
is better style.
^ permalink raw reply [flat|nested] 9+ messages in thread
* [PATCH v3] examples/vm_power: add support for list_foreach_safe
2022-03-21 9:33 ` [PATCH v2] examples/vm_power: add support for list_foreach_safe Shibin Koikkara Reeny
2022-03-21 16:16 ` Stephen Hemminger
@ 2022-03-22 14:43 ` Shibin Koikkara Reeny
2022-03-25 14:02 ` David Hunt
1 sibling, 1 reply; 9+ messages in thread
From: Shibin Koikkara Reeny @ 2022-03-22 14:43 UTC (permalink / raw)
To: david.hunt; +Cc: dev, Shibin Koikkara Reeny, alan.carew, stable
Asan tool reported LIST_FOREACH should be replaced with
LIST_FOREACH_SAFE. Added support for LIST_FOREACH_SAFE
macro in rte_os.h file as Linux header file sys/queue.h
don't support LIST_FOREACH_SAFE macro.
RTE_LIST_FOREACH_SAFE is alias for LIST_FOREACH_SAFE.
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>
---
v3: add blank line after declaration
v2: add support for list_foreach_safe
---
examples/vm_power_manager/channel_manager.c | 10 ++++++----
lib/eal/linux/include/rte_os.h | 11 +++++++++++
2 files changed, 17 insertions(+), 4 deletions(-)
diff --git a/examples/vm_power_manager/channel_manager.c b/examples/vm_power_manager/channel_manager.c
index 838465ab4b..2d54641f2e 100644
--- a/examples/vm_power_manager/channel_manager.c
+++ b/examples/vm_power_manager/channel_manager.c
@@ -66,8 +66,9 @@ LIST_HEAD(, virtual_machine_info) vm_list_head;
static struct virtual_machine_info *
find_domain_by_name(const char *name)
{
- struct virtual_machine_info *info;
- LIST_FOREACH(info, &vm_list_head, vms_info) {
+ struct virtual_machine_info *info, *t_info;
+
+ RTE_LIST_FOREACH_SAFE(info, &vm_list_head, vms_info, t_info) {
if (!strncmp(info->name, name, CHANNEL_MGR_MAX_NAME_LEN-1))
return info;
}
@@ -1005,9 +1006,9 @@ channel_manager_exit(void)
{
unsigned i;
char mask[RTE_MAX_LCORE];
- struct virtual_machine_info *vm_info;
+ struct virtual_machine_info *vm_info, *t_info;
- LIST_FOREACH(vm_info, &vm_list_head, vms_info) {
+ RTE_LIST_FOREACH_SAFE(vm_info, &vm_list_head, vms_info, t_info) {
rte_spinlock_lock(&(vm_info->config_spinlock));
@@ -1024,6 +1025,7 @@ channel_manager_exit(void)
LIST_REMOVE(vm_info, vms_info);
rte_free(vm_info);
+
}
if (global_hypervisor_available) {
diff --git a/lib/eal/linux/include/rte_os.h b/lib/eal/linux/include/rte_os.h
index c72bf5b7e6..3acff49360 100644
--- a/lib/eal/linux/include/rte_os.h
+++ b/lib/eal/linux/include/rte_os.h
@@ -25,6 +25,8 @@ extern "C" {
#define RTE_TAILQ_NEXT(elem, field) TAILQ_NEXT(elem, field)
#define RTE_STAILQ_HEAD(name, type) STAILQ_HEAD(name, type)
#define RTE_STAILQ_ENTRY(type) STAILQ_ENTRY(type)
+#define RTE_LIST_FIRST(head) LIST_FIRST(head)
+#define RTE_LIST_NEXT(elem, field) LIST_NEXT(elem, field)
#ifdef CPU_SETSIZE /* may require _GNU_SOURCE */
typedef cpu_set_t rte_cpuset_t;
@@ -46,6 +48,15 @@ typedef cpu_set_t rte_cpuset_t;
} while (0)
#endif
+#ifndef LIST_FOREACH_SAFE
+#define LIST_FOREACH_SAFE(var, head, field, tvar) \
+ for ((var) = RTE_LIST_FIRST(head); \
+ (var) && ((tvar) = RTE_LIST_NEXT((var), field), 1); \
+ (var) = (tvar))
+#endif
+#define RTE_LIST_FOREACH_SAFE(var, head, field, tvar) \
+ LIST_FOREACH_SAFE(var, head, field, tvar)
+
#ifdef __cplusplus
}
#endif
--
2.25.1
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH v3] examples/vm_power: add support for list_foreach_safe
2022-03-22 14:43 ` [PATCH v3] " Shibin Koikkara Reeny
@ 2022-03-25 14:02 ` David Hunt
0 siblings, 0 replies; 9+ messages in thread
From: David Hunt @ 2022-03-25 14:02 UTC (permalink / raw)
To: Shibin Koikkara Reeny; +Cc: dev, alan.carew, stable
Hi Shibin,
On 22/3/2022 2:43 PM, Shibin Koikkara Reeny wrote:
> Asan tool reported LIST_FOREACH should be replaced with
> LIST_FOREACH_SAFE. Added support for LIST_FOREACH_SAFE
> macro in rte_os.h file as Linux header file sys/queue.h
> don't support LIST_FOREACH_SAFE macro.
> RTE_LIST_FOREACH_SAFE is alias for LIST_FOREACH_SAFE.
>
> 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>
>
> ---
> v3: add blank line after declaration
> v2: add support for list_foreach_safe
> ---
> examples/vm_power_manager/channel_manager.c | 10 ++++++----
> lib/eal/linux/include/rte_os.h | 11 +++++++++++
> 2 files changed, 17 insertions(+), 4 deletions(-)
>
> diff --git a/examples/vm_power_manager/channel_manager.c b/examples/vm_power_manager/channel_manager.c
> index 838465ab4b..2d54641f2e 100644
> --- a/examples/vm_power_manager/channel_manager.c
> +++ b/examples/vm_power_manager/channel_manager.c
> @@ -66,8 +66,9 @@ LIST_HEAD(, virtual_machine_info) vm_list_head;
> static struct virtual_machine_info *
> find_domain_by_name(const char *name)
> {
> - struct virtual_machine_info *info;
> - LIST_FOREACH(info, &vm_list_head, vms_info) {
> + struct virtual_machine_info *info, *t_info;
> +
> + RTE_LIST_FOREACH_SAFE(info, &vm_list_head, vms_info, t_info) {
> if (!strncmp(info->name, name, CHANNEL_MGR_MAX_NAME_LEN-1))
> return info;
> }
> @@ -1005,9 +1006,9 @@ channel_manager_exit(void)
> {
> unsigned i;
> char mask[RTE_MAX_LCORE];
> - struct virtual_machine_info *vm_info;
> + struct virtual_machine_info *vm_info, *t_info;
>
> - LIST_FOREACH(vm_info, &vm_list_head, vms_info) {
> + RTE_LIST_FOREACH_SAFE(vm_info, &vm_list_head, vms_info, t_info) {
>
> rte_spinlock_lock(&(vm_info->config_spinlock));
>
> @@ -1024,6 +1025,7 @@ channel_manager_exit(void)
>
> LIST_REMOVE(vm_info, vms_info);
> rte_free(vm_info);
> +
> }
>
> if (global_hypervisor_available) {
> diff --git a/lib/eal/linux/include/rte_os.h b/lib/eal/linux/include/rte_os.h
> index c72bf5b7e6..3acff49360 100644
> --- a/lib/eal/linux/include/rte_os.h
> +++ b/lib/eal/linux/include/rte_os.h
> @@ -25,6 +25,8 @@ extern "C" {
> #define RTE_TAILQ_NEXT(elem, field) TAILQ_NEXT(elem, field)
> #define RTE_STAILQ_HEAD(name, type) STAILQ_HEAD(name, type)
> #define RTE_STAILQ_ENTRY(type) STAILQ_ENTRY(type)
> +#define RTE_LIST_FIRST(head) LIST_FIRST(head)
> +#define RTE_LIST_NEXT(elem, field) LIST_NEXT(elem, field)
>
> #ifdef CPU_SETSIZE /* may require _GNU_SOURCE */
> typedef cpu_set_t rte_cpuset_t;
> @@ -46,6 +48,15 @@ typedef cpu_set_t rte_cpuset_t;
> } while (0)
> #endif
>
> +#ifndef LIST_FOREACH_SAFE
> +#define LIST_FOREACH_SAFE(var, head, field, tvar) \
> + for ((var) = RTE_LIST_FIRST(head); \
> + (var) && ((tvar) = RTE_LIST_NEXT((var), field), 1); \
> + (var) = (tvar))
> +#endif
> +#define RTE_LIST_FOREACH_SAFE(var, head, field, tvar) \
> + LIST_FOREACH_SAFE(var, head, field, tvar)
> +
> #ifdef __cplusplus
> }
> #endif
Looks cleaner that the previous version.
Acked-by: David Hunt <david.hunt@intel.com>
^ permalink raw reply [flat|nested] 9+ messages in thread
end of thread, other threads:[~2022-03-25 14:02 UTC | newest]
Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-03-01 14:53 [PATCH] examples/vm_power: replace list foreach with while loop Shibin Koikkara Reeny
2022-03-08 13:26 ` Thomas Monjalon
2022-03-10 9:32 ` Koikkara Reeny, Shibin
2022-03-10 9:39 ` Thomas Monjalon
2022-03-10 17:21 ` Stephen Hemminger
2022-03-21 9:33 ` [PATCH v2] examples/vm_power: add support for list_foreach_safe Shibin Koikkara Reeny
2022-03-21 16:16 ` Stephen Hemminger
2022-03-22 14:43 ` [PATCH v3] " Shibin Koikkara Reeny
2022-03-25 14:02 ` David Hunt
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).