public inbox for linux-scsi@vger.kernel.org
 help / color / mirror / Atom feed
From: Yury Norov <yury.norov@gmail.com>
To: linux-kernel@vger.kernel.org,
	"James E.J. Bottomley" <James.Bottomley@HansenPartnership.com>,
	"Martin K. Petersen" <martin.petersen@oracle.com>,
	linux-scsi@vger.kernel.org
Cc: Yury Norov <yury.norov@gmail.com>,
	Alexey Klimov <alexey.klimov@linaro.org>,
	Bart Van Assche <bvanassche@acm.org>, Jan Kara <jack@suse.cz>,
	Linus Torvalds <torvalds@linux-foundation.org>,
	Matthew Wilcox <willy@infradead.org>,
	Mirsad Todorovac <mirsad.todorovac@alu.unizg.hr>,
	Rasmus Villemoes <linux@rasmusvillemoes.dk>,
	Sergey Shtylyov <s.shtylyov@omp.ru>
Subject: [PATCH v4 36/40] scsi: sr: drop locking around SR index bitmap
Date: Thu, 20 Jun 2024 10:56:59 -0700	[thread overview]
Message-ID: <20240620175703.605111-37-yury.norov@gmail.com> (raw)
In-Reply-To: <20240620175703.605111-1-yury.norov@gmail.com>

The driver accesses the sr_index_bits bitmaps to set/clear individual
bits only. Now that we have an atomic bit search helper, we can drop
the sr_index_lock that protects the sr_index_bits, and make all this
routine lockless.

While there, use DECLARE_BITMAP() to declare sr_index_bits.

Signed-off-by: Yury Norov <yury.norov@gmail.com>
---
 drivers/scsi/sr.c | 15 +++------------
 1 file changed, 3 insertions(+), 12 deletions(-)

diff --git a/drivers/scsi/sr.c b/drivers/scsi/sr.c
index 7ab000942b97..3b4e04ed8b4a 100644
--- a/drivers/scsi/sr.c
+++ b/drivers/scsi/sr.c
@@ -33,6 +33,7 @@
  *	check resource allocation in sr_init and some cleanups
  */
 
+#include <linux/find_atomic.h>
 #include <linux/module.h>
 #include <linux/fs.h>
 #include <linux/kernel.h>
@@ -103,8 +104,7 @@ static struct scsi_driver sr_template = {
 	.done			= sr_done,
 };
 
-static unsigned long sr_index_bits[SR_DISKS / BITS_PER_LONG];
-static DEFINE_SPINLOCK(sr_index_lock);
+static DECLARE_BITMAP(sr_index_bits, SR_DISKS);
 
 static struct lock_class_key sr_bio_compl_lkclass;
 
@@ -566,10 +566,7 @@ static void sr_free_disk(struct gendisk *disk)
 {
 	struct scsi_cd *cd = disk->private_data;
 
-	spin_lock(&sr_index_lock);
 	clear_bit(MINOR(disk_devt(disk)), sr_index_bits);
-	spin_unlock(&sr_index_lock);
-
 	unregister_cdrom(&cd->cdi);
 	mutex_destroy(&cd->lock);
 	kfree(cd);
@@ -628,15 +625,11 @@ static int sr_probe(struct device *dev)
 		goto fail_free;
 	mutex_init(&cd->lock);
 
-	spin_lock(&sr_index_lock);
-	minor = find_first_zero_bit(sr_index_bits, SR_DISKS);
+	minor = find_and_set_bit(sr_index_bits, SR_DISKS);
 	if (minor == SR_DISKS) {
-		spin_unlock(&sr_index_lock);
 		error = -EBUSY;
 		goto fail_put;
 	}
-	__set_bit(minor, sr_index_bits);
-	spin_unlock(&sr_index_lock);
 
 	disk->major = SCSI_CDROM_MAJOR;
 	disk->first_minor = minor;
@@ -700,9 +693,7 @@ static int sr_probe(struct device *dev)
 unregister_cdrom:
 	unregister_cdrom(&cd->cdi);
 fail_minor:
-	spin_lock(&sr_index_lock);
 	clear_bit(minor, sr_index_bits);
-	spin_unlock(&sr_index_lock);
 fail_put:
 	put_disk(disk);
 	mutex_destroy(&cd->lock);
-- 
2.43.0


  parent reply	other threads:[~2024-06-20 17:58 UTC|newest]

Thread overview: 12+ 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 15/40] scsi: core: optimize scsi_evt_emit() by using an atomic iterator Yury Norov
2024-06-20 17:56 ` [PATCH v4 16/40] scsi: mpi3mr: optimize the driver by using find_and_set_bit() Yury Norov
2024-06-20 17:56 ` [PATCH v4 17/40] scsi: qedi: optimize qedi_get_task_idx() " Yury Norov
2024-06-20 17:56 ` 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-37-yury.norov@gmail.com \
    --to=yury.norov@gmail.com \
    --cc=James.Bottomley@HansenPartnership.com \
    --cc=alexey.klimov@linaro.org \
    --cc=bvanassche@acm.org \
    --cc=jack@suse.cz \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-scsi@vger.kernel.org \
    --cc=linux@rasmusvillemoes.dk \
    --cc=martin.petersen@oracle.com \
    --cc=mirsad.todorovac@alu.unizg.hr \
    --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