linuxppc-dev.lists.ozlabs.org archive mirror
 help / color / mirror / Atom feed
From: Yury Norov <yury.norov@gmail.com>
To: linux-kernel@vger.kernel.org,
	Michael Ellerman <mpe@ellerman.id.au>,
	Nicholas Piggin <npiggin@gmail.com>,
	Christophe Leroy <christophe.leroy@csgroup.eu>,
	"Naveen N. Rao" <naveen.n.rao@linux.ibm.com>,
	Yury Norov <yury.norov@gmail.com>,
	linuxppc-dev@lists.ozlabs.org
Cc: Sergey Shtylyov <s.shtylyov@omp.ru>, Jan Kara <jack@suse.cz>,
	Bart Van Assche <bvanassche@acm.org>,
	Rasmus Villemoes <linux@rasmusvillemoes.dk>,
	Matthew Wilcox <willy@infradead.org>,
	Alexey Klimov <alexey.klimov@linaro.org>,
	Linus Torvalds <torvalds@linux-foundation.org>,
	Mirsad Todorovac <mirsad.todorovac@alu.unizg.hr>
Subject: [PATCH v4 40/40] powerpc/xive: drop locking around IRQ map
Date: Thu, 20 Jun 2024 10:57:03 -0700	[thread overview]
Message-ID: <20240620175703.605111-41-yury.norov@gmail.com> (raw)
In-Reply-To: <20240620175703.605111-1-yury.norov@gmail.com>

The code operates on individual bits of the bitmap, and leveraging
atomic find ops we can drop locking scheme around the map.

Signed-off-by: Yury Norov <yury.norov@gmail.com>
---
 arch/powerpc/sysdev/xive/spapr.c | 34 ++++++--------------------------
 1 file changed, 6 insertions(+), 28 deletions(-)

diff --git a/arch/powerpc/sysdev/xive/spapr.c b/arch/powerpc/sysdev/xive/spapr.c
index e45419264391..2b3b8ad75b42 100644
--- a/arch/powerpc/sysdev/xive/spapr.c
+++ b/arch/powerpc/sysdev/xive/spapr.c
@@ -17,6 +17,7 @@
 #include <linux/spinlock.h>
 #include <linux/bitmap.h>
 #include <linux/cpumask.h>
+#include <linux/find_atomic.h>
 #include <linux/mm.h>
 #include <linux/delay.h>
 #include <linux/libfdt.h>
@@ -41,7 +42,6 @@ struct xive_irq_bitmap {
 	unsigned long		*bitmap;
 	unsigned int		base;
 	unsigned int		count;
-	spinlock_t		lock;
 	struct list_head	list;
 };
 
@@ -55,7 +55,6 @@ static int __init xive_irq_bitmap_add(int base, int count)
 	if (!xibm)
 		return -ENOMEM;
 
-	spin_lock_init(&xibm->lock);
 	xibm->base = base;
 	xibm->count = count;
 	xibm->bitmap = bitmap_zalloc(xibm->count, GFP_KERNEL);
@@ -81,47 +80,26 @@ static void xive_irq_bitmap_remove_all(void)
 	}
 }
 
-static int __xive_irq_bitmap_alloc(struct xive_irq_bitmap *xibm)
-{
-	int irq;
-
-	irq = find_first_zero_bit(xibm->bitmap, xibm->count);
-	if (irq != xibm->count) {
-		set_bit(irq, xibm->bitmap);
-		irq += xibm->base;
-	} else {
-		irq = -ENOMEM;
-	}
-
-	return irq;
-}
-
 static int xive_irq_bitmap_alloc(void)
 {
 	struct xive_irq_bitmap *xibm;
-	unsigned long flags;
-	int irq = -ENOENT;
 
 	list_for_each_entry(xibm, &xive_irq_bitmaps, list) {
-		spin_lock_irqsave(&xibm->lock, flags);
-		irq = __xive_irq_bitmap_alloc(xibm);
-		spin_unlock_irqrestore(&xibm->lock, flags);
-		if (irq >= 0)
-			break;
+		int irq = find_and_set_bit(xibm->bitmap, xibm->count);
+
+		if (irq < xibm->count)
+			return irq + xibm->base;
 	}
-	return irq;
+	return -ENOENT;
 }
 
 static void xive_irq_bitmap_free(int irq)
 {
-	unsigned long flags;
 	struct xive_irq_bitmap *xibm;
 
 	list_for_each_entry(xibm, &xive_irq_bitmaps, list) {
 		if ((irq >= xibm->base) && (irq < xibm->base + xibm->count)) {
-			spin_lock_irqsave(&xibm->lock, flags);
 			clear_bit(irq - xibm->base, xibm->bitmap);
-			spin_unlock_irqrestore(&xibm->lock, flags);
 			break;
 		}
 	}
-- 
2.43.0


  parent reply	other threads:[~2024-06-20 18:02 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-06-20 17:56 [PATCH v4 00/40] lib/find: add atomic find_bit() primitives Yury Norov
2024-06-20 17:56 ` [PATCH v4 01/40] " Yury Norov
2024-06-20 17:56 ` [PATCH v4 02/40] lib/find: add test for atomic find_bit() ops Yury Norov
2024-06-20 17:56 ` [PATCH v4 18/40] powerpc: optimize arch code by using atomic find_bit() API Yury Norov
2024-06-20 17:57 ` [PATCH v4 37/40] KVM: PPC: Book3s HV: drop locking around kvmppc_uvmem_bitmap Yury Norov
2024-06-20 17:57 ` Yury Norov [this message]
2024-06-20 18:00 ` [PATCH v4 00/40] lib/find: add atomic find_bit() primitives Linus Torvalds
2024-06-20 18:32   ` Yury Norov
2024-06-20 19:26     ` Linus Torvalds
2024-06-20 20:20       ` Yury Norov
2024-06-20 20:32         ` Linus Torvalds

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=20240620175703.605111-41-yury.norov@gmail.com \
    --to=yury.norov@gmail.com \
    --cc=alexey.klimov@linaro.org \
    --cc=bvanassche@acm.org \
    --cc=christophe.leroy@csgroup.eu \
    --cc=jack@suse.cz \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux@rasmusvillemoes.dk \
    --cc=linuxppc-dev@lists.ozlabs.org \
    --cc=mirsad.todorovac@alu.unizg.hr \
    --cc=mpe@ellerman.id.au \
    --cc=naveen.n.rao@linux.ibm.com \
    --cc=npiggin@gmail.com \
    --cc=s.shtylyov@omp.ru \
    --cc=torvalds@linux-foundation.org \
    --cc=willy@infradead.org \
    /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).