linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2 0/2] powerpc: pci-ioda: Rework pnv_ioda_pick_m64_pe()
@ 2025-08-11 16:51 Yury Norov
  2025-08-11 16:51 ` [PATCH v2 1/2] powerpc: pci-ioda: use bitmap_alloc() in pnv_ioda_pick_m64_pe() Yury Norov
  2025-08-11 16:51 ` [PATCH v2 2/2] powerpc: pci-ioda: Optimize pnv_ioda_pick_m64_pe() Yury Norov
  0 siblings, 2 replies; 6+ messages in thread
From: Yury Norov @ 2025-08-11 16:51 UTC (permalink / raw)
  To: Jiri Slaby (SUSE), Madhavan Srinivasan, Michael Ellerman,
	Nicholas Piggin, Christophe Leroy, Thomas Gleixner,
	Frederic Barrat, Andrew Donnellan, Yury Norov, linuxppc-dev,
	linux-kernel

Use cleanup functionality and better bitmap API in the function

v1: https://lore.kernel.org/all/20250720010552.427903-1-yury.norov@gmail.com/
v2: 
 - add patch v2#1 that switches the function to bitmap_alloc() and
   clenup engine (Jiri);

Yury Norov (NVIDIA) (2):
  powerpc: pci-ioda: use bitmap_alloc() in pnv_ioda_pick_m64_pe()
  powerpc: pci-ioda: Optimize pnv_ioda_pick_m64_pe()

 arch/powerpc/platforms/powernv/pci-ioda.c | 27 +++++++----------------
 1 file changed, 8 insertions(+), 19 deletions(-)

-- 
2.43.0


^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH v2 1/2] powerpc: pci-ioda: use bitmap_alloc() in pnv_ioda_pick_m64_pe()
  2025-08-11 16:51 [PATCH v2 0/2] powerpc: pci-ioda: Rework pnv_ioda_pick_m64_pe() Yury Norov
@ 2025-08-11 16:51 ` Yury Norov
  2025-08-12  1:07   ` Andrew Donnellan
  2025-08-11 16:51 ` [PATCH v2 2/2] powerpc: pci-ioda: Optimize pnv_ioda_pick_m64_pe() Yury Norov
  1 sibling, 1 reply; 6+ messages in thread
From: Yury Norov @ 2025-08-11 16:51 UTC (permalink / raw)
  To: Jiri Slaby (SUSE), Madhavan Srinivasan, Michael Ellerman,
	Nicholas Piggin, Christophe Leroy, Thomas Gleixner,
	Frederic Barrat, Andrew Donnellan, Yury Norov, linuxppc-dev,
	linux-kernel

From: "Yury Norov (NVIDIA)" <yury.norov@gmail.com>

Use the dedicated bitmap_alloc() in pnv_ioda_pick_m64_pe() and drop
some housekeeping code.

Because pe_alloc is local, annotate it with __free() and get rid of
the explicit kfree() calls.

Suggested-by: Jiri Slaby <jirislaby@kernel.org>
Signed-off-by: Yury Norov (NVIDIA) <yury.norov@gmail.com>
---
 arch/powerpc/platforms/powernv/pci-ioda.c | 8 ++------
 1 file changed, 2 insertions(+), 6 deletions(-)

diff --git a/arch/powerpc/platforms/powernv/pci-ioda.c b/arch/powerpc/platforms/powernv/pci-ioda.c
index d8ccf2c9b98a..e2b0132fb6a1 100644
--- a/arch/powerpc/platforms/powernv/pci-ioda.c
+++ b/arch/powerpc/platforms/powernv/pci-ioda.c
@@ -292,18 +292,16 @@ static void pnv_ioda_reserve_m64_pe(struct pci_bus *bus,
 
 static struct pnv_ioda_pe *pnv_ioda_pick_m64_pe(struct pci_bus *bus, bool all)
 {
+	unsigned long *pe_alloc __free(bitmap) = NULL;
 	struct pnv_phb *phb = pci_bus_to_pnvhb(bus);
 	struct pnv_ioda_pe *master_pe, *pe;
-	unsigned long size, *pe_alloc;
 	int i;
 
 	/* Root bus shouldn't use M64 */
 	if (pci_is_root_bus(bus))
 		return NULL;
 
-	/* Allocate bitmap */
-	size = ALIGN(phb->ioda.total_pe_num / 8, sizeof(unsigned long));
-	pe_alloc = kzalloc(size, GFP_KERNEL);
+	pe_alloc = bitmap_alloc(phb->ioda.total_pe_num, GFP_KERNEL);
 	if (!pe_alloc) {
 		pr_warn("%s: Out of memory !\n",
 			__func__);
@@ -319,7 +317,6 @@ static struct pnv_ioda_pe *pnv_ioda_pick_m64_pe(struct pci_bus *bus, bool all)
 	 * pick M64 dependent PE#.
 	 */
 	if (bitmap_empty(pe_alloc, phb->ioda.total_pe_num)) {
-		kfree(pe_alloc);
 		return NULL;
 	}
 
@@ -345,7 +342,6 @@ static struct pnv_ioda_pe *pnv_ioda_pick_m64_pe(struct pci_bus *bus, bool all)
 		}
 	}
 
-	kfree(pe_alloc);
 	return master_pe;
 }
 
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH v2 2/2] powerpc: pci-ioda: Optimize pnv_ioda_pick_m64_pe()
  2025-08-11 16:51 [PATCH v2 0/2] powerpc: pci-ioda: Rework pnv_ioda_pick_m64_pe() Yury Norov
  2025-08-11 16:51 ` [PATCH v2 1/2] powerpc: pci-ioda: use bitmap_alloc() in pnv_ioda_pick_m64_pe() Yury Norov
