mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] net: openvswitch: Use for_each_cpu() where appropriate
@ 2025-08-18 17:28 Yury Norov
  2025-08-19 13:23 ` Ilya Maximets
  2025-08-21  2:50 ` patchwork-bot+netdevbpf
  0 siblings, 2 replies; 3+ messages in thread
From: Yury Norov @ 2025-08-18 17:28 UTC (permalink / raw)
  To: Aaron Conole, Eelco Chaudron, Ilya Maximets, David S. Miller,
	Eric Dumazet, Jakub Kicinski, Paolo Abeni, Simon Horman, netdev,
	dev, linux-kernel
  Cc: Yury Norov (NVIDIA)

From: "Yury Norov (NVIDIA)" <yury.norov@gmail.com>

Due to legacy reasons, openswitch code opencodes for_each_cpu() to make
sure that CPU0 is always considered.

Since commit c4b2bf6b4a35 ("openvswitch: Optimize operations for OvS
flow_stats."), the corresponding  flow->cpu_used_mask is initialized
such that CPU0 is explicitly set.

So, switch the code to using plain for_each_cpu().

Suggested-by: Ilya Maximets <i.maximets@ovn.org>
Signed-off-by: Yury Norov (NVIDIA) <yury.norov@gmail.com>
---
 net/openvswitch/flow.c       | 12 ++++--------
 net/openvswitch/flow_table.c |  7 +++----
 2 files changed, 7 insertions(+), 12 deletions(-)

v1: https://lore.kernel.org/all/20250814195838.388693-1-yury.norov@gmail.com/
v2:
 - always include CPU0 (Ilya);

diff --git a/net/openvswitch/flow.c b/net/openvswitch/flow.c
index b80bd3a90773..66366982f604 100644
--- a/net/openvswitch/flow.c
+++ b/net/openvswitch/flow.c
@@ -129,15 +129,13 @@ void ovs_flow_stats_get(const struct sw_flow *flow,
 			struct ovs_flow_stats *ovs_stats,
 			unsigned long *used, __be16 *tcp_flags)
 {
-	int cpu;
+	unsigned int cpu;
 
 	*used = 0;
 	*tcp_flags = 0;
 	memset(ovs_stats, 0, sizeof(*ovs_stats));
 
-	/* We open code this to make sure cpu 0 is always considered */
-	for (cpu = 0; cpu < nr_cpu_ids;
-	     cpu = cpumask_next(cpu, flow->cpu_used_mask)) {
+	for_each_cpu(cpu, flow->cpu_used_mask) {
 		struct sw_flow_stats *stats = rcu_dereference_ovsl(flow->stats[cpu]);
 
 		if (stats) {
@@ -158,11 +156,9 @@ void ovs_flow_stats_get(const struct sw_flow *flow,
 /* Called with ovs_mutex. */
 void ovs_flow_stats_clear(struct sw_flow *flow)
 {
-	int cpu;
+	unsigned int cpu;
 
-	/* We open code this to make sure cpu 0 is always considered */
-	for (cpu = 0; cpu < nr_cpu_ids;
-	     cpu = cpumask_next(cpu, flow->cpu_used_mask)) {
+	for_each_cpu(cpu, flow->cpu_used_mask) {
 		struct sw_flow_stats *stats = ovsl_dereference(flow->stats[cpu]);
 
 		if (stats) {
diff --git a/net/openvswitch/flow_table.c b/net/openvswitch/flow_table.c
index d108ae0bd0ee..ffc72a741a50 100644
--- a/net/openvswitch/flow_table.c
+++ b/net/openvswitch/flow_table.c
@@ -107,16 +107,15 @@ int ovs_flow_tbl_count(const struct flow_table *table)
 
 static void flow_free(struct sw_flow *flow)
 {
-	int cpu;
+	unsigned int cpu;
 
 	if (ovs_identifier_is_key(&flow->id))
 		kfree(flow->id.unmasked_key);
 	if (flow->sf_acts)
 		ovs_nla_free_flow_actions((struct sw_flow_actions __force *)
 					  flow->sf_acts);
-	/* We open code this to make sure cpu 0 is always considered */
-	for (cpu = 0; cpu < nr_cpu_ids;
-	     cpu = cpumask_next(cpu, flow->cpu_used_mask)) {
+
+	for_each_cpu(cpu, flow->cpu_used_mask) {
 		if (flow->stats[cpu])
 			kmem_cache_free(flow_stats_cache,
 					(struct sw_flow_stats __force *)flow->stats[cpu]);
-- 
2.43.0


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

* Re: [PATCH] net: openvswitch: Use for_each_cpu() where appropriate
  2025-08-18 17:28 [PATCH] net: openvswitch: Use for_each_cpu() where appropriate Yury Norov
@ 2025-08-19 13:23 ` Ilya Maximets
  2025-08-21  2:50 ` patchwork-bot+netdevbpf
  1 sibling, 0 replies; 3+ messages in thread
From: Ilya Maximets @ 2025-08-19 13:23 UTC (permalink / raw)
  To: Yury Norov, Aaron Conole, Eelco Chaudron, David S. Miller,
	Eric Dumazet, Jakub Kicinski, Paolo Abeni, Simon Horman, netdev,
	dev, linux-kernel
  Cc: i.maximets

On 8/18/25 7:28 PM, Yury Norov wrote:
> From: "Yury Norov (NVIDIA)" <yury.norov@gmail.com>
> 
> Due to legacy reasons, openswitch code opencodes for_each_cpu() to make
> sure that CPU0 is always considered.
> 
> Since commit c4b2bf6b4a35 ("openvswitch: Optimize operations for OvS
> flow_stats."), the corresponding  flow->cpu_used_mask is initialized
> such that CPU0 is explicitly set.
> 
> So, switch the code to using plain for_each_cpu().
> 
> Suggested-by: Ilya Maximets <i.maximets@ovn.org>
> Signed-off-by: Yury Norov (NVIDIA) <yury.norov@gmail.com>
> ---
>  net/openvswitch/flow.c       | 12 ++++--------
>  net/openvswitch/flow_table.c |  7 +++----
>  2 files changed, 7 insertions(+), 12 deletions(-)
> 
> v1: https://lore.kernel.org/all/20250814195838.388693-1-yury.norov@gmail.com/
> v2:
>  - always include CPU0 (Ilya);

nit: The subject prefix should've been [PATCH net-next v2].

The change itself looks correct to me.  Thanks!

Acked-by: Ilya Maximets <i.maximets@ovn.org>

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

* Re: [PATCH] net: openvswitch: Use for_each_cpu() where appropriate
  2025-08-18 17:28 [PATCH] net: openvswitch: Use for_each_cpu() where appropriate Yury Norov
  2025-08-19 13:23 ` Ilya Maximets
@ 2025-08-21  2:50 ` patchwork-bot+netdevbpf
  1 sibling, 0 replies; 3+ messages in thread
From: patchwork-bot+netdevbpf @ 2025-08-21  2:50 UTC (permalink / raw)
  To: Yury Norov
  Cc: aconole, echaudro, i.maximets, davem, edumazet, kuba, pabeni,
	horms, netdev, dev, linux-kernel

Hello:

This patch was applied to netdev/net-next.git (main)
by Jakub Kicinski <kuba@kernel.org>:

On Mon, 18 Aug 2025 13:28:05 -0400 you wrote:
> From: "Yury Norov (NVIDIA)" <yury.norov@gmail.com>
> 
> Due to legacy reasons, openswitch code opencodes for_each_cpu() to make
> sure that CPU0 is always considered.
> 
> Since commit c4b2bf6b4a35 ("openvswitch: Optimize operations for OvS
> flow_stats."), the corresponding  flow->cpu_used_mask is initialized
> such that CPU0 is explicitly set.
> 
> [...]

Here is the summary with links:
  - net: openvswitch: Use for_each_cpu() where appropriate
    https://git.kernel.org/netdev/net-next/c/62a2b3502573

You are awesome, thank you!
-- 
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html



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

end of thread, other threads:[~2025-08-21  2:49 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-08-18 17:28 [PATCH] net: openvswitch: Use for_each_cpu() where appropriate Yury Norov
2025-08-19 13:23 ` Ilya Maximets
2025-08-21  2:50 ` patchwork-bot+netdevbpf

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®