Commit 4c413128 authored by Stephen M. Cameron's avatar Stephen M. Cameron Committed by Christoph Hellwig

hpsa: remove spin lock around command allocation

It is already using atomic test_and_set_bit to do the
allocation.

There is some microscopic chance of starvation, but it is
so microscopic that it should never happen in reality.
Signed-off-by: default avatarDon Brace <don.brace@pmcs.com>
Reviewed-by: default avatarWebb Scales <webbnh@hp.com>
Signed-off-by: default avatarChristoph Hellwig <hch@lst.de>
parent 4fa604e1
...@@ -4607,19 +4607,32 @@ static struct CommandList *cmd_alloc(struct ctlr_info *h) ...@@ -4607,19 +4607,32 @@ static struct CommandList *cmd_alloc(struct ctlr_info *h)
int i; int i;
union u64bit temp64; union u64bit temp64;
dma_addr_t cmd_dma_handle, err_dma_handle; dma_addr_t cmd_dma_handle, err_dma_handle;
unsigned long flags; int loopcount;
/* There is some *extremely* small but non-zero chance that that
* multiple threads could get in here, and one thread could
* be scanning through the list of bits looking for a free
* one, but the free ones are always behind him, and other
* threads sneak in behind him and eat them before he can
* get to them, so that while there is always a free one, a
* very unlucky thread might be starved anyway, never able to
* beat the other threads. In reality, this happens so
* infrequently as to be indistinguishable from never.
*/
spin_lock_irqsave(&h->lock, flags); loopcount = 0;
do { do {
i = find_first_zero_bit(h->cmd_pool_bits, h->nr_cmds); i = find_first_zero_bit(h->cmd_pool_bits, h->nr_cmds);
if (i == h->nr_cmds) { if (i == h->nr_cmds)
spin_unlock_irqrestore(&h->lock, flags); i = 0;
loopcount++;
} while (test_and_set_bit(i & (BITS_PER_LONG - 1),
h->cmd_pool_bits + (i / BITS_PER_LONG)) != 0 &&
loopcount < 10);
/* Thread got starved? We do not expect this to ever happen. */
if (loopcount >= 10)
return NULL; return NULL;
}
} while (test_and_set_bit
(i & (BITS_PER_LONG - 1),
h->cmd_pool_bits + (i / BITS_PER_LONG)) != 0);
spin_unlock_irqrestore(&h->lock, flags);
c = h->cmd_pool + i; c = h->cmd_pool + i;
memset(c, 0, sizeof(*c)); memset(c, 0, sizeof(*c));
...@@ -4679,13 +4692,10 @@ static struct CommandList *cmd_special_alloc(struct ctlr_info *h) ...@@ -4679,13 +4692,10 @@ static struct CommandList *cmd_special_alloc(struct ctlr_info *h)
static void cmd_free(struct ctlr_info *h, struct CommandList *c) static void cmd_free(struct ctlr_info *h, struct CommandList *c)
{ {
int i; int i;
unsigned long flags;
i = c - h->cmd_pool; i = c - h->cmd_pool;
spin_lock_irqsave(&h->lock, flags);
clear_bit(i & (BITS_PER_LONG - 1), clear_bit(i & (BITS_PER_LONG - 1),
h->cmd_pool_bits + (i / BITS_PER_LONG)); h->cmd_pool_bits + (i / BITS_PER_LONG));
spin_unlock_irqrestore(&h->lock, flags);
} }
static void cmd_special_free(struct ctlr_info *h, struct CommandList *c) static void cmd_special_free(struct ctlr_info *h, struct CommandList *c)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment