* [PATCH v3 1/2] powerpc: pci-ioda: use bitmap_alloc() in pnv_ioda_pick_m64_pe()
2025-08-14 19:09 [PATCH v3 0/2] powerpc: pci-ioda: Rework pnv_ioda_pick_m64_pe() Yury Norov
@ 2025-08-14 19:09 ` Yury Norov
2025-08-14 19:09 ` [PATCH v3 2/2] powerpc: pci-ioda: Optimize pnv_ioda_pick_m64_pe() Yury Norov
2026-04-08 4:29 ` [PATCH v3 0/2] powerpc: pci-ioda: Rework pnv_ioda_pick_m64_pe() Madhavan Srinivasan
2 siblings, 0 replies; 4+ messages in thread
From: Yury Norov @ 2025-08-14 19:09 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..2a4b916205c1 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_zalloc(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] 4+ messages in thread* [PATCH v3 2/2] powerpc: pci-ioda: Optimize pnv_ioda_pick_m64_pe()
2025-08-14 19:09 [PATCH v3 0/2] powerpc: pci-ioda: Rework pnv_ioda_pick_m64_pe() Yury Norov
2025-08-14 19:09 ` [PATCH v3 1/2] powerpc: pci-ioda: use bitmap_alloc() in pnv_ioda_pick_m64_pe() Yury Norov
@ 2025-08-14 19:09 ` Yury Norov
2026-04-08 4:29 ` [PATCH v3 0/2] powerpc: pci-ioda: Rework pnv_ioda_pick_m64_pe() Madhavan Srinivasan
2 siblings, 0 replies; 4+ messages in thread
From: Yury Norov @ 2025-08-14 19:09 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().
Reviewed-by: Andrew Donnellan <ajd@linux.ibm.com>
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 2a4b916205c1..23b1db3f15a9 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] 4+ messages in thread* Re: [PATCH v3 0/2] powerpc: pci-ioda: Rework pnv_ioda_pick_m64_pe()
2025-08-14 19:09 [PATCH v3 0/2] powerpc: pci-ioda: Rework pnv_ioda_pick_m64_pe() Yury Norov
2025-08-14 19:09 ` [PATCH v3 1/2] powerpc: pci-ioda: use bitmap_alloc() in pnv_ioda_pick_m64_pe() Yury Norov
2025-08-14 19:09 ` [PATCH v3 2/2] powerpc: pci-ioda: Optimize pnv_ioda_pick_m64_pe() Yury Norov
@ 2026-04-08 4:29 ` Madhavan Srinivasan
2 siblings, 0 replies; 4+ messages in thread
From: Madhavan Srinivasan @ 2026-04-08 4:29 UTC (permalink / raw)
To: Jiri Slaby (SUSE), Michael Ellerman, Nicholas Piggin,
Frederic Barrat, Andrew Donnellan, linuxppc-dev, linux-kernel,
Christophe Leroy, Thomas Gleixner, Yury Norov
On Thu, 14 Aug 2025 15:09:34 -0400, Yury Norov wrote:
> Use cleanup functionality and better bitmap API in the function
>
> v1: https://lore.kernel.org/all/20250720010552.427903-1-yury.norov@gmail.com/
> v2: https://lore.kernel.org/all/20250811165130.37552-1-yury.norov@gmail.com/
> v3:
> - use bitmap_zalloc in #1 (Andrew);
>
> [...]
Applied to powerpc/next.
[1/2] powerpc: pci-ioda: use bitmap_alloc() in pnv_ioda_pick_m64_pe()
https://git.kernel.org/powerpc/c/f73338d089deedb4f4f1e49751c30b8b7f595ecd
[2/2] powerpc: pci-ioda: Optimize pnv_ioda_pick_m64_pe()
https://git.kernel.org/powerpc/c/bd77a34e9a619ee92c03cbb227ca86d814aa6601
cheers
^ permalink raw reply [flat|nested] 4+ messages in thread