Skip to content

Commit

Permalink
mtip32xx: avoid using semaphores
Browse files Browse the repository at this point in the history
The "cmd_slot_unal" semaphore is never used in a blocking way
but only as an atomic counter. Change the code to using
atomic_dec_if_positive() as a better API.

Signed-off-by: Arnd Bergmann <arnd@arndb.de>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
  • Loading branch information
Arnd Bergmann authored and Jens Axboe committed Dec 10, 2018
1 parent 6f75723 commit e4025e4
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
6 changes: 3 additions & 3 deletions drivers/block/mtip32xx/mtip32xx.c
Original file line number Diff line number Diff line change
Expand Up @@ -2680,7 +2680,7 @@ static void mtip_softirq_done_fn(struct request *rq)
cmd->direction);

if (unlikely(cmd->unaligned))
up(&dd->port->cmd_slot_unal);
atomic_inc(&dd->port->cmd_slot_unal);

blk_mq_end_request(rq, cmd->status);
}
Expand Down Expand Up @@ -2990,7 +2990,7 @@ static int mtip_hw_init(struct driver_data *dd)
else
dd->unal_qdepth = 0;

sema_init(&dd->port->cmd_slot_unal, dd->unal_qdepth);
atomic_set(&dd->port->cmd_slot_unal, dd->unal_qdepth);

/* Spinlock to prevent concurrent issue */
for (i = 0; i < MTIP_MAX_SLOT_GROUPS; i++)
Expand Down Expand Up @@ -3533,7 +3533,7 @@ static bool mtip_check_unal_depth(struct blk_mq_hw_ctx *hctx,
cmd->unaligned = 1;
}

if (cmd->unaligned && down_trylock(&dd->port->cmd_slot_unal))
if (cmd->unaligned && atomic_dec_if_positive(&dd->port->cmd_slot_unal) >= 0)
return true;

return false;
Expand Down
4 changes: 2 additions & 2 deletions drivers/block/mtip32xx/mtip32xx.h
Original file line number Diff line number Diff line change
Expand Up @@ -433,8 +433,8 @@ struct mtip_port {
*/
unsigned long ic_pause_timer;

/* Semaphore to control queue depth of unaligned IOs */
struct semaphore cmd_slot_unal;
/* Counter to control queue depth of unaligned IOs */
atomic_t cmd_slot_unal;

/* Spinlock for working around command-issue bug. */
spinlock_t cmd_issue_lock[MTIP_MAX_SLOT_GROUPS];
Expand Down

0 comments on commit e4025e4

Please sign in to comment.