* [PATCH] mlx4: use bitmap library
@ 2010-08-21 9:24 Akinobu Mita
2010-08-23 3:52 ` David Miller
0 siblings, 1 reply; 4+ messages in thread
From: Akinobu Mita @ 2010-08-21 9:24 UTC (permalink / raw)
To: netdev; +Cc: Akinobu Mita, Roland Dreier, David S. Miller
Use bitmap_set() and bitmap_clear()
Signed-off-by: Akinobu Mita <akinobu.mita@gmail.com>
Cc: Roland Dreier <rolandd@cisco.com>
Cc: netdev@vger.kernel.org
Cc: "David S. Miller" <davem@davemloft.net>
---
drivers/net/mlx4/alloc.c | 15 ++++-----------
1 files changed, 4 insertions(+), 11 deletions(-)
diff --git a/drivers/net/mlx4/alloc.c b/drivers/net/mlx4/alloc.c
index 8c85156..76595bd 100644
--- a/drivers/net/mlx4/alloc.c
+++ b/drivers/net/mlx4/alloc.c
@@ -74,7 +74,7 @@ void mlx4_bitmap_free(struct mlx4_bitmap *bitmap, u32 obj)
u32 mlx4_bitmap_alloc_range(struct mlx4_bitmap *bitmap, int cnt, int align)
{
- u32 obj, i;
+ u32 obj;
if (likely(cnt == 1 && align == 1))
return mlx4_bitmap_alloc(bitmap);
@@ -91,8 +91,7 @@ u32 mlx4_bitmap_alloc_range(struct mlx4_bitmap *bitmap, int cnt, int align)
}
if (obj < bitmap->max) {
- for (i = 0; i < cnt; i++)
- set_bit(obj + i, bitmap->table);
+ bitmap_set(bitmap->table, obj, cnt);
if (obj == bitmap->last) {
bitmap->last = (obj + cnt);
if (bitmap->last >= bitmap->max)
@@ -109,13 +108,10 @@ u32 mlx4_bitmap_alloc_range(struct mlx4_bitmap *bitmap, int cnt, int align)
void mlx4_bitmap_free_range(struct mlx4_bitmap *bitmap, u32 obj, int cnt)
{
- u32 i;
-
obj &= bitmap->max + bitmap->reserved_top - 1;
spin_lock(&bitmap->lock);
- for (i = 0; i < cnt; i++)
- clear_bit(obj + i, bitmap->table);
+ bitmap_clear(bitmap->table, obj, cnt);
bitmap->last = min(bitmap->last, obj);
bitmap->top = (bitmap->top + bitmap->max + bitmap->reserved_top)
& bitmap->mask;
@@ -125,8 +121,6 @@ void mlx4_bitmap_free_range(struct mlx4_bitmap *bitmap, u32 obj, int cnt)
int mlx4_bitmap_init(struct mlx4_bitmap *bitmap, u32 num, u32 mask,
u32 reserved_bot, u32 reserved_top)
{
- int i;
-
/* num must be a power of 2 */
if (num != roundup_pow_of_two(num))
return -EINVAL;
@@ -142,8 +136,7 @@ int mlx4_bitmap_init(struct mlx4_bitmap *bitmap, u32 num, u32 mask,
if (!bitmap->table)
return -ENOMEM;
- for (i = 0; i < reserved_bot; ++i)
- set_bit(i, bitmap->table);
+ bitmap_set(bitmap->table, 0, reserved_bot);
return 0;
}
--
1.6.0.6
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH] mlx4: use bitmap library
2010-08-21 9:24 [PATCH] mlx4: use bitmap library Akinobu Mita
@ 2010-08-23 3:52 ` David Miller
2010-08-23 4:21 ` Akinobu Mita
0 siblings, 1 reply; 4+ messages in thread
From: David Miller @ 2010-08-23 3:52 UTC (permalink / raw)
To: akinobu.mita; +Cc: netdev, rolandd
From: Akinobu Mita <akinobu.mita@gmail.com>
Date: Sat, 21 Aug 2010 18:24:48 +0900
> Use bitmap_set() and bitmap_clear()
>
> Signed-off-by: Akinobu Mita <akinobu.mita@gmail.com>
Unlike loops calling set_bit() and clear_bit(), bitmap_set() and
bitmap_clear() are not atomic.
Are you sure this is ok here?
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] mlx4: use bitmap library
2010-08-23 3:52 ` David Miller
@ 2010-08-23 4:21 ` Akinobu Mita
2010-08-23 4:26 ` David Miller
0 siblings, 1 reply; 4+ messages in thread
From: Akinobu Mita @ 2010-08-23 4:21 UTC (permalink / raw)
To: David Miller; +Cc: netdev, rolandd
2010/8/23 David Miller <davem@davemloft.net>:
> From: Akinobu Mita <akinobu.mita@gmail.com>
> Date: Sat, 21 Aug 2010 18:24:48 +0900
>
>> Use bitmap_set() and bitmap_clear()
>>
>> Signed-off-by: Akinobu Mita <akinobu.mita@gmail.com>
>
> Unlike loops calling set_bit() and clear_bit(), bitmap_set() and
> bitmap_clear() are not atomic.
>
> Are you sure this is ok here?
>
I think this ok. Because the bitmap region is searched by
bitmap_find_next_zero_area() which cannot be atomic and
setting and clearing the bitmap region is protected by bitmap->lock
(except for initialization of the bitmap in mlx4_bitmap_init).
This change should be done when I submitted commit
43ff8b60853793fb0155b3e465739d2170c3aa2f ("mlx4: use
bitmap_find_next_zero_area")
at the same time.
I'll recheck this is ok and update the commit message for this change,
then resubmit the patch.
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2010-08-23 4:26 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-08-21 9:24 [PATCH] mlx4: use bitmap library Akinobu Mita
2010-08-23 3:52 ` David Miller
2010-08-23 4:21 ` Akinobu Mita
2010-08-23 4:26 ` David Miller
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).