From: Michael Neuling <mikey@neuling.org>
To: greg@kroah.com, arnd@arndb.de, mpe@ellerman.id.au,
benh@kernel.crashing.org
Cc: cbe-oss-dev@lists.ozlabs.org, mikey@neuling.org,
"Aneesh Kumar K.V" <aneesh.kumar@linux.vnet.ibm.com>,
imunsie@au.ibm.com, linux-kernel@vger.kernel.org,
linuxppc-dev@ozlabs.org, jk@ozlabs.org, anton@samba.org
Subject: [PATCH v4 04/16] powerpc/msi: Improve IRQ bitmap allocator
Date: Wed, 8 Oct 2014 19:54:53 +1100 [thread overview]
Message-ID: <1412758505-23495-5-git-send-email-mikey@neuling.org> (raw)
In-Reply-To: <1412758505-23495-1-git-send-email-mikey@neuling.org>
From: Ian Munsie <imunsie@au1.ibm.com>
Currently msi_bitmap_alloc_hwirqs() will round up any IRQ allocation requests
to the nearest power of 2. eg. ask for 5 IRQs and you'll get 8. This wastes a
lot of IRQs which can be a scarce resource.
For cxl we may require multiple IRQs for every context that is attached to the
accelerator. There may be 1000s of contexts attached, hence we can easily run
out of IRQs, especially if we are needlessly wasting them.
This changes the msi_bitmap_alloc_hwirqs() to allocate only the required number
of IRQs, hence avoiding this wastage. It keeps the natural alignment
requirement though.
Signed-off-by: Ian Munsie <imunsie@au1.ibm.com>
Signed-off-by: Michael Neuling <mikey@neuling.org>
---
arch/powerpc/sysdev/msi_bitmap.c | 36 +++++++++++++++++++++++++-----------
1 file changed, 25 insertions(+), 11 deletions(-)
diff --git a/arch/powerpc/sysdev/msi_bitmap.c b/arch/powerpc/sysdev/msi_bitmap.c
index 2ff6302..871d94b 100644
--- a/arch/powerpc/sysdev/msi_bitmap.c
+++ b/arch/powerpc/sysdev/msi_bitmap.c
@@ -20,32 +20,37 @@ int msi_bitmap_alloc_hwirqs(struct msi_bitmap *bmp, int num)
int offset, order = get_count_order(num);
spin_lock_irqsave(&bmp->lock, flags);
- /*
- * This is fast, but stricter than we need. We might want to add
- * a fallback routine which does a linear search with no alignment.
- */
- offset = bitmap_find_free_region(bmp->bitmap, bmp->irq_count, order);
+
+ offset = bitmap_find_next_zero_area(bmp->bitmap, bmp->irq_count, 0,
+ num, (1 << order) - 1);
+ if (offset > bmp->irq_count)
+ goto err;
+
+ bitmap_set(bmp->bitmap, offset, num);
spin_unlock_irqrestore(&bmp->lock, flags);
- pr_debug("msi_bitmap: allocated 0x%x (2^%d) at offset 0x%x\n",
- num, order, offset);
+ pr_debug("msi_bitmap: allocated 0x%x at offset 0x%x\n", num, offset);
return offset;
+err:
+ spin_unlock_irqrestore(&bmp->lock, flags);
+ return -ENOMEM;
}
+EXPORT_SYMBOL(msi_bitmap_alloc_hwirqs);
void msi_bitmap_free_hwirqs(struct msi_bitmap *bmp, unsigned int offset,
unsigned int num)
{
unsigned long flags;
- int order = get_count_order(num);
- pr_debug("msi_bitmap: freeing 0x%x (2^%d) at offset 0x%x\n",
- num, order, offset);
+ pr_debug("msi_bitmap: freeing 0x%x at offset 0x%x\n",
+ num, offset);
spin_lock_irqsave(&bmp->lock, flags);
- bitmap_release_region(bmp->bitmap, offset, order);
+ bitmap_clear(bmp->bitmap, offset, num);
spin_unlock_irqrestore(&bmp->lock, flags);
}
+EXPORT_SYMBOL(msi_bitmap_free_hwirqs);
void msi_bitmap_reserve_hwirq(struct msi_bitmap *bmp, unsigned int hwirq)
{
@@ -180,6 +185,15 @@ void __init test_basics(void)
msi_bitmap_free_hwirqs(&bmp, size / 2, 1);
check(msi_bitmap_alloc_hwirqs(&bmp, 1) == size / 2);
+ /* Check we get a naturally aligned offset */
+ check(msi_bitmap_alloc_hwirqs(&bmp, 2) % 2 == 0);
+ check(msi_bitmap_alloc_hwirqs(&bmp, 4) % 4 == 0);
+ check(msi_bitmap_alloc_hwirqs(&bmp, 8) % 8 == 0);
+ check(msi_bitmap_alloc_hwirqs(&bmp, 9) % 16 == 0);
+ check(msi_bitmap_alloc_hwirqs(&bmp, 3) % 4 == 0);
+ check(msi_bitmap_alloc_hwirqs(&bmp, 7) % 8 == 0);
+ check(msi_bitmap_alloc_hwirqs(&bmp, 121) % 128 == 0);
+
msi_bitmap_free(&bmp);
/* Clients may check bitmap == NULL for "not-allocated" */
--
1.9.1
next prev parent reply other threads:[~2014-10-08 8:55 UTC|newest]
Thread overview: 26+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-10-08 8:54 [PATCH v4 0/16] POWER8 Coherent Accelerator device driver Michael Neuling
2014-10-08 8:54 ` [PATCH v4 01/16] powerpc/cell: Move spu_handle_mm_fault() out of cell platform Michael Neuling
2014-10-09 15:01 ` Aneesh Kumar K.V
2014-10-08 8:54 ` [PATCH v4 02/16] powerpc/cell: Move data segment faulting code " Michael Neuling
2014-10-09 15:04 ` Aneesh Kumar K.V
2014-10-08 8:54 ` [PATCH v4 03/16] powerpc/cell: Make spu_flush_all_slbs() generic Michael Neuling
2014-10-09 15:04 ` Aneesh Kumar K.V
2014-10-08 8:54 ` Michael Neuling [this message]
2014-10-08 8:54 ` [PATCH v4 05/16] powerpc/mm: Export mmu_kernel_ssize and mmu_linear_psize Michael Neuling
2014-10-09 15:05 ` Aneesh Kumar K.V
2014-10-08 8:54 ` [PATCH v4 06/16] powerpc/powernv: Split out set MSI IRQ chip code Michael Neuling
2014-10-08 8:54 ` [PATCH v4 07/16] cxl: Add new header for call backs and structs Michael Neuling
2014-10-08 8:54 ` [PATCH v4 08/16] powerpc/powerpc: Add new PCIe functions for allocating cxl interrupts Michael Neuling
2014-10-08 8:54 ` [PATCH v4 09/16] powerpc/mm: Add new hash_page_mm() Michael Neuling
2014-10-09 15:28 ` Aneesh Kumar K.V
2014-10-08 8:54 ` [PATCH v4 10/16] powerpc/opal: Add PHB to cxl mode call Michael Neuling
2014-10-08 8:55 ` [PATCH v4 11/16] powerpc/mm: Add hooks for cxl Michael Neuling
2014-10-09 15:20 ` Aneesh Kumar K.V
2014-10-08 8:55 ` [PATCH v4 12/16] cxl: Add base builtin support Michael Neuling
2014-10-08 8:55 ` [PATCH v4 13/16] cxl: Driver code for powernv PCIe based cards for userspace access Michael Neuling
2014-10-08 10:28 ` Ian Munsie
2014-10-08 10:41 ` [PATCH] CXL: Fix afu_read() not doing finish_wait() on signal or non-blocking Ian Munsie
2014-10-09 0:17 ` Ian Munsie
2014-10-08 8:55 ` [PATCH v4 14/16] cxl: Add userspace header file Michael Neuling
2014-10-08 8:55 ` [PATCH v4 15/16] cxl: Add driver to Kbuild and Makefiles Michael Neuling
2014-10-08 8:55 ` [PATCH v4 16/16] cxl: Add documentation for userspace APIs Michael Neuling
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=1412758505-23495-5-git-send-email-mikey@neuling.org \
--to=mikey@neuling.org \
--cc=aneesh.kumar@linux.vnet.ibm.com \
--cc=anton@samba.org \
--cc=arnd@arndb.de \
--cc=benh@kernel.crashing.org \
--cc=cbe-oss-dev@lists.ozlabs.org \
--cc=greg@kroah.com \
--cc=imunsie@au.ibm.com \
--cc=jk@ozlabs.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linuxppc-dev@ozlabs.org \
--cc=mpe@ellerman.id.au \
/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;
as well as URLs for NNTP newsgroup(s).