@ 2025-08-11 16:51 ` Yury Norov
  2025-08-12  3:45   ` Andrew Donnellan
  1 sibling, 1 reply; 6+ messages in thread
From: Yury Norov @ 2025-08-11 16:51 UTC (permalink / raw)
  To: Jiri Slaby (SUSE), Madhavan Srinivasan, Michael Ellerman,
	Nicholas Piggin, Christophe Leroy, Thomas Gleixner,
	Frederic Barrat, Andrew Donnellan, Yury Norov, linuxppc-dev,
	linux-kernel

From: "Yury Norov (NVIDIA)" <yury.norov@gmail.com>

bitmap_empty() in pnv_ioda_pick_m64_pe() is O(N) and useless because
the following find_next_bit() does the same work.

Drop it, and while there replace a while() loop with the dedicated
for_each_set_bit().

Signed-off-by: Yury Norov (NVIDIA) <yury.norov@gmail.com>
---
 arch/powerpc/platforms/powernv/pci-ioda.c | 19 ++++++-------------
 1 file changed, 6 insertions(+), 13 deletions(-)

diff --git a/arch/powerpc/platforms/powernv/pci-ioda.c b/arch/powerpc/platforms/powernv/pci-ioda.c
index e2b0132fb6a1..325197ac19e5 100644
--- a/arch/powerpc/platforms/powernv/pci-ioda.c
+++ b/arch/powerpc/platforms/powernv/pci-ioda.c
@@ -295,7 +295,7 @@ static struct pnv_ioda_pe *pnv_ioda_pick_m64_pe(struct pci_bus *bus, bool all)
 	unsigned long *pe_alloc __free(bitmap) = NULL;
 	struct pnv_phb *phb = pci_bus_to_pnvhb(bus);
 	struct pnv_ioda_pe *master_pe, *pe;
-	int i;
+	unsigned int i;
 
 	/* Root bus shouldn't use M64 */
 	if (pci_is_root_bus(bus))
@@ -311,23 +311,16 @@ static struct pnv_ioda_pe *pnv_ioda_pick_m64_pe(struct pci_bus *bus, bool all)
 	/* Figure out reserved PE numbers by the PE */
 	pnv_ioda_reserve_m64_pe(bus, pe_alloc, all);
 
-	/*
-	 * the current bus might not own M64 window and that's all
-	 * contributed by its child buses. For the case, we needn't
-	 * pick M64 dependent PE#.
-	 */
-	if (bitmap_empty(pe_alloc, phb->ioda.total_pe_num)) {
-		return NULL;
-	}
-
 	/*
 	 * Figure out the master PE and put all slave PEs to master
 	 * PE's list to form compound PE.
+	 *
+	 * The current bus might not own M64 window and that's all
+	 * contributed by its child buses. For the case, we needn't
+	 * pick M64 dependent PE#.
 	 */
 	master_pe = NULL;
