mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Yury Norov <yury.norov@gmail.com>
To: linux-kernel@vger.kernel.org, Matt Wu <wuqiang.matt@bytedance.com>
Cc: Yury Norov <yury.norov@gmail.com>,
	Rasmus Villemoes <linux@rasmusvillemoes.dk>
Subject: [PATCH 01/14] objpool: rework objpool_pop()
Date: Sat, 28 Dec 2024 10:49:33 -0800	[thread overview]
Message-ID: <20241228184949.31582-2-yury.norov@gmail.com> (raw)
In-Reply-To: <20241228184949.31582-1-yury.norov@gmail.com>

The function has to track number of iterations to prevent an infinite
loop. for_each_cpu_wrap() macro takes care of it, which simplifies user
code.

Similarly to for_each_possible_cpu() flavor, this patch introduces
for_each_possible_cpu_wrap() version of iterator to keep usage of the
API simple and coherent.

Signed-off-by: Yury Norov <yury.norov@gmail.com>
---
 include/linux/cpumask.h | 6 ++++++
 include/linux/objpool.h | 7 +++----
 2 files changed, 9 insertions(+), 4 deletions(-)

diff --git a/include/linux/cpumask.h b/include/linux/cpumask.h
index 9278a50d514f..5cf69a110c1c 100644
--- a/include/linux/cpumask.h
+++ b/include/linux/cpumask.h
@@ -1033,11 +1033,17 @@ extern const DECLARE_BITMAP(cpu_all_bits, NR_CPUS);
 #define for_each_possible_cpu(cpu)	for ((cpu) = 0; (cpu) < 1; (cpu)++)
 #define for_each_online_cpu(cpu)	for ((cpu) = 0; (cpu) < 1; (cpu)++)
 #define for_each_present_cpu(cpu)	for ((cpu) = 0; (cpu) < 1; (cpu)++)
+
+#define for_each_possible_cpu_wrap(cpu, start)	\
+	for ((void)(start), (cpu) = 0; (cpu) < 1; (cpu)++)
 #else
 #define for_each_possible_cpu(cpu) for_each_cpu((cpu), cpu_possible_mask)
 #define for_each_online_cpu(cpu)   for_each_cpu((cpu), cpu_online_mask)
 #define for_each_enabled_cpu(cpu)   for_each_cpu((cpu), cpu_enabled_mask)
 #define for_each_present_cpu(cpu)  for_each_cpu((cpu), cpu_present_mask)
+
+#define for_each_possible_cpu_wrap(cpu, start)	\
+	for_each_cpu_wrap((cpu), cpu_possible_mask, (start))
 #endif
 
 /* Wrappers for arch boot code to manipulate normally-constant masks */
diff --git a/include/linux/objpool.h b/include/linux/objpool.h
index cb1758eaa2d3..b713a1fe7521 100644
--- a/include/linux/objpool.h
+++ b/include/linux/objpool.h
@@ -170,17 +170,16 @@ static inline void *objpool_pop(struct objpool_head *pool)
 {
 	void *obj = NULL;
 	unsigned long flags;
-	int i, cpu;
+	int start, cpu;
 
 	/* disable local irq to avoid preemption & interruption */
 	raw_local_irq_save(flags);
 
-	cpu = raw_smp_processor_id();
-	for (i = 0; i < pool->nr_possible_cpus; i++) {
+	start = raw_smp_processor_id();
+	for_each_possible_cpu_wrap(cpu, start) {
 		obj = __objpool_try_get_slot(pool, cpu);
 		if (obj)
 			break;
-		cpu = cpumask_next_wrap(cpu, cpu_possible_mask, -1, 1);
 	}
 	raw_local_irq_restore(flags);
 
-- 
2.43.0


  reply	other threads:[~2024-12-28 18:49 UTC|newest]

Thread overview: 34+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-12-28 18:49 [PATCH 00/14] cpumask: cleanup cpumask_next_wrap() implementation and usage Yury Norov
2024-12-28 18:49 ` Yury Norov [this message]
2024-12-28 18:49 ` [PATCH 02/14] virtio_net: simplify virtnet_set_affinity() Yury Norov
2024-12-28 18:49 ` [PATCH 03/14] ibmvnic: simplify ibmvnic_set_queue_affinity() Yury Norov
2025-01-07 22:37   ` Nick Child
2025-01-07 22:42     ` Yury Norov
2025-01-07 23:04       ` Yury Norov
2025-01-08 14:08         ` [PATCH 03/14] ibmvnic: simplify ibmvnic_set_queue_affinity()y Nick Child
2024-12-28 18:49 ` [PATCH 04/14] powerpc/xmon: simplify xmon_batch_next_cpu() Yury Norov
2024-12-28 18:49 ` [PATCH 05/14] cpumask: deprecate cpumask_next_wrap() Yury Norov
2025-01-03 17:39   ` Bjorn Helgaas
2024-12-28 18:49 ` [PATCH 06/14] cpumask: re-introduce cpumask_next{,_and}_wrap() Yury Norov
2025-01-03 17:44   ` Bjorn Helgaas
2025-01-15  3:41     ` Yury Norov
2025-01-07 13:28   ` Alexander Gordeev
2025-01-15  3:38     ` Yury Norov
2024-12-28 18:49 ` [PATCH 07/14] cpumask: use cpumask_next_wrap() where appropriate Yury Norov
2024-12-28 18:49 ` [PATCH 08/14] padata: switch padata_find_next() to using cpumask_next_wrap() Yury Norov
2025-01-04  0:33   ` Herbert Xu
2025-01-07 19:02   ` Daniel Jordan
2024-12-28 18:49 ` [PATCH 09/14] s390: switch stop_machine_yield() " Yury Norov
2024-12-28 18:49 ` [PATCH 10/14] nvme-tcp: switch nvme_tcp_set_queue_io_cpu() " Yury Norov
2024-12-30  8:31   ` Sagi Grimberg
2024-12-28 18:49 ` [PATCH 11/14] scsi: lpfc: switch lpfc_irq_rebalance() " Yury Norov
2024-12-31  1:05   ` Justin Tee
2024-12-28 18:49 ` [PATCH 12/14] scsi: lpfc: rework lpfc_next_{online,present}_cpu() Yury Norov
2024-12-31  1:06   ` Justin Tee
2024-12-28 18:49 ` [PATCH 13/14] PCI: hv: switch hv_compose_multi_msi_req_get_cpu() to using cpumask_next_wrap() Yury Norov
2024-12-29 17:34   ` Michael Kelley
2025-01-03 17:45   ` Bjorn Helgaas
2025-01-03 18:56     ` Yury Norov
2024-12-28 18:49 ` [PATCH 14/14] cpumask: drop cpumask_next_wrap_old() Yury Norov
2025-01-03  7:02 ` [PATCH 00/14] cpumask: cleanup cpumask_next_wrap() implementation and usage Christoph Hellwig
2025-01-03 15:21   ` Yury Norov

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20241228184949.31582-2-yury.norov@gmail.com \
    --to=yury.norov@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux@rasmusvillemoes.dk \
    --cc=wuqiang.matt@bytedance.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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®