aboutsummaryrefslogtreecommitdiffstats
path: root/extras/libmemif/src
diff options
context:
space:
mode:
authormbly <mbly@ciena.com>2023-12-05 09:36:49 -0800
committerDave Wallace <dwallacelf@gmail.com>2024-01-12 03:22:06 +0000
commita90877982011966740ddba106ef7bd624ecea6c1 (patch)
tree82c976553aab49d5930f913a129bab81355b0189 /extras/libmemif/src
parent985334219458c57b569fdbafcfc6b0d117cc48cf (diff)
libmemif: Fix for memif_buffer_alloc rewind logic
Rewind logic was not supporting count = 1, where size was > memif_buffer_size and a rewind is required. Fixed slot-->next_buf bug for !master as well. Type: fix Change-Id: I65cf0d3d0c105f37125412a613e5ff8c5da9a3a2 Signed-off-by: mbly <mbly@ciena.com>
Diffstat (limited to 'extras/libmemif/src')
-rw-r--r--extras/libmemif/src/main.c31
1 files changed, 13 insertions, 18 deletions
diff --git a/extras/libmemif/src/main.c b/extras/libmemif/src/main.c
index e87d4c58859..cb07bf6eb2f 100644
--- a/extras/libmemif/src/main.c
+++ b/extras/libmemif/src/main.c
@@ -1550,9 +1550,8 @@ memif_buffer_alloc (memif_conn_handle_t conn, uint16_t qid,
uint16_t ns;
int err = MEMIF_ERR_SUCCESS; /* 0 */
uint16_t dst_left, src_left;
- uint16_t saved_count;
+ uint16_t saved_count_out, delta_count;
uint16_t saved_next_buf;
- uint16_t slot;
memif_buffer_t *saved_b;
*count_out = 0;
@@ -1568,7 +1567,7 @@ memif_buffer_alloc (memif_conn_handle_t conn, uint16_t qid,
b0 = (bufs + *count_out);
saved_b = b0;
- saved_count = count;
+ saved_count_out = *count_out;
saved_next_buf = mq->next_buf;
b0->desc_index = mq->next_buf;
@@ -1584,12 +1583,8 @@ memif_buffer_alloc (memif_conn_handle_t conn, uint16_t qid,
{
if (EXPECT_FALSE (dst_left == 0))
{
- if (count && ns)
+ if (ns)
{
- *count_out += 1;
- mq->next_buf++;
- ns--;
-
ring->desc[b0->desc_index & mask].flags |=
MEMIF_DESC_FLAG_NEXT;
b0->flags |= MEMIF_BUFFER_FLAG_NEXT;
@@ -1600,13 +1595,14 @@ memif_buffer_alloc (memif_conn_handle_t conn, uint16_t qid,
ring->desc[mq->next_buf & mask].length :
c->run_args.buffer_size;
ring->desc[mq->next_buf & mask].flags = 0;
+ b0->flags = 0;
}
else
{
/* rollback allocated chain buffers */
- memset (saved_b, 0, sizeof (memif_buffer_t)
- * (saved_count - count + 1));
- *count_out -= saved_count - count;
+ delta_count = *count_out - saved_count_out;
+ memset (saved_b, 0, sizeof (memif_buffer_t) * delta_count);
+ *count_out -= delta_count;
mq->next_buf = saved_next_buf;
goto no_ns;
}
@@ -1616,7 +1612,7 @@ memif_buffer_alloc (memif_conn_handle_t conn, uint16_t qid,
/* slave resets buffer offset */
if (c->args.is_master == 0)
{
- memif_desc_t *d = &ring->desc[slot & mask];
+ memif_desc_t *d = &ring->desc[mq->next_buf & mask];
if (ms->get_external_buffer_offset)
d->offset = ms->get_external_buffer_offset (c->private_ctx);
else
@@ -1626,18 +1622,17 @@ memif_buffer_alloc (memif_conn_handle_t conn, uint16_t qid,
src_left -= b0->len;
dst_left -= b0->len;
+ *count_out += 1;
+ mq->next_buf++;
+ ns--;
}
-
- *count_out += 1;
- mq->next_buf++;
- ns--;
count--;
}
no_ns:
- DBG ("allocated: %u/%u bufs. Next buffer pointer %d", *count_out, count,
- mq->next_buf);
+ DBG ("allocated: %u/%u bufs, size: %u. Next buffer pointer %d", *count_out,
+ count, size, mq->next_buf);
if (count)
{