Skip to content

Commit 5551d21

Browse files
YuryNorovkuba-moo
authored andcommitted
wireguard: queueing: simplify wg_cpumask_next_online()
wg_cpumask_choose_online() opencodes cpumask_nth(). Use it and make the function significantly simpler. While there, fix opencoded cpu_online() too. Signed-off-by: Yury Norov <[email protected]> Reviewed-by: Simon Horman <[email protected]> Signed-off-by: Jason A. Donenfeld <[email protected]> Link: https://patch.msgid.link/[email protected] Signed-off-by: Jakub Kicinski <[email protected]>
1 parent 4094920 commit 5551d21

File tree

1 file changed

+4
-9
lines changed

1 file changed

+4
-9
lines changed

drivers/net/wireguard/queueing.h

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -104,16 +104,11 @@ static inline void wg_reset_packet(struct sk_buff *skb, bool encapsulating)
104104

105105
static inline int wg_cpumask_choose_online(int *stored_cpu, unsigned int id)
106106
{
107-
unsigned int cpu = *stored_cpu, cpu_index, i;
107+
unsigned int cpu = *stored_cpu;
108+
109+
if (unlikely(cpu >= nr_cpu_ids || !cpu_online(cpu)))
110+
cpu = *stored_cpu = cpumask_nth(id % num_online_cpus(), cpu_online_mask);
108111

109-
if (unlikely(cpu >= nr_cpu_ids ||
110-
!cpumask_test_cpu(cpu, cpu_online_mask))) {
111-
cpu_index = id % cpumask_weight(cpu_online_mask);
112-
cpu = cpumask_first(cpu_online_mask);
113-
for (i = 0; i < cpu_index; ++i)
114-
cpu = cpumask_next(cpu, cpu_online_mask);
115-
*stored_cpu = cpu;
116-
}
117112
return cpu;
118113
}
119114

0 commit comments

Comments
 (0)