* [PATCH] wireguard/queueing: simplify wg_cpumask_next_online()
@ 2025-06-04 23:36 Yury Norov
2025-06-05 4:23 ` Yury Norov
2025-06-18 11:51 ` kernel test robot
0 siblings, 2 replies; 6+ messages in thread
From: Yury Norov @ 2025-06-04 23:36 UTC (permalink / raw)
To: Jason A. Donenfeld, Andrew Lunn, David S. Miller, Eric Dumazet,
Jakub Kicinski, Paolo Abeni, wireguard, netdev, linux-kernel
Cc: Yury Norov
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 <yury.norov@gmail.com>
---
drivers/net/wireguard/queueing.h | 14 ++++----------
1 file changed, 4 insertions(+), 10 deletions(-)
diff --git a/drivers/net/wireguard/queueing.h b/drivers/net/wireguard/queueing.h
index 7eb76724b3ed..3bfe16f71af0 100644
--- a/drivers/net/wireguard/queueing.h
+++ b/drivers/net/wireguard/queueing.h
@@ -104,17 +104,11 @@ static inline void wg_reset_packet(struct sk_buff *skb, bool encapsulating)
static inline int wg_cpumask_choose_online(int *stored_cpu, unsigned int id)
{
- unsigned int cpu = *stored_cpu, cpu_index, i;
+ if (likely(*stored_cpu < nr_cpu_ids && cpu_online(*stored_cpu)))
+ return cpu;
- if (unlikely(cpu >= nr_cpu_ids ||
- !cpumask_test_cpu(cpu, cpu_online_mask))) {
- cpu_index = id % cpumask_weight(cpu_online_mask);
- cpu = cpumask_first(cpu_online_mask);
- for (i = 0; i < cpu_index; ++i)
- cpu = cpumask_next(cpu, cpu_online_mask);
- *stored_cpu = cpu;
- }
- return cpu;
+ *stored_cpu = cpumask_nth(id % num_online_cpus(), cpu_online_mask);
+ return *stored_cpu;
}
/* This function is racy, in the sense that it's called while last_cpu is
--
2.43.0
^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH] wireguard/queueing: simplify wg_cpumask_next_online()
2025-06-04 23:36 [PATCH] wireguard/queueing: simplify wg_cpumask_next_online() Yury Norov
@ 2025-06-05 4:23 ` Yury Norov
2025-06-05 11:33 ` Jason A. Donenfeld
2025-06-18 11:51 ` kernel test robot
1 sibling, 1 reply; 6+ messages in thread
From: Yury Norov @ 2025-06-05 4:23 UTC (permalink / raw)
To: Jason A. Donenfeld, Andrew Lunn, David S. Miller, Eric Dumazet,
Jakub Kicinski, Paolo Abeni, wireguard, netdev, linux-kernel
On Wed, Jun 04, 2025 at 07:36:55PM -0400, Yury Norov wrote:
> 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 <yury.norov@gmail.com>
> ---
> drivers/net/wireguard/queueing.h | 14 ++++----------
> 1 file changed, 4 insertions(+), 10 deletions(-)
>
> diff --git a/drivers/net/wireguard/queueing.h b/drivers/net/wireguard/queueing.h
> index 7eb76724b3ed..3bfe16f71af0 100644
> --- a/drivers/net/wireguard/queueing.h
> +++ b/drivers/net/wireguard/queueing.h
> @@ -104,17 +104,11 @@ static inline void wg_reset_packet(struct sk_buff *skb, bool encapsulating)
>
> static inline int wg_cpumask_choose_online(int *stored_cpu, unsigned int id)
> {
> - unsigned int cpu = *stored_cpu, cpu_index, i;
> + if (likely(*stored_cpu < nr_cpu_ids && cpu_online(*stored_cpu)))
> + return cpu;
Oops... This should be
return *stored_cpu;
I'll resend, sorry for noise.
>
> - if (unlikely(cpu >= nr_cpu_ids ||
> - !cpumask_test_cpu(cpu, cpu_online_mask))) {
> - cpu_index = id % cpumask_weight(cpu_online_mask);
> - cpu = cpumask_first(cpu_online_mask);
> - for (i = 0; i < cpu_index; ++i)
> - cpu = cpumask_next(cpu, cpu_online_mask);
> - *stored_cpu = cpu;
> - }
> - return cpu;
> + *stored_cpu = cpumask_nth(id % num_online_cpus(), cpu_online_mask);
> + return *stored_cpu;
> }
>
> /* This function is racy, in the sense that it's called while last_cpu is
> --
> 2.43.0
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] wireguard/queueing: simplify wg_cpumask_next_online()
2025-06-05 4:23 ` Yury Norov
@ 2025-06-05 11:33 ` Jason A. Donenfeld
2025-06-05 14:24 ` Yury Norov
0 siblings, 1 reply; 6+ messages in thread
From: Jason A. Donenfeld @ 2025-06-05 11:33 UTC (permalink / raw)
To: Yury Norov
Cc: Andrew Lunn, David S. Miller, Eric Dumazet, Jakub Kicinski,
Paolo Abeni, wireguard, netdev, linux-kernel
On Thu, Jun 05, 2025 at 12:23:29AM -0400, Yury Norov wrote:
> On Wed, Jun 04, 2025 at 07:36:55PM -0400, Yury Norov wrote:
> > 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 <yury.norov@gmail.com>
> > ---
> > drivers/net/wireguard/queueing.h | 14 ++++----------
> > 1 file changed, 4 insertions(+), 10 deletions(-)
> >
> > diff --git a/drivers/net/wireguard/queueing.h b/drivers/net/wireguard/queueing.h
> > index 7eb76724b3ed..3bfe16f71af0 100644
> > --- a/drivers/net/wireguard/queueing.h
> > +++ b/drivers/net/wireguard/queueing.h
> > @@ -104,17 +104,11 @@ static inline void wg_reset_packet(struct sk_buff *skb, bool encapsulating)
> >
> > static inline int wg_cpumask_choose_online(int *stored_cpu, unsigned int id)
> > {
> > - unsigned int cpu = *stored_cpu, cpu_index, i;
> > + if (likely(*stored_cpu < nr_cpu_ids && cpu_online(*stored_cpu)))
> > + return cpu;
>
> Oops... This should be
> return *stored_cpu;
Maybe it's best to structure the function something like:
unsigned int cpu = *stored_cpu;
if (unlikely(cpu >= nr_cpu_ids || !cpu_online(cpu))) {
cpu = *stored_cpu = cpumask_nth(id % num_online_cpus(), cpu_online_mask);
return cpu;
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] wireguard/queueing: simplify wg_cpumask_next_online()
2025-06-05 11:33 ` Jason A. Donenfeld
@ 2025-06-05 14:24 ` Yury Norov
2025-06-05 15:47 ` Jason A. Donenfeld
0 siblings, 1 reply; 6+ messages in thread
From: Yury Norov @ 2025-06-05 14:24 UTC (permalink / raw)
To: Jason A. Donenfeld
Cc: Andrew Lunn, David S. Miller, Eric Dumazet, Jakub Kicinski,
Paolo Abeni, wireguard, netdev, linux-kernel
On Thu, Jun 05, 2025 at 01:33:19PM +0200, Jason A. Donenfeld wrote:
> On Thu, Jun 05, 2025 at 12:23:29AM -0400, Yury Norov wrote:
> > On Wed, Jun 04, 2025 at 07:36:55PM -0400, Yury Norov wrote:
> > > 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 <yury.norov@gmail.com>
> > > ---
> > > drivers/net/wireguard/queueing.h | 14 ++++----------
> > > 1 file changed, 4 insertions(+), 10 deletions(-)
> > >
> > > diff --git a/drivers/net/wireguard/queueing.h b/drivers/net/wireguard/queueing.h
> > > index 7eb76724b3ed..3bfe16f71af0 100644
> > > --- a/drivers/net/wireguard/queueing.h
> > > +++ b/drivers/net/wireguard/queueing.h
> > > @@ -104,17 +104,11 @@ static inline void wg_reset_packet(struct sk_buff *skb, bool encapsulating)
> > >
> > > static inline int wg_cpumask_choose_online(int *stored_cpu, unsigned int id)
> > > {
> > > - unsigned int cpu = *stored_cpu, cpu_index, i;
> > > + if (likely(*stored_cpu < nr_cpu_ids && cpu_online(*stored_cpu)))
> > > + return cpu;
> >
> > Oops... This should be
> > return *stored_cpu;
>
> Maybe it's best to structure the function something like:
>
> unsigned int cpu = *stored_cpu;
> if (unlikely(cpu >= nr_cpu_ids || !cpu_online(cpu))) {
> cpu = *stored_cpu = cpumask_nth(id % num_online_cpus(), cpu_online_mask);
> return cpu;
If you prefer. I'll send v2 shortly
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] wireguard/queueing: simplify wg_cpumask_next_online()
2025-06-05 14:24 ` Yury Norov
@ 2025-06-05 15:47 ` Jason A. Donenfeld
0 siblings, 0 replies; 6+ messages in thread
From: Jason A. Donenfeld @ 2025-06-05 15:47 UTC (permalink / raw)
To: Yury Norov
Cc: Andrew Lunn, David S. Miller, Eric Dumazet, Jakub Kicinski,
Paolo Abeni, wireguard, netdev, linux-kernel
On Thu, Jun 05, 2025 at 10:24:32AM -0400, Yury Norov wrote:
> On Thu, Jun 05, 2025 at 01:33:19PM +0200, Jason A. Donenfeld wrote:
> > On Thu, Jun 05, 2025 at 12:23:29AM -0400, Yury Norov wrote:
> > > On Wed, Jun 04, 2025 at 07:36:55PM -0400, Yury Norov wrote:
> > > > 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 <yury.norov@gmail.com>
> > > > ---
> > > > drivers/net/wireguard/queueing.h | 14 ++++----------
> > > > 1 file changed, 4 insertions(+), 10 deletions(-)
> > > >
> > > > diff --git a/drivers/net/wireguard/queueing.h b/drivers/net/wireguard/queueing.h
> > > > index 7eb76724b3ed..3bfe16f71af0 100644
> > > > --- a/drivers/net/wireguard/queueing.h
> > > > +++ b/drivers/net/wireguard/queueing.h
> > > > @@ -104,17 +104,11 @@ static inline void wg_reset_packet(struct sk_buff *skb, bool encapsulating)
> > > >
> > > > static inline int wg_cpumask_choose_online(int *stored_cpu, unsigned int id)
> > > > {
> > > > - unsigned int cpu = *stored_cpu, cpu_index, i;
> > > > + if (likely(*stored_cpu < nr_cpu_ids && cpu_online(*stored_cpu)))
> > > > + return cpu;
> > >
> > > Oops... This should be
> > > return *stored_cpu;
> >
> > Maybe it's best to structure the function something like:
> >
> > unsigned int cpu = *stored_cpu;
> > if (unlikely(cpu >= nr_cpu_ids || !cpu_online(cpu))) {
> > cpu = *stored_cpu = cpumask_nth(id % num_online_cpus(), cpu_online_mask);
> > return cpu;
>
> If you prefer. I'll send v2 shortly
While you're at it, fix the commit subject to match the format used by
every single other wireguard commit. `$ git log --oneline drivers/net/wireguard`
to see what I mean.
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] wireguard/queueing: simplify wg_cpumask_next_online()
2025-06-04 23:36 [PATCH] wireguard/queueing: simplify wg_cpumask_next_online() Yury Norov
2025-06-05 4:23 ` Yury Norov
@ 2025-06-18 11:51 ` kernel test robot
1 sibling, 0 replies; 6+ messages in thread
From: kernel test robot @ 2025-06-18 11:51 UTC (permalink / raw)
To: Yury Norov; +Cc: oe-kbuild-all
Hi Yury,
kernel test robot noticed the following build errors:
[auto build test ERROR on linus/master]
[also build test ERROR on crng-random/master v6.16-rc2 next-20250618]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]
url: https://github.com/intel-lab-lkp/linux/commits/Yury-Norov/wireguard-queueing-simplify-wg_cpumask_next_online/20250605-073832
base: linus/master
patch link: https://lore.kernel.org/r/20250604233656.41896-1-yury.norov%40gmail.com
patch subject: [PATCH] wireguard/queueing: simplify wg_cpumask_next_online()
config: nios2-allyesconfig (https://download.01.org/0day-ci/archive/20250618/202506181915.j2LnH7Ai-lkp@intel.com/config)
compiler: nios2-linux-gcc (GCC) 14.2.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20250618/202506181915.j2LnH7Ai-lkp@intel.com/reproduce)
If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/202506181915.j2LnH7Ai-lkp@intel.com/
All errors (new ones prefixed by >>):
In file included from drivers/net/wireguard/main.c:9:
drivers/net/wireguard/queueing.h: In function 'wg_cpumask_choose_online':
>> drivers/net/wireguard/queueing.h:108:24: error: 'cpu' undeclared (first use in this function)
108 | return cpu;
| ^~~
drivers/net/wireguard/queueing.h:108:24: note: each undeclared identifier is reported only once for each function it appears in
vim +/cpu +108 drivers/net/wireguard/queueing.h
e7096c131e5161f Jason A. Donenfeld 2019-12-09 104
e7096c131e5161f Jason A. Donenfeld 2019-12-09 105 static inline int wg_cpumask_choose_online(int *stored_cpu, unsigned int id)
e7096c131e5161f Jason A. Donenfeld 2019-12-09 106 {
b74b49327e49f39 Yury Norov 2025-06-04 107 if (likely(*stored_cpu < nr_cpu_ids && cpu_online(*stored_cpu)))
e7096c131e5161f Jason A. Donenfeld 2019-12-09 @108 return cpu;
b74b49327e49f39 Yury Norov 2025-06-04 109
b74b49327e49f39 Yury Norov 2025-06-04 110 *stored_cpu = cpumask_nth(id % num_online_cpus(), cpu_online_mask);
b74b49327e49f39 Yury Norov 2025-06-04 111 return *stored_cpu;
e7096c131e5161f Jason A. Donenfeld 2019-12-09 112 }
e7096c131e5161f Jason A. Donenfeld 2019-12-09 113
--
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2025-06-18 11:51 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-06-04 23:36 [PATCH] wireguard/queueing: simplify wg_cpumask_next_online() Yury Norov
2025-06-05 4:23 ` Yury Norov
2025-06-05 11:33 ` Jason A. Donenfeld
2025-06-05 14:24 ` Yury Norov
2025-06-05 15:47 ` Jason A. Donenfeld
2025-06-18 11:51 ` kernel test robot
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.