2023-11-18 15:53:44

by Yury Norov

[permalink] [raw]
Subject: [PATCH 15/34] scsi: use atomic find_bit() API where appropriate

SCSI code opencodes atomic bit allocation/traversing generic routines.
Switch it to use dedicated functions.

Signed-off-by: Yury Norov <[email protected]>
---
drivers/scsi/mpi3mr/mpi3mr_os.c | 21 ++++++---------------
drivers/scsi/qedi/qedi_main.c | 9 +--------
drivers/scsi/scsi_lib.c | 5 ++---
3 files changed, 9 insertions(+), 26 deletions(-)

diff --git a/drivers/scsi/mpi3mr/mpi3mr_os.c b/drivers/scsi/mpi3mr/mpi3mr_os.c
index 040031eb0c12..11139a2008fd 100644
--- a/drivers/scsi/mpi3mr/mpi3mr_os.c
+++ b/drivers/scsi/mpi3mr/mpi3mr_os.c
@@ -2276,13 +2276,9 @@ static void mpi3mr_dev_rmhs_send_tm(struct mpi3mr_ioc *mrioc, u16 handle,
if (drv_cmd)
goto issue_cmd;
do {
- cmd_idx = find_first_zero_bit(mrioc->devrem_bitmap,
- MPI3MR_NUM_DEVRMCMD);
- if (cmd_idx < MPI3MR_NUM_DEVRMCMD) {
- if (!test_and_set_bit(cmd_idx, mrioc->devrem_bitmap))
- break;
- cmd_idx = MPI3MR_NUM_DEVRMCMD;
- }
+ cmd_idx = find_and_set_bit(mrioc->devrem_bitmap, MPI3MR_NUM_DEVRMCMD);
+ if (cmd_idx < MPI3MR_NUM_DEVRMCMD)
+ break;
} while (retrycount--);

if (cmd_idx >= MPI3MR_NUM_DEVRMCMD) {
@@ -2417,14 +2413,9 @@ static void mpi3mr_send_event_ack(struct mpi3mr_ioc *mrioc, u8 event,
"sending event ack in the top half for event(0x%02x), event_ctx(0x%08x)\n",
event, event_ctx);
do {
- cmd_idx = find_first_zero_bit(mrioc->evtack_cmds_bitmap,
- MPI3MR_NUM_EVTACKCMD);
- if (cmd_idx < MPI3MR_NUM_EVTACKCMD) {
- if (!test_and_set_bit(cmd_idx,
- mrioc->evtack_cmds_bitmap))
- break;
- cmd_idx = MPI3MR_NUM_EVTACKCMD;
- }
+ cmd_idx = find_and_set_bit(mrioc->evtack_cmds_bitmap, MPI3MR_NUM_EVTACKCMD);
+ if (cmd_idx < MPI3MR_NUM_EVTACKCMD)
+ break;
} while (retrycount--);

if (cmd_idx >= MPI3MR_NUM_EVTACKCMD) {
diff --git a/drivers/scsi/qedi/qedi_main.c b/drivers/scsi/qedi/qedi_main.c
index cd0180b1f5b9..2f940c6898ef 100644
--- a/drivers/scsi/qedi/qedi_main.c
+++ b/drivers/scsi/qedi/qedi_main.c
@@ -1824,20 +1824,13 @@ int qedi_get_task_idx(struct qedi_ctx *qedi)
{
s16 tmp_idx;

-again:
- tmp_idx = find_first_zero_bit(qedi->task_idx_map,
- MAX_ISCSI_TASK_ENTRIES);
+ tmp_idx = find_and_set_bit(qedi->task_idx_map, MAX_ISCSI_TASK_ENTRIES);

if (tmp_idx >= MAX_ISCSI_TASK_ENTRIES) {
QEDI_ERR(&qedi->dbg_ctx, "FW task context pool is full.\n");
tmp_idx = -1;
- goto err_idx;
}

- if (test_and_set_bit(tmp_idx, qedi->task_idx_map))
- goto again;
-
-err_idx:
return tmp_idx;
}

diff --git a/drivers/scsi/scsi_lib.c b/drivers/scsi/scsi_lib.c
index cf3864f72093..4460a37f4864 100644
--- a/drivers/scsi/scsi_lib.c
+++ b/drivers/scsi/scsi_lib.c
@@ -2499,9 +2499,8 @@ void scsi_evt_thread(struct work_struct *work)

sdev = container_of(work, struct scsi_device, event_work);

- for (evt_type = SDEV_EVT_FIRST; evt_type <= SDEV_EVT_LAST; evt_type++)
- if (test_and_clear_bit(evt_type, sdev->pending_events))
- sdev_evt_send_simple(sdev, evt_type, GFP_KERNEL);
+ for_each_test_and_clear_bit(evt_type, sdev->pending_events, SDEV_EVT_LAST)
+ sdev_evt_send_simple(sdev, evt_type, GFP_KERNEL);

while (1) {
struct scsi_event *evt;
--
2.39.2


2023-11-18 16:31:07

by Bart Van Assche

[permalink] [raw]
Subject: Re: [PATCH 15/34] scsi: use atomic find_bit() API where appropriate

On 11/18/23 07:50, Yury Norov wrote:
> drivers/scsi/mpi3mr/mpi3mr_os.c | 21 ++++++---------------
> drivers/scsi/qedi/qedi_main.c | 9 +--------
> drivers/scsi/scsi_lib.c | 5 ++---
> 3 files changed, 9 insertions(+), 26 deletions(-)

One patch for each of the above source files please. mpi3mr and qedi are
both SCSI drivers. scsi_lib.c is a source file from the SCSI core.

> diff --git a/drivers/scsi/scsi_lib.c b/drivers/scsi/scsi_lib.c
> index cf3864f72093..4460a37f4864 100644
> --- a/drivers/scsi/scsi_lib.c
> +++ b/drivers/scsi/scsi_lib.c
> @@ -2499,9 +2499,8 @@ void scsi_evt_thread(struct work_struct *work)
>
> sdev = container_of(work, struct scsi_device, event_work);
>
> - for (evt_type = SDEV_EVT_FIRST; evt_type <= SDEV_EVT_LAST; evt_type++)
> - if (test_and_clear_bit(evt_type, sdev->pending_events))
> - sdev_evt_send_simple(sdev, evt_type, GFP_KERNEL);
> + for_each_test_and_clear_bit(evt_type, sdev->pending_events, SDEV_EVT_LAST)
> + sdev_evt_send_simple(sdev, evt_type, GFP_KERNEL);

Hmm ... the original code iterates over the range 1 .. SDEV_EVT_LAST
while the new code iterates over the range 0 .. SDEV_EVT_LAST - 1.
Please fix this.

Thanks,

Bart.