-	i = -1;
-	while ((i = find_next_bit(pe_alloc, phb->ioda.total_pe_num, i + 1)) <
-		phb->ioda.total_pe_num) {
+	for_each_set_bit(i, pe_alloc, phb->ioda.total_pe_num) {
 		pe = &phb->ioda.pe_array[i];
 
 		phb->ioda.m64_segmap[pe->pe_number] = pe->pe_number;
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH v2 1/2] powerpc: pci-ioda: use bitmap_alloc() in pnv_ioda_pick_m64_pe()
  2025-08-11 16:51 ` [PATCH v2 1/2] powerpc: pci-ioda: use bitmap_alloc() in pnv_ioda_pick_m64_pe() Yury Norov
@ 2025-08-12  1:07   ` Andrew Donnellan
  2025-08-14  0:43     ` Yury Norov
  0 siblings, 1 reply; 6+ messages in thread
From: Andrew Donnellan @ 2025-08-12  1:07 UTC (permalink / raw)
  To: Yury Norov, Jiri Slaby (SUSE), Madhavan Srinivasan,
	Michael Ellerman, Nicholas Piggin, Christophe Leroy,
	Thomas Gleixner, Frederic Barrat, linuxppc-dev, linux-kernel

On Mon, 2025-08-11 at 12:51 -0400, Yury Norov wrote:

> -	/* Allocate bitmap */
> -	size = ALIGN(phb->ioda.total_pe_num / 8, sizeof(unsigned long));
> -	pe_alloc = kzalloc(size, GFP_KERNEL);
> +	pe_alloc = bitmap_alloc(phb->ioda.total_pe_num, GFP_KERNEL);

I haven't checked whether or not this has practical impact given what we later
do with the bitmap - does this need to be bitmap_zalloc() to match the existing
use of kzalloc()?

-- 
Andrew Donnellan    OzLabs, ADL Canberra
ajd@linux.ibm.com   IBM Australia Limited

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH v2 2/2] powerpc: pci-ioda: Optimize pnv_ioda_pick_m64_pe()
  2025-08-11 16:51 ` [PATCH v2 2/2] powerpc: pci-ioda: Optimize pnv_ioda_pick_m64_pe() Yury Norov
@ 2025-08-12  3:45   ` Andrew Donnellan
  0 siblings, 0 replies; 6+ messages in thread
From: Andrew Donnellan @ 2025-08-12  3:45 UTC (permalink / raw)
  To: Yury Norov, Jiri Slaby (SUSE), Madhavan Srinivasan,
	Michael Ellerman, Nicholas Piggin, Christophe Leroy,
	Thomas Gleixner, Frederic Barrat, linuxppc-dev, linux-kernel

On Mon, 2025-08-11 at 12:51 -0400, Yury Norov wrote:
> From: "Yury Norov (NVIDIA)" <yury.norov@gmail.com>
> 
> bitmap_empty() in pnv_ioda_pick_m64_pe() is O(N) and useless because
> the following find_next_bit() does the same work.
> 
> Drop it, and while there replace a while() loop with the dedicated
> for_each_set_bit().
> 
> Signed-off-by: Yury Norov (NVIDIA) <yury.norov@gmail.com>

Reviewed-by: Andrew Donnellan <ajd@linux.ibm.com>

-- 
Andrew Donnellan    OzLabs, ADL Canberra
ajd@linux.ibm.com   IBM Australia Limited

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH v2 1/2] powerpc: pci-ioda: use bitmap_alloc() in pnv_ioda_pick_m64_pe()
  2025-08-12  1:07   ` Andrew Donnellan
@ 2025-08-14  0:43     ` Yury Norov
  0 siblings, 0 replies; 6+ messages in thread
From: Yury Norov @ 2025-08-14  0:43 UTC (permalink / raw)
  To: Andrew Donnellan
  Cc: Jiri Slaby (SUSE), Madhavan Srinivasan, Michael Ellerman,
	Nicholas Piggin, Christophe Leroy, Thomas Gleixner,
	Frederic Barrat, linuxppc-dev, linux-kernel

On Tue, Aug 12, 2025 at 11:07:08AM +1000, Andrew Donnellan wrote:
> On Mon, 2025-08-11 at 12:51 -0400, Yury Norov wrote:
> 
> > -	/* Allocate bitmap */
> > -	size = ALIGN(phb->ioda.total_pe_num / 8, sizeof(unsigned long));
> > -	pe_alloc = kzalloc(size, GFP_KERNEL);
> > +	pe_alloc = bitmap_alloc(phb->ioda.total_pe_num, GFP_KERNEL);
> 
> I haven't checked whether or not this has practical impact given what we later
> do with the bitmap - does this need to be bitmap_zalloc() to match the existing
> use of kzalloc()?

That's fair. I'll send v3 with bitmap_zalloc().

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2025-08-14  0:43 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-08-11 16:51 [PATCH v2 0/2] powerpc: pci-ioda: Rework pnv_ioda_pick_m64_pe() Yury Norov
2025-08-11 16:51 ` [PATCH v2 1/2] powerpc: pci-ioda: use bitmap_alloc() in pnv_ioda_pick_m64_pe() Yury Norov
2025-08-12  1:07   ` Andrew Donnellan
2025-08-14  0:43     ` Yury Norov
2025-08-11 16:51 ` [PATCH v2 2/2] powerpc: pci-ioda: Optimize pnv_ioda_pick_m64_pe() Yury Norov
2025-08-12  3:45   ` Andrew Donnellan

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).