diff options
author | mbly <mbly@ciena.com> | 2023-12-06 12:22:14 -0800 |
---|---|---|
committer | Dave Wallace <dwallacelf@gmail.com> | 2024-01-12 03:22:30 +0000 |
commit | 00e9fe6ca771bfbe7ee62e80a44903ffb227cae2 (patch) | |
tree | 7e831e35240435a058a431d175ece17306339b5e | |
parent | a90877982011966740ddba106ef7bd624ecea6c1 (diff) |
libmemif: fix for memif_init_queues slot math
Increase slot variable to u32 to address combinations of num-queues and queue-size that cause slot variable to wrap when declared as u16, e.g. num-queues > 8 && queue-size is 2^12
Type: fix
Change-Id: I5bd6198d60395156a06f1a280ea2594824ceaa9d
Signed-off-by: mbly <mbly@ciena.com>
-rw-r--r-- | extras/libmemif/src/main.c | 14 |
1 files changed, 9 insertions, 5 deletions
diff --git a/extras/libmemif/src/main.c b/extras/libmemif/src/main.c index cb07bf6eb2f..6f9ba2fe229 100644 --- a/extras/libmemif/src/main.c +++ b/extras/libmemif/src/main.c @@ -1258,6 +1258,7 @@ memif_init_queues (memif_connection_t *conn) int i, j; memif_ring_t *ring; memif_socket_t *ms = (memif_socket_t *) conn->args.socket; + uint32_t ring_size = 1 << conn->run_args.log2_ring_size; for (i = 0; i < conn->run_args.num_s2m_rings; i++) { @@ -1266,9 +1267,11 @@ memif_init_queues (memif_connection_t *conn) ring->head = ring->tail = 0; ring->cookie = MEMIF_COOKIE; ring->flags = 0; - for (j = 0; j < (1 << conn->run_args.log2_ring_size); j++) + uint32_t base = i; + uint32_t ring_offset = base * ring_size; + for (j = 0; j < ring_size; j++) { - uint16_t slot = i * (1 << conn->run_args.log2_ring_size) + j; + uint32_t slot = ring_offset + j; ring->desc[j].region = 1; ring->desc[j].offset = conn->regions[1].buffer_offset + @@ -1283,10 +1286,11 @@ memif_init_queues (memif_connection_t *conn) ring->head = ring->tail = 0; ring->cookie = MEMIF_COOKIE; ring->flags = 0; - for (j = 0; j < (1 << conn->run_args.log2_ring_size); j++) + uint32_t base = conn->run_args.num_s2m_rings + i; + uint32_t ring_offset = base * ring_size; + for (j = 0; j < ring_size; j++) { - uint16_t slot = (i + conn->run_args.num_s2m_rings) * - (1 << conn->run_args.log2_ring_size) + j; + uint32_t slot = ring_offset + j; ring->desc[j].region = 1; ring->desc[j].offset = conn->regions[1].buffer_offset + |