[PATCH 04/13] scsi: get rid of lock in __scsi_put_command()

From: Jens Axboe
Date: Mon May 25 2009 - 03:32:29 EST


A memory barrier is enough to check for the list being empty
or not, then we only have to grab the lock if we stole the
reserved command (which is very unlikely).

Signed-off-by: Jens Axboe <jens.axboe@xxxxxxxxxx>
---
drivers/scsi/scsi.c | 10 +++++-----
1 files changed, 5 insertions(+), 5 deletions(-)

diff --git a/drivers/scsi/scsi.c b/drivers/scsi/scsi.c
index 6a993af..da33b7a 100644
--- a/drivers/scsi/scsi.c
+++ b/drivers/scsi/scsi.c
@@ -293,15 +293,15 @@ EXPORT_SYMBOL(scsi_get_command);
void __scsi_put_command(struct Scsi_Host *shost, struct scsi_cmnd *cmd,
struct device *dev)
{
- unsigned long flags;
-
- /* changing locks here, don't need to restore the irq state */
- spin_lock_irqsave(&shost->free_list_lock, flags);
+ smp_mb();
if (unlikely(list_empty(&shost->free_list))) {
+ unsigned long flags;
+
+ spin_lock_irqsave(&shost->free_list_lock, flags);
list_add(&cmd->list, &shost->free_list);
+ spin_unlock_irqrestore(&shost->free_list_lock, flags);
cmd = NULL;
}
- spin_unlock_irqrestore(&shost->free_list_lock, flags);

if (likely(cmd != NULL))
scsi_pool_free_command(shost->cmd_pool, cmd);
--
1.6.3.rc0.1.gf800

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/