summaryrefslogtreecommitdiffstats
path: root/src/svm/fifo_segment.c
diff options
context:
space:
mode:
authorFlorin Coras <fcoras@cisco.com>2020-12-09 12:51:13 -0800
committerDamjan Marion <dmarion@me.com>2020-12-26 16:58:10 +0000
commitaf588825ba4586fadbdb742953ca640e94cd59ef (patch)
treefc4e36bd9b9ef760247ec6e8ab41ba70f9e84152 /src/svm/fifo_segment.c
parent2c1084a69bccac812bf2d763b113d1e5b7f08686 (diff)
svm: change fifo pointers to offsets
Type: improvement Signed-off-by: Florin Coras <fcoras@cisco.com> Change-Id: I113a630d6db4741f54e508f7e0ed77be139df0e4
Diffstat (limited to 'src/svm/fifo_segment.c')
-rw-r--r--src/svm/fifo_segment.c73
1 files changed, 38 insertions, 35 deletions
diff --git a/src/svm/fifo_segment.c b/src/svm/fifo_segment.c
index 19fd0520666..008cca4f350 100644
--- a/src/svm/fifo_segment.c
+++ b/src/svm/fifo_segment.c
@@ -148,28 +148,30 @@ fss_chunk_fl_index_is_valid (fifo_segment_slice_t * fss, u32 fl_index)
}
static void
-fss_chunk_free_list_push (fifo_segment_slice_t * fss, u32 fl_index,
- svm_fifo_chunk_t * c)
+fss_chunk_free_list_push (fifo_segment_header_t *fsh,
+ fifo_segment_slice_t *fss, u32 fl_index,
+ svm_fifo_chunk_t *c)
{
fss_chunk_freelist_lock (fss);
c->next = fss->free_chunks[fl_index];
- fss->free_chunks[fl_index] = c;
+ fss->free_chunks[fl_index] = fs_chunk_sptr (fsh, c);
fss_chunk_freelist_unlock (fss);
}
static void
-fss_chunk_free_list_push_list (fifo_segment_slice_t * fss, u32 fl_index,
- svm_fifo_chunk_t * head,
- svm_fifo_chunk_t * tail)
+fss_chunk_free_list_push_list (fifo_segment_header_t *fsh,
+ fifo_segment_slice_t *fss, u32 fl_index,
+ svm_fifo_chunk_t *head, svm_fifo_chunk_t *tail)
{
fss_chunk_freelist_lock (fss);
tail->next = fss->free_chunks[fl_index];
- fss->free_chunks[fl_index] = head;
+ fss->free_chunks[fl_index] = fs_chunk_sptr (fsh, head);
fss_chunk_freelist_unlock (fss);
}
static svm_fifo_chunk_t *
-fss_chunk_free_list_pop (fifo_segment_slice_t * fss, u32 fl_index)
+fss_chunk_free_list_pop (fifo_segment_header_t *fsh, fifo_segment_slice_t *fss,
+ u32 fl_index)
{
svm_fifo_chunk_t *c;
@@ -183,7 +185,7 @@ fss_chunk_free_list_pop (fifo_segment_slice_t * fss, u32 fl_index)
return 0;
}
- c = fss->free_chunks[fl_index];
+ c = fs_chunk_ptr (fsh, fss->free_chunks[fl_index]);
fss->free_chunks[fl_index] = c->next;
fss_chunk_freelist_unlock (fss);
@@ -435,10 +437,10 @@ fs_try_alloc_multi_chunk (fifo_segment_header_t * fsh,
while (req_bytes)
{
- c = fss_chunk_free_list_pop (fss, fl_index);
+ c = fss_chunk_free_list_pop (fsh, fss, fl_index);
if (c)
{
- c->next = first;
+ c->next = fs_chunk_sptr (fsh, first);
first = c;
n_alloc += fl_size;
req_bytes -= clib_min (fl_size, req_bytes);
@@ -453,8 +455,8 @@ fs_try_alloc_multi_chunk (fifo_segment_header_t * fsh,
while (c)
{
fl_index = fs_freelist_for_size (c->length);
- next = c->next;
- fss_chunk_free_list_push (fss, fl_index, c);
+ next = fs_chunk_ptr (fsh, c->next);
+ fss_chunk_free_list_push (fsh, fss, fl_index, c);
c = next;
}
n_alloc = 0;
@@ -464,7 +466,7 @@ fs_try_alloc_multi_chunk (fifo_segment_header_t * fsh,
fl_index = fs_freelist_for_size (data_bytes) + 1;
if (!fss_chunk_fl_index_is_valid (fss, fl_index))
return 0;
- first = fss_chunk_free_list_pop (fss, fl_index);
+ first = fss_chunk_free_list_pop (fsh, fss, fl_index);
if (first)
{
first->next = 0;
@@ -541,13 +543,13 @@ fsh_try_alloc_chunk_batch (fifo_segment_header_t * fsh,
{
c->start_byte = 0;
c->length = rounded_data_size;
- c->next = head;
+ c->next = fs_chunk_sptr (fsh, head);
head = c;
cmem += sizeof (*c) + rounded_data_size;
c = (svm_fifo_chunk_t *) cmem;
}
- fss_chunk_free_list_push_list (fss, fl_index, head, tail);
+ fss_chunk_free_list_push_list (fsh, fss, fl_index, head, tail);
fss->num_chunks[fl_index] += batch_size;
fss_fl_chunk_bytes_add (fss, total_chunk_bytes);
fsh_cached_bytes_add (fsh, total_chunk_bytes);
@@ -593,7 +595,7 @@ fsh_try_alloc_chunk (fifo_segment_header_t * fsh,
fl_index = fs_freelist_for_size (data_bytes);
free_list:
- c = fss_chunk_free_list_pop (fss, fl_index);
+ c = fss_chunk_free_list_pop (fsh, fss, fl_index);
if (c)
{
c->next = 0;
@@ -678,10 +680,10 @@ fs_try_alloc_fifo (fifo_segment_header_t *fsh, u32 slice_index, u32 data_bytes)
return 0;
}
- sf->start_chunk = c;
+ sf->start_chunk = fs_chunk_sptr (fsh, c);
while (c->next)
- c = c->next;
- sf->end_chunk = c;
+ c = fs_chunk_ptr (fsh, c->next);
+ sf->end_chunk = fs_chunk_sptr (fsh, c);
sf->size = data_bytes;
sf->slice_index = slice_index;
@@ -710,9 +712,9 @@ fsh_slice_collect_chunks (fifo_segment_header_t * fsh,
while (c)
{
CLIB_MEM_UNPOISON (c, sizeof (*c));
- next = c->next;
+ next = fs_chunk_ptr (fsh, c->next);
fl_index = fs_freelist_for_size (c->length);
- fss_chunk_free_list_push (fss, fl_index, c);
+ fss_chunk_free_list_push (fsh, fss, fl_index, c);
n_collect += fs_freelist_index_to_size (fl_index);
c = next;
}
@@ -842,7 +844,7 @@ fifo_segment_free_fifo (fifo_segment_t * fs, svm_fifo_t * f)
fss = fsh_slice_get (fsh, sf->slice_index);
/* Free fifo chunks */
- fsh_slice_collect_chunks (fsh, fss, sf->start_chunk);
+ fsh_slice_collect_chunks (fsh, fss, fs_chunk_ptr (fsh, f->shr->start_chunk));
sf->start_chunk = sf->end_chunk = 0;
sf->head_chunk = sf->tail_chunk = 0;
@@ -895,12 +897,12 @@ fifo_segment_detach_fifo (fifo_segment_t * fs, svm_fifo_t * f)
if (f->flags & SVM_FIFO_F_LL_TRACKED)
fss_fifo_del_active_list (fss, f);
- c = f->shr->start_chunk;
+ c = fs_chunk_ptr (fs->h, f->shr->start_chunk);
while (c)
{
fl_index = fs_freelist_for_size (c->length);
clib_atomic_fetch_sub_rel (&fss->num_chunks[fl_index], 1);
- c = c->next;
+ c = fs_chunk_ptr (fs->h, c->next);
}
}
@@ -918,12 +920,12 @@ fifo_segment_attach_fifo (fifo_segment_t * fs, svm_fifo_t * f,
if (f->flags & SVM_FIFO_F_LL_TRACKED)
fss_fifo_add_active_list (fss, f);
- c = f->shr->start_chunk;
+ c = fs_chunk_ptr (fs->h, f->shr->start_chunk);
while (c)
{
fl_index = fs_freelist_for_size (c->length);
clib_atomic_fetch_add_rel (&fss->num_chunks[fl_index], 1);
- c = c->next;
+ c = fs_chunk_ptr (fs->h, c->next);
}
}
@@ -1068,7 +1070,8 @@ fifo_segment_num_free_fifos (fifo_segment_t * fs)
}
static u32
-fs_slice_num_free_chunks (fifo_segment_slice_t * fss, u32 size)
+fs_slice_num_free_chunks (fifo_segment_header_t *fsh,
+ fifo_segment_slice_t *fss, u32 size)
{
u32 count = 0, rounded_size, fl_index;
svm_fifo_chunk_t *c;
@@ -1079,13 +1082,13 @@ fs_slice_num_free_chunks (fifo_segment_slice_t * fss, u32 size)
{
for (i = 0; i < FS_CHUNK_VEC_LEN; i++)
{
- c = fss->free_chunks[i];
+ c = fs_chunk_ptr (fsh, fss->free_chunks[i]);
if (c == 0)
continue;
while (c)
{
- c = c->next;
+ c = fs_chunk_ptr (fsh, c->next);
count++;
}
}
@@ -1098,13 +1101,13 @@ fs_slice_num_free_chunks (fifo_segment_slice_t * fss, u32 size)
if (fl_index >= FS_CHUNK_VEC_LEN)
return 0;
- c = fss->free_chunks[fl_index];
+ c = fs_chunk_ptr (fsh, fss->free_chunks[fl_index]);
if (c == 0)
return 0;
while (c)
{
- c = c->next;
+ c = fs_chunk_ptr (fsh, c->next);
count++;
}
return count;
@@ -1121,7 +1124,7 @@ fifo_segment_num_free_chunks (fifo_segment_t * fs, u32 size)
for (slice_index = 0; slice_index < fs->n_slices; slice_index++)
{
fss = fsh_slice_get (fsh, slice_index);
- count += fs_slice_num_free_chunks (fss, size);
+ count += fs_slice_num_free_chunks (fsh, fss, size);
}
return count;
}
@@ -1328,13 +1331,13 @@ format_fifo_segment (u8 * s, va_list * args)
fss = fsh_slice_get (fsh, slice_index);
for (i = 0; i < FS_CHUNK_VEC_LEN; i++)
{
- c = fss->free_chunks[i];
+ c = fs_chunk_ptr (fsh, fss->free_chunks[i]);
if (c == 0 && fss->num_chunks[i] == 0)
continue;
count = 0;
while (c)
{
- c = c->next;
+ c = fs_chunk_ptr (fsh, c->next);
count++;
}