* [PATCH v2 03/13] ibmvnic: simplify ibmvnic_set_queue_affinity()
2025-01-28 16:46 [PATCH v2 00/13] cpumask: cleanup cpumask_next_wrap() implementation and usage Yury Norov
@ 2025-01-28 16:46 ` Yury Norov
2025-02-05 23:10 ` Nick Child
2025-01-28 16:46 ` [PATCH v2 04/13] powerpc/xmon: simplify xmon_batch_next_cpu() Yury Norov
` (3 subsequent siblings)
4 siblings, 1 reply; 7+ messages in thread
From: Yury Norov @ 2025-01-28 16:46 UTC (permalink / raw)
To: linux-kernel, netdev, linuxppc-dev, Haren Myneni, Rick Lindsley,
Nick Child, Thomas Falcon, Michael Ellerman, Nicholas Piggin,
Christophe Leroy, Naveen N Rao, Madhavan Srinivasan,
David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni
Cc: Yury Norov, Christoph Hellwig, Rasmus Villemoes
A loop based on cpumask_next_wrap() opencodes the dedicated macro
for_each_online_cpu_wrap(). Using the macro allows to avoid setting
bits affinity mask more than once when stride >= num_online_cpus.
This also helps to drop cpumask handling code in the caller function.
CC: Nick Child <nnac123@linux.ibm.com>
Signed-off-by: Yury Norov <yury.norov@gmail.com>
---
drivers/net/ethernet/ibm/ibmvnic.c | 18 +++++++++++-------
1 file changed, 11 insertions(+), 7 deletions(-)
diff --git a/drivers/net/ethernet/ibm/ibmvnic.c b/drivers/net/ethernet/ibm/ibmvnic.c
index e95ae0d39948..bef18ff69065 100644
--- a/drivers/net/ethernet/ibm/ibmvnic.c
+++ b/drivers/net/ethernet/ibm/ibmvnic.c
@@ -234,11 +234,17 @@ static int ibmvnic_set_queue_affinity(struct ibmvnic_sub_crq_queue *queue,
(*stragglers)--;
}
/* atomic write is safer than writing bit by bit directly */
- for (i = 0; i < stride; i++) {
- cpumask_set_cpu(*cpu, mask);
- *cpu = cpumask_next_wrap(*cpu, cpu_online_mask,
- nr_cpu_ids, false);
+ for_each_online_cpu_wrap(i, *cpu) {
+ if (!stride--) {
+ /* For the next queue we start from the first
+ * unused CPU in this queue
+ */
+ *cpu = i;
+ break;
+ }
+ cpumask_set_cpu(i, mask);
}
+
/* set queue affinity mask */
cpumask_copy(queue->affinity_mask, mask);
rc = irq_set_affinity_and_hint(queue->irq, queue->affinity_mask);
@@ -256,7 +262,7 @@ static void ibmvnic_set_affinity(struct ibmvnic_adapter *adapter)
int num_rxqs = adapter->num_active_rx_scrqs, i_rxqs = 0;
int num_txqs = adapter->num_active_tx_scrqs, i_txqs = 0;
int total_queues, stride, stragglers, i;
- unsigned int num_cpu, cpu;
+ unsigned int num_cpu, cpu = 0;
bool is_rx_queue;
int rc = 0;
@@ -274,8 +280,6 @@ static void ibmvnic_set_affinity(struct ibmvnic_adapter *adapter)
stride = max_t(int, num_cpu / total_queues, 1);
/* number of leftover cpu's */
stragglers = num_cpu >= total_queues ? num_cpu % total_queues : 0;
- /* next available cpu to assign irq to */
- cpu = cpumask_next(-1, cpu_online_mask);
for (i = 0; i < total_queues; i++) {
is_rx_queue = false;
--
2.43.0
^ permalink raw reply related [flat|nested] 7+ messages in thread* Re: [PATCH v2 03/13] ibmvnic: simplify ibmvnic_set_queue_affinity()
2025-01-28 16:46 ` [PATCH v2 03/13] ibmvnic: simplify ibmvnic_set_queue_affinity() Yury Norov
@ 2025-02-05 23:10 ` Nick Child
0 siblings, 0 replies; 7+ messages in thread
From: Nick Child @ 2025-02-05 23:10 UTC (permalink / raw)
To: Yury Norov
Cc: linux-kernel, netdev, linuxppc-dev, Haren Myneni, Rick Lindsley,
Thomas Falcon, Michael Ellerman, Nicholas Piggin,
Christophe Leroy, Naveen N Rao, Madhavan Srinivasan,
David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
Christoph Hellwig, Rasmus Villemoes
On Tue, Jan 28, 2025 at 11:46:32AM -0500, Yury Norov wrote:
> A loop based on cpumask_next_wrap() opencodes the dedicated macro
> for_each_online_cpu_wrap(). Using the macro allows to avoid setting
> bits affinity mask more than once when stride >= num_online_cpus.
>
nit: Same comment as left in patch 2. Don't think re-iterating over
cpu's was ever possible. But I do think the patch improves readability
and simplifies things.
> This also helps to drop cpumask handling code in the caller function.
>
> CC: Nick Child <nnac123@linux.ibm.com>
> Signed-off-by: Yury Norov <yury.norov@gmail.com>
Built/booted kernel (patch 10 is ill-formated), messed around with n
online cpu and n queues. All ibmvnic affinity values look correct.
Thanks!
Tested-by: Nick Child <nnac123@linux.ibm.com>
> ---
> drivers/net/ethernet/ibm/ibmvnic.c | 18 +++++++++++-------
> 1 file changed, 11 insertions(+), 7 deletions(-)
>
> diff --git a/drivers/net/ethernet/ibm/ibmvnic.c b/drivers/net/ethernet/ibm/ibmvnic.c
> index e95ae0d39948..bef18ff69065 100644
> --- a/drivers/net/ethernet/ibm/ibmvnic.c
> +++ b/drivers/net/ethernet/ibm/ibmvnic.c
> @@ -234,11 +234,17 @@ static int ibmvnic_set_queue_affinity(struct ibmvnic_sub_crq_queue *queue,
> (*stragglers)--;
> }
> /* atomic write is safer than writing bit by bit directly */
> - for (i = 0; i < stride; i++) {
> - cpumask_set_cpu(*cpu, mask);
> - *cpu = cpumask_next_wrap(*cpu, cpu_online_mask,
> - nr_cpu_ids, false);
> + for_each_online_cpu_wrap(i, *cpu) {
> + if (!stride--) {
> + /* For the next queue we start from the first
> + * unused CPU in this queue
> + */
> + *cpu = i;
> + break;
> + }
> + cpumask_set_cpu(i, mask);
> }
> +
> /* set queue affinity mask */
> cpumask_copy(queue->affinity_mask, mask);
> rc = irq_set_affinity_and_hint(queue->irq, queue->affinity_mask);
> @@ -256,7 +262,7 @@ static void ibmvnic_set_affinity(struct ibmvnic_adapter *adapter)
> int num_rxqs = adapter->num_active_rx_scrqs, i_rxqs = 0;
> int num_txqs = adapter->num_active_tx_scrqs, i_txqs = 0;
> int total_queues, stride, stragglers, i;
> - unsigned int num_cpu, cpu;
> + unsigned int num_cpu, cpu = 0;
> bool is_rx_queue;
> int rc = 0;
>
> @@ -274,8 +280,6 @@ static void ibmvnic_set_affinity(struct ibmvnic_adapter *adapter)
> stride = max_t(int, num_cpu / total_queues, 1);
> /* number of leftover cpu's */
> stragglers = num_cpu >= total_queues ? num_cpu % total_queues : 0;
> - /* next available cpu to assign irq to */
> - cpu = cpumask_next(-1, cpu_online_mask);
>
> for (i = 0; i < total_queues; i++) {
> is_rx_queue = false;
> --
> 2.43.0
>
^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH v2 04/13] powerpc/xmon: simplify xmon_batch_next_cpu()
2025-01-28 16:46 [PATCH v2 00/13] cpumask: cleanup cpumask_next_wrap() implementation and usage Yury Norov
2025-01-28 16:46 ` [PATCH v2 03/13] ibmvnic: simplify ibmvnic_set_queue_affinity() Yury Norov
@ 2025-01-28 16:46 ` Yury Norov
2025-01-28 16:46 ` [PATCH v2 05/13] cpumask: deprecate cpumask_next_wrap() Yury Norov
` (2 subsequent siblings)
4 siblings, 0 replies; 7+ messages in thread
From: Yury Norov @ 2025-01-28 16:46 UTC (permalink / raw)
To: linux-kernel, linuxppc-dev, Michael Ellerman, Nicholas Piggin,
Christophe Leroy, Naveen N Rao, Madhavan Srinivasan
Cc: Yury Norov, Christoph Hellwig, Rasmus Villemoes
The function opencodes for_each_cpu_wrap() macro. As a loop termination
condition it uses cpumask_empty(), which is O(N), and it makes the whole
algorithm O(N^2). Switching to for_each_cpu_wrap() simplifies the logic,
and makes the algorithm linear.
Signed-off-by: Yury Norov <yury.norov@gmail.com>
---
arch/powerpc/xmon/xmon.c | 6 +-----
1 file changed, 1 insertion(+), 5 deletions(-)
diff --git a/arch/powerpc/xmon/xmon.c b/arch/powerpc/xmon/xmon.c
index 268859e4df87..1acb53aab252 100644
--- a/arch/powerpc/xmon/xmon.c
+++ b/arch/powerpc/xmon/xmon.c
@@ -1271,11 +1271,7 @@ static int xmon_batch_next_cpu(void)
{
unsigned long cpu;
- while (!cpumask_empty(&xmon_batch_cpus)) {
- cpu = cpumask_next_wrap(smp_processor_id(), &xmon_batch_cpus,
- xmon_batch_start_cpu, true);
- if (cpu >= nr_cpu_ids)
- break;
+ for_each_cpu_wrap(cpu, &xmon_batch_cpus, xmon_batch_start_cpu) {
if (xmon_batch_start_cpu == -1)
xmon_batch_start_cpu = cpu;
if (xmon_switch_cpu(cpu))
--
2.43.0
^ permalink raw reply related [flat|nested] 7+ messages in thread* [PATCH v2 05/13] cpumask: deprecate cpumask_next_wrap()
2025-01-28 16:46 [PATCH v2 00/13] cpumask: cleanup cpumask_next_wrap() implementation and usage Yury Norov
2025-01-28 16:46 ` [PATCH v2 03/13] ibmvnic: simplify ibmvnic_set_queue_affinity() Yury Norov
2025-01-28 16:46 ` [PATCH v2 04/13] powerpc/xmon: simplify xmon_batch_next_cpu() Yury Norov
@ 2025-01-28 16:46 ` Yury Norov
2025-01-28 16:46 ` [PATCH v2 06/13] cpumask: re-introduce cpumask_next{,_and}_wrap() Yury Norov
2025-02-24 21:18 ` [PATCH v2 00/13] cpumask: cleanup cpumask_next_wrap() implementation and usage Michael S. Tsirkin
4 siblings, 0 replies; 7+ messages in thread
From: Yury Norov @ 2025-01-28 16:46 UTC (permalink / raw)
To: linux-kernel, linuxppc-dev, linux-s390, netdev, virtualization,
linux-nvme, linux-hyperv, linux-pci, linux-scsi, linux-crypto,
Michael Ellerman, Nicholas Piggin, Christophe Leroy, Naveen N Rao,
Madhavan Srinivasan, Heiko Carstens, Vasily Gorbik,
Alexander Gordeev, Christian Borntraeger, Sven Schnelle,
Haren Myneni, Rick Lindsley, Nick Child, Thomas Falcon,
Andrew Lunn, David S. Miller, Eric Dumazet, Jakub Kicinski,
Paolo Abeni, Michael S. Tsirkin, Jason Wang, Xuan Zhuo,
Eugenio Pérez, Keith Busch, Jens Axboe, Christoph Hellwig,
Sagi Grimberg, K. Y. Srinivasan, Haiyang Zhang, Wei Liu,
Dexuan Cui, Lorenzo Pieralisi, Krzysztof Wilczyński,
Manivannan Sadhasivam, Rob Herring, Bjorn Helgaas, James Smart,
Dick Kennedy, James E.J. Bottomley, Martin K. Petersen,
Yury Norov, Rasmus Villemoes, Matt Wu, Steffen Klassert,
Daniel Jordan, Andrew Morton, Greg Kurz, Peter Xu,
Shrikanth Hegde, Hendrik Brueckner
The next patch aligns implementation of cpumask_next_wrap() with the
find_next_bit_wrap(), and it changes function signature.
To make the transition smooth, this patch deprecates current
implementation by adding an _old suffix. The following patches switch
current users to the new implementation one by one.
No functional changes were intended.
Signed-off-by: Yury Norov <yury.norov@gmail.com>
---
arch/s390/kernel/processor.c | 2 +-
drivers/pci/controller/pci-hyperv.c | 2 +-
drivers/scsi/lpfc/lpfc_init.c | 2 +-
include/linux/cpumask.h | 4 ++--
kernel/padata.c | 2 +-
lib/cpumask.c | 6 +++---
6 files changed, 9 insertions(+), 9 deletions(-)
diff --git a/arch/s390/kernel/processor.c b/arch/s390/kernel/processor.c
index 5ce9a795a0fe..42ca61909030 100644
--- a/arch/s390/kernel/processor.c
+++ b/arch/s390/kernel/processor.c
@@ -72,7 +72,7 @@ void notrace stop_machine_yield(const struct cpumask *cpumask)
this_cpu = smp_processor_id();
if (__this_cpu_inc_return(cpu_relax_retry) >= spin_retry) {
__this_cpu_write(cpu_relax_retry, 0);
- cpu = cpumask_next_wrap(this_cpu, cpumask, this_cpu, false);
+ cpu = cpumask_next_wrap_old(this_cpu, cpumask, this_cpu, false);
if (cpu >= nr_cpu_ids)
return;
if (arch_vcpu_is_preempted(cpu))
diff --git a/drivers/pci/controller/pci-hyperv.c b/drivers/pci/controller/pci-hyperv.c
index 6084b38bdda1..c39316966de5 100644
--- a/drivers/pci/controller/pci-hyperv.c
+++ b/drivers/pci/controller/pci-hyperv.c
@@ -1757,7 +1757,7 @@ static int hv_compose_multi_msi_req_get_cpu(void)
spin_lock_irqsave(&multi_msi_cpu_lock, flags);
- cpu_next = cpumask_next_wrap(cpu_next, cpu_online_mask, nr_cpu_ids,
+ cpu_next = cpumask_next_wrap_old(cpu_next, cpu_online_mask, nr_cpu_ids,
false);
cpu = cpu_next;
diff --git a/drivers/scsi/lpfc/lpfc_init.c b/drivers/scsi/lpfc/lpfc_init.c
index 7f57397d91a9..31622fb0614a 100644
--- a/drivers/scsi/lpfc/lpfc_init.c
+++ b/drivers/scsi/lpfc/lpfc_init.c
@@ -12876,7 +12876,7 @@ lpfc_irq_rebalance(struct lpfc_hba *phba, unsigned int cpu, bool offline)
if (offline) {
/* Find next online CPU on original mask */
- cpu_next = cpumask_next_wrap(cpu, orig_mask, cpu, true);
+ cpu_next = cpumask_next_wrap_old(cpu, orig_mask, cpu, true);
cpu_select = lpfc_next_online_cpu(orig_mask, cpu_next);
/* Found a valid CPU */
diff --git a/include/linux/cpumask.h b/include/linux/cpumask.h
index 30042351f15f..b267a4f6a917 100644
--- a/include/linux/cpumask.h
+++ b/include/linux/cpumask.h
@@ -296,7 +296,7 @@ unsigned int cpumask_next_and(int n, const struct cpumask *src1p,
#if NR_CPUS == 1
static __always_inline
-unsigned int cpumask_next_wrap(int n, const struct cpumask *mask, int start, bool wrap)
+unsigned int cpumask_next_wrap_old(int n, const struct cpumask *mask, int start, bool wrap)
{
cpumask_check(start);
if (n != -1)
@@ -312,7 +312,7 @@ unsigned int cpumask_next_wrap(int n, const struct cpumask *mask, int start, boo
return cpumask_first(mask);
}
#else
-unsigned int __pure cpumask_next_wrap(int n, const struct cpumask *mask, int start, bool wrap);
+unsigned int __pure cpumask_next_wrap_old(int n, const struct cpumask *mask, int start, bool wrap);
#endif
/**
diff --git a/kernel/padata.c b/kernel/padata.c
index 418987056340..78e202fabf90 100644
--- a/kernel/padata.c
+++ b/kernel/padata.c
@@ -290,7 +290,7 @@ static struct padata_priv *padata_find_next(struct parallel_data *pd,
if (remove_object) {
list_del_init(&padata->list);
++pd->processed;
- pd->cpu = cpumask_next_wrap(cpu, pd->cpumask.pcpu, -1, false);
+ pd->cpu = cpumask_next_wrap_old(cpu, pd->cpumask.pcpu, -1, false);
}
spin_unlock(&reorder->lock);
diff --git a/lib/cpumask.c b/lib/cpumask.c
index e77ee9d46f71..c9a9b451772a 100644
--- a/lib/cpumask.c
+++ b/lib/cpumask.c
@@ -8,7 +8,7 @@
#include <linux/numa.h>
/**
- * cpumask_next_wrap - helper to implement for_each_cpu_wrap
+ * cpumask_next_wrap_old - helper to implement for_each_cpu_wrap
* @n: the cpu prior to the place to search
* @mask: the cpumask pointer
* @start: the start point of the iteration
@@ -19,7 +19,7 @@
* Note: the @wrap argument is required for the start condition when
* we cannot assume @start is set in @mask.
*/
-unsigned int cpumask_next_wrap(int n, const struct cpumask *mask, int start, bool wrap)
+unsigned int cpumask_next_wrap_old(int n, const struct cpumask *mask, int start, bool wrap)
{
unsigned int next;
@@ -37,7 +37,7 @@ unsigned int cpumask_next_wrap(int n, const struct cpumask *mask, int start, boo
return next;
}
-EXPORT_SYMBOL(cpumask_next_wrap);
+EXPORT_SYMBOL(cpumask_next_wrap_old);
/* These are not inline because of header tangles. */
#ifdef CONFIG_CPUMASK_OFFSTACK
--
2.43.0
^ permalink raw reply related [flat|nested] 7+ messages in thread* [PATCH v2 06/13] cpumask: re-introduce cpumask_next{,_and}_wrap()
2025-01-28 16:46 [PATCH v2 00/13] cpumask: cleanup cpumask_next_wrap() implementation and usage Yury Norov
` (2 preceding siblings ...)
2025-01-28 16:46 ` [PATCH v2 05/13] cpumask: deprecate cpumask_next_wrap() Yury Norov
@ 2025-01-28 16:46 ` Yury Norov
2025-02-24 21:18 ` [PATCH v2 00/13] cpumask: cleanup cpumask_next_wrap() implementation and usage Michael S. Tsirkin
4 siblings, 0 replies; 7+ messages in thread
From: Yury Norov @ 2025-01-28 16:46 UTC (permalink / raw)
To: linux-kernel, linuxppc-dev, linux-s390, netdev, virtualization,
linux-nvme, linux-hyperv, linux-pci, linux-scsi, linux-crypto,
Michael Ellerman, Nicholas Piggin, Christophe Leroy, Naveen N Rao,
Madhavan Srinivasan, Heiko Carstens, Vasily Gorbik,
Alexander Gordeev, Christian Borntraeger, Sven Schnelle,
Haren Myneni, Rick Lindsley, Nick Child, Thomas Falcon,
Andrew Lunn, David S. Miller, Eric Dumazet, Jakub Kicinski,
Paolo Abeni, Michael S. Tsirkin, Jason Wang, Xuan Zhuo,
Eugenio Pérez, Keith Busch, Jens Axboe, Christoph Hellwig,
Sagi Grimberg, K. Y. Srinivasan, Haiyang Zhang, Wei Liu,
Dexuan Cui, Lorenzo Pieralisi, Krzysztof Wilczyński,
Manivannan Sadhasivam, Rob Herring, Bjorn Helgaas, James Smart,
Dick Kennedy, James E.J. Bottomley, Martin K. Petersen,
Yury Norov, Rasmus Villemoes, Matt Wu, Steffen Klassert,
Daniel Jordan, Andrew Morton, Greg Kurz, Peter Xu,
Shrikanth Hegde, Hendrik Brueckner
Cc: Bjorn Helgaas
cpumask_next_wrap_old() has two additional parameters, comparing to its
generic counterpart find_next_bit_wrap(). The reason for that is
historical.
Before 4fe49b3b97c262 ("lib/bitmap: introduce for_each_set_bit_wrap()
macro"), cpumask_next_wrap() was used to implement for_each_cpu_wrap()
iterator. Now that the iterator is an alias to generic
for_each_set_bit_wrap(), the additional parameters aren't used and may
confuse readers.
All existing users call cpumask_next_wrap() in a way that makes it
possible to turn it to straight and simple alias to find_next_bit_wrap().
In a couple of places kernel users opencode missing cpumask_next_and_wrap().
Add it as well.
CC: Alexander Gordeev <agordeev@linux.ibm.com>
CC: Bjorn Helgaas <helgaas@kernel.org>
Signed-off-by: Yury Norov <yury.norov@gmail.com>
---
include/linux/cpumask.h | 38 ++++++++++++++++++++++++++++++++++++++
1 file changed, 38 insertions(+)
diff --git a/include/linux/cpumask.h b/include/linux/cpumask.h
index b267a4f6a917..4f3d8d66e86e 100644
--- a/include/linux/cpumask.h
+++ b/include/linux/cpumask.h
@@ -284,6 +284,44 @@ unsigned int cpumask_next_and(int n, const struct cpumask *src1p,
small_cpumask_bits, n + 1);
}
+/**
+ * cpumask_next_and_wrap - get the next cpu in *src1p & *src2p, starting from
+ * @n+1. If nothing found, wrap around and start from
+ * the beginning
+ * @n: the cpu prior to the place to search (i.e. search starts from @n+1)
+ * @src1p: the first cpumask pointer
+ * @src2p: the second cpumask pointer
+ *
+ * Return: next set bit, wrapped if needed, or >= nr_cpu_ids if @src1p & @src2p is empty.
+ */
+static __always_inline
+unsigned int cpumask_next_and_wrap(int n, const struct cpumask *src1p,
+ const struct cpumask *src2p)
+{
+ /* -1 is a legal arg here. */
+ if (n != -1)
+ cpumask_check(n);
+ return find_next_and_bit_wrap(cpumask_bits(src1p), cpumask_bits(src2p),
+ small_cpumask_bits, n + 1);
+}
+
+/**
+ * cpumask_next_wrap - get the next cpu in *src, starting from @n+1. If nothing
+ * found, wrap around and start from the beginning
+ * @n: the cpu prior to the place to search (i.e. search starts from @n+1)
+ * @src: cpumask pointer
+ *
+ * Return: next set bit, wrapped if needed, or >= nr_cpu_ids if @src is empty.
+ */
+static __always_inline
+unsigned int cpumask_next_wrap(int n, const struct cpumask *src)
+{
+ /* -1 is a legal arg here. */
+ if (n != -1)
+ cpumask_check(n);
+ return find_next_bit_wrap(cpumask_bits(src), small_cpumask_bits, n + 1);
+}
+
/**
* for_each_cpu - iterate over every cpu in a mask
* @cpu: the (optionally unsigned) integer iterator
--
2.43.0
^ permalink raw reply related [flat|nested] 7+ messages in thread* Re: [PATCH v2 00/13] cpumask: cleanup cpumask_next_wrap() implementation and usage
2025-01-28 16:46 [PATCH v2 00/13] cpumask: cleanup cpumask_next_wrap() implementation and usage Yury Norov
` (3 preceding siblings ...)
2025-01-28 16:46 ` [PATCH v2 06/13] cpumask: re-introduce cpumask_next{,_and}_wrap() Yury Norov
@ 2025-02-24 21:18 ` Michael S. Tsirkin
4 siblings, 0 replies; 7+ messages in thread
From: Michael S. Tsirkin @ 2025-02-24 21:18 UTC (permalink / raw)
To: Yury Norov
Cc: linux-kernel, linuxppc-dev, linux-s390, netdev, virtualization,
linux-nvme, linux-hyperv, linux-pci, linux-scsi, linux-crypto,
Michael Ellerman, Nicholas Piggin, Christophe Leroy, Naveen N Rao,
Madhavan Srinivasan, Heiko Carstens, Vasily Gorbik,
Alexander Gordeev, Christian Borntraeger, Sven Schnelle,
Haren Myneni, Rick Lindsley, Nick Child, Thomas Falcon,
Andrew Lunn, David S. Miller, Eric Dumazet, Jakub Kicinski,
Paolo Abeni, Jason Wang, Xuan Zhuo, Eugenio Pérez,
Keith Busch, Jens Axboe, Christoph Hellwig, Sagi Grimberg,
K. Y. Srinivasan, Haiyang Zhang, Wei Liu, Dexuan Cui,
Lorenzo Pieralisi, Krzysztof Wilczyński,
Manivannan Sadhasivam, Rob Herring, Bjorn Helgaas, James Smart,
Dick Kennedy, James E.J. Bottomley, Martin K. Petersen,
Rasmus Villemoes, Matt Wu, Steffen Klassert, Daniel Jordan,
Andrew Morton, Greg Kurz, Peter Xu, Shrikanth Hegde,
Hendrik Brueckner
On Tue, Jan 28, 2025 at 11:46:29AM -0500, Yury Norov wrote:
> cpumask_next_wrap() is overly complicated, comparing to it's generic
> version find_next_bit_wrap(), not mentioning it duplicates the above.
> It roots to the times when the function was used in the implementation
> of for_each_cpu_wrap() iterator. The function has 2 additional parameters
> that were used to catch loop termination condition for the iterator.
> (Although, only one is needed.)
>
> Since 4fe49b3b97c262 ("lib/bitmap: introduce for_each_set_bit_wrap()
> macro"), for_each_cpu_wrap() is wired to corresponding generic
> wrapping bitmap iterator, and additional complexity of
> cpumask_next_wrap() is not needed anymore.
>
> All existing users call cpumask_next_wrap() in a manner that makes
> it possible to turn it to a straight and simple alias to
> find_next_bit_wrap().
>
> This series replaces historical 4-parameter cpumask_next_wrap() with a
> thin 2-parameter wrapper around find_next_bit_wrap().
>
> Where it's possible to use for_each_cpu_wrap() iterator, the code is
> switched to use it because it's always preferable to use iterators over
> open loops.
>
> This series touches various scattered subsystems and To-list for the
> whole series is quite a long. To minimize noise, I send cover-letter and
> key patches #5 and 6 to every person involved. All other patches are sent
> individually to those pointed by scripts/get_maintainers.pl.
>
> I'd like to move the series with my bitmap-for-next branch as a whole.
virtio-net changes are straight-forward, so
Acked-by: Michael S. Tsirkin <mst@redhat.com>
> v1: https://lore.kernel.org/netdev/20241228184949.31582-1-yury.norov@gmail.com/T/
> v2:
> - rebase on top of today's origin/master;
> - drop #v1-10: not needed since v6.14 @ Sagi Grinberg;
> - #2, #3: fix picking next unused CPU @ Nick Child;
> - fix typos, cleanup comments @ Bjorn Helgaas, Alexander Gordeev;
> - CC Christoph Hellwig for the whole series.
>
> Yury Norov (13):
> objpool: rework objpool_pop()
> virtio_net: simplify virtnet_set_affinity()
> ibmvnic: simplify ibmvnic_set_queue_affinity()
> powerpc/xmon: simplify xmon_batch_next_cpu()
> cpumask: deprecate cpumask_next_wrap()
> cpumask: re-introduce cpumask_next{,_and}_wrap()
> cpumask: use cpumask_next_wrap() where appropriate
> padata: switch padata_find_next() to using cpumask_next_wrap()
> s390: switch stop_machine_yield() to using cpumask_next_wrap()
> scsi: lpfc: switch lpfc_irq_rebalance() to using cpumask_next_wrap()
> scsi: lpfc: rework lpfc_next_{online,present}_cpu()
> PCI: hv: Switch hv_compose_multi_msi_req_get_cpu() to using
> cpumask_next_wrap()
> cpumask: drop cpumask_next_wrap_old()
>
> arch/powerpc/xmon/xmon.c | 6 +--
> arch/s390/kernel/processor.c | 2 +-
> drivers/net/ethernet/ibm/ibmvnic.c | 18 +++++---
> drivers/net/virtio_net.c | 12 ++---
> drivers/pci/controller/pci-hyperv.c | 3 +-
> drivers/scsi/lpfc/lpfc.h | 23 +++-------
> drivers/scsi/lpfc/lpfc_init.c | 2 +-
> include/linux/cpumask.h | 69 ++++++++++++++++++++---------
> include/linux/objpool.h | 7 ++-
> kernel/padata.c | 2 +-
> lib/cpumask.c | 37 +---------------
> 11 files changed, 81 insertions(+), 100 deletions(-)
>
> --
> 2.43.0
^ permalink raw reply [flat|nested] 7+ messages in thread