Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

net: openvswitch: Use for_each_cpu() where appropriate

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>
Acked-by: Ilya Maximets <i.maximets@ovn.org>
Link: https://patch.msgid.link/20250818172806.189325-1-yury.norov@gmail.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>

authored by

Yury Norov (NVIDIA) and committed by
Jakub Kicinski
62a2b350 a5c10aa3

+7 -12
+4 -8
net/openvswitch/flow.c
··· 129 129 struct ovs_flow_stats *ovs_stats, 130 130 unsigned long *used, __be16 *tcp_flags) 131 131 { 132 - int cpu; 132 + unsigned int cpu; 133 133 134 134 *used = 0; 135 135 *tcp_flags = 0; 136 136 memset(ovs_stats, 0, sizeof(*ovs_stats)); 137 137 138 - /* We open code this to make sure cpu 0 is always considered */ 139 - for (cpu = 0; cpu < nr_cpu_ids; 140 - cpu = cpumask_next(cpu, flow->cpu_used_mask)) { 138 + for_each_cpu(cpu, flow->cpu_used_mask) { 141 139 struct sw_flow_stats *stats = rcu_dereference_ovsl(flow->stats[cpu]); 142 140 143 141 if (stats) { ··· 156 158 /* Called with ovs_mutex. */ 157 159 void ovs_flow_stats_clear(struct sw_flow *flow) 158 160 { 159 - int cpu; 161 + unsigned int cpu; 160 162 161 - /* We open code this to make sure cpu 0 is always considered */ 162 - for (cpu = 0; cpu < nr_cpu_ids; 163 - cpu = cpumask_next(cpu, flow->cpu_used_mask)) { 163 + for_each_cpu(cpu, flow->cpu_used_mask) { 164 164 struct sw_flow_stats *stats = ovsl_dereference(flow->stats[cpu]); 165 165 166 166 if (stats) {
+3 -4
net/openvswitch/flow_table.c
··· 107 107 108 108 static void flow_free(struct sw_flow *flow) 109 109 { 110 - int cpu; 110 + unsigned int cpu; 111 111 112 112 if (ovs_identifier_is_key(&flow->id)) 113 113 kfree(flow->id.unmasked_key); 114 114 if (flow->sf_acts) 115 115 ovs_nla_free_flow_actions((struct sw_flow_actions __force *) 116 116 flow->sf_acts); 117 - /* We open code this to make sure cpu 0 is always considered */ 118 - for (cpu = 0; cpu < nr_cpu_ids; 119 - cpu = cpumask_next(cpu, flow->cpu_used_mask)) { 117 + 118 + for_each_cpu(cpu, flow->cpu_used_mask) { 120 119 if (flow->stats[cpu]) 121 120 kmem_cache_free(flow_stats_cache, 122 121 (struct sw_flow_stats __force *)flow->stats[cpu]);