From 9d17b551a228da78290ad46c5e5b7601b8780985 Mon Sep 17 00:00:00 2001 From: Florin Coras Date: Wed, 18 Dec 2024 23:20:14 -0800 Subject: [PATCH] svm: improve ooo try collect Use modular arithmetic just like the other ooo functions. Type: improvement Signed-off-by: Florin Coras Change-Id: Ie39bb928634fe0956339feafb41667ec9cafeee2 --- src/svm/svm_fifo.c | 17 +++++------------ 1 file changed, 5 insertions(+), 12 deletions(-) diff --git a/src/svm/svm_fifo.c b/src/svm/svm_fifo.c index 6107ea1a5c8..d5c1ae657d9 100644 --- a/src/svm/svm_fifo.c +++ b/src/svm/svm_fifo.c @@ -309,27 +309,21 @@ check_tail: static int ooo_segment_try_collect (svm_fifo_t * f, u32 n_bytes_enqueued, u32 * tail) { - u32 s_index, bytes = 0; + u32 s_index, s_end, bytes = 0; ooo_segment_t *s; - i32 diff; s = pool_elt_at_index (f->ooo_segments, f->ooos_list_head); - diff = *tail - s->start; - - ASSERT (diff != n_bytes_enqueued); - - if (diff > n_bytes_enqueued) - return 0; /* If last tail update overlaps one/multiple ooo segments, remove them */ - while (0 <= diff && diff < n_bytes_enqueued) + while (f_pos_leq (s->start, *tail)) { s_index = s - f->ooo_segments; + s_end = ooo_segment_end_pos (s); /* Segment end is beyond the tail. Advance tail and remove segment */ - if (s->length > diff) + if (f_pos_leq (*tail, s_end)) { - bytes = s->length - diff; + bytes = s_end - *tail; *tail = *tail + bytes; ooo_segment_free (f, s_index); break; @@ -339,7 +333,6 @@ ooo_segment_try_collect (svm_fifo_t * f, u32 n_bytes_enqueued, u32 * tail) if (s->next != OOO_SEGMENT_INVALID_INDEX) { s = pool_elt_at_index (f->ooo_segments, s->next); - diff = *tail - s->start; ooo_segment_free (f, s_index); } /* End of search */ -- 2.16.6