Tune pool_get / pool_put
Stop spending cycles repeatedly tail-trimming the pool free element bitmap; possibly at the expense of slightly hurting pool_foreach peformance. Change-Id: I8a7f3e7b26c71d7496ba9393b2a167dc7f538355 Signed-off-by: Dave Barach <dave@barachs.net>
This commit is contained in:

committed by
Damjan Marion

parent
6e74aa2b98
commit
0654dcc7b9
@ -201,8 +201,8 @@ do { \
|
||||
/* Return free element from free list. */ \
|
||||
uword _pool_var (i) = _pool_var (p)->free_indices[_pool_var (l) - 1]; \
|
||||
(E) = (P) + _pool_var (i); \
|
||||
_pool_var (p)->free_bitmap = \
|
||||
clib_bitmap_andnoti (_pool_var (p)->free_bitmap, _pool_var (i)); \
|
||||
clib_bitmap_set_no_check (_pool_var (p)->free_bitmap, \
|
||||
_pool_var (i), 0); \
|
||||
_vec_len (_pool_var (p)->free_indices) = _pool_var (l) - 1; \
|
||||
} \
|
||||
else \
|
||||
@ -220,7 +220,8 @@ do { \
|
||||
pool_aligned_header_bytes, \
|
||||
/* align */ (A)); \
|
||||
E = vec_end (P) - 1; \
|
||||
} \
|
||||
pool_validate_index (P, vec_len(P)-1); \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
/** Allocate an object E from a pool P (unspecified alignment). */
|
||||
@ -263,7 +264,7 @@ do { \
|
||||
({ \
|
||||
pool_header_t * _pool_var (p) = pool_header (P); \
|
||||
uword _pool_var (i) = (E) - (P); \
|
||||
(_pool_var (i) < vec_len (P)) ? clib_bitmap_get (_pool_var (p)->free_bitmap, _pool_i) : 1; \
|
||||
(_pool_var (i) < vec_len (P)) ? clib_bitmap_get_no_check (_pool_var (p)->free_bitmap, _pool_i) : 1; \
|
||||
})
|
||||
|
||||
/** Use free bitmap to query whether given index is free */
|
||||
@ -278,8 +279,9 @@ do { \
|
||||
ASSERT (! pool_is_free (P, E)); \
|
||||
\
|
||||
/* Add element to free bitmap and to free list. */ \
|
||||
_pool_var (p)->free_bitmap = \
|
||||
clib_bitmap_ori (_pool_var (p)->free_bitmap, _pool_var (l)); \
|
||||
clib_bitmap_set_no_check (_pool_var (p)->free_bitmap, \
|
||||
_pool_var (l), 1); \
|
||||
\
|
||||
/* Preallocated pool? */ \
|
||||
if (_pool_var (p)->max_elts) \
|
||||
{ \
|
||||
|
@ -28,17 +28,45 @@ main (int argc, char *argv[])
|
||||
{
|
||||
int i;
|
||||
uword next;
|
||||
u32 last_len = 0;
|
||||
u32 *tp = 0;
|
||||
u32 *junk;
|
||||
|
||||
for (i = 0; i < 70; i++)
|
||||
pool_get (tp, junk);
|
||||
{
|
||||
pool_get (tp, junk);
|
||||
if (vec_len (tp) > last_len)
|
||||
{
|
||||
last_len = vec_len (tp);
|
||||
fformat (stdout, "vec_len (tp) now %d\n", last_len);
|
||||
}
|
||||
}
|
||||
|
||||
(void) junk; /* compiler warning */
|
||||
|
||||
pool_put_index (tp, 1);
|
||||
pool_put_index (tp, 65);
|
||||
|
||||
for (i = 0; i < 70; i++)
|
||||
{
|
||||
int is_free;
|
||||
|
||||
is_free = pool_is_free_index (tp, i);
|
||||
|
||||
if (is_free == 0)
|
||||
{
|
||||
if (i == 1 || i == 65)
|
||||
clib_warning ("oops, free index %d reported busy", i);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (i != 1 && i != 65)
|
||||
clib_warning ("oops, busy index %d reported free", i);
|
||||
}
|
||||
}
|
||||
|
||||
fformat (stdout, "vec_len (tp) is %d\n", vec_len (tp));
|
||||
|
||||
next = ~0;
|
||||
do
|
||||
{
|
||||
@ -47,6 +75,25 @@ main (int argc, char *argv[])
|
||||
}
|
||||
while (next != ~0);
|
||||
|
||||
/* *INDENT-OFF* */
|
||||
pool_foreach (junk, tp,
|
||||
({
|
||||
int is_free;
|
||||
|
||||
is_free = pool_is_free_index (tp, junk - tp);
|
||||
if (is_free == 0)
|
||||
{
|
||||
if (i == 1 || i == 65)
|
||||
clib_warning ("oops, free index %d reported busy", i);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (i != 1 && i != 65)
|
||||
clib_warning ("oops, busy index %d reported free", i);
|
||||
}
|
||||
}));
|
||||
/* *INDENT-ON* */
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user