mlx4_core: maintain available field in bitmap allocator
Add mlx4_bitmap_avail() to give the number of available resources. We want to use this as a hint to whether to allocate a resources or not. This patch is introduced to be used with allocation blue flame registers. Signed-off-by: Eli Cohen <eli@mellanox.co.il> Signed-off-by: David S. Miller <davem@davemloft.net>
This commit is contained in:
parent
c1b43dca13
commit
42d1e017e2
2 changed files with 15 additions and 0 deletions
|
@ -62,6 +62,9 @@ u32 mlx4_bitmap_alloc(struct mlx4_bitmap *bitmap)
|
||||||
} else
|
} else
|
||||||
obj = -1;
|
obj = -1;
|
||||||
|
|
||||||
|
if (obj != -1)
|
||||||
|
--bitmap->avail;
|
||||||
|
|
||||||
spin_unlock(&bitmap->lock);
|
spin_unlock(&bitmap->lock);
|
||||||
|
|
||||||
return obj;
|
return obj;
|
||||||
|
@ -101,11 +104,19 @@ u32 mlx4_bitmap_alloc_range(struct mlx4_bitmap *bitmap, int cnt, int align)
|
||||||
} else
|
} else
|
||||||
obj = -1;
|
obj = -1;
|
||||||
|
|
||||||
|
if (obj != -1)
|
||||||
|
bitmap->avail -= cnt;
|
||||||
|
|
||||||
spin_unlock(&bitmap->lock);
|
spin_unlock(&bitmap->lock);
|
||||||
|
|
||||||
return obj;
|
return obj;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
u32 mlx4_bitmap_avail(struct mlx4_bitmap *bitmap)
|
||||||
|
{
|
||||||
|
return bitmap->avail;
|
||||||
|
}
|
||||||
|
|
||||||
void mlx4_bitmap_free_range(struct mlx4_bitmap *bitmap, u32 obj, int cnt)
|
void mlx4_bitmap_free_range(struct mlx4_bitmap *bitmap, u32 obj, int cnt)
|
||||||
{
|
{
|
||||||
obj &= bitmap->max + bitmap->reserved_top - 1;
|
obj &= bitmap->max + bitmap->reserved_top - 1;
|
||||||
|
@ -115,6 +126,7 @@ void mlx4_bitmap_free_range(struct mlx4_bitmap *bitmap, u32 obj, int cnt)
|
||||||
bitmap->last = min(bitmap->last, obj);
|
bitmap->last = min(bitmap->last, obj);
|
||||||
bitmap->top = (bitmap->top + bitmap->max + bitmap->reserved_top)
|
bitmap->top = (bitmap->top + bitmap->max + bitmap->reserved_top)
|
||||||
& bitmap->mask;
|
& bitmap->mask;
|
||||||
|
bitmap->avail += cnt;
|
||||||
spin_unlock(&bitmap->lock);
|
spin_unlock(&bitmap->lock);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -130,6 +142,7 @@ int mlx4_bitmap_init(struct mlx4_bitmap *bitmap, u32 num, u32 mask,
|
||||||
bitmap->max = num - reserved_top;
|
bitmap->max = num - reserved_top;
|
||||||
bitmap->mask = mask;
|
bitmap->mask = mask;
|
||||||
bitmap->reserved_top = reserved_top;
|
bitmap->reserved_top = reserved_top;
|
||||||
|
bitmap->avail = num - reserved_top - reserved_bot;
|
||||||
spin_lock_init(&bitmap->lock);
|
spin_lock_init(&bitmap->lock);
|
||||||
bitmap->table = kzalloc(BITS_TO_LONGS(bitmap->max) *
|
bitmap->table = kzalloc(BITS_TO_LONGS(bitmap->max) *
|
||||||
sizeof (long), GFP_KERNEL);
|
sizeof (long), GFP_KERNEL);
|
||||||
|
|
|
@ -105,6 +105,7 @@ struct mlx4_bitmap {
|
||||||
u32 max;
|
u32 max;
|
||||||
u32 reserved_top;
|
u32 reserved_top;
|
||||||
u32 mask;
|
u32 mask;
|
||||||
|
u32 avail;
|
||||||
spinlock_t lock;
|
spinlock_t lock;
|
||||||
unsigned long *table;
|
unsigned long *table;
|
||||||
};
|
};
|
||||||
|
@ -371,6 +372,7 @@ u32 mlx4_bitmap_alloc(struct mlx4_bitmap *bitmap);
|
||||||
void mlx4_bitmap_free(struct mlx4_bitmap *bitmap, u32 obj);
|
void mlx4_bitmap_free(struct mlx4_bitmap *bitmap, u32 obj);
|
||||||
u32 mlx4_bitmap_alloc_range(struct mlx4_bitmap *bitmap, int cnt, int align);
|
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);
|
void mlx4_bitmap_free_range(struct mlx4_bitmap *bitmap, u32 obj, int cnt);
|
||||||
|
u32 mlx4_bitmap_avail(struct mlx4_bitmap *bitmap);
|
||||||
int mlx4_bitmap_init(struct mlx4_bitmap *bitmap, u32 num, u32 mask,
|
int mlx4_bitmap_init(struct mlx4_bitmap *bitmap, u32 num, u32 mask,
|
||||||
u32 reserved_bot, u32 resetrved_top);
|
u32 reserved_bot, u32 resetrved_top);
|
||||||
void mlx4_bitmap_cleanup(struct mlx4_bitmap *bitmap);
|
void mlx4_bitmap_cleanup(struct mlx4_bitmap *bitmap);
|
||||||
|
|
Loading…
Reference in a new issue